cm-unit-popup.vue 12 KB

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