cm-unit-popup.vue 11 KB

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