diff --git a/components/Coupons.vue b/components/Coupons.vue index bd82d9e..63a3b68 100644 --- a/components/Coupons.vue +++ b/components/Coupons.vue @@ -1,18 +1,32 @@ @@ -26,16 +47,26 @@ import Coupons from '@/components/Coupons.vue' export default { name: 'CouponsPopup', - components: {SubSection, Coupons}, + components: { SubSection, Coupons }, props: { twoList: { type: Object, - default: {} + default: { + usable: [], + unusable: [] + } + } + }, + data() { + return { + webUrl: this.$VUE_APP_RESOURCES_URL, + current: 0, + couponId: uni.getStorageSync('couponId') || 0 } }, computed: { list() { - let temp = this.current === 0 ? this.twoList['usable'] : this.twoList['unusable'] + const temp = this.current === 0 ? this.twoList['usable'] : this.twoList['unusable'] return this.$global.deepClone(temp) }, canUse() { @@ -45,44 +76,20 @@ export default { return this.twoList['unusable'].length } }, - watch: { - current() { - this.selectCoupon(this.couponId) - } - }, - data() { - return { - webUrl: this.$VUE_APP_RESOURCES_URL, - current: 0, - couponId: 0 - } - }, - mounted() { - this.couponId = uni.getStorageSync('couponId') || 0 - this.selectCoupon(this.couponId) - }, methods: { changeNav(index) { this.current = index }, selectCoupon(id) { - const isCancel = this.couponId === id - this.couponId = isCancel ? 0 : id - - this.list?.forEach(item => { - if (!isCancel) { - item.checked = id === item.id - } else { - item.checked = false - } + this.couponId = id + this.list.map(item => { + item.checked = id === item.id }) }, setCoupon() { if (this.current === 1) return - // if (this.couponId !== 0) { - uni.setStorageSync('couponId', this.couponId) - // } - this.$emit('close') + uni.setStorageSync('couponId', this.couponId) + this.$emit('change') } } } diff --git a/pages/order/OrderSubmission/index.vue b/pages/order/OrderSubmission/index.vue index 4fc7ac2..9c2a6a8 100644 --- a/pages/order/OrderSubmission/index.vue +++ b/pages/order/OrderSubmission/index.vue @@ -185,8 +185,18 @@ - - + + @@ -272,8 +282,11 @@ export default { lotteryRecordId:'', payPassword: null, // v9-2 - couponList: {}, - couponId: 0, + couponList: { + unusable: [], + usable: [] + }, + couponId: uni.getStorageSync('couponId') || 0, couponIndex: -1, show: false }; @@ -354,35 +367,42 @@ export default { }); }, getCartInfo() { - var that = this; - // const cartIds = this.$yroute.query.id; - if (!that.cartid && !that.lotteryRecordId) { + const _this = this + if (!_this.cartid && !_this.lotteryRecordId) { uni.showToast({ title: "参数有误", icon: "none", duration: 2000 - }); - return this.$yrouter.back(); + }) + return this.$yrouter.back() } - postOrderConfirm(that.cartid,that.lotteryRecordId) - .then(res => { - that.offlinePayStatus = res.data.offline_pay_status; - that.orderGroupInfo = res.data; - that.deduction = res.data.deduction; - that.couponList = res.data.couponList - that.addressInfo = res.data.addressInfo || {}; - that.systemStore = res.data.systemStore || {}; - that.storeSelfMention = res.data.storeSelfMention; - that.couponId = uni.getStorageSync('couponId') || 0 - that.computedPrice() + postOrderConfirm(_this.cartid,_this.lotteryRecordId).then(res => { + const { data } = res + _this.offlinePayStatus = data.offline_pay_status + _this.orderGroupInfo = data + _this.deduction = data.deduction + _this.couponList = data.couponList + if (_this.couponId > 0) { + _this.couponList['usable'].map((item, index) => { + if (item.id === _this.couponId) { + item.checked = true + _this.couponIndex = index + } else { + item.checked = false + } }) - .catch(err => { - uni.showToast({ - title: err.msg, - icon: "none", - duration: 2000 - }); - }); + } + _this.addressInfo = data.addressInfo || {} + _this.systemStore = data.systemStore || {} + _this.storeSelfMention = data.storeSelfMention + _this.computedPrice() + }).catch(err => { + uni.showToast({ + title: err.msg, + icon: "none", + duration: 2000 + }) + }) }, addressTap: function () { //改用跳转页面方式 diff --git a/pages/shop/GoodsCon/index.vue b/pages/shop/GoodsCon/index.vue index d68156a..be348da 100644 --- a/pages/shop/GoodsCon/index.vue +++ b/pages/shop/GoodsCon/index.vue @@ -202,7 +202,7 @@ - +