cm-unit-popup.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  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 }}
  24. <!-- <text class="tips" v-if="sku.stock === 0">缺货</text> -->
  25. </view>
  26. </view>
  27. </view>
  28. <view class="sku-unit-nunbox">
  29. <!-- <view class="sku-unit-nunbox" v-if="skuProduct.step === 2">
  30. <view class="text">*该商品只能以起订量的整数倍购买</view>
  31. </view> -->
  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. :class="[isQuantity == true ? 'disabled' : '']"
  39. @click="changeCountSub"
  40. ></view>
  41. <input
  42. class="btn-input"
  43. type="number"
  44. v-model="productCount"
  45. maxlength="4"
  46. @blur="changeNumber($event)"
  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()
  151. },
  152. computed: {
  153. ...mapState(['hasLogin'])
  154. },
  155. methods: {
  156. async initData(data) {
  157. const userInfo = await this.$api.getStorage()
  158. if (userInfo.userIdentity == 1 || userInfo.userIdentity == 3) {
  159. this.isShowButton = false
  160. } else {
  161. this.isShowButton = true
  162. }
  163. this.skuList = this.skuProduct.organizeSkus
  164. this.productCount = this.skuList[0].minBuyNumber
  165. this.handleMinNumber = this.skuList[0].minBuyNumber
  166. this.handleStock = this.skuList[0].stock
  167. // if (this.skuList[0].ladderPriceList) {
  168. // this.isShowLadder = true
  169. // this.ladderPriceList = this.skuList[0].ladderPriceList
  170. // }
  171. },
  172. //popup弹窗数量增加按钮
  173. changeCountAdd() {
  174. if (this.productCount === this.handleStock) {
  175. this.isStock = true
  176. return
  177. }
  178. if (this.skuProduct.step == 2) {
  179. this.productCount += this.handleMinNumber
  180. } else {
  181. this.productCount++
  182. }
  183. this.totalLadderPrice()
  184. },
  185. //popup弹窗数量减按钮
  186. changeCountSub() {
  187. if (this.productCount <= this.handleMinNumber) {
  188. this.productCount = this.handleMinNumber
  189. this.isQuantity = true
  190. this.$util.msg(`该商品最小起订量为${this.handleMinNumber}`, 2000)
  191. return
  192. } else {
  193. if (this.skuProduct.step == 2) {
  194. this.productCount -= this.handleMinNumber
  195. } else {
  196. this.productCount--
  197. }
  198. this.totalLadderPrice()
  199. this.isQuantity = false
  200. }
  201. },
  202. changeNumber(e) {
  203. let _value = e.detail.value
  204. if (!this.$api.isNumber(_value)) {
  205. this.productCount = this.handleMinNumber
  206. } else if (_value < this.handleMinNumber) {
  207. this.$util.msg(`该商品最小起订量为${this.handleMinNumber}`, 2000)
  208. this.productCount = this.handleMinNumber
  209. } else if (_value % this.handleMinNumber != 0) {
  210. this.$util.msg('购买量必须为起订量的整数倍', 2000)
  211. this.productCount = this.handleMinNumber
  212. } else if (_value > this.handleStock) {
  213. this.productCount = this.handleStock
  214. } else {
  215. this.productCount = e.detail.value
  216. }
  217. this.totalLadderPrice()
  218. },
  219. totalLadderPrice() {
  220. //单独处理活动价格和阶梯价格
  221. if (this.ladderPriceList.length > 0) {
  222. this.ladderPriceList.forEach((ladder, index) => {
  223. if (this.productCount >= ladder.buyNum) {
  224. this.$parent.skuProduct.price = ladder.buyPrice
  225. }
  226. })
  227. }
  228. },
  229. handleConfirm(type) {
  230. if (this.hasLogin) {
  231. if (this.isBtnDisable || this.goodsData.disabled) {
  232. return
  233. }
  234. this.$emit('buyConfirm', { type: type, productCount: this.productCount })
  235. this.$parent.popupShow3 = false
  236. } else {
  237. this.$api.navigateTo('/pages/login/login')
  238. }
  239. },
  240. handleBtnConfirm() {
  241. //确定加入购物车或立即购买
  242. if (this.isBtnDisable || this.goodsData.disabled) {
  243. return
  244. }
  245. if (process.env.NODE_ENV != 'development') {
  246. // 友盟埋点商品详情确认购买商品点击事件
  247. this.$uma.trackEvent('Um_Event_ProductShoppingConfirm', {
  248. Um_Key_PageName: '商品购买确认',
  249. Um_Key_SourcePage: '商品详情',
  250. Um_Key_ProductID: `${this.skuProduct.productId}`
  251. })
  252. }
  253. this.$emit('buyConfirm', { type: this.btnType, productCount: this.productCount })
  254. this.$parent.popupShow3 = false
  255. },
  256. handleChoisSku(sku, index) {
  257. // 选择SKU
  258. this.skuIndex = index
  259. this.productCount = this.handleMinNumber = sku.minBuyNumber
  260. this.handleStock = sku.stock
  261. this.isBtnDisable = sku.stock === 0
  262. this.ladderPriceList = sku.ladderPriceList
  263. this.isShowLadder = sku.ladderPriceList ? true : false
  264. this.$emit('skuClick', sku)
  265. },
  266. showLaddePopup() {
  267. // 点击显示阶梯价
  268. this.laddePopupShow = true
  269. },
  270. hidePopup() {
  271. //隐藏
  272. this.$parent.popupShow3 = false
  273. }
  274. }
  275. }
  276. </script>
  277. <style lang="scss">
  278. .tui-shopping-main {
  279. width: 100%;
  280. .tui-sku-title {
  281. width: 100%;
  282. height: 136rpx;
  283. float: left;
  284. margin-bottom: 30rpx;
  285. .tui-sku-image {
  286. width: 138rpx;
  287. height: 138rpx;
  288. float: left;
  289. border-radius: 8rpx;
  290. margin-right: 30rpx;
  291. box-sizing: border-box;
  292. border: 1px dashed #e1e1e1;
  293. image {
  294. width: 134rpx;
  295. height: 134rpx;
  296. border-radius: 10rpx;
  297. }
  298. }
  299. .tui-sku-price {
  300. height: 136rpx;
  301. float: left;
  302. }
  303. }
  304. .tui-sku-unit {
  305. width: 100%;
  306. height: auto;
  307. float: left;
  308. .sku-unit-h1 {
  309. font-size: 28rpx;
  310. line-height: 40rpx;
  311. color: #333333;
  312. font-weight: bold;
  313. }
  314. .sku-unit-li {
  315. width: 100%;
  316. height: auto;
  317. .unit-li {
  318. padding: 0 24rpx;
  319. line-height: 48rpx;
  320. text-align: center;
  321. font-size: 24rpx;
  322. color: #666666;
  323. background: #f5f5f5;
  324. float: left;
  325. margin-right: 16rpx;
  326. margin-top: 12rpx;
  327. margin-bottom: 12rpx;
  328. border-radius: 24rpx;
  329. position: relative;
  330. box-sizing: border-box;
  331. border: 1px solid #f5f5f5;
  332. &.active {
  333. border-color: $color-system;
  334. background: #FFF8EF;
  335. color: $color-system;
  336. .tips {
  337. background: #FF5B00;
  338. }
  339. }
  340. .tips {
  341. padding: 0 10rpx;
  342. line-height: 32rpx;
  343. text-align: center;
  344. font-size: 22rpx;
  345. color: #ffffff;
  346. background: #cccccc;
  347. float: left;
  348. border-radius: 16rpx;
  349. position: absolute;
  350. right: -12rpx;
  351. top: -15rpx;
  352. }
  353. }
  354. }
  355. }
  356. .sku-unit-nunbox {
  357. justify-content: space-between;
  358. align-items: center;
  359. width: 100%;
  360. height: auto;
  361. float: left;
  362. margin-top: 30rpx;
  363. .sku-unit-nunbox-t {
  364. width: 100%;
  365. height: 44rpx;
  366. position: relative;
  367. margin-bottom: 10rpx;
  368. .text {
  369. font-size: $font-size-24;
  370. line-height: 48rpx;
  371. color: #999999;
  372. }
  373. .sku-unit-nunbox-text {
  374. line-height: 44rpx;
  375. font-size: $font-size-28;
  376. float: left;
  377. font-weight: bold;
  378. }
  379. .sku-unit-nunbox-num {
  380. float: right;
  381. .number-box {
  382. display: flex;
  383. justify-content: center;
  384. align-items: center;
  385. border: 2rpx solid #D5D5D5;
  386. border-radius: 30rpx;
  387. height: 48rpx;
  388. margin-left: 20rpx;
  389. .iconfont {
  390. font-size: $font-size-24;
  391. padding: 0 18rpx;
  392. color: #D5D5D5;
  393. text-align: center;
  394. line-height: 48rpx;
  395. font-weight: bold;
  396. background: #F7F7F7;
  397. &.icon-jianhao {
  398. border-radius: 30rpx 0 0 30rpx;
  399. &.disabled {
  400. background: #f5f5f5;
  401. }
  402. }
  403. &.icon-jiahao {
  404. border-radius: 0 30rpx 30rpx 0;
  405. &.disabled {
  406. background: #f5f5f5;
  407. }
  408. }
  409. }
  410. .btn-input {
  411. width: 62rpx;
  412. height: 48rpx;
  413. line-height: 48rpx;
  414. background: #ffffff;
  415. border-radius: 4rpx;
  416. text-align: center;
  417. font-size: $font-size-28;
  418. }
  419. }
  420. }
  421. }
  422. }
  423. .sku-unit-ladel {
  424. width: 100%;
  425. height: 64rpx;
  426. line-height: 64rpx;
  427. float: left;
  428. margin-top: 20rpx;
  429. text-align: center;
  430. font-size: 24rpx;
  431. background: #FFF8EF;
  432. color: #F3B574;
  433. }
  434. }
  435. .tui-flex-1 {
  436. .tui-button {
  437. &.disabled {
  438. background: rgba(243,181,116,0.5);
  439. }
  440. }
  441. }
  442. .tui-modal-flex {
  443. width: 100%;
  444. height: 84rpx;
  445. margin-top: 40rpx;
  446. display: flex;
  447. .tui-modal-button {
  448. flex: 1;
  449. line-height: 84rpx;
  450. font-size: $font-size-28;
  451. text-align: center;
  452. border-radius: 42rpx;
  453. padding: 0;
  454. margin: 0 15rpx;
  455. box-sizing: border-box;
  456. &.cancel {
  457. background: #FFF4E6;
  458. color: #F3B574;
  459. &.disabled {
  460. background-color: #e1e1e1;
  461. color: #ffffff;
  462. }
  463. }
  464. &.confirm {
  465. background: $btn-confirm;
  466. color: #ffffff;
  467. &.disabled {
  468. background: rgba(243,181,116,0.5);
  469. }
  470. }
  471. }
  472. }
  473. </style>