cm-unit-popup.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  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. @click="handleBuyConfirm"
  106. >
  107. 加入购物车
  108. </button>
  109. </view>
  110. </view>
  111. </view>
  112. </tui-bottom-popup>
  113. </template>
  114. <script>
  115. import { mapState, mapMutations } from 'vuex'
  116. export default {
  117. name: 'cm-unit-popup',
  118. props: {
  119. skuProduct: {
  120. type: Object
  121. },
  122. popupShow: {
  123. type: Boolean,
  124. default: false
  125. },
  126. type: {
  127. type: Number,
  128. default: 1
  129. }
  130. },
  131. data() {
  132. return {
  133. skuIndex: 0,
  134. userIdentity: 0,
  135. productCount: 0,
  136. buyRetailPriceStep: 1,
  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. }
  151. },
  152. filters: {
  153. NumFormat(value) {
  154. //处理金额
  155. return Number(value).toFixed(2)
  156. }
  157. },
  158. created() {
  159. this.initData()
  160. },
  161. computed: {
  162. ...mapState(['hasLogin'])
  163. },
  164. methods: {
  165. async initData(data) {
  166. const clubInfo = await this.$api.getComStorage('orderUserInfo')
  167. const userInfo = await this.$api.getStorage()
  168. this.userIdentity = userInfo.userIdentity
  169. this.skuList = this.skuProduct.skus
  170. this.isBtnDisabled = this.skuList[0].stock === 0
  171. this.addParams.clubId = clubInfo.clubId ? clubInfo.clubId : 0
  172. this.addParams.serviceProviderId = userInfo.serviceProviderId
  173. this.addParams.skuId = this.skuProduct.skuId
  174. this.productCount = this.skuProduct.minBuyNumber
  175. this.buyRetailPriceStep = this.skuProduct.step
  176. if (this.skuProduct.ladderPriceFlag == 1) {
  177. this.addParams.productCount = this.skuProduct.maxBuyNumber ? this.skuProduct.maxBuyNumber : 1
  178. } else {
  179. this.addParams.productCount = this.skuProduct.minBuyNumber
  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. },
  205. //popup弹窗数量减按钮
  206. changeCountSub() {
  207. if (this.productCount <= this.handleMinNumber) {
  208. this.productCount = this.handleMinNumber
  209. this.isQuantity = true
  210. this.$util.msg(`该商品最小起订量为${this.handleMinNumber}`, 2000)
  211. return
  212. } else {
  213. if (this.skuProduct.step == 2) {
  214. this.productCount -= this.handleMinNumber
  215. } else {
  216. this.productCount--
  217. }
  218. this.isQuantity = false
  219. }
  220. },
  221. changeNumber(e) {
  222. let _value = e.detail.value
  223. if (!this.$api.isNumber(_value)) {
  224. this.productCount = this.handleMinNumber
  225. } else if (_value < this.handleMinNumber) {
  226. this.$util.msg(`该商品最小起订量为${this.handleMinNumber}`, 2000)
  227. this.productCount = this.handleMinNumber
  228. } else if (_value % this.handleMinNumber != 0) {
  229. this.$util.msg('购买量必须为起订量的整数倍', 2000)
  230. this.productCount = this.handleMinNumber
  231. } else if (_value > this.handleStock) {
  232. this.productCount = this.handleStock
  233. } else {
  234. this.productCount = e.detail.value
  235. }
  236. },
  237. handleBuyConfirm() {
  238. this.addParams.productCount = this.productCount
  239. this.handleAddClubCart(this.addParams)
  240. },
  241. handleAddClubCart(params) {
  242. //增加购物车成功和toast弹窗提示成功
  243. this.SellerService.ShoppingCartAddCart(params)
  244. .then(response => {
  245. this.$parent.popupShow = false
  246. this.$util.msg('加入购物车成功', 1500, true, 'success')
  247. this.$parent.getClubProductNum()
  248. })
  249. .catch(error => {
  250. this.$util.msg(error.msg, 2000)
  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.popupShow = 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: #e15616;
  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 #ffe6dc;
  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: #999999;
  411. text-align: center;
  412. line-height: 48rpx;
  413. font-weight: bold;
  414. background: #fef6f3;
  415. &.icon-jianhao {
  416. border-radius: 30rpx 0 0 30rpx;
  417. }
  418. &.icon-jiahao {
  419. border-radius: 0 30rpx 30rpx 0;
  420. }
  421. }
  422. .btn-input {
  423. width: 62rpx;
  424. height: 48rpx;
  425. line-height: 48rpx;
  426. background: #ffffff;
  427. border-radius: 4rpx;
  428. text-align: center;
  429. font-size: $font-size-28;
  430. }
  431. }
  432. }
  433. }
  434. }
  435. }
  436. .tui-popup-btn {
  437. width: 100%;
  438. float: left;
  439. .tui-modal-flex {
  440. width: 100%;
  441. height: 84rpx;
  442. margin-top: 40rpx;
  443. display: flex;
  444. .tui-modal-button {
  445. flex: 1;
  446. line-height: 84rpx;
  447. font-size: $font-size-28;
  448. text-align: center;
  449. border-radius: 42rpx;
  450. padding: 0;
  451. margin: 0 15rpx;
  452. box-sizing: border-box;
  453. &.confirm {
  454. background: $btn-confirm;
  455. color: #ffffff;
  456. &.disabled {
  457. background: linear-gradient(135deg, rgba(242, 143, 49, 0.5) 0%, rgba(225, 86, 22, 0.5) 100%);
  458. }
  459. }
  460. }
  461. }
  462. }
  463. </style>