cm-unit-popup.vue 13 KB

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