cm-unit-popup.vue 13 KB

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