cm-unit-popup.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  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-t" 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{
  234. if (this.skuProduct.step == 2) {
  235. if (_value % this.handleMinNumber != 0) {
  236. this.$util.msg('购买量必须为起订量的整数倍', 2000)
  237. this.productCount = this.handleMinNumber
  238. } else if (_value > this.handleStock) {
  239. this.productCount = this.handleStock
  240. } else {
  241. this.productCount = _value
  242. }
  243. }else{
  244. if (_value > this.handleStock) {
  245. this.productCount = this.handleStock
  246. } else {
  247. this.productCount = _value
  248. }
  249. }
  250. }
  251. this.totalLadderPrice()
  252. },
  253. totalLadderPrice() {
  254. //单独处理活动价格和阶梯价格
  255. if(this.ladderPriceList.length>0){
  256. this.ladderPriceList.forEach((ladder, index) => {
  257. if (this.productCount >= ladder.buyNum) {
  258. this.skuProduct.price = ladder.buyPrice
  259. }
  260. })
  261. }
  262. },
  263. handleBuyConfirm() {
  264. if (this.skuProduct.step == 2) {
  265. if (this.productCount % this.handleMinNumber != 0) {
  266. this.$util.msg('购买量必须为起订量的整数倍', 2000)
  267. this.productCount = this.handleMinNumber
  268. return
  269. }
  270. }else{
  271. this.addParams.productCount = this.productCount
  272. this.handleAddClubCart(this.addParams)
  273. }
  274. },
  275. handleAddClubCart(params) {
  276. //增加购物车成功和toast弹窗提示成功
  277. this.SellerService.ShoppingCartAddCart(params)
  278. .then(response => {
  279. this.$parent.popupShow = false
  280. this.$util.msg('加入购物车成功', 1500, true, 'success')
  281. this.$parent.getClubProductNum()
  282. this.$emit('handleFuction')
  283. })
  284. .catch(error => {
  285. this.$util.msg(error.msg, 2000)
  286. })
  287. },
  288. handleChoisSku(sku, index) {
  289. // 选择SKU
  290. this.skuIndex = index
  291. this.productCount = this.addParams.productCount = this.handleMinNumber = sku.minBuyNumber
  292. this.addParams.skuId = sku.skuId
  293. this.handleStock = sku.stock
  294. this.skuProduct.price = sku.price
  295. this.skuProduct.originalPrice = sku.originalPrice
  296. this.isBtnDisabled = sku.stock === 0
  297. if(sku.ladderPriceList.length>0){
  298. this.ladderPriceList = sku.ladderPriceList
  299. }
  300. this.$emit('skuClick', sku)
  301. },
  302. hidePopup() {
  303. this.$parent.popupShow = false
  304. }
  305. }
  306. }
  307. </script>
  308. <style lang="scss">
  309. .tui-popup-box {
  310. padding: 40rpx 24rpx 0 24rpx;
  311. }
  312. .tui-shopping-main {
  313. width: 100%;
  314. .tui-sku-title {
  315. width: 100%;
  316. height: 136rpx;
  317. float: left;
  318. margin-bottom: 30rpx;
  319. .tui-sku-image {
  320. width: 138rpx;
  321. height: 138rpx;
  322. float: left;
  323. border-radius: 8rpx;
  324. margin-right: 30rpx;
  325. box-sizing: border-box;
  326. border: 1px dashed #e1e1e1;
  327. image {
  328. width: 134rpx;
  329. height: 134rpx;
  330. border-radius: 10rpx;
  331. }
  332. }
  333. .tui-sku-price {
  334. height: 136rpx;
  335. float: left;
  336. .sku-price-viw {
  337. width: 100%;
  338. height: 40rpx;
  339. margin-bottom: 24rpx;
  340. .sku-price-text {
  341. font-size: 28rpx;
  342. line-height: 40rpx;
  343. color: #f94b4b;
  344. font-weight: bold;
  345. .sku-price-l {
  346. float: left;
  347. font-weight: normal;
  348. }
  349. &.none {
  350. text-decoration: line-through;
  351. color: #999999;
  352. font-weight: normal;
  353. }
  354. }
  355. }
  356. .sku-price-vip {
  357. width: 100%;
  358. height: 40rpx;
  359. }
  360. }
  361. }
  362. .tui-sku-unit {
  363. width: 100%;
  364. height: auto;
  365. float: left;
  366. .sku-unit-h1 {
  367. font-size: 28rpx;
  368. line-height: 40rpx;
  369. color: #333333;
  370. font-weight: bold;
  371. }
  372. .sku-unit-li {
  373. width: 100%;
  374. height: auto;
  375. .unit-li {
  376. padding: 0 24rpx;
  377. line-height: 48rpx;
  378. text-align: center;
  379. font-size: 24rpx;
  380. color: #666666;
  381. background: #f5f5f5;
  382. float: left;
  383. margin-right: 16rpx;
  384. margin-top: 12rpx;
  385. margin-bottom: 12rpx;
  386. border-radius: 24rpx;
  387. position: relative;
  388. box-sizing: border-box;
  389. border: 1px solid #f5f5f5;
  390. &.active {
  391. border-color: $color-system;
  392. background: #fff1eb;
  393. color: $color-system;
  394. .tips {
  395. background: #FF5B00;
  396. }
  397. }
  398. .tips {
  399. padding: 0 10rpx;
  400. line-height: 32rpx;
  401. text-align: center;
  402. font-size: 22rpx;
  403. color: #ffffff;
  404. background: #cccccc;
  405. float: left;
  406. border-radius: 16rpx;
  407. position: absolute;
  408. right: -12rpx;
  409. top: -15rpx;
  410. }
  411. }
  412. }
  413. }
  414. .sku-unit-nunbox {
  415. justify-content: space-between;
  416. align-items: center;
  417. width: 100%;
  418. height: auto;
  419. float: left;
  420. margin-top: 30rpx;
  421. .sku-unit-nunbox-t {
  422. width: 100%;
  423. height: 44rpx;
  424. position: relative;
  425. margin-bottom: 20rpx;
  426. .text {
  427. font-size: $font-size-24;
  428. line-height: 48rpx;
  429. color: #FF5B00;
  430. }
  431. .sku-unit-nunbox-text {
  432. line-height: 44rpx;
  433. font-size: $font-size-28;
  434. float: left;
  435. font-weight: bold;
  436. }
  437. .sku-unit-nunbox-num {
  438. float: right;
  439. .number-box {
  440. display: flex;
  441. justify-content: center;
  442. align-items: center;
  443. border: 2rpx solid #ffe6dc;
  444. border-radius: 30rpx;
  445. height: 48rpx;
  446. margin-left: 20rpx;
  447. .iconfont {
  448. font-size: $font-size-24;
  449. padding: 0 18rpx;
  450. color: #999999;
  451. text-align: center;
  452. line-height: 48rpx;
  453. font-weight: bold;
  454. background: #fef6f3;
  455. &.icon-jianhao {
  456. border-radius: 30rpx 0 0 30rpx;
  457. }
  458. &.icon-jiahao {
  459. border-radius: 0 30rpx 30rpx 0;
  460. }
  461. }
  462. .btn-input {
  463. width: 62rpx;
  464. height: 48rpx;
  465. line-height: 48rpx;
  466. background: #ffffff;
  467. border-radius: 4rpx;
  468. text-align: center;
  469. font-size: $font-size-28;
  470. }
  471. }
  472. }
  473. }
  474. }
  475. }
  476. .tui-popup-btn {
  477. width: 100%;
  478. float: left;
  479. .tui-modal-flex {
  480. width: 100%;
  481. height: 84rpx;
  482. margin-top: 40rpx;
  483. display: flex;
  484. .tui-modal-button {
  485. flex: 1;
  486. line-height: 84rpx;
  487. font-size: $font-size-28;
  488. text-align: center;
  489. border-radius: 42rpx;
  490. padding: 0;
  491. margin: 0 15rpx;
  492. box-sizing: border-box;
  493. &.confirm {
  494. background: $btn-confirm;
  495. color: #ffffff;
  496. &.disabled {
  497. background: linear-gradient(135deg, rgba(242, 143, 49, 0.5) 0%, rgba(225, 86, 22, 0.5) 100%);
  498. }
  499. }
  500. }
  501. }
  502. }
  503. </style>