cm-unit-popup.vue 12 KB

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