cm-unit-popup.vue 12 KB

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