|
|
@@ -181,63 +181,50 @@
|
|
|
user: null,
|
|
|
payParams: null,
|
|
|
userinfo: {},
|
|
|
- isPaying: false, // 防止重复支付
|
|
|
- payDebounceTimer: null // 防抖定时器
|
|
|
+ isPaying: false, // 防止重复支付
|
|
|
+ payDebounceTimer: null // 防抖定时器
|
|
|
}
|
|
|
},
|
|
|
onLoad(option) {
|
|
|
- this.getSafeUserInfo();
|
|
|
- this.orderId = JSON.parse(option.orderId);
|
|
|
- // this.orderBindUser(this.orderId)
|
|
|
- this.getStoreOrderById();
|
|
|
- this.getStoreConfig();
|
|
|
- this.getUserInfo();
|
|
|
+ this.getSafeUserInfo();
|
|
|
+ this.orderId = JSON.parse(option.orderId);
|
|
|
+ // this.orderBindUser(this.orderId)
|
|
|
+ this.getStoreOrderById();
|
|
|
+ this.getStoreConfig();
|
|
|
+ this.getUserInfo();
|
|
|
},
|
|
|
onUnload() {
|
|
|
this.clearPayTypeFun()
|
|
|
},
|
|
|
- //发送给朋友
|
|
|
- // onShareAppMessage(res) {
|
|
|
- // return {
|
|
|
- // title: "帮TA支付",
|
|
|
- // path: '/pages_user/user/otherPaymentOrder?orderId='+this.orderId,
|
|
|
- // imageUrl: this.$store.state.imgpath+'/app/image/logo.png' //分享图标,路径可以是本地文件路径、代码包文件路径或者网络图片路径.支持PNG及JPG。显示图片长宽比是 5:4
|
|
|
- // }
|
|
|
-
|
|
|
- // },
|
|
|
- methods: {getSafeUserInfo() {
|
|
|
- try {
|
|
|
- const userInfoStr = uni.getStorageSync('userInfo');
|
|
|
- if (!userInfoStr) {
|
|
|
- this.userinfo = {};
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // 如果是字符串,解析为对象
|
|
|
- if (typeof userInfoStr === 'string') {
|
|
|
- this.userinfo = JSON.parse(userInfoStr);
|
|
|
- } else {
|
|
|
- // 如果是对象,直接使用
|
|
|
- this.userinfo = userInfoStr;
|
|
|
- }
|
|
|
-
|
|
|
- console.log('获取到的用户信息:', this.userinfo);
|
|
|
- } catch (error) {
|
|
|
- console.error('获取用户信息失败:', error);
|
|
|
- this.userinfo = {};
|
|
|
- }
|
|
|
-},clearTokenAndRedirect() {
|
|
|
- // 清除 token
|
|
|
- uni.removeStorageSync('AppToken');
|
|
|
- uni.removeStorageSync('userInfo');
|
|
|
-
|
|
|
- // 跳转到登录页
|
|
|
- setTimeout(() => {
|
|
|
- uni.reLaunch({
|
|
|
- url: '/pages/auth/login'
|
|
|
- });
|
|
|
- }, 500);
|
|
|
-},
|
|
|
+ methods: {
|
|
|
+ getSafeUserInfo() {
|
|
|
+ try {
|
|
|
+ const userInfoStr = uni.getStorageSync('userInfo');
|
|
|
+ if (!userInfoStr) {
|
|
|
+ this.userinfo = {};
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果是字符串,解析为对象
|
|
|
+ if (typeof userInfoStr === 'string') {
|
|
|
+ this.userinfo = JSON.parse(userInfoStr);
|
|
|
+ } else {
|
|
|
+ // 如果是对象,直接使用
|
|
|
+ this.userinfo = userInfoStr;
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log('获取到的用户信息:', this.userinfo);
|
|
|
+ } catch (error) {
|
|
|
+ console.error('获取用户信息失败:', error);
|
|
|
+ this.userinfo = {};
|
|
|
+ }
|
|
|
+ },
|
|
|
+ redirectToLogin() {
|
|
|
+ // 直接跳转到登录页,不删除token和userInfo
|
|
|
+ uni.navigateTo({
|
|
|
+ url: '/pages/auth/login'
|
|
|
+ });
|
|
|
+ },
|
|
|
async clearPayTypeFun() {
|
|
|
this.payParams && this.payParams.orderId && await clearPayType(this.payParams)
|
|
|
},
|
|
|
@@ -269,11 +256,6 @@
|
|
|
this.getStoreOrderById();
|
|
|
this.getStoreConfig();
|
|
|
this.getUserInfo();
|
|
|
- // uni.showShareMenu({
|
|
|
- // withShareTicket:true,
|
|
|
- // //小程序的原生菜单中显示分享按钮,才能够让发送给朋友与分享到朋友圈两个按钮可以点击
|
|
|
- // menus:["shareAppMessage"] //不设置默认发送给朋友
|
|
|
- // })
|
|
|
} else {
|
|
|
uni.showToast({
|
|
|
icon: 'none',
|
|
|
@@ -399,60 +381,62 @@
|
|
|
// 防抖后的支付方法
|
|
|
// 修复后的支付方法
|
|
|
payOrder() {
|
|
|
- // 1. 安全地获取用户信息
|
|
|
- this.getSafeUserInfo();
|
|
|
-
|
|
|
- // 2. 检查 maOpenId,但不要直接修改字符串
|
|
|
- console.log('支付前检查用户信息:', this.userinfo);
|
|
|
-
|
|
|
- // 3. 检查用户信息是否有效
|
|
|
- if (!this.userinfo || Object.keys(this.userinfo).length === 0) {
|
|
|
- uni.showToast({
|
|
|
- title: '用户信息异常,请重新登录',
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
-
|
|
|
- // 清除 token 并跳转到登录页
|
|
|
- this.clearTokenAndRedirect();
|
|
|
- return;
|
|
|
- }
|
|
|
- // 4. 检查 maOpenId,如果不存在则提示重新登录
|
|
|
- if (!this.userinfo.maOpenId) {
|
|
|
- uni.showModal({
|
|
|
- title: '提示',
|
|
|
- content: '用户信息不完整,需要重新登录',
|
|
|
- success: (res) => {
|
|
|
- if (res.confirm) {
|
|
|
- this.clearTokenAndRedirect();
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- // 5. 检查登录状态
|
|
|
- this.utils.isLogin().then(res => {
|
|
|
- if (res) {
|
|
|
- // 创建防抖函数实例
|
|
|
- const debouncedPay = this.debounce(function() {
|
|
|
- this.executePay();
|
|
|
- }, 1000); // 1秒防抖时间
|
|
|
+ // 1. 安全地获取用户信息
|
|
|
+ this.getSafeUserInfo();
|
|
|
+
|
|
|
+ // 2. 检查 maOpenId,但不要直接修改字符串
|
|
|
+ // 3. 检查用户信息是否有效
|
|
|
+ if (!this.userinfo || Object.keys(this.userinfo).length === 0) {
|
|
|
+ uni.showToast({
|
|
|
+ title: '用户信息异常,请重新登录',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+
|
|
|
+ // 直接跳转到登录页
|
|
|
+ this.redirectToLogin();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 检查 maOpenId,如果不存在则提示重新登录
|
|
|
+ if (!this.userinfo.maOpenId) {
|
|
|
+ uni.showModal({
|
|
|
+ title: '提示',
|
|
|
+ content: '用户信息不完整,需要重新登录',
|
|
|
+ success: (res) => {
|
|
|
+ if (res.confirm) {
|
|
|
+ this.redirectToLogin();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 5. 检查登录状态
|
|
|
+ this.utils.isLogin().then(res => {
|
|
|
+ if (res) {
|
|
|
+ // 创建防抖函数实例
|
|
|
+ const debouncedPay = this.debounce(function() {
|
|
|
+ this.executePay();
|
|
|
+ }, 1000); // 1秒防抖时间
|
|
|
+
|
|
|
+ // 执行防抖函数
|
|
|
+ debouncedPay();
|
|
|
+ } else {
|
|
|
+ // 未登录,直接跳转到登录页
|
|
|
+ this.redirectToLogin();
|
|
|
+ }
|
|
|
+ }).catch(err => {
|
|
|
+ console.error('检查登录状态失败:', err);
|
|
|
+ uni.showToast({
|
|
|
+ title: '登录状态异常',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ // 登录状态异常,也跳转到登录页
|
|
|
+ this.redirectToLogin();
|
|
|
+ });
|
|
|
+ },
|
|
|
|
|
|
- // 执行防抖函数
|
|
|
- debouncedPay();
|
|
|
- } else {
|
|
|
- // 未登录,跳转到登录页
|
|
|
- this.clearTokenAndRedirect();
|
|
|
- }
|
|
|
- }).catch(err => {
|
|
|
- console.error('检查登录状态失败:', err);
|
|
|
- uni.showToast({
|
|
|
- title: '登录状态异常',
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
- });
|
|
|
- }, // 实际的支付执行逻辑
|
|
|
+ // 实际的支付执行逻辑
|
|
|
executePay() {
|
|
|
var data = {
|
|
|
orderId: this.order.id,
|
|
|
@@ -514,70 +498,7 @@
|
|
|
});
|
|
|
}
|
|
|
);
|
|
|
- },
|
|
|
- // payOrder(){
|
|
|
- // var data = {orderId:this.order.id,payType:this.order.payType};
|
|
|
- // var that=this;
|
|
|
- // uni.showLoading();
|
|
|
- // pay(data).then(
|
|
|
- // res => {
|
|
|
- // if(res.code==200){
|
|
|
- // console.log(res);
|
|
|
- // if(res.payType==1||res.payType==2||res.payType==3){
|
|
|
- // uni.requestPayment({
|
|
|
- // provider: 'wxpay',
|
|
|
- // timeStamp: res.result.timeStamp,
|
|
|
- // nonceStr:res.result.nonceStr,
|
|
|
- // package: res.result.packageValue,
|
|
|
- // signType: res.result.signType,
|
|
|
- // paySign: res.result.paySign,
|
|
|
- // success: function(res) {
|
|
|
- // console.log('yess:' + JSON.stringify(res));
|
|
|
- // uni.hideLoading();
|
|
|
- // uni.redirectTo({
|
|
|
- // url:"success?order="+JSON.stringify(that.order)
|
|
|
- // })
|
|
|
- // },
|
|
|
- // fail: function(err) {
|
|
|
- // uni.showToast({
|
|
|
- // icon:'none',
|
|
|
- // title:'fail:' + JSON.stringify(err),
|
|
|
- // });
|
|
|
- // console.log('fail:' + JSON.stringify(err));
|
|
|
- // uni.hideLoading();
|
|
|
- // },
|
|
|
- // complete: (err) => {
|
|
|
- // console.log('fail:' + JSON.stringify(err));
|
|
|
- // }
|
|
|
- // });
|
|
|
- // }
|
|
|
- // // else if(res.payType==3){
|
|
|
- // // uni.hideLoading();
|
|
|
- // // if(that.order.isPrescribe){
|
|
|
- // // //如果是处方订单开处方
|
|
|
- // // uni.redirectTo({
|
|
|
- // // url:"prescribe?orderId="+that.order.id
|
|
|
- // // })
|
|
|
- // // }
|
|
|
- // // else{
|
|
|
- // // //如果是普通订单
|
|
|
- // // uni.redirectTo({
|
|
|
- // // url:"success?order="+JSON.stringify(that.order)
|
|
|
- // // })
|
|
|
- // // }
|
|
|
- // // }
|
|
|
-
|
|
|
- // }else{
|
|
|
- // uni.showToast({
|
|
|
- // icon:'none',
|
|
|
- // title: res.msg,
|
|
|
- // });
|
|
|
- // }
|
|
|
- // },
|
|
|
- // rej => {}
|
|
|
- // );
|
|
|
-
|
|
|
- // }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
</script>
|