fix: pay
All checks were successful
构建并部署前端到生产环境 / build-and-deploy (push) Successful in 56s

This commit is contained in:
luo
2026-07-03 09:07:28 +08:00
parent 6756ad5700
commit a9fbbea1e6
7 changed files with 144 additions and 35 deletions

View File

@@ -73,9 +73,9 @@
</template>
<script setup>
import { ref, reactive, onMounted } from 'vue';
import { ref, reactive, onMounted, computed } from 'vue';
import { onShow } from '@dcloudio/uni-app';
import { orderApi } from '@/api/index.js';
import { assetApi, orderApi } from '@/api/index.js';
import { useUserStore } from '@/store/index.js';
import {
consumePendingPaymentRefresh,
@@ -97,10 +97,14 @@
const orderPayingId = ref(null);
const pageSize = 10;
const filterIndex = ref(0);
const paymentMethodOptions = [
{ label: '微信支付', value: 'wechat' },
{ label: '支付宝支付', value: 'alipay' }
];
const isDeviceAsset = ref(true);
let assetTypePromise = null;
const paymentMethodOptions = computed(() => [
isDeviceAsset.value
? { label: '微信支付', value: 'wechat' }
: { label: '支付宝支付', value: 'alipay' },
{ label: '钱包支付', value: 'wallet' }
]);
const filterOptions = [
{ label: '全部', value: null },
{ label: '待支付', value: 1 },
@@ -124,6 +128,24 @@
return classMap[status] || '';
};
const loadAssetType = async () => {
if (!userStore.state.identifier) return;
if (assetTypePromise) return assetTypePromise;
assetTypePromise = assetApi.getInfo(userStore.state.identifier)
.then((data) => {
isDeviceAsset.value = data.asset_type === 'device';
})
.catch((error) => {
console.error('加载资产类型失败', error);
})
.finally(() => {
assetTypePromise = null;
});
return assetTypePromise;
};
const resetOrderListAndLoad = () => {
page.value = 1;
noMore.value = false;
@@ -203,13 +225,15 @@
const isOrderPaying = (order) => orderPayingId.value === order.order_id;
const showOrderPaymentMethods = (order) => {
const showOrderPaymentMethods = async (order) => {
if (orderPayingId.value !== null || !order?.order_id) return;
await loadAssetType();
const options = paymentMethodOptions.value;
uni.showActionSheet({
itemList: paymentMethodOptions.map((item) => item.label),
itemList: options.map((item) => item.label),
success: ({ tapIndex }) => {
const selectedMethod = paymentMethodOptions[tapIndex]?.value;
const selectedMethod = options[tapIndex]?.value;
if (selectedMethod) {
handleOrderPayment(order, selectedMethod);
}
@@ -230,6 +254,14 @@
const payData = await orderApi.pay(order.order_id, paymentMethod);
uni.hideLoading();
if (paymentMethod === 'wallet') {
showPaymentToast(true, '支付成功');
setTimeout(() => {
resetOrderListAndLoad();
}, 1500);
return;
}
if (paymentMethod === 'wechat') {
if (!isValidWechatPayConfig(payData?.pay_config)) {
uni.showToast({
@@ -281,6 +313,7 @@
});
onMounted(() => {
loadAssetType();
loadOrderList();
});
</script>