This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
<view class="flex-col-g20">
|
||||
<view class="iccid">ICCID: {{ item.iccid }}</view>
|
||||
<view class="operator">运营商: {{ getCarrier(item.carrier_type).name }}</view>
|
||||
<view class="slot">卡槽位: {{ item.slot_position || '-' }}</view>
|
||||
<view v-if="item.isDevice" class="slot">卡槽位: {{ item.slot_position || '-' }}</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -81,13 +81,14 @@
|
||||
iccid: card.iccid,
|
||||
carrier_type: card.carrier_type,
|
||||
slot_position: card.slot_position,
|
||||
isDevice: true,
|
||||
isRealName: card.real_name_status === 1
|
||||
})));
|
||||
} else if (assetData.identifier) {
|
||||
} else if (assetData.iccid) {
|
||||
list.splice(0, list.length, {
|
||||
iccid: assetData.identifier,
|
||||
iccid: assetData.iccid,
|
||||
carrier_type: assetData.carrier_type,
|
||||
slot_position: 1,
|
||||
isDevice: false,
|
||||
isRealName: assetData.real_name_status === 1
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
</view>
|
||||
|
||||
<view class="payment-methods">
|
||||
<view class="method-item" :class="{ active: paymentMethod === 'wechat' }" @tap="selectPaymentMethod('wechat')">
|
||||
<view v-if="isDeviceAsset" class="method-item" :class="{ active: paymentMethod === 'wechat' }" @tap="selectPaymentMethod('wechat')">
|
||||
<view class="method-left">
|
||||
<image class="method-icon" src="/static/wechat.png" mode="aspectFit"></image>
|
||||
<text class="method-name">微信支付</text>
|
||||
@@ -67,7 +67,7 @@
|
||||
<view class="method-radio" :class="{ checked: paymentMethod === 'wechat' }"></view>
|
||||
</view>
|
||||
|
||||
<view class="method-item" :class="{ active: paymentMethod === 'alipay' }" @tap="selectPaymentMethod('alipay')">
|
||||
<view v-else class="method-item" :class="{ active: paymentMethod === 'alipay' }" @tap="selectPaymentMethod('alipay')">
|
||||
<view class="method-left">
|
||||
<view class="method-icon method-badge method-badge-alipay">支</view>
|
||||
<text class="method-name">支付宝支付</text>
|
||||
@@ -120,6 +120,8 @@
|
||||
const paymentMethod = ref('wechat');
|
||||
const walletBalance = ref(0);
|
||||
const paySubmitting = ref(false);
|
||||
const isDeviceAsset = ref(true);
|
||||
let assetTypePromise = null;
|
||||
|
||||
const formatMoney = (amount) => {
|
||||
if (!amount && amount !== 0) return '0.00';
|
||||
@@ -133,6 +135,40 @@
|
||||
return `${allowance} ${unit}`;
|
||||
};
|
||||
|
||||
const getDefaultPaymentMethod = () => isDeviceAsset.value ? 'wechat' : 'alipay';
|
||||
|
||||
const isPaymentMethodAvailable = (method) => {
|
||||
if (method === 'wallet') return true;
|
||||
if (method === 'wechat') return isDeviceAsset.value;
|
||||
if (method === 'alipay') return !isDeviceAsset.value;
|
||||
return false;
|
||||
};
|
||||
|
||||
const normalizePaymentMethod = () => {
|
||||
if (!isPaymentMethodAvailable(paymentMethod.value)) {
|
||||
paymentMethod.value = getDefaultPaymentMethod();
|
||||
}
|
||||
};
|
||||
|
||||
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';
|
||||
normalizePaymentMethod();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('加载资产类型失败', error);
|
||||
})
|
||||
.finally(() => {
|
||||
assetTypePromise = null;
|
||||
});
|
||||
|
||||
return assetTypePromise;
|
||||
};
|
||||
|
||||
const loadPackages = async () => {
|
||||
loading.value = true;
|
||||
try {
|
||||
@@ -154,17 +190,20 @@
|
||||
};
|
||||
|
||||
const syncPackagePageState = () => {
|
||||
loadAssetType();
|
||||
loadPackages();
|
||||
loadWalletBalance();
|
||||
};
|
||||
|
||||
const buyPackage = (item) => {
|
||||
const buyPackage = async (item) => {
|
||||
await loadAssetType();
|
||||
currentPackage.value = item;
|
||||
paymentMethod.value = 'wechat';
|
||||
paymentMethod.value = getDefaultPaymentMethod();
|
||||
showModal.value = true;
|
||||
};
|
||||
|
||||
const selectPaymentMethod = (method) => {
|
||||
if (!isPaymentMethodAvailable(method)) return;
|
||||
paymentMethod.value = method;
|
||||
};
|
||||
|
||||
@@ -203,7 +242,9 @@
|
||||
};
|
||||
|
||||
const getCreateOrderPaymentMethod = () => {
|
||||
return paymentMethod.value === 'alipay' ? 'alipay' : undefined;
|
||||
if (paymentMethod.value === 'alipay') return 'alipay';
|
||||
if (paymentMethod.value === 'wallet' && !isDeviceAsset.value) return 'alipay';
|
||||
return undefined;
|
||||
};
|
||||
|
||||
const confirmPay = async () => {
|
||||
|
||||
Reference in New Issue
Block a user