|
|
|
@ -23,8 +23,11 @@
|
|
|
|
<view class="section-title">选择支付方式</view>
|
|
|
|
<view class="section-title">选择支付方式</view>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 钱包支付 -->
|
|
|
|
<!-- 钱包支付 -->
|
|
|
|
<view class="payment-item" :class="{ active: selectedPayment === 'wallet' }"
|
|
|
|
<view
|
|
|
|
@click="selectPayment('wallet')">
|
|
|
|
class="payment-item"
|
|
|
|
|
|
|
|
:class="{ active: selectedPayment === 'wallet' }"
|
|
|
|
|
|
|
|
@click="selectPayment('wallet')"
|
|
|
|
|
|
|
|
>
|
|
|
|
<view class="payment-info">
|
|
|
|
<view class="payment-info">
|
|
|
|
<uv-icon name="empty-coupon" color="#07c160" size="24"></uv-icon>
|
|
|
|
<uv-icon name="empty-coupon" color="#07c160" size="24"></uv-icon>
|
|
|
|
<view class="payment-details">
|
|
|
|
<view class="payment-details">
|
|
|
|
@ -32,12 +35,19 @@
|
|
|
|
<text class="payment-desc">余额:¥{{ walletBalance }}</text>
|
|
|
|
<text class="payment-desc">余额:¥{{ walletBalance }}</text>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
<uv-icon name="checkmark-circle-fill" :color="selectedPayment === 'wallet' ? '#ff3333' : '#ccc'"
|
|
|
|
<uv-icon
|
|
|
|
size="20"></uv-icon>
|
|
|
|
name="checkmark-circle-fill"
|
|
|
|
|
|
|
|
:color="selectedPayment === 'wallet' ? '#ff3333' : '#ccc'"
|
|
|
|
|
|
|
|
size="20"
|
|
|
|
|
|
|
|
></uv-icon>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 微信支付 -->
|
|
|
|
<!-- 微信支付 -->
|
|
|
|
<view class="payment-item" :class="{ active: selectedPayment === 'wxpay' }" @click="selectPayment('wxpay')">
|
|
|
|
<view
|
|
|
|
|
|
|
|
class="payment-item"
|
|
|
|
|
|
|
|
:class="{ active: selectedPayment === 'wxpay' }"
|
|
|
|
|
|
|
|
@click="selectPayment('wxpay')"
|
|
|
|
|
|
|
|
>
|
|
|
|
<view class="payment-info">
|
|
|
|
<view class="payment-info">
|
|
|
|
<uv-icon name="weixin-fill" color="#07c160" size="24"></uv-icon>
|
|
|
|
<uv-icon name="weixin-fill" color="#07c160" size="24"></uv-icon>
|
|
|
|
<view class="payment-details">
|
|
|
|
<view class="payment-details">
|
|
|
|
@ -45,28 +55,47 @@
|
|
|
|
<text class="payment-desc">推荐使用微信支付</text>
|
|
|
|
<text class="payment-desc">推荐使用微信支付</text>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
<uv-icon name="checkmark-circle-fill" :color="selectedPayment === 'wxpay' ? '#ff3333' : '#ccc'"
|
|
|
|
<uv-icon
|
|
|
|
size="20"></uv-icon>
|
|
|
|
name="checkmark-circle-fill"
|
|
|
|
|
|
|
|
:color="selectedPayment === 'wxpay' ? '#ff3333' : '#ccc'"
|
|
|
|
|
|
|
|
size="20"
|
|
|
|
|
|
|
|
></uv-icon>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 支付宝支付 - 仅在H5环境显示 -->
|
|
|
|
<!-- 支付宝支付 - 仅在H5环境显示 -->
|
|
|
|
<view v-if="showAlipay" class="payment-item" :class="{ active: selectedPayment === 'alipay' }"
|
|
|
|
<view
|
|
|
|
@click="selectPayment('alipay')">
|
|
|
|
v-if="showAlipay"
|
|
|
|
|
|
|
|
class="payment-item"
|
|
|
|
|
|
|
|
:class="{ active: selectedPayment === 'alipay' }"
|
|
|
|
|
|
|
|
@click="selectPayment('alipay')"
|
|
|
|
|
|
|
|
>
|
|
|
|
<view class="payment-info">
|
|
|
|
<view class="payment-info">
|
|
|
|
<uv-icon name="/static/imgs/alipay.png" color="#1677ff" size="24"></uv-icon>
|
|
|
|
<uv-icon
|
|
|
|
|
|
|
|
name="/static/imgs/alipay.png"
|
|
|
|
|
|
|
|
color="#1677ff"
|
|
|
|
|
|
|
|
size="24"
|
|
|
|
|
|
|
|
></uv-icon>
|
|
|
|
<view class="payment-details">
|
|
|
|
<view class="payment-details">
|
|
|
|
<text class="payment-name">支付宝</text>
|
|
|
|
<text class="payment-name">支付宝</text>
|
|
|
|
<text class="payment-desc">安全便捷的支付方式</text>
|
|
|
|
<text class="payment-desc">安全便捷的支付方式</text>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
<uv-icon name="checkmark-circle-fill" :color="selectedPayment === 'alipay' ? '#ff3333' : '#ccc'"
|
|
|
|
<uv-icon
|
|
|
|
size="20"></uv-icon>
|
|
|
|
name="checkmark-circle-fill"
|
|
|
|
|
|
|
|
:color="selectedPayment === 'alipay' ? '#ff3333' : '#ccc'"
|
|
|
|
|
|
|
|
size="20"
|
|
|
|
|
|
|
|
></uv-icon>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 底部支付按钮 -->
|
|
|
|
<!-- 底部支付按钮 -->
|
|
|
|
<view class="bottom-section">
|
|
|
|
<view class="bottom-section">
|
|
|
|
<uv-button type="primary" size="large" @click="confirmPayment" :loading="paying">
|
|
|
|
<uv-button
|
|
|
|
|
|
|
|
type="primary"
|
|
|
|
|
|
|
|
size="large"
|
|
|
|
|
|
|
|
@click="confirmPayment"
|
|
|
|
|
|
|
|
:loading="paying"
|
|
|
|
|
|
|
|
>
|
|
|
|
立即支付 ¥{{ planPrice }}
|
|
|
|
立即支付 ¥{{ planPrice }}
|
|
|
|
</uv-button>
|
|
|
|
</uv-button>
|
|
|
|
<view class="agreement">
|
|
|
|
<view class="agreement">
|
|
|
|
@ -78,26 +107,17 @@
|
|
|
|
</template>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
<script setup>
|
|
|
|
import {
|
|
|
|
import { ref, onMounted } from "vue";
|
|
|
|
ref,
|
|
|
|
import { onLoad, onShow } from "@dcloudio/uni-app";
|
|
|
|
onMounted
|
|
|
|
import { useAuthStore, useUserStore } from "@/store";
|
|
|
|
} from "vue";
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
|
|
|
onLoad,
|
|
|
|
|
|
|
|
onShow
|
|
|
|
|
|
|
|
} from "@dcloudio/uni-app";
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
|
|
|
useAuthStore,
|
|
|
|
|
|
|
|
useUserStore
|
|
|
|
|
|
|
|
} from "@/store";
|
|
|
|
|
|
|
|
import RPC from "@/utils/request";
|
|
|
|
import RPC from "@/utils/request";
|
|
|
|
|
|
|
|
|
|
|
|
const authStore = useAuthStore();
|
|
|
|
const authStore = useAuthStore();
|
|
|
|
const userStore = useUserStore();
|
|
|
|
const userStore = useUserStore();
|
|
|
|
|
|
|
|
|
|
|
|
// 页面参数
|
|
|
|
// 页面参数
|
|
|
|
const planId = ref('');
|
|
|
|
const planId = ref("");
|
|
|
|
const planName = ref('');
|
|
|
|
const planName = ref("");
|
|
|
|
const planPrice = ref(0);
|
|
|
|
const planPrice = ref(0);
|
|
|
|
|
|
|
|
|
|
|
|
// 响应式数据
|
|
|
|
// 响应式数据
|
|
|
|
@ -109,12 +129,12 @@
|
|
|
|
// 获取钱包余额
|
|
|
|
// 获取钱包余额
|
|
|
|
const getWalletBalance = async () => {
|
|
|
|
const getWalletBalance = async () => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const res = await RPC.post('/membership/user/info', {
|
|
|
|
const res = await RPC.post("/membership/user/info", {
|
|
|
|
user_id: userStore.userInfo.id
|
|
|
|
user_id: userStore.userInfo.id,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
walletBalance.value = res.wallet_balance || 0;
|
|
|
|
walletBalance.value = res.wallet_balance || 0;
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
console.error('获取钱包余额失败:', error);
|
|
|
|
console.error("获取钱包余额失败:", error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
@ -125,8 +145,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
// 页面加载时获取参数
|
|
|
|
// 页面加载时获取参数
|
|
|
|
onLoad((options) => {
|
|
|
|
onLoad((options) => {
|
|
|
|
planId.value = Number(options.planId) || '';
|
|
|
|
planId.value = Number(options.planId) || "";
|
|
|
|
planName.value = decodeURIComponent(options.planName || '');
|
|
|
|
planName.value = decodeURIComponent(options.planName || "");
|
|
|
|
planPrice.value = parseFloat(options.planPrice || 0);
|
|
|
|
planPrice.value = parseFloat(options.planPrice || 0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
@ -164,7 +184,7 @@
|
|
|
|
console.log("微信支付成功:", paymentResult);
|
|
|
|
console.log("微信支付成功:", paymentResult);
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
success: true,
|
|
|
|
success: true,
|
|
|
|
data: paymentResult
|
|
|
|
data: paymentResult,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
console.error("微信支付失败:", error);
|
|
|
|
console.error("微信支付失败:", error);
|
|
|
|
@ -181,7 +201,7 @@
|
|
|
|
window.location.href = payUrl;
|
|
|
|
window.location.href = payUrl;
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
success: true,
|
|
|
|
success: true,
|
|
|
|
redirect: true
|
|
|
|
redirect: true,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
// #endif
|
|
|
|
// #endif
|
|
|
|
};
|
|
|
|
};
|
|
|
|
@ -194,7 +214,7 @@
|
|
|
|
window.location.href = payUrl;
|
|
|
|
window.location.href = payUrl;
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
success: true,
|
|
|
|
success: true,
|
|
|
|
redirect: true
|
|
|
|
redirect: true,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
// #endif
|
|
|
|
// #endif
|
|
|
|
};
|
|
|
|
};
|
|
|
|
@ -208,7 +228,7 @@
|
|
|
|
},
|
|
|
|
},
|
|
|
|
fail: (err) => {
|
|
|
|
fail: (err) => {
|
|
|
|
reject(err);
|
|
|
|
reject(err);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -229,7 +249,7 @@
|
|
|
|
const orderParams = {
|
|
|
|
const orderParams = {
|
|
|
|
user_id: userStore.userInfo?.id,
|
|
|
|
user_id: userStore.userInfo?.id,
|
|
|
|
plan_id: planId.value,
|
|
|
|
plan_id: planId.value,
|
|
|
|
pay_channel: selectedPayment.value
|
|
|
|
pay_channel: selectedPayment.value,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
uni.showLoading({
|
|
|
|
uni.showLoading({
|
|
|
|
@ -237,88 +257,97 @@
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 2. 创建订单
|
|
|
|
// 2. 创建订单
|
|
|
|
const orderNum = await RPC.post('/membership/order/create', orderParams);
|
|
|
|
const orderNum = await RPC.post("/membership/order/create", orderParams);
|
|
|
|
|
|
|
|
|
|
|
|
uni.hideLoading();
|
|
|
|
uni.hideLoading();
|
|
|
|
let orderResult = {}
|
|
|
|
let orderResult = {};
|
|
|
|
|
|
|
|
|
|
|
|
// 3. 根据支付方式调用对应的支付方法
|
|
|
|
// 3. 根据支付方式调用对应的支付方法
|
|
|
|
let paymentResult;
|
|
|
|
let paymentResult;
|
|
|
|
if (selectedPayment.value === "wxpay") {
|
|
|
|
if (selectedPayment.value === "wxpay") {
|
|
|
|
// #ifdef MP-WEIXIN
|
|
|
|
// #ifdef MP-WEIXIN
|
|
|
|
const res = await uni.login({
|
|
|
|
const res = await uni.login({
|
|
|
|
provider: 'weixin'
|
|
|
|
provider: "weixin",
|
|
|
|
})
|
|
|
|
});
|
|
|
|
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": orderNum.order_no
|
|
|
|
order_no: orderNum.order_no,
|
|
|
|
})
|
|
|
|
});
|
|
|
|
// #endif
|
|
|
|
// #endif
|
|
|
|
|
|
|
|
|
|
|
|
// #ifdef H5
|
|
|
|
// #ifdef H5
|
|
|
|
orderResult = await RPC.post('/membership/order/pay_by_wechat_h5', {
|
|
|
|
orderResult = await RPC.post("/membership/order/pay_by_wechat_h5", {
|
|
|
|
"order_no": orderNum.order_no
|
|
|
|
order_no: orderNum.order_no,
|
|
|
|
})
|
|
|
|
});
|
|
|
|
// #endif
|
|
|
|
// #endif
|
|
|
|
|
|
|
|
|
|
|
|
uni.showLoading({
|
|
|
|
uni.showLoading({
|
|
|
|
title: "正在跳转微信支付...",
|
|
|
|
title: "正在跳转微信支付...",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
console.log('orderResult', orderResult)
|
|
|
|
console.log("orderResult", orderResult);
|
|
|
|
paymentResult = await wechatPay(orderResult);
|
|
|
|
paymentResult = await wechatPay(orderResult);
|
|
|
|
} else if (selectedPayment.value === "alipay") {
|
|
|
|
} else if (selectedPayment.value === "alipay") {
|
|
|
|
orderResult = await RPC.post('/membership/order/pay_by_alipay', {
|
|
|
|
orderResult = await RPC.post("/membership/order/pay_by_alipay", {
|
|
|
|
"order_no": orderNum.order_no
|
|
|
|
order_no: orderNum.order_no,
|
|
|
|
})
|
|
|
|
});
|
|
|
|
uni.showLoading({
|
|
|
|
uni.showLoading({
|
|
|
|
title: "正在跳转支付宝...",
|
|
|
|
title: "正在跳转支付宝...",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
console.log('orderResult', orderResult)
|
|
|
|
console.log("orderResult", orderResult);
|
|
|
|
|
|
|
|
// if (1 == 1) {
|
|
|
|
|
|
|
|
// uni.redirectTo({
|
|
|
|
|
|
|
|
// url: `/pagesA/payment-result/payment-result?order_no=${orderNum.order_no}`,
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// uni.hideLoading();
|
|
|
|
|
|
|
|
// return;
|
|
|
|
|
|
|
|
// }
|
|
|
|
paymentResult = await alipayPay(orderResult);
|
|
|
|
paymentResult = await alipayPay(orderResult);
|
|
|
|
} else if (selectedPayment.value === 'wallet') {
|
|
|
|
} else if (selectedPayment.value === "wallet") {
|
|
|
|
const res = await showModalAsync({
|
|
|
|
const res = await showModalAsync({
|
|
|
|
title: '确认支付',
|
|
|
|
title: "确认支付",
|
|
|
|
content: '确认使用钱包余额支付?'
|
|
|
|
content: "确认使用钱包余额支付?",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (res.confirm) {
|
|
|
|
if (res.confirm) {
|
|
|
|
paymentResult = await RPC.post('/membership/order/pay_by_wallet', {
|
|
|
|
paymentResult = await RPC.post("/membership/order/pay_by_wallet", {
|
|
|
|
order_no: orderNum.order_no
|
|
|
|
order_no: orderNum.order_no,
|
|
|
|
})
|
|
|
|
});
|
|
|
|
console.log('paymentResult', paymentResult)
|
|
|
|
console.log("paymentResult", paymentResult);
|
|
|
|
} else if (res.cancel) {
|
|
|
|
} else if (res.cancel) {
|
|
|
|
console.log('用户点击了取消');
|
|
|
|
console.log("用户点击了取消");
|
|
|
|
paymentResult = { success: false }
|
|
|
|
paymentResult = { success: false };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uni.hideLoading();
|
|
|
|
uni.hideLoading();
|
|
|
|
console.log('paymentResult', paymentResult)
|
|
|
|
console.log("paymentResult", paymentResult);
|
|
|
|
|
|
|
|
|
|
|
|
// 4. 处理支付结果
|
|
|
|
// 4. 处理支付结果
|
|
|
|
if (paymentResult?.success) {
|
|
|
|
if (paymentResult?.success) {
|
|
|
|
if (paymentResult.redirect) {
|
|
|
|
if (paymentResult.redirect) {
|
|
|
|
// H5跳转支付,不需要额外处理
|
|
|
|
// H5跳转支付,跳转到支付结果页面查询状态
|
|
|
|
uni.showToast({
|
|
|
|
uni.redirectTo({
|
|
|
|
title: "正在跳转支付页面...",
|
|
|
|
url: `/pagesA/payment-result/payment-result?order_no=${orderNum.order_no}`,
|
|
|
|
icon: "loading",
|
|
|
|
|
|
|
|
duration: 2000,
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 支付成功,跳转到支付结果页面
|
|
|
|
|
|
|
|
// 延迟跳转回上一页或首页
|
|
|
|
// 支付成功
|
|
|
|
// 支付成功
|
|
|
|
setTimeout(() => {
|
|
|
|
setTimeout(() => {
|
|
|
|
uni.showToast({
|
|
|
|
uni.showToast({
|
|
|
|
title: "支付成功",
|
|
|
|
title: "支付成功",
|
|
|
|
icon: "success",
|
|
|
|
icon: "success",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
// 延迟跳转回上一页或首页
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
|
|
uni.navigateBack({
|
|
|
|
|
|
|
|
delta: 2 // 返回到会员页面
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}, 1500);
|
|
|
|
setTimeout(() => {
|
|
|
|
}, 1000)
|
|
|
|
uni.navigateBack();
|
|
|
|
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 支付失败或取消,也跳转到支付结果页面
|
|
|
|
|
|
|
|
uni.redirectTo({
|
|
|
|
|
|
|
|
url: `/pagesA/payment-result/payment-result?order_no=${orderNum.order_no}`,
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
uni.hideLoading();
|
|
|
|
uni.hideLoading();
|
|
|
|
@ -329,7 +358,7 @@
|
|
|
|
} else if (error.message) {
|
|
|
|
} else if (error.message) {
|
|
|
|
errorMessage = error.message;
|
|
|
|
errorMessage = error.message;
|
|
|
|
} else if (error) {
|
|
|
|
} else if (error) {
|
|
|
|
errorMessage = error
|
|
|
|
errorMessage = error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uni.showToast({
|
|
|
|
uni.showToast({
|
|
|
|
|