Fix(商品/订单):[#1021]商品详情页购买时选择优惠券,点击“立即购买”后已显示扣除优惠金额,但点开提交订单页面的优惠券时,优惠券未勾选

This commit is contained in:
lifizer
2024-03-29 23:23:39 +08:00
parent 6eedbfd240
commit 78f1c7b3b6
4 changed files with 122 additions and 76 deletions
+46 -39
View File
@@ -2,20 +2,41 @@
<view class="popup-coupons">
<view class="popup-box">
<view class="popup-title bold tc">选择优惠券</view>
<SubSection :current="current" :can-use="canUse" :not-use="notUse" radioModel @change="changeNav"/>
<SubSection
:current="current"
:can-use="canUse"
:not-use="notUse"
radio-model
@change="changeNav"
/>
<view class="list-box">
<view style="margin-bottom: 20rpx" v-for="(item,index) in list" :key="index">
<Coupons :data="item" radioModel @change="selectCoupon"/>
<view
v-for="(item, index) in list"
:key="index"
style="margin-bottom: 20rpx"
>
<Coupons
:data="item"
radio-model
@change="selectCoupon"
/>
</view>
<view class="tc" v-if="list.length===0">
<view
v-if="list.length === 0"
class="tc"
>
<image class="zero-coupons" :src="webUrl+'/20231201201733142658.png'" mode="scaleToFill"/>
</view>
</view>
</view>
<button disabled></button>
<view class="btn-done bold flex jc-center ai-center" :class="{'btn-disabled':current===1}" @click="setCoupon" v-if="current===0">确定
<view
v-if="current === 0"
:class="{ 'btn-disabled': current === 1 }"
class="btn-done bold flex jc-center ai-center"
@click="setCoupon"
>
确定
</view>
</view>
</template>
@@ -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')
}
}
}