【类 型】:fix

【原  因】:异步加载订单 的延时  造成 支付倒计时显示错误
【过  程】:watch监听order_time 的变化 有倒计时的信息之后 再进行 倒计时的相关 例如视图渲染 以免报错
【影  响】:

# 类型 包含:
# feat:新功能(feature)
# fix:修补bug
# docs:文档(documentation)
# style: 格式(不影响代码运行的变动)
# refactor:重构(即不是新增功能,也不是修改bug的代码变动)
# test:增加测试
# chore:构建过程或辅助工具的变动
This commit is contained in:
sszdot 2024-12-17 11:35:17 +08:00
parent 002e507aaa
commit 9b7ca6de06

View File

@ -10,9 +10,12 @@
<view class="flex column msb bodyBox"> <view class="flex column msb bodyBox">
<view> <view>
<view class="priceBox fb flex mc">¥{{fullPrice | formatPrice}}</view> <view class="priceBox fb flex mc">¥{{fullPrice | formatPrice}}</view>
<view class="fcb fz24 flex mc"> <view class="fcb fz24 flex mc" v-if="countdown !== ''">
<span class="m-r-24">支付剩余时间</span> <span class="m-r-24">支付剩余时间</span>
<span v-if="order_time!==0">{{ countdown }}</span> <span>{{ countdown }}</span>
</view>
<view class="fcb fz24 flex mc" v-else>
<span>订单加载中···</span>
</view> </view>
<view class="flex msb mac rad8 bg-w m-l-24 m-r-24 m-t-24 p-24"> <view class="flex msb mac rad8 bg-w m-l-24 m-r-24 m-t-24 p-24">
<view class="flex mac"> <view class="flex mac">
@ -42,7 +45,7 @@
return { return {
order_sn: '', // order_sn: '', //
fullPrice: 0, // fullPrice: 0, //
order_time: 0, // order_time: -1, //
countdown: '', // countdown: '', //
timer: null, // timer: null, //
} }
@ -51,51 +54,58 @@
this.$store.dispatch('fetchOrderList') this.$store.dispatch('fetchOrderList')
this.order_sn = options.order_sn // this.order_sn = options.order_sn //
this.fullPrice = Number(options.fullPrice) // this.fullPrice = Number(options.fullPrice) //
// if (this.orderShow) {
this.timer = setInterval(() => { this.order_time = Number(this.orderShow.order_time)
if (this.order_time && this.order_time > 0) {
let tempTime = this.order_time + 100 - Math.floor(Date.now() / 1000)
if (tempTime <= 0) {
this.countdown = '00:00'
clearInterval(this.timer) //
//
uni.navigateTo({
url: '/pages/index/index' // Tab
})
} else {
this.countdown = this.formatSeconds(tempTime)
} }
} else {
this.countdown = '00:00'
clearInterval(this.timer) //
// order_time
uni.switchTab({
url: '/pages/index/index' //
})
}
}, 1000)
}, },
computed: { computed: {
// //
orderShow() { orderShow() {
if (this.$store.state.orderList && this.$store.state.orderList.length > 0) { if (this.$store.state.orderList && this.$store.state.orderList.length > 0) {
// 使 find null // 使 find
return this.$store.state.orderList.find((item) => item.order_sn === this.order_sn) || null; return this.$store.state.orderList.find(item => item.order_sn === this.order_sn) || null
}
return null // orderList null
} }
return null; // orderList null
},
}, },
filters: { filters: {
formatPrice, // formatPrice, //
}, },
watch: { watch: {
'orderShow': { orderShow: {
handler(newVal, oldVal) { handler(val) {
if (newVal) { //
this.order_time = Number(newVal.order_time) if (val && val.order_time) {
this.order_time = Number(val.order_time)
} else {
this.order_time = -1 //
} }
}, },
deep: true deep: true,
immediate: true,
},
order_time: {
handler(val) {
if (this.timer) {
clearInterval(this.timer) //
}
// order_time
if (!val || val < 0) return
this.timer = setInterval(() => {
const tempTime = this.order_time + 900 - Math.floor(Date.now() / 1000)
if (tempTime <= 0) {
this.countdown = '00:00'
clearInterval(this.timer) //
//
uni.navigateTo({
url: '/pages/index/index', // Tab
})
} else {
this.countdown = this.formatSeconds(tempTime)
}
}, 1000)
},
immediate: true, //
} }
}, },
methods: { methods: {
@ -113,12 +123,12 @@
}).then((res) => { }).then((res) => {
if (res.data.status === 1) { if (res.data.status === 1) {
// //
this.requestPayment(res.data.payMsg); this.requestPayment(res.data.payMsg)
} else { } else {
uni.showToast({ uni.showToast({
title: '支付失败', title: '支付失败',
icon: 'error' icon: 'error'
}); })
console.error(res.data.msg) console.error(res.data.msg)
} }
}) })
@ -143,10 +153,10 @@
uni.showToast({ uni.showToast({
title: '支付失败', title: '支付失败',
icon: 'error' icon: 'error'
}); })
console.error(err) console.error(err)
} }
}); })
}, },