diff --git a/components/Coupons.vue b/components/Coupons.vue index d64046c..e10ee0c 100644 --- a/components/Coupons.vue +++ b/components/Coupons.vue @@ -6,7 +6,7 @@ class="coupons__cover" mode="widthFix" /> - + { diff --git a/components/CouponsPopup.vue b/components/CouponsPopup.vue index ebd0171..a7b2936 100644 --- a/components/CouponsPopup.vue +++ b/components/CouponsPopup.vue @@ -14,7 +14,7 @@ @change="changeNav" v-if="showTab" /> - + 券后价 @@ -61,6 +61,7 @@ @@ -75,6 +76,7 @@ > { + this.couponList = res.data.result.couponList + if(!f) { + this.couponId = res.data.result.defaultCouponId + } const data = res.data; if (data.status === "EXTEND_ORDER") { this.$yrouter.replace({ @@ -797,8 +805,17 @@ export default { if(!item) return if (this.couponList.usable.length === 0) return this.show = !this.show - this.couponId = uni.getStorageSync('couponId') || 0 + if(!item.id) { + this.couponId = 0 + this.couponTitle = '' + this.computedPrice(1) + return + } + this.couponId = item.id this.couponTitle = item.couponTitle + this.computedPrice(1) + // this.couponId = uni.getStorageSync('couponId') || 0 + // this.couponTitle = item.couponTitle } } }; diff --git a/pages/shop/GoodsCon/index.vue b/pages/shop/GoodsCon/index.vue index 7beac23..7b1dd79 100644 --- a/pages/shop/GoodsCon/index.vue +++ b/pages/shop/GoodsCon/index.vue @@ -207,7 +207,8 @@ @ok="setCoupon" @change="changeCoupons" @close="changeCoupons()" - :showTab="false" + :showTab="false" + :showRadio="false" :currentPrice="storeInfo.price" /> @@ -1458,7 +1459,6 @@ export default { path: "/pages/order/OrderSubmission/index", query: { id: res.data.cartId, - couponId: that.couponId, // 优惠券ID discount: that.storeInfo.discount, } }) @@ -1467,7 +1467,8 @@ export default { if(news === 2) { const coupId = that.couponId ? that.couponId : (that.couponList.usable[0] && that.couponList.usable[0].id || '') uni.navigateTo({ - url: '/pkg_user/views/gift/gift?cartId=' + res.data.cartId + '&couponId=' + coupId + (that.storeInfo.discount ? '&discount=' + that.storeInfo.discount : '') + // + '&couponId=' + coupId + url: '/pkg_user/views/gift/gift?cartId=' + res.data.cartId + (that.storeInfo.discount ? '&discount=' + that.storeInfo.discount : '') }) } if(news === 0) { diff --git a/pkg_user/views/gift/gift.vue b/pkg_user/views/gift/gift.vue index 1c519f1..3c828ca 100644 --- a/pkg_user/views/gift/gift.vue +++ b/pkg_user/views/gift/gift.vue @@ -106,14 +106,14 @@ 价格明细 - 商品总价: + 商品总价: {{ computedResult.totalPrice }} - 平台折扣: + 平台折扣: - @@ -121,11 +121,20 @@ - 优惠券: - + + + 优惠券: + + + + {{ couponTitle }} + + + - {{ computedResult.couponPrice }} + @@ -178,6 +187,22 @@ :show.sync="showPayPicker" @confirm="onPayConfirm" /> + + + @@ -189,12 +214,14 @@ import {mapGetters} from "vuex"; import giftTips from './components/giftTips.vue' import CoverPicker from './components/CoverPicker.vue' import PayPicker from './components/PayPicker.vue'; +import CouponsPopup from "@/components/CouponsPopup.vue" export default { components: { giftTips, CoverPicker, PayPicker, - passkeyborad + passkeyborad, + CouponsPopup }, data() { return { @@ -227,11 +254,24 @@ export default { defaultIndex:0, discount: null, computedResult: {}, + couponList: { + unusable: [], + usable: [] + }, + couponTitle: '', + showPopup: false + } + }, + watch: { + async couponId(value) { + this.couponIndex = this.couponList['usable']?.findIndex(item => item.id === +value) + this.couponTitle = this.couponList['usable']?.[this.couponIndex]?.couponTitle + await this.computedPrice(this.goodsInfo.cartNum, 1) } }, onLoad(opts) { this.cartId = opts.cartId - this.couponId = opts.couponId + // this.couponId = opts.couponId || 0 this.discount = opts.discount this.getGift() }, @@ -256,6 +296,26 @@ export default { }) }, methods: { + showCouponsPopup() { + this.showPopup = !this.showPopup + }, + close() { + this.showPopup = !this.showPopup + }, + changeCoupons(item) { + if(!item) return + if (this.couponList.usable && this.couponList.usable.length === 0) return + this.showPopup = !this.showPopup + if(!item.id) { + this.couponId = 0 + this.couponTitle = '' + this.computedPrice(this.goodsInfo.cartNum, 1) + return + } + this.couponId = item.id + this.couponTitle = item.couponTitle + this.computedPrice(this.goodsInfo.cartNum, 1) + }, makeAgain() { const params = { orderId: this.orderId, @@ -290,7 +350,12 @@ export default { },10) this.$forceUpdate() }, - computedPrice(num) { + /** + * 计算价格 + * @param {Number} num 数量 + * @param {Boolean} f 有值时 couponId不取默认值 + */ + computedPrice(num, f) { const params = { cartId: this.cartId, couponId: this.couponId, @@ -300,6 +365,11 @@ export default { params.discount = this.discount } getGiftCardSendOrderAmount(this.orderKey, params).then(res => { + this.couponList = res.data.result.couponList + if(!f) { + this.couponId = res.data.result.defaultCouponId || 0 + this.$forceUpdate() + } this.payPrice = res.data.result.payPrice this.computedResult = res.data.result this.$forceUpdate() @@ -335,10 +405,9 @@ export default { this.selectedCover = res.data.specialGiftCardTemplate.cover this.giftImage = res.data.specialGiftCardTemplate.image this.defaultIndex = this.coverList.findIndex(item => item.id === this.templateId) - console.log(this.defaultIndex, 'defaultIndex'); - if(!this.couponId) { - this.couponId = res.data.couponList.usable[0] && res.data.couponList.usable[0].id || '' - } + // if(!this.couponId) { + // this.couponId = res.data.couponList.usable[0] && res.data.couponList.usable[0].id || '' + // } this.computedPrice(this.goodsInfo.cartNum) }) }, @@ -460,17 +529,17 @@ export default { } }) .catch(err => { console.log(err); - uni.hideLoading(); - uni.showToast({ - title:err.msg, - icon: "none", - duration: 2000 - }); - }).finally(() => { - this.isShowPayPwdPop = false; - this.$refs.payPwdPop.clear();//清空支付密码 - this.$refs.payPwdPop.close();//关闭支付密码弹窗 - }); + uni.hideLoading(); + uni.showToast({ + title:err.msg, + icon: "none", + duration: 2000 + }); + }).finally(() => { + this.isShowPayPwdPop = false; + this.$refs.payPwdPop.clear();//清空支付密码 + this.$refs.payPwdPop.close();//关闭支付密码弹窗 + }); } } }