This commit is contained in:
@@ -155,7 +155,7 @@
|
||||
</view>
|
||||
|
||||
<view class="payment-methods">
|
||||
<view class="method-item" :class="{ active: rechargePaymentMethod === 'wechat' }" @tap="selectRechargePaymentMethod('wechat')">
|
||||
<view v-if="isDeviceAsset" class="method-item" :class="{ active: rechargePaymentMethod === 'wechat' }" @tap="selectRechargePaymentMethod('wechat')">
|
||||
<view class="method-left">
|
||||
<image class="method-icon" src="/static/wechat.png" mode="aspectFit"></image>
|
||||
<text class="method-name">微信支付</text>
|
||||
@@ -163,7 +163,7 @@
|
||||
<view class="method-radio" :class="{ checked: rechargePaymentMethod === 'wechat' }"></view>
|
||||
</view>
|
||||
|
||||
<view class="method-item" :class="{ active: rechargePaymentMethod === 'alipay' }" @tap="selectRechargePaymentMethod('alipay')">
|
||||
<view v-else class="method-item" :class="{ active: rechargePaymentMethod === 'alipay' }" @tap="selectRechargePaymentMethod('alipay')">
|
||||
<view class="method-left">
|
||||
<view class="method-icon method-badge method-badge-alipay">支</view>
|
||||
<text class="method-name">支付宝支付</text>
|
||||
@@ -186,9 +186,9 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted } from 'vue';
|
||||
import { ref, reactive, onMounted, computed } from 'vue';
|
||||
import { onShow } from '@dcloudio/uni-app';
|
||||
import { walletApi } from '@/api/index.js';
|
||||
import { assetApi, walletApi } from '@/api/index.js';
|
||||
import { useUserStore } from '@/store/index.js';
|
||||
import {
|
||||
consumePendingPaymentRefresh,
|
||||
@@ -229,10 +229,13 @@
|
||||
const rechargePaymentMethod = ref('wechat');
|
||||
const rechargeSubmitting = ref(false);
|
||||
const rechargeOrderSubmittingKey = ref(null);
|
||||
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' }
|
||||
]);
|
||||
const rechargeAmounts = [
|
||||
{ value: 1000, label: '10' },
|
||||
{ value: 2000, label: '20' },
|
||||
@@ -305,6 +308,34 @@
|
||||
return rechargeOrderSubmittingKey.value === getRechargeOrderSubmitKey(rechargeOrder);
|
||||
};
|
||||
|
||||
const getDefaultRechargePaymentMethod = () => isDeviceAsset.value ? 'wechat' : 'alipay';
|
||||
|
||||
const normalizeRechargePaymentMethod = () => {
|
||||
const defaultMethod = getDefaultRechargePaymentMethod();
|
||||
if (rechargePaymentMethod.value !== defaultMethod) {
|
||||
rechargePaymentMethod.value = defaultMethod;
|
||||
}
|
||||
};
|
||||
|
||||
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';
|
||||
normalizeRechargePaymentMethod();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('加载资产类型失败', error);
|
||||
})
|
||||
.finally(() => {
|
||||
assetTypePromise = null;
|
||||
});
|
||||
|
||||
return assetTypePromise;
|
||||
};
|
||||
|
||||
const resetRechargeListAndLoad = () => {
|
||||
rechargePage.value = 1;
|
||||
rechargeNoMore.value = false;
|
||||
@@ -318,6 +349,7 @@
|
||||
};
|
||||
|
||||
const syncWalletStatus = () => {
|
||||
loadAssetType();
|
||||
loadWalletDetail();
|
||||
resetRechargeListAndLoad();
|
||||
resetTransactionListAndLoad();
|
||||
@@ -337,8 +369,9 @@
|
||||
}, 3000);
|
||||
};
|
||||
|
||||
const openRechargeModal = () => {
|
||||
rechargePaymentMethod.value = 'wechat';
|
||||
const openRechargeModal = async () => {
|
||||
await loadAssetType();
|
||||
rechargePaymentMethod.value = getDefaultRechargePaymentMethod();
|
||||
showRechargeModal.value = true;
|
||||
};
|
||||
|
||||
@@ -354,6 +387,7 @@
|
||||
};
|
||||
|
||||
const selectRechargePaymentMethod = (method) => {
|
||||
if (method !== getDefaultRechargePaymentMethod()) return;
|
||||
rechargePaymentMethod.value = method;
|
||||
};
|
||||
|
||||
@@ -602,13 +636,15 @@
|
||||
}
|
||||
};
|
||||
|
||||
const showRechargePaymentMethods = (rechargeOrder) => {
|
||||
const showRechargePaymentMethods = async (rechargeOrder) => {
|
||||
if (rechargeOrderSubmittingKey.value !== null) 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) {
|
||||
handleRechargePayment(rechargeOrder, selectedMethod);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user