支付位置修改

main
Lufaneng 10 months ago
parent 26be228f0a
commit 2a0fa0836d

@ -100,6 +100,13 @@
{ {
"navigationBarTitleText" : "充值" "navigationBarTitleText" : "充值"
} }
},
{
"path" : "payment/payment",
"style" :
{
"navigationBarTitleText" : "确认支付"
}
} }
] ]
} }

File diff suppressed because it is too large Load Diff

@ -2,7 +2,7 @@
<view class="container"> <view class="container">
<uv-sticky bgColor="#fff" :offsetTop="isWeChatH5 ? -50 : 0"> <uv-sticky bgColor="#fff" :offsetTop="isWeChatH5 ? -50 : 0">
<div class="tabBox"> <div class="tabBox">
<div class="tabItem" :class="{selected:active==='全部'}" @click="switchTab('全部')"></div> <div class="tabItem" :class="{selected:active==='全部'}" @click="switchTab('全部')"></div>
<div class="tabItem" :class="{selected:active==='图纸生成'}" @click="switchTab('图纸生成')"></div> <div class="tabItem" :class="{selected:active==='图纸生成'}" @click="switchTab('图纸生成')"></div>
<div class="tabItem" :class="{selected:active==='会员购买'}" @click="switchTab('会员购买')"></div> <div class="tabItem" :class="{selected:active==='会员购买'}" @click="switchTab('会员购买')"></div>
<div class="tabItem" :class="{selected:active==='钱包充值'}" @click="switchTab('钱包充值')"></div> <div class="tabItem" :class="{selected:active==='钱包充值'}" @click="switchTab('钱包充值')"></div>
@ -124,7 +124,7 @@
import HeaderCustom from '/components/HeaderCustom/HeaderCustom.vue' import HeaderCustom from '/components/HeaderCustom/HeaderCustom.vue'
import RPC from "@/utils/request"; import RPC from "@/utils/request";
import dayjs from "dayjs"; import dayjs from "dayjs";
const isWeChatH5 = ref(false) const isWeChatH5 = ref(false)
// #ifdef H5 // #ifdef H5
if (navigator.userAgent.toLowerCase().indexOf('micromessenger') !== -1) { if (navigator.userAgent.toLowerCase().indexOf('micromessenger') !== -1) {
@ -315,40 +315,12 @@
// #ifdef H5 // #ifdef H5
// H5 // H5
if (typeof WeixinJSBridge !== "undefined") { const payUrl = orderInfo.mwebUrl; // H5
return new Promise((resolve, reject) => { window.location.href = payUrl;
WeixinJSBridge.invoke( return {
"getBrandWCPayRequest", { success: true,
appId: 'wxc504638e03981812', redirect: true
timeStamp: orderInfo.timeStamp, };
nonceStr: orderInfo.nonceStr,
package: orderInfo.package,
signType: orderInfo.signType,
paySign: orderInfo.paySign,
},
(res) => {
if (res.err_msg === "get_brand_wcpay_request:ok") {
resolve({
success: true,
data: res
});
} else if (res.err_msg === "get_brand_wcpay_request:cancel") {
reject(new Error("用户取消支付"));
} else {
reject(new Error("微信支付失败"));
}
}
);
});
} else {
//
const payUrl = orderInfo.mwebUrl; // H5
window.location.href = payUrl;
return {
success: true,
redirect: true
};
}
// #endif // #endif
}; };
@ -390,13 +362,22 @@
let paymentResult; let paymentResult;
if (order.pay_channel === "wxpay") { if (order.pay_channel === "wxpay") {
// #ifdef MP-WEIXIN
const res = await uni.login({ const res = await uni.login({
provider: 'weixin' provider: 'weixin'
}) })
const orderResult = await RPC.post('/membership/order/pay_by_wechat_mini', { orderResult = await RPC.post('/membership/order/pay_by_wechat_mini', {
code: res.code, code: res.code,
"order_no": order.order_no "order_no": orderNum.order_no
})
// #endif
// #ifdef H5
orderResult = await RPC.post('/membership/order/pay_by_wechat_h5', {
"order_no": orderNum.order_no
}) })
// #endif
uni.showLoading({ uni.showLoading({
title: "正在跳转微信支付...", title: "正在跳转微信支付...",
}); });
@ -411,6 +392,7 @@
}); });
paymentResult = await alipayPay(orderResult); paymentResult = await alipayPay(orderResult);
} else if (order.pay_channel === 'wallet') { } else if (order.pay_channel === 'wallet') {
uni.hideLoading()
const res = await showModalAsync({ const res = await showModalAsync({
title: '确认支付', title: '确认支付',
content: '确认使用钱包余额支付?' content: '确认使用钱包余额支付?'

@ -37,7 +37,7 @@
<view class="profile-item" @click="changePhone"> <view class="profile-item" @click="changePhone">
<view class="item-label">手机号</view> <view class="item-label">手机号</view>
<view class="item-content"> <view class="item-content">
<text class="item-value">{{ userStore.userInfo.phone }}</text> <text class="item-value">{{ userStore.userInfo.phone }}</text>
<uv-icon name="arrow-right" size="16" color="#ccc"></uv-icon> <uv-icon name="arrow-right" size="16" color="#ccc"></uv-icon>
</view> </view>
</view> </view>
@ -45,17 +45,8 @@
<!-- 应用设置 --> <!-- 应用设置 -->
<view class="app-section"> <!-- <view class="app-section">
<!-- 缓存 -->
<!-- <view class="profile-item" @click="clearCache">
<view class="item-label">缓存</view>
<view class="item-content">
<text class="item-value">{{ cacheSize }}</text>
<uv-icon name="arrow-right" size="16" color="#ccc"></uv-icon>
</view>
</view> -->
<!-- 用户协议 -->
<view class="profile-item" @click="viewUserAgreement"> <view class="profile-item" @click="viewUserAgreement">
<view class="item-label">用户协议</view> <view class="item-label">用户协议</view>
<view class="item-content"> <view class="item-content">
@ -63,21 +54,20 @@
</view> </view>
</view> </view>
<!-- 关于我们 -->
<view class="profile-item" @click="viewAbout"> <view class="profile-item" @click="viewAbout">
<view class="item-label">关于我们</view> <view class="item-label">关于我们</view>
<view class="item-content"> <view class="item-content">
<uv-icon name="arrow-right" size="16" color="#ccc"></uv-icon> <uv-icon name="arrow-right" size="16" color="#ccc"></uv-icon>
</view> </view>
</view> </view>
</view> </view> -->
<!-- 退出登录按钮 --> <!-- 退出登录按钮 -->
<view class="logout-section"> <!-- <view class="logout-section">
<uv-button type="primary" size="large" @click="logout" :loading="logoutLoading"> <uv-button type="primary" size="large" @click="logout" :loading="logoutLoading">
退出登录 退出登录
</uv-button> </uv-button>
</view> </view> -->
<!-- 编辑弹窗 --> <!-- 编辑弹窗 -->
<uv-popup ref="editPopup" mode="center" @close="closeEditModal" :round="10"> <uv-popup ref="editPopup" mode="center" @close="closeEditModal" :round="10">
@ -463,14 +453,14 @@
const bindPhoneInfo = ref({ const bindPhoneInfo = ref({
phone: "", phone: "",
code: "", code: "",
}); });
const changePhone = () => { const changePhone = () => {
bindPhoneInfo.value = { bindPhoneInfo.value = {
phone: "", phone: "",
code: "", code: "",
} }
popup.value.open() popup.value.open()
} }
const bindPhoneRules = ref({ const bindPhoneRules = ref({
phone: [{ phone: [{
@ -489,98 +479,98 @@
message: "请输入验证码", message: "请输入验证码",
trigger: ["blur", "change"], trigger: ["blur", "change"],
}, },
}); });
const bindCodeChange = (text) => { const bindCodeChange = (text) => {
bindCodeTips.value = text; bindCodeTips.value = text;
}; };
const closeBindPhoneModal = () => { const closeBindPhoneModal = () => {
popup.value.close(); popup.value.close();
bindPhoneInfo.value = { bindPhoneInfo.value = {
phone: "", phone: "",
code: "", code: "",
}; };
bindCodeTips.value = "获取验证码"; bindCodeTips.value = "获取验证码";
}; };
const confirmBindPhone = async () => { const confirmBindPhone = async () => {
try { try {
await bindPhoneForm.value.validate(); await bindPhoneForm.value.validate();
bindingPhone.value = true; bindingPhone.value = true;
// API // API
RPC.post('/user/bind_phone', { RPC.post('/user/bind_phone', {
phone: bindPhoneInfo.value.phone, phone: bindPhoneInfo.value.phone,
code: bindPhoneInfo.value.code, code: bindPhoneInfo.value.code,
token: authStore.accessToken token: authStore.accessToken
}).then((res) => { }).then((res) => {
console.log('bind_phone', res) console.log('bind_phone', res)
bindingPhone.value = false; bindingPhone.value = false;
uni.showToast({ uni.showToast({
title: "换绑成功", title: "换绑成功",
icon: "success", icon: "success",
}); });
popup.value.close() popup.value.close()
RPC.post('/user/info', { RPC.post('/user/info', {
token: authStore.accessToken, token: authStore.accessToken,
}) })
.then((res) => { .then((res) => {
userStore.setUserInfo(res) userStore.setUserInfo(res)
}) })
}) })
} catch (error) { } catch (error) {
console.error("换绑手机号失败:", error); console.error("换绑手机号失败:", error);
bindingPhone.value = false; bindingPhone.value = false;
} }
}; };
const getBindCode = () => { const getBindCode = () => {
if (!bindPhoneInfo.value.phone) { if (!bindPhoneInfo.value.phone) {
uni.showToast({ uni.showToast({
title: "请输入手机号", title: "请输入手机号",
icon: "none", icon: "none",
}); });
return; return;
} }
if (!/^1[3-9]\d{9}$/.test(bindPhoneInfo.value.phone)) { if (!/^1[3-9]\d{9}$/.test(bindPhoneInfo.value.phone)) {
uni.showToast({ uni.showToast({
title: "请输入正确的手机号", title: "请输入正确的手机号",
icon: "none", icon: "none",
}); });
return; return;
} }
if (bindCodeRef.value.canGetCode) { if (bindCodeRef.value.canGetCode) {
uni.showLoading({ uni.showLoading({
title: "正在获取验证码", title: "正在获取验证码",
}); });
// API // API
RPC.post('/user/bind_phone/send_code', { RPC.post('/user/bind_phone/send_code', {
phone: bindPhoneInfo.value.phone, phone: bindPhoneInfo.value.phone,
token: authStore.accessToken token: authStore.accessToken
}).then(() => { }).then(() => {
uni.hideLoading() uni.hideLoading()
uni.showToast({ uni.showToast({
title: '验证码已发送', title: '验证码已发送',
icon: 'success' icon: 'success'
}) })
bindCodeRef.value.start() bindCodeRef.value.start()
}).catch(() => { }).catch(() => {
uni.hideLoading() uni.hideLoading()
uni.showToast({ uni.showToast({
title: '发送失败,请重试', title: '发送失败,请重试',
icon: 'none' icon: 'none'
}) })
}) })
} else { } else {
uni.showToast({ uni.showToast({
title: "倒计时结束后再发送", title: "倒计时结束后再发送",
icon: "none", icon: "none",
}); });
} }
}; };
</script> </script>
@ -707,43 +697,43 @@
.sheet-cancel { .sheet-cancel {
margin-top: 10px; margin-top: 10px;
} }
} }
.bind-phone-modal { .bind-phone-modal {
width: 320px; width: 320px;
padding: 24px; padding: 24px;
.modal-header { .modal-header {
text-align: center; text-align: center;
margin-bottom: 24px; margin-bottom: 24px;
.modal-title { .modal-title {
font-size: 18px; font-size: 18px;
font-weight: bold; font-weight: bold;
color: #333; color: #333;
margin-bottom: 8px; margin-bottom: 8px;
} }
.modal-subtitle { .modal-subtitle {
font-size: 14px; font-size: 14px;
color: #666; color: #666;
} }
} }
.modal-form { .modal-form {
margin-bottom: 24px; margin-bottom: 24px;
.uv-form-item { .uv-form-item {
margin-bottom: 16px; margin-bottom: 16px;
} }
} }
.modal-actions { .modal-actions {
display: flex; display: flex;
gap: 12px; gap: 12px;
.uv-button { .uv-button {
flex: 1; flex: 1;
} }
} }
} }
</style> </style>

@ -0,0 +1,510 @@
<template>
<view class="container">
<!-- 顶部导航 -->
<!-- <view class="header">
<view class="header-title">确认支付</view>
</view> -->
<!-- 订单信息 -->
<view class="order-info">
<view class="order-title">订单详情</view>
<view class="order-item">
<view class="item-name">{{ planName }}</view>
<view class="item-price">¥{{ planPrice }}</view>
</view>
<!-- <view class="order-total">
<text class="total-label">合计</text>
<text class="total-price">¥{{ planPrice }}</text>
</view> -->
</view>
<!-- 支付方式 -->
<view class="payment-section">
<view class="section-title">选择支付方式</view>
<!-- 钱包支付 -->
<view class="payment-item" :class="{ active: selectedPayment === 'wallet' }"
@click="selectPayment('wallet')">
<view class="payment-info">
<uv-icon name="empty-coupon" color="#07c160" size="24"></uv-icon>
<view class="payment-details">
<text class="payment-name">钱包支付</text>
<text class="payment-desc">余额¥{{ walletBalance }}</text>
</view>
</view>
<uv-icon name="checkmark-circle-fill" :color="selectedPayment === 'wallet' ? '#ff3333' : '#ccc'"
size="20"></uv-icon>
</view>
<!-- 微信支付 -->
<view class="payment-item" :class="{ active: selectedPayment === 'wxpay' }" @click="selectPayment('wxpay')">
<view class="payment-info">
<uv-icon name="weixin-fill" color="#07c160" size="24"></uv-icon>
<view class="payment-details">
<text class="payment-name">微信支付</text>
<text class="payment-desc">推荐使用微信支付</text>
</view>
</view>
<uv-icon name="checkmark-circle-fill" :color="selectedPayment === 'wxpay' ? '#ff3333' : '#ccc'"
size="20"></uv-icon>
</view>
<!-- 支付宝支付 - 仅在H5环境显示 -->
<view v-if="showAlipay" class="payment-item" :class="{ active: selectedPayment === 'alipay' }"
@click="selectPayment('alipay')">
<view class="payment-info">
<uv-icon name="/static/imgs/alipay.png" color="#1677ff" size="24"></uv-icon>
<view class="payment-details">
<text class="payment-name">支付宝</text>
<text class="payment-desc">安全便捷的支付方式</text>
</view>
</view>
<uv-icon name="checkmark-circle-fill" :color="selectedPayment === 'alipay' ? '#ff3333' : '#ccc'"
size="20"></uv-icon>
</view>
</view>
<!-- 底部支付按钮 -->
<view class="bottom-section">
<uv-button type="primary" size="large" @click="confirmPayment" :loading="paying">
立即支付 ¥{{ planPrice }}
</uv-button>
<view class="agreement">
支付即表示同意
<text class="link" @click="showAgreement"></text>
</view>
</view>
</view>
</template>
<script setup>
import {
ref,
onMounted
} from "vue";
import {
onLoad,
onShow
} from "@dcloudio/uni-app";
import {
useAuthStore,
useUserStore
} from "@/store";
import RPC from "@/utils/request";
const authStore = useAuthStore();
const userStore = useUserStore();
//
const planId = ref('');
const planName = ref('');
const planPrice = ref(0);
//
const selectedPayment = ref("wxpay"); //
const paying = ref(false);
const showAlipay = ref(true); //
const walletBalance = ref(0);
//
const getWalletBalance = async () => {
try {
const res = await RPC.post('/membership/user/info', {
user_id: userStore.userInfo.id
});
walletBalance.value = res.wallet_balance || 0;
} catch (error) {
console.error('获取钱包余额失败:', error);
}
};
//
const selectPayment = (payment) => {
selectedPayment.value = payment;
};
//
onLoad((options) => {
planId.value = Number(options.planId) || '';
planName.value = decodeURIComponent(options.planName || '');
planPrice.value = parseFloat(options.planPrice || 0);
});
onShow(() => {
getWalletBalance();
});
//
const checkEnvironment = () => {
// #ifdef MP-WEIXIN
//
showAlipay.value = false;
// #endif
// #ifdef H5
// H5
showAlipay.value = true;
// #endif
};
//
const wechatPay = async (orderInfo) => {
// #ifdef MP-WEIXIN
//
try {
const paymentResult = await uni.requestPayment({
provider: "wxpay",
timeStamp: orderInfo.timeStamp,
nonceStr: orderInfo.nonceStr,
package: orderInfo.package,
signType: orderInfo.signType,
paySign: orderInfo.paySign,
});
console.log("微信支付成功:", paymentResult);
return {
success: true,
data: paymentResult
};
} catch (error) {
console.error("微信支付失败:", error);
if (error.errMsg === "requestPayment:fail cancel") {
throw new Error("用户取消支付");
}
throw new Error("微信支付失败");
}
// #endif
// #ifdef H5
// H5
const payUrl = orderInfo.mwebUrl; // H5
window.location.href = payUrl;
return {
success: true,
redirect: true
};
// #endif
};
// H5
const alipayPay = async (orderInfo) => {
// #ifdef H5
// H5
const payUrl = orderInfo.pay_url; // H5
window.location.href = payUrl;
return {
success: true,
redirect: true
};
// #endif
};
function showModalAsync(options) {
return new Promise((resolve, reject) => {
uni.showModal({
...options,
success: (res) => {
resolve(res);
},
fail: (err) => {
reject(err);
}
});
});
}
//
const confirmPayment = async () => {
if (!selectedPayment.value) {
uni.showToast({
title: "请选择支付方式",
icon: "none",
});
return;
}
paying.value = true;
try {
// 1.
const orderParams = {
user_id: userStore.userInfo?.id,
plan_id: planId.value,
pay_channel: selectedPayment.value
};
uni.showLoading({
title: "正在创建订单...",
});
// 2.
const orderNum = await RPC.post('/membership/order/create', orderParams);
uni.hideLoading();
let orderResult = {}
// 3.
let paymentResult;
if (selectedPayment.value === "wxpay") {
// #ifdef MP-WEIXIN
const res = await uni.login({
provider: 'weixin'
})
orderResult = await RPC.post('/membership/order/pay_by_wechat_mini', {
code: res.code,
"order_no": orderNum.order_no
})
// #endif
// #ifdef H5
orderResult = await RPC.post('/membership/order/pay_by_wechat_h5', {
"order_no": orderNum.order_no
})
// #endif
uni.showLoading({
title: "正在跳转微信支付...",
});
console.log('orderResult', orderResult)
paymentResult = await wechatPay(orderResult);
} else if (selectedPayment.value === "alipay") {
orderResult = await RPC.post('/membership/order/pay_by_alipay', {
"order_no": orderNum.order_no
})
uni.showLoading({
title: "正在跳转支付宝...",
});
console.log('orderResult', orderResult)
paymentResult = await alipayPay(orderResult);
} else if (selectedPayment.value === 'wallet') {
const res = await showModalAsync({
title: '确认支付',
content: '确认使用钱包余额支付?'
});
if (res.confirm) {
paymentResult = await RPC.post('/membership/order/pay_by_wallet', {
order_no: orderNum.order_no
})
console.log('paymentResult', paymentResult)
} else if (res.cancel) {
console.log('用户点击了取消');
paymentResult = { success: false }
}
}
uni.hideLoading();
console.log('paymentResult', paymentResult)
// 4.
if (paymentResult?.success) {
if (paymentResult.redirect) {
// H5
uni.showToast({
title: "正在跳转支付页面...",
icon: "loading",
duration: 2000,
});
} else {
//
setTimeout(() => {
uni.showToast({
title: "支付成功",
icon: "success",
});
//
setTimeout(() => {
uni.navigateBack({
delta: 2 //
});
}, 1500);
}, 1000)
}
}
} catch (error) {
uni.hideLoading();
console.error("支付失败:", error);
let errorMessage = "支付失败,请重试";
if (error.message === "用户取消支付") {
errorMessage = "支付已取消";
} else if (error.message) {
errorMessage = error.message;
} else if (error) {
errorMessage = error
}
uni.showToast({
title: errorMessage,
icon: "none",
});
} finally {
paying.value = false;
}
};
//
const showAgreement = () => {
uni.navigateTo({
url: "/pagesA/user-agreement/user-agreement",
});
};
onMounted(() => {
checkEnvironment();
});
</script>
<style lang="scss" scoped>
.container {
font-size: 14px;
background-color: #f8f8f8;
min-height: 100vh;
padding-bottom: 120px;
}
.header {
background: white;
padding: 20px 16px;
border-bottom: 1px solid #f0f0f0;
.header-title {
font-size: 18px;
font-weight: 500;
color: #333;
text-align: center;
}
}
.order-info {
background: white;
margin: 16px;
border-radius: 12px;
padding: 16px;
.order-title {
font-size: 16px;
font-weight: 500;
color: #333;
margin-bottom: 16px;
}
.order-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 12px 0;
border-bottom: 1px solid #f0f0f0;
.item-name {
font-size: 14px;
color: #333;
}
.item-price {
font-size: 16px;
font-weight: 500;
color: #ff3333;
}
}
.order-total {
display: flex;
justify-content: flex-end;
align-items: center;
padding: 12px 0 0;
.total-label {
font-size: 14px;
color: #666;
margin-right: 8px;
}
.total-price {
font-size: 18px;
font-weight: bold;
color: #ff3333;
}
}
}
.payment-section {
background: white;
margin: 0 16px 16px;
border-radius: 12px;
padding: 16px;
.section-title {
font-size: 16px;
font-weight: 500;
color: #333;
margin-bottom: 16px;
}
.payment-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 16px;
margin-bottom: 8px;
border: 1px solid #e5e5e5;
border-radius: 8px;
transition: all 0.3s;
&.active {
border-color: #4285f4;
background-color: #f0f7ff;
}
&:last-child {
margin-bottom: 0;
}
.payment-info {
display: flex;
align-items: center;
gap: 12px;
.payment-details {
display: flex;
flex-direction: column;
.payment-name {
font-size: 14px;
color: #333;
margin-bottom: 2px;
}
.payment-desc {
font-size: 12px;
color: #999;
}
}
}
}
}
.bottom-section {
position: fixed;
bottom: 0;
left: 0;
right: 0;
background: white;
padding: 16px;
border-top: 1px solid #e5e5e5;
/* #ifdef H5 */
bottom: 50px;
/* H5环境下给tabBar留出空间 */
/* #endif */
.agreement {
text-align: center;
font-size: 12px;
color: #999;
margin-top: 12px;
.link {
color: #4285f4;
}
}
}
</style>
Loading…
Cancel
Save