cm-unit-popup.vue 12 KB

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