cm-unit-popup.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  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" 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. this.addParams.productCount = this.productCount
  297. this.handleAddClubCart(this.addParams)
  298. }
  299. },
  300. handleToConfirm(data) {
  301. //跳转确认订单页面
  302. this.$api.navigateTo(`/pages/user/order/create-order?type=1&data=${JSON.stringify({ data: data })}`)
  303. this.hidePopup()
  304. },
  305. handleAddClubCart(params) {
  306. //增加购物车成功和toast弹窗提示成功
  307. this.ProductService.shoppingAddCart(params)
  308. .then(response => {
  309. this.$util.msg('加入购物车成功', 1500, true, 'success')
  310. this.$parent.GetUserCartNumber()
  311. this.hidePopup()
  312. })
  313. .catch(error => {
  314. console.log('error', error.msg)
  315. })
  316. },
  317. handleChoisSku(sku, index) {
  318. // 选择SKU
  319. this.skuIndex = index
  320. this.addParams.productCount = this.handleMinNumber = sku.minBuyNumber
  321. this.addParams.skuId = sku.skuId
  322. this.handleStock = sku.stock
  323. this.isBtnDisabled = sku.stock === 0
  324. this.$emit('skuClick', sku)
  325. },
  326. hidePopup() {
  327. this.$parent.popupShow1 = false
  328. }
  329. }
  330. }
  331. </script>
  332. <style lang="scss">
  333. .tui-popup-box {
  334. padding: 40rpx 24rpx 0 24rpx;
  335. }
  336. .tui-shopping-main {
  337. width: 100%;
  338. .tui-sku-title {
  339. width: 100%;
  340. height: 136rpx;
  341. float: left;
  342. margin-bottom: 30rpx;
  343. .tui-sku-image {
  344. width: 138rpx;
  345. height: 138rpx;
  346. float: left;
  347. border-radius: 8rpx;
  348. margin-right: 30rpx;
  349. box-sizing: border-box;
  350. border: 1px dashed #e1e1e1;
  351. image {
  352. width: 134rpx;
  353. height: 134rpx;
  354. border-radius: 10rpx;
  355. }
  356. }
  357. .tui-sku-price {
  358. height: 136rpx;
  359. float: left;
  360. .sku-price-viw {
  361. width: 100%;
  362. height: 40rpx;
  363. margin-bottom: 24rpx;
  364. .sku-price-text {
  365. font-size: 28rpx;
  366. line-height: 40rpx;
  367. color: #f94b4b;
  368. font-weight: bold;
  369. .sku-price-l {
  370. float: left;
  371. font-weight: normal;
  372. }
  373. &.none {
  374. text-decoration: line-through;
  375. color: #999999;
  376. font-weight: normal;
  377. }
  378. }
  379. }
  380. .sku-price-vip {
  381. width: 100%;
  382. height: 40rpx;
  383. }
  384. }
  385. }
  386. .tui-sku-unit {
  387. width: 100%;
  388. height: auto;
  389. float: left;
  390. .sku-unit-h1 {
  391. font-size: 28rpx;
  392. line-height: 40rpx;
  393. color: #333333;
  394. font-weight: bold;
  395. }
  396. .sku-unit-li {
  397. width: 100%;
  398. height: auto;
  399. .unit-li {
  400. padding: 0 24rpx;
  401. line-height: 48rpx;
  402. text-align: center;
  403. font-size: 24rpx;
  404. color: #666666;
  405. background: #f5f5f5;
  406. float: left;
  407. margin-right: 16rpx;
  408. margin-top: 12rpx;
  409. margin-bottom: 12rpx;
  410. border-radius: 24rpx;
  411. position: relative;
  412. box-sizing: border-box;
  413. border: 1px solid #f5f5f5;
  414. &.active {
  415. border-color: $color-system;
  416. background: #fff1eb;
  417. color: $color-system;
  418. .tips {
  419. background: #FF5B00;
  420. }
  421. }
  422. .tips {
  423. padding: 0 10rpx;
  424. line-height: 32rpx;
  425. text-align: center;
  426. font-size: 22rpx;
  427. color: #ffffff;
  428. background: #cccccc;
  429. float: left;
  430. border-radius: 16rpx;
  431. position: absolute;
  432. right: -12rpx;
  433. top: -15rpx;
  434. }
  435. }
  436. }
  437. }
  438. .sku-unit-nunbox {
  439. justify-content: space-between;
  440. align-items: center;
  441. width: 100%;
  442. height: auto;
  443. float: left;
  444. margin-top: 30rpx;
  445. .sku-unit-nunbox-t {
  446. width: 100%;
  447. height: 44rpx;
  448. position: relative;
  449. margin-bottom: 20rpx;
  450. .text {
  451. font-size: $font-size-24;
  452. line-height: 48rpx;
  453. color: #999999;
  454. }
  455. .sku-unit-nunbox-text {
  456. line-height: 44rpx;
  457. font-size: $font-size-28;
  458. float: left;
  459. font-weight: bold;
  460. }
  461. .sku-unit-nunbox-num {
  462. float: right;
  463. .number-box {
  464. display: flex;
  465. justify-content: center;
  466. align-items: center;
  467. border: 2rpx solid #ffe6dc;
  468. border-radius: 30rpx;
  469. height: 48rpx;
  470. margin-left: 20rpx;
  471. .iconfont {
  472. font-size: $font-size-24;
  473. padding: 0 18rpx;
  474. color: #999999;
  475. text-align: center;
  476. line-height: 48rpx;
  477. font-weight: bold;
  478. background: #fef6f3;
  479. &.icon-jianhao {
  480. border-radius: 30rpx 0 0 30rpx;
  481. &.disabled {
  482. background: #f5f5f5;
  483. }
  484. }
  485. &.icon-jiahao {
  486. border-radius: 0 30rpx 30rpx 0;
  487. &.disabled {
  488. background: #f5f5f5;
  489. }
  490. }
  491. }
  492. .btn-input {
  493. width: 62rpx;
  494. height: 48rpx;
  495. line-height: 48rpx;
  496. background: #ffffff;
  497. border-radius: 4rpx;
  498. text-align: center;
  499. font-size: $font-size-28;
  500. }
  501. }
  502. }
  503. }
  504. }
  505. }
  506. .tui-popup-btn {
  507. width: 100%;
  508. float: left;
  509. .tui-modal-flex {
  510. width: 100%;
  511. height: 84rpx;
  512. margin-top: 40rpx;
  513. display: flex;
  514. .tui-modal-button {
  515. flex: 1;
  516. line-height: 84rpx;
  517. font-size: $font-size-28;
  518. text-align: center;
  519. border-radius: 42rpx;
  520. padding: 0;
  521. margin: 0 15rpx;
  522. box-sizing: border-box;
  523. &.cancel {
  524. background: #ffe6dc;
  525. color: #FF5B00;
  526. &.disabled {
  527. background-color: #e1e1e1;
  528. color: #ffffff;
  529. }
  530. }
  531. &.confirm {
  532. background: $btn-confirm;
  533. color: #ffffff;
  534. &.disabled {
  535. background: linear-gradient(135deg, rgba(242, 143, 49, 0.5) 0%, rgba(225, 86, 22, 0.5) 100%);
  536. }
  537. }
  538. }
  539. }
  540. }
  541. </style>