Skip to content

Commit

Permalink
Merge pull request woniudiancang#17 from mydaoyuan/bugfix
Browse files Browse the repository at this point in the history
fixbug:修复确认订单页面快速点击下单按钮导致的重复下单问题
  • Loading branch information
woniudiancang authored Nov 14, 2021
2 parents 128e792 + 0c8173a commit 448cd67
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
40 changes: 27 additions & 13 deletions pages/pay/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Page({
curCoupon: null, // 当前选择使用的优惠券
curCouponShowText: '请选择使用优惠券', // 当前选择使用的优惠券
peisongType: 'zq', // 配送方式 kd,zq 分别表示快递/到店自取
submitLoding: false,
remark: '',

currentDate: new Date().getHours() + ':' + (new Date().getMinutes() % 10 === 0 ? new Date().getMinutes() : Math.ceil(new Date().getMinutes() / 10) * 10),
Expand Down Expand Up @@ -134,6 +135,7 @@ Page({
this.data.remark = e.detail.value
},
goCreateOrder(){
if (this.data.submitLoding) return
const mobile = this.data.mobile
if (this.data.peisongType == 'zq' && !mobile) {
wx.showToast({
Expand All @@ -149,20 +151,24 @@ Page({
})
return
}
this.setData({
submitLoding: true
})
const subscribe_ids = wx.getStorageSync('subscribe_ids')
if (subscribe_ids) {
wx.requestSubscribeMessage({
tmplIds: subscribe_ids.split(','),
success(res) {

},
fail(e) {
console.error(e)
},
complete: (e) => {
this.createOrder(true)
},
})
wx.requestSubscribeMessage({
tmplIds: subscribe_ids.split(','),
success(res) {},
fail(e) {
this.setData({
submitLoding: false
})
console.error(e)
},
complete: (e) => {
this.createOrder(true)
},
})
} else {
this.createOrder(true)
}
Expand Down Expand Up @@ -273,7 +279,15 @@ Page({
});
return;
}
that.processAfterCreateOrder(res)
return that.processAfterCreateOrder(res)
})
.finally(() => {
// 再唤起微信支付的时候,有大约1s的弹窗动画过度,加上 1s 的延迟可以稳定防止重复下单
setTimeout(() => {
this.setData({
submitLoding: false
})
}, 1000)
})
},
async processAfterCreateOrder(res) {
Expand Down
2 changes: 1 addition & 1 deletion pages/pay/index.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
button-text="{{peisongType == 'kd' && amountReal < shopInfo.serviceAmountMin ? shopInfo.serviceAmountMin + '元起送' : '立即支付'}}"
bind:submit="goCreateOrder"
button-class="pay-btn"
disabled="{{peisongType == 'kd' && amountReal < shopInfo.serviceAmountMin}}"
disabled="{{(peisongType == 'kd' && amountReal < shopInfo.serviceAmountMin) || submitLoding }}"
/>
<van-submit-bar
wx:else
Expand Down

0 comments on commit 448cd67

Please sign in to comment.