cm-unit-popup.vue 14 KB

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