cm-unit-popup.vue 11 KB

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