cm-unit-popup.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. <template name="cm-parameter">
  2. <!-- 相关规格 -->
  3. <tui-bottom-popup :radius="true" :show="popupShow" @close="hidePopup">
  4. <view class="tui-popup-box clearfix">
  5. <view class="tui-shopping-main" :style="{ paddingBottom: isIphoneX ? '68rpx' : '34rpx' }">
  6. <view class="tui-sku-title">
  7. <view class="tui-sku-image"> <image :src="skuProduct.image" mode=""></image> </view>
  8. <view class="tui-sku-price">
  9. <view class="sku-price-viw">
  10. <view
  11. class="sku-price-text">
  12. ¥{{skuProduct.price | NumFormat}}
  13. </view>
  14. </view>
  15. </view>
  16. </view>
  17. <view class="tui-sku-unit">
  18. <view class="sku-unit-h1">规格:</view>
  19. <view class="sku-unit-li">
  20. <view
  21. class="unit-li"
  22. v-for="(sku, index) in skuList"
  23. @click="handleChoisSku(sku, index)"
  24. :key="index"
  25. :class="skuIndex === index ? 'active' : ''"
  26. >
  27. {{ sku.unit }}
  28. </view>
  29. </view>
  30. </view>
  31. <view class="sku-unit-nunbox">
  32. <view class="sku-unit-nunbox-t">
  33. <view class="sku-unit-nunbox-text">购买数量:</view>
  34. <view class="sku-unit-nunbox-num">
  35. <view class="number-box">
  36. <view
  37. class="iconfont icon-jianhao"
  38. @click="changeCountSub"
  39. :class="[isQuantity ? 'disabled' : '']"
  40. ></view>
  41. <input
  42. class="btn-input"
  43. type="number"
  44. v-model="productCount"
  45. maxlength="4"
  46. @blur="changeNumber($event)"
  47. />
  48. <view
  49. class="iconfont icon-jiahao"
  50. @click="changeCountAdd"
  51. :class="[isStock == true ? 'disabled' : '']"
  52. ></view>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. <view class="tui-right-flex tui-popup-btn" :style="{ paddingBottom: isIphoneX ? '68rpx' : '34rpx' }">
  59. <view class="tui-modal-flex">
  60. <button
  61. class="tui-modal-button cancel"
  62. @click="handleBuyConfirm('add')"
  63. :disabled="isBtnDisabled"
  64. :class="[isBtnDisabled ? 'disabled' : '']"
  65. >
  66. 加入购物车
  67. </button>
  68. <button
  69. class="tui-modal-button confirm"
  70. @click="handleBuyConfirm('buy')"
  71. :disabled="isBtnDisabled"
  72. :class="[isBtnDisabled ? 'disabled' : '']"
  73. >
  74. 立即购买
  75. </button>
  76. </view>
  77. </view>
  78. </view>
  79. </tui-bottom-popup>
  80. </template>
  81. <script>
  82. import { mapState, mapMutations } from 'vuex'
  83. import uniGrader from '@/components/uni-grade/uni-grade.vue'
  84. export default {
  85. name: 'cm-unit-popup',
  86. components: {
  87. uniGrader
  88. },
  89. props: {
  90. skuProduct: {
  91. type: Object
  92. },
  93. popupShow: {
  94. type: Boolean,
  95. default: false
  96. },
  97. type: {
  98. type: Number,
  99. default: 1
  100. }
  101. },
  102. data() {
  103. return {
  104. vipFlag: 0, // 是否是超级会员 0否 1是
  105. skuIndex: 0,
  106. isStock: false, //
  107. isQuantity: false,
  108. handleStock: 0, // 规格库存
  109. handleMinNumber: 1, // 规格起订量
  110. productCount: 0,
  111. skuList: [],
  112. addParams: {
  113. skuId: 0,
  114. productCount: 0,
  115. productId: 0,
  116. userId: 0,
  117. source: 1
  118. },
  119. isBtnDisabled: false
  120. }
  121. },
  122. filters: {
  123. NumFormat(value) {
  124. //处理金额
  125. return Number(value).toFixed(2)
  126. }
  127. },
  128. created() {
  129. this.initData()
  130. },
  131. computed: {
  132. ...mapState(['hasLogin'])
  133. },
  134. methods: {
  135. async initData() {
  136. const userInfo = await this.$api.getStorage()
  137. this.vipFlag = userInfo.vipFlag ? userInfo.vipFlag : 0
  138. this.addParams.userId = userInfo.userId ? userInfo.userId : 0
  139. this.addParams.productId = this.skuProduct.productId
  140. this.skuList = this.skuProduct.skus
  141. this.productCount = this.skuList[0].minBuyNumber
  142. this.addParams.skuId = this.skuList[0].skuId
  143. this.handleMinNumber = this.skuList[0].minBuyNumber
  144. this.handleStock = this.skuList[0].stock
  145. //处理禁用按钮商品
  146. this.isBtnDisabled = this.isDisabledFlag(this.skuProduct)
  147. this.isBtnDisabled = this.skuList[0].stock === 0
  148. },
  149. isDisabledFlag(pros) {
  150. // 非会员
  151. if (!this.vipFlag === 1) return true
  152. // 商品已下架 || 库存为0
  153. if (pros.validFlag == 3 || pros.stock == 0) return true
  154. // 商品价格不公开
  155. if (pros.priceFlag === 1) return true
  156. // 商品价格仅资质机构可见 && 机构为普通机构
  157. if (pros.priceFlag === 2 && this.userIdentity === 4) return true
  158. // 商品价格仅医美机构可见 && 机构为普通机构
  159. if (pros.priceFlag === 3 && this.userIdentity === 4) return true
  160. // 商品价格仅医美机构可见 && 机构为资质机构 && 不是医美机构
  161. if (pros.priceFlag === 3 && this.userIdentity === 2 && this.firstClubType != 1) return true
  162. //其他
  163. return false
  164. },
  165. isShowVipFlag(pros) {
  166. // 未登录 || 非会员
  167. if (!this.hasLogin || !this.vipFlag === 1) return false
  168. // 商品所有机构可见
  169. if (pros.priceFlag === 0) return true
  170. // 商品价格仅资质机构可见
  171. if (pros.priceFlag === 2 && this.userIdentity === 2) return true
  172. // 商品价格仅医美机构可见
  173. if (pros.priceFlag === 3 && this.userIdentity === 2 && this.firstClubType == 1) return true
  174. // 其它
  175. return false
  176. },
  177. PromotionsFormat(promo) {
  178. //促销活动类型数据处理
  179. if (promo != null) {
  180. if (promo.type == 1 && promo.mode == 1) {
  181. return true
  182. } else {
  183. return false
  184. }
  185. }
  186. return false
  187. },
  188. //popup弹窗数量增加按钮
  189. changeCountAdd() {
  190. if (this.productCount === this.handleStock) {
  191. this.isStock = true
  192. return
  193. }
  194. this.productCount++
  195. },
  196. //popup弹窗数量减按钮
  197. changeCountSub() {
  198. if (this.productCount <= this.handleMinNumber) {
  199. this.productCount = this.handleMinNumber
  200. this.isQuantity = true
  201. return
  202. } else {
  203. this.productCount--
  204. this.isQuantity = false
  205. }
  206. },
  207. changeNumber(e) {
  208. let _value = e.detail.value
  209. if (!this.$api.isNumber(_value)) {
  210. this.productCount = this.handleMinNumber
  211. } else if (_value < this.handleMinNumber) {
  212. this.$util.msg(`该商品最小起订量为${this.handleMinNumber}`, 2000)
  213. this.productCount = this.handleMinNumber
  214. } else if (_value % this.handleMinNumber != 0) {
  215. this.$util.msg('购买量必须为起订量的整数倍', 2000)
  216. this.productCount = this.handleMinNumber
  217. } else if (_value > this.handleStock) {
  218. this.productCount = this.handleStock
  219. } else {
  220. this.productCount = e.detail.value
  221. }
  222. },
  223. handleBuyConfirm(type) {
  224. // 监听确定选择规格
  225. if (type == 'buy') {
  226. this.handleToConfirm({
  227. productIds: this.addParams.productId,
  228. skuId: this.addParams.skuId,
  229. productCount: this.productCount
  230. })
  231. } else {
  232. this.addParams.productCount = this.productCount
  233. this.handleAddClubCart(this.addParams)
  234. }
  235. },
  236. handleToConfirm(data) {
  237. //跳转确认订单页面
  238. this.$api.navigateTo(`/pages/user/order/create-order?type=1&data=${JSON.stringify({ data: data })}`)
  239. this.hidePopup()
  240. },
  241. handleAddClubCart(params) {
  242. //增加购物车成功和toast弹窗提示成功
  243. this.ProductService.shoppingAddCart(params)
  244. .then(response => {
  245. this.$util.msg('加入购物车成功', 1500, true, 'success')
  246. this.$parent.GetUserCartNumber()
  247. this.hidePopup()
  248. })
  249. .catch(error => {
  250. console.log('error', error.msg)
  251. })
  252. },
  253. handleChoisSku(sku, index) {
  254. // 选择SKU
  255. this.skuIndex = index
  256. this.addParams.productCount = this.handleMinNumber = sku.minBuyNumber
  257. this.addParams.skuId = sku.skuId
  258. this.handleStock = sku.stock
  259. this.isBtnDisabled = sku.stock === 0
  260. this.$emit('skuClick', sku)
  261. },
  262. hidePopup() {
  263. this.$parent.popupShow1 = false
  264. }
  265. }
  266. }
  267. </script>
  268. <style lang="scss">
  269. .tui-popup-box {
  270. padding: 40rpx 24rpx 0 24rpx;
  271. }
  272. .tui-shopping-main {
  273. width: 100%;
  274. .tui-sku-title {
  275. width: 100%;
  276. height: 136rpx;
  277. float: left;
  278. margin-bottom: 30rpx;
  279. .tui-sku-image {
  280. width: 138rpx;
  281. height: 138rpx;
  282. float: left;
  283. border-radius: 8rpx;
  284. margin-right: 30rpx;
  285. box-sizing: border-box;
  286. border: 1px dashed #e1e1e1;
  287. image {
  288. width: 134rpx;
  289. height: 134rpx;
  290. border-radius: 10rpx;
  291. }
  292. }
  293. .tui-sku-price {
  294. height: 136rpx;
  295. float: left;
  296. .sku-price-viw {
  297. width: 100%;
  298. height: 40rpx;
  299. margin-bottom: 24rpx;
  300. .sku-price-text {
  301. font-size: 28rpx;
  302. line-height: 40rpx;
  303. color: #f94b4b;
  304. font-weight: bold;
  305. .sku-price-l {
  306. float: left;
  307. font-weight: normal;
  308. }
  309. &.none {
  310. text-decoration: line-through;
  311. color: #999999;
  312. font-weight: normal;
  313. }
  314. }
  315. }
  316. .sku-price-vip {
  317. width: 100%;
  318. height: 40rpx;
  319. }
  320. }
  321. }
  322. .tui-sku-unit {
  323. width: 100%;
  324. height: auto;
  325. float: left;
  326. .sku-unit-h1 {
  327. font-size: 28rpx;
  328. line-height: 40rpx;
  329. color: #333333;
  330. font-weight: bold;
  331. }
  332. .sku-unit-li {
  333. width: 100%;
  334. height: auto;
  335. .unit-li {
  336. padding: 0 24rpx;
  337. line-height: 48rpx;
  338. text-align: center;
  339. font-size: 24rpx;
  340. color: #666666;
  341. background: #f5f5f5;
  342. float: left;
  343. margin-right: 16rpx;
  344. margin-top: 12rpx;
  345. margin-bottom: 12rpx;
  346. border-radius: 24rpx;
  347. position: relative;
  348. box-sizing: border-box;
  349. border: 1px solid #f5f5f5;
  350. &.active {
  351. border-color: $color-system;
  352. background: #fff1eb;
  353. color: $color-system;
  354. .tips {
  355. background: #F3B574;
  356. }
  357. }
  358. .tips {
  359. padding: 0 10rpx;
  360. line-height: 32rpx;
  361. text-align: center;
  362. font-size: 22rpx;
  363. color: #ffffff;
  364. background: #cccccc;
  365. float: left;
  366. border-radius: 16rpx;
  367. position: absolute;
  368. right: -12rpx;
  369. top: -15rpx;
  370. }
  371. }
  372. }
  373. }
  374. .sku-unit-nunbox {
  375. justify-content: space-between;
  376. align-items: center;
  377. width: 100%;
  378. height: auto;
  379. float: left;
  380. margin-top: 30rpx;
  381. .sku-unit-nunbox-t {
  382. width: 100%;
  383. height: 44rpx;
  384. position: relative;
  385. margin-bottom: 20rpx;
  386. .text {
  387. font-size: $font-size-24;
  388. line-height: 48rpx;
  389. color: #999999;
  390. }
  391. .sku-unit-nunbox-text {
  392. line-height: 44rpx;
  393. font-size: $font-size-28;
  394. float: left;
  395. font-weight: bold;
  396. }
  397. .sku-unit-nunbox-num {
  398. float: right;
  399. .number-box {
  400. display: flex;
  401. justify-content: center;
  402. align-items: center;
  403. border: 2rpx solid #D5D5D5;
  404. border-radius: 30rpx;
  405. height: 48rpx;
  406. margin-left: 20rpx;
  407. .iconfont {
  408. font-size: $font-size-24;
  409. padding: 0 18rpx;
  410. color: #333333;
  411. text-align: center;
  412. line-height: 48rpx;
  413. font-weight: bold;
  414. background: #F7F7F7;
  415. &.icon-jianhao {
  416. border-radius: 30rpx 0 0 30rpx;
  417. &.disabled {
  418. background: #f5f5f5;
  419. }
  420. }
  421. &.icon-jiahao {
  422. border-radius: 0 30rpx 30rpx 0;
  423. &.disabled {
  424. background: #f5f5f5;
  425. }
  426. }
  427. }
  428. .btn-input {
  429. width: 62rpx;
  430. height: 48rpx;
  431. line-height: 48rpx;
  432. background: #ffffff;
  433. border-radius: 4rpx;
  434. text-align: center;
  435. font-size: $font-size-28;
  436. }
  437. }
  438. }
  439. }
  440. }
  441. }
  442. .tui-popup-btn {
  443. width: 100%;
  444. float: left;
  445. .tui-modal-flex {
  446. width: 100%;
  447. height: 84rpx;
  448. margin-top: 40rpx;
  449. display: flex;
  450. .tui-modal-button {
  451. flex: 1;
  452. line-height: 84rpx;
  453. font-size: $font-size-28;
  454. text-align: center;
  455. border-radius: 42rpx;
  456. padding: 0;
  457. margin: 0 15rpx;
  458. box-sizing: border-box;
  459. &.cancel {
  460. background: #FFF4E6;
  461. color: #F3B574;
  462. &.disabled {
  463. background-color: #e1e1e1;
  464. color: #ffffff;
  465. }
  466. }
  467. &.confirm {
  468. background: $btn-confirm;
  469. color: #ffffff;
  470. &.disabled {
  471. background: rgba(243,181,116,0.5);
  472. }
  473. }
  474. }
  475. }
  476. }
  477. </style>