cm-unit-popup.vue 12 KB

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