cm-unit-popup.vue 11 KB

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