cm-unit-popup.vue 13 KB

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