1. 修复支付0元弹出报错

This commit is contained in:
李琦
2026-06-24 10:28:47 +08:00
parent dcf6c37195
commit 3f699fa2c6
2 changed files with 263 additions and 20 deletions

View File

@@ -250,6 +250,7 @@
this.show = false;
},
opened() {
const that = this;
// 获取支付配置
registePay({
method: "post",
@@ -258,11 +259,36 @@
store_id: uni.getStorageSync('store_id') || '11001',
}
}).then((res) => {
// console.log(res, 'pay');
uni.showLoading({
title: "加载中"
});
if (res.data.errcode != 0) {
uni.hideLoading();
that.$refs.uToast.show({
title: res.data.msg || '支付失败',
type: 'default',
icon: false
});
return;
}
if (res.data.data.is_paid == 1) {
uni.hideLoading();
setTimeout(() => {
uni.showToast({
title: '支付成功',
duration: 1500,
mask: false,
icon: 'success'
});
}, 400);
setTimeout(() => {
that.getInfo();
}, 2900);
return;
}
uni.requestPayment({
provider: res.data.data.appId,
timeStamp: res.data.data.timestamp,
@@ -270,8 +296,7 @@
package: res.data.data.package,
signType: res.data.data.signType,
paySign: res.data.data.paySign,
success: (res) => {
// console.log('success:' + JSON.stringify(res));
success: () => {
uni.hideLoading();
setTimeout(() => {
uni.showToast({
@@ -279,27 +304,32 @@
duration: 1500,
mask: false,
icon: 'success'
})
}, 400)
});
}, 400);
setTimeout(() => {
this.getInfo()
}, 2900)
that.getInfo();
}, 2900);
},
fail: function(err) {
// console.log('fail:' + JSON.stringify(err));
uni.hideLoading();
setTimeout(() => {
uni.showToast({
title: res.data.msg || '支付失败',
duration: 1500,
mask: false,
icon: 'error'
})
}, 400)
that.$refs.uToast.show({
title: (err && err.errMsg) || '支付失败',
type: 'default',
icon: false
});
}, 400);
}
})
})
});
}).catch((err) => {
console.error('registePay', err);
uni.hideLoading();
that.$refs.uToast.show({
title: '支付失败',
type: 'default',
icon: false
});
});
},
// 返回首页
goHome() {

View File

@@ -1,5 +1,12 @@
<template>
<view class="container safe-area-inset-bottom">
<!-- #ifdef MP-WEIXIN -->
<page-container
:show="pageBackGuardShow"
:overlay="false"
@leave="onPageBackGuardLeave"
/>
<!-- #endif -->
<MessageNotification />
<!-- 预约信息 -->
<view class="title">
@@ -101,12 +108,28 @@
<!-- 须知 -->
<u-popup v-model="show" :safe-area-inset-bottom="true" mode="bottom" height="68%" border-radius="20"
:closeable="true">
:closeable="true" z-index="20000">
<view class="agreen">
<u-parse :html="content"></u-parse>
</view>
</u-popup>
<!-- 未勾选须知时的确认弹窗 -->
<u-popup v-model="showConfirm" mode="center" border-radius="24" width="600" z-index="10075">
<view class="confirm-modal">
<view class="confirm-title">预约挂号须知</view>
<view class="confirm-desc">
请您在使用前仔细阅读并同意
<text class="link" @click="show=true">预约挂号须知</text>
</view>
<view class="confirm-footer">
<button class="cancel-btn" @click="showConfirm = false">不同意</button>
<button class="agree-btn" @click="agreeAndRegister">同意并挂号</button>
</view>
</view>
</u-popup>
<!-- 底部 -->
<view class="footer">
<block v-if="registList.is_pay==0">
@@ -118,7 +141,7 @@
</view>
<!-- 按钮 -->
<button class="btn" @click="next" :class="form['check']?'':'bg'" :disabled="!form['check']">确认挂号
<button class="btn" @click="handleRegisterClick">确认挂号
</button>
</block>
<view class="gh_" v-if="registList.is_pay==1" @click="toHome">
@@ -149,6 +172,7 @@
data() {
return {
show: false,
showConfirm: false,
know: "",
form: {
check: false
@@ -169,8 +193,24 @@
rInfo: {},
_urlDoctorId: '',
_getInfoPromise: null,
pageBackGuardShow: false,
_suppressPageBackGuardLeave: false,
}
},
computed: {
shouldEnablePageBackGuard() {
return !(this.registList && this.registList.is_pay == 1);
},
},
watch: {
'registList.is_pay'(val) {
if (val == 1) {
this.setPageBackGuardShow(false, { suppressLeave: true });
} else {
this.syncPageBackGuard();
}
},
},
onLoad(e) {
const uid = uni.getStorageSync('user_id');
this.currentUserId = 'user-' + (uid !== '' && uid !== undefined && uid !== null ? uid : '2512');
@@ -202,9 +242,123 @@
this._getInfoPromise.then(() => this.ensureDoctorAfterLoad());
} else {
this.ensureDoctorAfterLoad();
this.syncPageBackGuard();
}
},
onBackPress() {
if (this.closeTopOverlayIfAny()) {
return true;
}
if (this.registList && this.registList.is_pay == 1) {
return false;
}
this.promptExitBeforeLeave();
return true;
},
methods: {
handleRegisterClick() {
if (!this.form.check) {
this.showConfirm = true;
return;
}
this.next();
},
agreeAndRegister() {
this.form.check = true;
this.showConfirm = false;
this.next();
},
closeTopOverlayIfAny() {
if (this.show) {
this.show = false;
return true;
}
if (this.showConfirm) {
this.showConfirm = false;
return true;
}
return false;
},
setPageBackGuardShow(show, { suppressLeave = false } = {}) {
// #ifdef MP-WEIXIN
if (suppressLeave) this._suppressPageBackGuardLeave = true;
this.pageBackGuardShow = !!show;
// #endif
},
syncPageBackGuard() {
// #ifdef MP-WEIXIN
this.$nextTick(() => {
this.setPageBackGuardShow(this.shouldEnablePageBackGuard, {
suppressLeave: !this.shouldEnablePageBackGuard,
});
});
// #endif
},
safeNavigateBack() {
// #ifdef MP-WEIXIN
this.setPageBackGuardShow(false, { suppressLeave: true });
setTimeout(() => {
uni.navigateBack();
}, 16);
// #endif
// #ifndef MP-WEIXIN
uni.navigateBack();
// #endif
},
onPageBackGuardLeave() {
// #ifdef MP-WEIXIN
if (this._suppressPageBackGuardLeave) {
this._suppressPageBackGuardLeave = false;
return;
}
if (this.closeTopOverlayIfAny()) {
this.$nextTick(() => {
this.setPageBackGuardShow(this.shouldEnablePageBackGuard, { suppressLeave: true });
});
return;
}
if (this.registList && this.registList.is_pay == 1) {
this.setPageBackGuardShow(false, { suppressLeave: true });
setTimeout(() => {
uni.navigateBack();
}, 16);
return;
}
this.setPageBackGuardShow(false);
this.promptExitBeforeLeave({
onStay: () => {
this.syncPageBackGuard();
},
onExit: () => {
this.safeNavigateBack();
},
});
// #endif
},
disableBackGuardBeforeLeave() {
this.setPageBackGuardShow(false, { suppressLeave: true });
},
promptExitBeforeLeave({ onStay, onExit } = {}) {
uni.showModal({
title: '提示',
content: '当前未挂号成功,是否继续还是退出?',
cancelText: '继续',
confirmText: '退出',
success: (res) => {
if (res.confirm) {
if (onExit) {
onExit();
} else {
this.safeNavigateBack();
}
} else if (onStay) {
onStay();
} else {
this.syncPageBackGuard();
}
},
});
},
stripDoctorPrefix(raw) {
if (raw === null || raw === undefined || raw === '') return '';
return String(raw).replace(/^doctor-/, '').trim();
@@ -298,6 +452,7 @@
that.applyDoctorNumericId(that.registList.service_user_id);
}
}
that.syncPageBackGuard();
});
this._getInfoPromise = p;
return p;
@@ -399,12 +554,14 @@
}),
);
uni.hideLoading();
that.disableBackGuardBeforeLeave();
uni.redirectTo({
url: '/subPackages/follow-up/medication-info?mode=clinic_post_register',
});
return;
}
uni.hideLoading();
that.disableBackGuardBeforeLeave();
uni.navigateTo({ url: chatUrl });
};
genOrderApi({
@@ -468,6 +625,7 @@
return;
}
setTimeout(() => {
that.disableBackGuardBeforeLeave();
uni.navigateTo({
url: `/subPackages/register/register-success?id=${that.register_id}&register_type=${that.registList.register_type}`,
})
@@ -492,6 +650,7 @@
return;
}
setTimeout(() => {
that.disableBackGuardBeforeLeave();
uni.navigateTo({
url: '/subPackages/register/register-success?id=' + that.register_id
})
@@ -705,5 +864,59 @@
.agreen {
padding: 60rpx 50rpx 20rpx;
}
.confirm-modal {
padding: 40rpx 30rpx;
background: #fff;
.confirm-title {
font-size: 34rpx;
font-weight: bold;
color: #333;
text-align: center;
margin-bottom: 30rpx;
}
.confirm-desc {
font-size: 28rpx;
color: #666;
line-height: 1.6;
margin-bottom: 40rpx;
text-align: center;
.link {
color: #2979FF;
}
}
.confirm-footer {
display: flex;
justify-content: space-between;
gap: 20rpx;
button {
flex: 1;
height: 80rpx;
line-height: 80rpx;
border-radius: 40rpx;
font-size: 30rpx;
border: none;
&::after {
border: none;
}
}
.cancel-btn {
background: #F5F7FA;
color: #909399;
}
.agree-btn {
background: #4175EE;
color: #FFFFFF;
}
}
}
}
</style>