cm-unit-popup.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. <template name="cm-parameter">
  2. <!-- 相关规格 -->
  3. <view>
  4. <tui-bottom-popup :radius="true" :show="popupShow" @close="hidePopup">
  5. <view class="tui-popup-box clearfix">
  6. <view class="tui-shopping-main" :style="{ paddingBottom: isIphoneX ? '68rpx' : '34rpx' }">
  7. <view class="tui-sku-title">
  8. <view class="tui-sku-image"> <image :src="product.mainImage" mode=""></image> </view>
  9. <view class="tui-sku-price"> <cmUnitPrice :product="product"></cmUnitPrice> </view>
  10. </view>
  11. <view class="tui-sku-unit">
  12. <view class="sku-unit-h1">规格:</view>
  13. <view class="sku-unit-li">
  14. <view
  15. class="unit-li"
  16. v-for="(sku, index) in skuList"
  17. @click="handleChoisSku(sku, index)"
  18. :key="index"
  19. :class="skuIndex === index ? 'active' : ''"
  20. >
  21. {{ sku.unit }} <text class="tips">缺货</text>
  22. </view>
  23. </view>
  24. </view>
  25. <view class="sku-unit-nunbox">
  26. <view class="sku-unit-nunbox" v-if="product.step === 2">
  27. <view class="text">*该商品只能以起订量的整数倍购买</view>
  28. </view>
  29. <view class="sku-unit-nunbox-t">
  30. <view class="sku-unit-nunbox-text">购买数量:</view>
  31. <view class="sku-unit-nunbox-num">
  32. <view class="number-box">
  33. <view
  34. class="iconfont icon-jianhao"
  35. :class="[isQuantity == true ? 'disabled' : '']"
  36. @click="changeCountSub"
  37. ></view>
  38. <input
  39. class="btn-input"
  40. type="number"
  41. v-model="number"
  42. maxlength="4"
  43. @blur="changeNumber($event)"
  44. />
  45. <view
  46. class="iconfont icon-jiahao"
  47. :class="[isStock == true ? 'disabled' : '']"
  48. @click="changeCountAdd"
  49. ></view>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. <view class="sku-unit-ladel" v-if="isShowLadder" @click.stop="showLaddePopup"> 此规格商品存在阶梯价格,点击查看 >>> </view>
  55. </view>
  56. <view
  57. class="tui-right-flex tui-popup-btn"
  58. v-if="isShowButton"
  59. :style="{ paddingBottom: isIphoneX ? '68rpx' : '34rpx' }"
  60. >
  61. <view class="tui-flex-1" v-if="type === 1">
  62. <view class="tui-button" @click="btnConfirm">确定</view>
  63. </view>
  64. <view class="tui-modal-flex" v-else>
  65. <button
  66. class="tui-modal-button cancel"
  67. :disabled="goodsData.disabled"
  68. :class="[goodsData.disabled ? 'disabled' : '']"
  69. @click="handleConfirm('add')"
  70. >
  71. 加入购物车
  72. </button>
  73. <button
  74. class="tui-modal-button confirm"
  75. :disabled="goodsData.disabled"
  76. :class="[goodsData.disabled ? 'disabled' : '']"
  77. @click="handleConfirm('buy')"
  78. >
  79. 立即购买
  80. </button>
  81. </view>
  82. </view>
  83. </view>
  84. </tui-bottom-popup>
  85. <!-- 阶梯价弹窗 -->
  86. <cmLadderPopup v-if="laddePopupShow" :show="laddePopupShow" :list="ladderPriceList"></cmLadderPopup>
  87. </view>
  88. </template>
  89. <script>
  90. import { mapState, mapMutations } from 'vuex'
  91. import uniGrader from '@/components/uni-grade/uni-grade.vue'
  92. import cmUnitPrice from './cm-unit-price.vue'
  93. import cmLadderPopup from '@/components/cm-module/productDetails/cm-ladder-popup.vue'
  94. export default {
  95. name: 'cm-unit-popup',
  96. components: {
  97. uniGrader,
  98. cmUnitPrice,
  99. cmLadderPopup
  100. },
  101. props: {
  102. product: {
  103. type: Object
  104. },
  105. goodsData: {
  106. type: Object
  107. },
  108. popupShow: {
  109. type: Boolean,
  110. default: false
  111. },
  112. type: {
  113. type: Number,
  114. default: 1
  115. }
  116. },
  117. data() {
  118. return {
  119. skuIndex: 0,
  120. number: 0,
  121. buyRetailPrice: 0,
  122. ladderPriceList: [],
  123. isStock:false,//
  124. isQuantity: false,
  125. isShowButton: false,
  126. skuList: [
  127. {
  128. unit: '135ml70ml', // 规格
  129. normalPrice: 1000, // 市场价
  130. price: 500, // 售价
  131. costPrice: 500, // 结算价
  132. stock: 100 ,// 库存
  133. minBuyNumber:1,//起订量
  134. ladderPriceList:[
  135. {
  136. numRange:'1-10',
  137. buyPrice:500
  138. },
  139. {
  140. numRange:'10-100',
  141. buyPrice:5000
  142. },
  143. {
  144. numRange:'100-1000',
  145. buyPrice:50000
  146. },
  147. ]
  148. },
  149. {
  150. unit: ' 精华70ml', // 规格
  151. normalPrice: 1000, // 市场价
  152. price: 500, // 售价
  153. costPrice: 500, // 结算价
  154. stock: 100 ,// 库存
  155. minBuyNumber:1,//起订量
  156. ladderPriceList:null
  157. },
  158. {
  159. unit: '精华70ml', // 规格
  160. normalPrice: 1000, // 市场价
  161. price: 500, // 售价
  162. costPrice: 500, // 结算价
  163. stock: 100 ,// 库存
  164. minBuyNumber:1,//起订量
  165. ladderPriceList:null
  166. },
  167. {
  168. unit: '【70ml】2瓶', // 规格
  169. normalPrice: 1000, // 市场价
  170. price: 500, // 售价
  171. costPrice: 500, // 结算价
  172. stock: 100 ,// 库存
  173. minBuyNumber:1,//起订量
  174. ladderPriceList:[
  175. {
  176. numRange:'1-10',
  177. buyPrice:500
  178. },
  179. {
  180. numRange:'10-100',
  181. buyPrice:5000
  182. },
  183. {
  184. numRange:'100-1000',
  185. buyPrice:50000
  186. },
  187. ]
  188. },
  189. {
  190. unit: '【50ml】3瓶', // 规格
  191. normalPrice: 1000, // 市场价
  192. price: 500, // 售价
  193. costPrice: 500, // 结算价
  194. stock: 100 ,// 库存
  195. minBuyNumber:1,//起订量
  196. ladderPriceList:null
  197. },
  198. {
  199. unit: '【50ml】3瓶', // 规格
  200. normalPrice: 1000, // 市场价
  201. price: 500, // 售价
  202. costPrice: 500, // 结算价
  203. stock: 100 ,// 库存
  204. minBuyNumber:1,//起订量
  205. ladderPriceList:[
  206. {
  207. numRange:'1-10',
  208. buyPrice:500
  209. },
  210. {
  211. numRange:'10-100',
  212. buyPrice:5000
  213. },
  214. {
  215. numRange:'100-1000',
  216. buyPrice:50000
  217. },
  218. ]
  219. }
  220. ],
  221. handleStock:0,// 规格库存
  222. handleMinNumber:1, // 规格起订量
  223. isShowLadder:false,
  224. laddePopupShow:false,
  225. }
  226. },
  227. created() {
  228. console.log('product', this.product)
  229. this.number = this.skuList[0].minBuyNumber
  230. this.handleMinNumber = this.skuList[0].minBuyNumber
  231. this.handleStock = this.skuList[0].stock
  232. this.buyRetailPrice = this.product.price
  233. this.initData()
  234. },
  235. computed: {
  236. ...mapState(['hasLogin'])
  237. },
  238. methods: {
  239. async initData(data) {
  240. const userInfo = await this.$api.getStorage()
  241. if (userInfo.userIdentity == 0 || userInfo.userIdentity == 2 || userInfo.userIdentity == 4) {
  242. this.isShowButton = true
  243. } else {
  244. this.isShowButton = false
  245. }
  246. if(this.product.skuList[0].ladderPriceList){ this.isShowLadder = true }
  247. },
  248. //popup弹窗数量增加按钮
  249. changeCountAdd() {
  250. if(this.number === this.handleStock){
  251. this.isStock = true
  252. return
  253. }
  254. if (this.product.step == 2) {
  255. this.number += this.handleMinNumber
  256. } else {
  257. this.number++
  258. }
  259. this.processActivityPrice()
  260. },
  261. //popup弹窗数量减按钮
  262. changeCountSub() {
  263. if (this.number <= this.handleMinNumber) {
  264. this.number = this.handleMinNumber
  265. this.isQuantity = true
  266. this.$util.msg(`该商品最小起订量为${this.handleMinNumber}`, 2000)
  267. return
  268. } else {
  269. if (this.product.step == 2) {
  270. this.number -= this.handleMinNumber
  271. } else {
  272. this.number--
  273. }
  274. this.processActivityPrice()
  275. this.isQuantity = false
  276. }
  277. },
  278. changeNumber(e) {
  279. let _value = e.detail.value
  280. if (!this.$api.isNumber(_value)) {
  281. this.number = this.handleMinNumber
  282. } else if (_value < this.handleMinNumber) {
  283. this.$util.msg(`该商品最小起订量为${this.handleMinNumber}`, 2000)
  284. this.number = this.handleMinNumber
  285. } else if (_value % this.handleMinNumber != 0) {
  286. this.$util.msg('购买量必须为起订量的整数倍', 2000)
  287. this.number = this.handleMinNumber
  288. } else if(_value > this.handleStock) {
  289. this.number = this.handleStock
  290. }else{
  291. this.number = e.detail.value
  292. }
  293. this.processActivityPrice()
  294. },
  295. processActivityPrice() {
  296. //单独处理活动价格和阶梯价格
  297. if ((this.product.ladderPriceFlag == '0' && this.product.actStatus == 0) || this.product.actStatus == 1) {
  298. this.buyRetailPrice = this.product.price
  299. } else {
  300. this.ladderPriceList.forEach((item, index) => {
  301. if (this.number >= item.buyNum) {
  302. this.buyRetailPrice = item.buyPrice
  303. }
  304. })
  305. }
  306. },
  307. handleConfirm(type) {
  308. if (this.hasLogin) {
  309. switch (type) {
  310. case 'add':
  311. // 友盟埋点商品详情加入购物车点击事件
  312. if (process.env.NODE_ENV != 'development') {
  313. this.$uma.trackEvent('Um_Event_ProductAddCart', {
  314. Um_Key_PageName: '加入购物车',
  315. Um_Key_SourcePage: '商品详情',
  316. Um_Key_ProductID: `${this.product.productId}`
  317. })
  318. }
  319. if (this.ladderPriceFlag) {
  320. this.processActivityPrice()
  321. }
  322. break
  323. case 'buy':
  324. // 友盟埋点商品详情立即购买点击事件
  325. if (process.env.NODE_ENV != 'development') {
  326. this.$uma.trackEvent('Um_Event_ProductBuyConfirm', {
  327. Um_Key_PageName: '立即购买',
  328. Um_Key_SourcePage: '商品详情',
  329. Um_Key_ProductID: `${this.product.productId}`
  330. })
  331. }
  332. break
  333. }
  334. let data = { type: type }
  335. this.$emit('buyConfirm', data)
  336. this.$parent.popupShow3 = false
  337. } else {
  338. this.$api.navigateTo('/pages/login/login')
  339. }
  340. },
  341. btnConfirm() {
  342. //加入购物车&&立即购买跳转订单页并关闭弹窗
  343. // 友盟埋点商品详情确认购买商品点击事件
  344. if (process.env.NODE_ENV != 'development') {
  345. this.$uma.trackEvent('Um_Event_ProductShoppingConfirm', {
  346. Um_Key_PageName: '商品购买确认',
  347. Um_Key_SourcePage: '商品详情',
  348. Um_Key_ProductID: `${this.product.productId}`
  349. })
  350. }
  351. let data = { type: type }
  352. this.$emit('buyConfirm', data)
  353. this.$parent.popupShow3 = false
  354. },
  355. handleChoisSku(sku, index) {
  356. // 选择SKU
  357. this.skuIndex = index
  358. this.number = this.handleMinNumber = sku.minBuyNumber
  359. this.handleStock = sku.stock
  360. console.log('handleStock',this.handleStock)
  361. this.ladderPriceList = sku.ladderPriceList
  362. this.isShowLadder = sku.ladderPriceList ? true : false
  363. },
  364. showLaddePopup(){
  365. // 点击显示阶梯价
  366. this.laddePopupShow = true
  367. },
  368. hidePopup() {
  369. //隐藏
  370. this.$parent.popupShow3 = false
  371. }
  372. }
  373. }
  374. </script>
  375. <style lang="scss">
  376. .tui-shopping-main {
  377. width: 100%;
  378. .tui-sku-title {
  379. width: 100%;
  380. height: 136rpx;
  381. float: left;
  382. margin-bottom: 30rpx;
  383. .tui-sku-image {
  384. width: 138rpx;
  385. height: 138rpx;
  386. float: left;
  387. border-radius: 8rpx;
  388. margin-right: 30rpx;
  389. box-sizing: border-box;
  390. border: 1px dashed #e1e1e1;
  391. image {
  392. width: 134rpx;
  393. height: 134rpx;
  394. border-radius: 10rpx;
  395. }
  396. }
  397. .tui-sku-price {
  398. height: 136rpx;
  399. float: left;
  400. }
  401. }
  402. .tui-sku-unit {
  403. width: 100%;
  404. height: auto;
  405. float: left;
  406. .sku-unit-h1 {
  407. font-size: 28rpx;
  408. line-height: 40rpx;
  409. color: #333333;
  410. font-weight: bold;
  411. }
  412. .sku-unit-li {
  413. width: 100%;
  414. height: auto;
  415. .unit-li {
  416. padding: 0 24rpx;
  417. line-height: 48rpx;
  418. text-align: center;
  419. font-size: 24rpx;
  420. color: #666666;
  421. background: #f5f5f5;
  422. float: left;
  423. margin-right: 16rpx;
  424. margin-top: 12rpx;
  425. margin-bottom: 12rpx;
  426. border-radius: 24rpx;
  427. position: relative;
  428. box-sizing: border-box;
  429. border: 1px solid #f5f5f5;
  430. &.active {
  431. border-color: $color-system;
  432. background: #fff1eb;
  433. color: $color-system;
  434. .tips {
  435. background: #e15616;
  436. }
  437. }
  438. .tips {
  439. padding: 0 10rpx;
  440. line-height: 32rpx;
  441. text-align: center;
  442. font-size: 22rpx;
  443. color: #ffffff;
  444. background: #cccccc;
  445. float: left;
  446. border-radius: 16rpx;
  447. position: absolute;
  448. right: -12rpx;
  449. top: -15rpx;
  450. }
  451. }
  452. }
  453. }
  454. .sku-unit-nunbox {
  455. justify-content: space-between;
  456. align-items: center;
  457. width: 100%;
  458. height: auto;
  459. float: left;
  460. margin-top: 30rpx;
  461. .sku-unit-nunbox-t {
  462. width: 100%;
  463. height: 44rpx;
  464. position: relative;
  465. margin-bottom: 10rpx;
  466. .text {
  467. font-size: $font-size-24;
  468. line-height: 48rpx;
  469. color: #999999;
  470. }
  471. .sku-unit-nunbox-text {
  472. line-height: 44rpx;
  473. font-size: $font-size-28;
  474. float: left;
  475. font-weight: bold;
  476. }
  477. .sku-unit-nunbox-num {
  478. float: right;
  479. .number-box {
  480. display: flex;
  481. justify-content: center;
  482. align-items: center;
  483. border: 2rpx solid #ffe6dc;
  484. border-radius: 30rpx;
  485. height: 48rpx;
  486. margin-left: 20rpx;
  487. .iconfont {
  488. font-size: $font-size-24;
  489. padding: 0 18rpx;
  490. color: #999999;
  491. text-align: center;
  492. line-height: 48rpx;
  493. font-weight: bold;
  494. background: #fef6f3;
  495. &.icon-jianhao {
  496. border-radius: 30rpx 0 0 30rpx;
  497. }
  498. &.icon-jiahao {
  499. border-radius: 0 30rpx 30rpx 0;
  500. &.disabled{
  501. background: #F5F5F5;
  502. }
  503. }
  504. }
  505. .btn-input {
  506. width: 62rpx;
  507. height: 48rpx;
  508. line-height: 48rpx;
  509. background: #ffffff;
  510. border-radius: 4rpx;
  511. text-align: center;
  512. font-size: $font-size-28;
  513. }
  514. }
  515. }
  516. }
  517. }
  518. .sku-unit-ladel {
  519. width: 100%;
  520. height: 64rpx;
  521. line-height: 64rpx;
  522. float: left;
  523. margin-top: 20rpx;
  524. text-align: center;
  525. font-size: 24rpx;
  526. background: #fffaf8;
  527. color: #e15616;
  528. }
  529. }
  530. .tui-modal-flex {
  531. width: 100%;
  532. height: 84rpx;
  533. margin-top: 40rpx;
  534. display: flex;
  535. .tui-modal-button {
  536. flex: 1;
  537. line-height: 84rpx;
  538. font-size: $font-size-28;
  539. text-align: center;
  540. border-radius: 42rpx;
  541. padding: 0;
  542. margin: 0 15rpx;
  543. box-sizing: border-box;
  544. &.cancel {
  545. background: #ffe6dc;
  546. color: #e15616;
  547. &.disabled{
  548. background-color: #e1e1e1;
  549. color: #ffffff;
  550. }
  551. }
  552. &.confirm {
  553. background: $btn-confirm;
  554. color: #ffffff;
  555. &.disabled {
  556. background: linear-gradient(135deg, rgba(242, 143, 49, 0.5) 0%, rgba(225, 86, 22, 0.5) 100%);
  557. }
  558. }
  559. }
  560. }
  561. </style>