cm-unit-popup.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  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.organizeSkus
  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. this.$emit('buyConfirm', { type: type, productCount: this.productCount })
  234. this.$parent.popupShow3 = false
  235. } else {
  236. this.$api.navigateTo('/pages/login/login')
  237. }
  238. },
  239. handleBtnConfirm() {
  240. //确定加入购物车或立即购买
  241. if (this.isBtnDisable || this.goodsData.disabled) {
  242. return
  243. }
  244. if (process.env.NODE_ENV != 'development') {
  245. // 友盟埋点商品详情确认购买商品点击事件
  246. this.$uma.trackEvent('Um_Event_ProductShoppingConfirm', {
  247. Um_Key_PageName: '商品购买确认',
  248. Um_Key_SourcePage: '商品详情',
  249. Um_Key_ProductID: `${this.skuProduct.productId}`
  250. })
  251. }
  252. this.$emit('buyConfirm', { type: this.btnType, productCount: this.productCount })
  253. this.$parent.popupShow3 = false
  254. },
  255. handleChoisSku(sku, index) {
  256. // 选择SKU
  257. this.skuIndex = index
  258. this.productCount = this.handleMinNumber = sku.minBuyNumber
  259. this.handleStock = sku.stock
  260. this.isBtnDisable = sku.stock === 0
  261. this.ladderPriceList = sku.ladderPriceList
  262. this.isShowLadder = sku.ladderPriceList ? true : false
  263. this.$emit('skuClick', sku)
  264. },
  265. showLaddePopup() {
  266. // 点击显示阶梯价
  267. this.laddePopupShow = true
  268. },
  269. hidePopup() {
  270. //隐藏
  271. this.$parent.popupShow3 = false
  272. }
  273. }
  274. }
  275. </script>
  276. <style lang="scss">
  277. .tui-shopping-main {
  278. width: 100%;
  279. .tui-sku-title {
  280. width: 100%;
  281. height: 136rpx;
  282. float: left;
  283. margin-bottom: 30rpx;
  284. .tui-sku-image {
  285. width: 138rpx;
  286. height: 138rpx;
  287. float: left;
  288. border-radius: 8rpx;
  289. margin-right: 30rpx;
  290. box-sizing: border-box;
  291. border: 1px dashed #e1e1e1;
  292. image {
  293. width: 134rpx;
  294. height: 134rpx;
  295. border-radius: 10rpx;
  296. }
  297. }
  298. .tui-sku-price {
  299. height: 136rpx;
  300. float: left;
  301. }
  302. }
  303. .tui-sku-unit {
  304. width: 100%;
  305. height: auto;
  306. float: left;
  307. .sku-unit-h1 {
  308. font-size: 28rpx;
  309. line-height: 40rpx;
  310. color: #333333;
  311. font-weight: bold;
  312. }
  313. .sku-unit-li {
  314. width: 100%;
  315. height: auto;
  316. .unit-li {
  317. padding: 0 24rpx;
  318. line-height: 48rpx;
  319. text-align: center;
  320. font-size: 24rpx;
  321. color: #666666;
  322. background: #f5f5f5;
  323. float: left;
  324. margin-right: 16rpx;
  325. margin-top: 12rpx;
  326. margin-bottom: 12rpx;
  327. border-radius: 24rpx;
  328. position: relative;
  329. box-sizing: border-box;
  330. border: 1px solid #f5f5f5;
  331. &.active {
  332. border-color: $color-system;
  333. background: #FFF8EF;
  334. color: $color-system;
  335. .tips {
  336. background: #FF5B00;
  337. }
  338. }
  339. .tips {
  340. padding: 0 10rpx;
  341. line-height: 32rpx;
  342. text-align: center;
  343. font-size: 22rpx;
  344. color: #ffffff;
  345. background: #cccccc;
  346. float: left;
  347. border-radius: 16rpx;
  348. position: absolute;
  349. right: -12rpx;
  350. top: -15rpx;
  351. }
  352. }
  353. }
  354. }
  355. .sku-unit-nunbox {
  356. justify-content: space-between;
  357. align-items: center;
  358. width: 100%;
  359. height: auto;
  360. float: left;
  361. margin-top: 30rpx;
  362. .sku-unit-nunbox-t {
  363. width: 100%;
  364. height: 44rpx;
  365. position: relative;
  366. margin-bottom: 10rpx;
  367. .text {
  368. font-size: $font-size-24;
  369. line-height: 48rpx;
  370. color: #999999;
  371. }
  372. .sku-unit-nunbox-text {
  373. line-height: 44rpx;
  374. font-size: $font-size-28;
  375. float: left;
  376. font-weight: bold;
  377. }
  378. .sku-unit-nunbox-num {
  379. float: right;
  380. .number-box {
  381. display: flex;
  382. justify-content: center;
  383. align-items: center;
  384. border: 2rpx solid #D5D5D5;
  385. border-radius: 30rpx;
  386. height: 48rpx;
  387. margin-left: 20rpx;
  388. .iconfont {
  389. font-size: $font-size-24;
  390. padding: 0 18rpx;
  391. color: #D5D5D5;
  392. text-align: center;
  393. line-height: 48rpx;
  394. font-weight: bold;
  395. background: #F7F7F7;
  396. &.icon-jianhao {
  397. border-radius: 30rpx 0 0 30rpx;
  398. &.disabled {
  399. background: #f5f5f5;
  400. }
  401. }
  402. &.icon-jiahao {
  403. border-radius: 0 30rpx 30rpx 0;
  404. &.disabled {
  405. background: #f5f5f5;
  406. }
  407. }
  408. }
  409. .btn-input {
  410. width: 62rpx;
  411. height: 48rpx;
  412. line-height: 48rpx;
  413. background: #ffffff;
  414. border-radius: 4rpx;
  415. text-align: center;
  416. font-size: $font-size-28;
  417. }
  418. }
  419. }
  420. }
  421. }
  422. .sku-unit-ladel {
  423. width: 100%;
  424. height: 64rpx;
  425. line-height: 64rpx;
  426. float: left;
  427. margin-top: 20rpx;
  428. text-align: center;
  429. font-size: 24rpx;
  430. background: #FFF8EF;
  431. color: #F3B574;
  432. }
  433. }
  434. .tui-flex-1 {
  435. .tui-button {
  436. &.disabled {
  437. background: rgba(243,181,116,0.5);
  438. }
  439. }
  440. }
  441. .tui-modal-flex {
  442. width: 100%;
  443. height: 84rpx;
  444. margin-top: 40rpx;
  445. display: flex;
  446. .tui-modal-button {
  447. flex: 1;
  448. line-height: 84rpx;
  449. font-size: $font-size-28;
  450. text-align: center;
  451. border-radius: 42rpx;
  452. padding: 0;
  453. margin: 0 15rpx;
  454. box-sizing: border-box;
  455. &.cancel {
  456. background: #FFF4E6;
  457. color: #F3B574;
  458. &.disabled {
  459. background-color: #e1e1e1;
  460. color: #ffffff;
  461. }
  462. }
  463. &.confirm {
  464. background: $btn-confirm;
  465. color: #ffffff;
  466. &.disabled {
  467. background: rgba(243,181,116,0.5);
  468. }
  469. }
  470. }
  471. }
  472. </style>