【类 型】:fix
【原 因】:异步加载订单 的延时 造成 支付倒计时显示错误 【过 程】:watch监听order_time 的变化 有倒计时的信息之后 再进行 倒计时的相关 例如视图渲染 以免报错 【影 响】: # 类型 包含: # feat:新功能(feature) # fix:修补bug # docs:文档(documentation) # style: 格式(不影响代码运行的变动) # refactor:重构(即不是新增功能,也不是修改bug的代码变动) # test:增加测试 # chore:构建过程或辅助工具的变动
This commit is contained in:
parent
002e507aaa
commit
9b7ca6de06
@ -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)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user