cm-unit-popup.vue 12 KB

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