This commit is contained in:
@@ -2,13 +2,13 @@
|
||||
<up-popup :show="show" mode="center" @close="close">
|
||||
<view class="renewal-popup">
|
||||
<view class="popup-header">
|
||||
<view class="popup-title">立即续费</view>
|
||||
<view class="popup-title">{{ popupTitle }}</view>
|
||||
<view class="popup-close" @tap="close">×</view>
|
||||
</view>
|
||||
|
||||
<view class="package-summary">
|
||||
<view class="summary-label">续费套餐</view>
|
||||
<view class="summary-name">{{ packageNamesText }}</view>
|
||||
<view class="summary-label">{{ summaryLabel }}</view>
|
||||
<view class="summary-name">{{ summaryName }}</view>
|
||||
</view>
|
||||
|
||||
<view class="payment-methods">
|
||||
@@ -33,7 +33,7 @@
|
||||
<view class="popup-footer">
|
||||
<button class="btn-apple btn-secondary" @tap="close">取消</button>
|
||||
<button class="btn-apple btn-primary" :disabled="submitting" @tap="confirmPay">
|
||||
{{ submitting ? '处理中...' : '确认续费' }}
|
||||
{{ submitting ? '处理中...' : confirmText }}
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
@@ -68,8 +68,16 @@
|
||||
const paymentMethod = ref('alipay');
|
||||
const allowedPaymentMethods = ref([]);
|
||||
const assetInfo = ref({});
|
||||
const operationMode = ref('renewal');
|
||||
const orderPaymentId = ref(null);
|
||||
const paymentMethodOptions = computed(() => getPaymentMethodOptions(allowedPaymentMethods.value));
|
||||
const packageNamesText = computed(() => packageNames.value.filter(Boolean).join('、') || '当前套餐');
|
||||
const popupTitle = computed(() => operationMode.value === 'order-payment' ? '立即支付' : '立即续费');
|
||||
const summaryLabel = computed(() => operationMode.value === 'order-payment' ? '支付订单' : '续费套餐');
|
||||
const summaryName = computed(() => operationMode.value === 'order-payment'
|
||||
? packageNamesText.value.replace(/^当前套餐$/, '当前订单')
|
||||
: packageNamesText.value);
|
||||
const confirmText = computed(() => operationMode.value === 'order-payment' ? '确认支付' : '确认续费');
|
||||
|
||||
const hasPreparedPaymentData = (paymentData) => {
|
||||
return isValidWechatPayConfig(paymentData?.pay_config) ||
|
||||
@@ -87,6 +95,8 @@
|
||||
};
|
||||
|
||||
const open = async (ids, names = []) => {
|
||||
operationMode.value = 'renewal';
|
||||
orderPaymentId.value = null;
|
||||
const validIds = [...new Set((Array.isArray(ids) ? ids : [ids])
|
||||
.map((value) => Number(value))
|
||||
.filter((value) => Number.isInteger(value) && value > 0))];
|
||||
@@ -130,6 +140,32 @@
|
||||
show.value = true;
|
||||
};
|
||||
|
||||
const openOrderPayment = async (orderId, names = []) => {
|
||||
if (!orderId) return;
|
||||
if (!props.identifier) {
|
||||
uni.showToast({ title: '未找到当前资产', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
|
||||
operationMode.value = 'order-payment';
|
||||
orderPaymentId.value = orderId;
|
||||
packageIds.value = [];
|
||||
packageNames.value = Array.isArray(names) ? names.filter(Boolean) : [];
|
||||
try {
|
||||
await loadAssetInfo();
|
||||
} catch (error) {
|
||||
console.error('加载订单支付方式失败', error);
|
||||
uni.showToast({ title: error.msg || error.message || '加载支付方式失败', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
|
||||
if (!paymentMethodOptions.value.length) {
|
||||
uni.showToast({ title: '暂无可用支付方式', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
show.value = true;
|
||||
};
|
||||
|
||||
const selectPaymentMethod = (method) => {
|
||||
if (paymentMethodOptions.value.some((item) => item.value === method)) {
|
||||
paymentMethod.value = method;
|
||||
@@ -143,7 +179,7 @@
|
||||
showPaymentToast(status === 2, status === 2 ? '支付成功' : '支付结果确认中');
|
||||
if (status === 2) emit('completed');
|
||||
} catch (error) {
|
||||
console.error('确认续费订单状态失败', error);
|
||||
console.error('确认订单支付状态失败', error);
|
||||
showPaymentToast(false, '支付结果确认失败,请稍后查看订单');
|
||||
}
|
||||
};
|
||||
@@ -209,7 +245,12 @@
|
||||
};
|
||||
|
||||
const confirmPay = async () => {
|
||||
if (submitting.value || !packageIds.value.length) return;
|
||||
if (submitting.value) return;
|
||||
if (operationMode.value === 'order-payment') {
|
||||
await confirmOrderPayment();
|
||||
return;
|
||||
}
|
||||
if (!packageIds.value.length) return;
|
||||
submitting.value = true;
|
||||
uni.showLoading({ title: '创建订单...', mask: true });
|
||||
|
||||
@@ -250,7 +291,50 @@
|
||||
}
|
||||
};
|
||||
|
||||
defineExpose({ open });
|
||||
const confirmOrderPayment = async () => {
|
||||
if (!orderPaymentId.value) return;
|
||||
submitting.value = true;
|
||||
uni.showLoading({ title: '准备支付...', mask: true });
|
||||
|
||||
try {
|
||||
const payData = await orderApi.pay(orderPaymentId.value, paymentMethod.value);
|
||||
uni.hideLoading();
|
||||
show.value = false;
|
||||
|
||||
if (paymentMethod.value === 'wallet') {
|
||||
await confirmOrderStatus(orderPaymentId.value);
|
||||
return;
|
||||
}
|
||||
|
||||
if (paymentMethod.value === 'wechat') {
|
||||
if (!isValidWechatPayConfig(payData?.pay_config)) {
|
||||
uni.showToast({ title: '支付参数获取失败', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await wechatH5Pay(payData.pay_config);
|
||||
await confirmOrderStatus(orderPaymentId.value);
|
||||
} catch (error) {
|
||||
handlePaymentError(error);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isValidAlipayPaymentLink(payData?.payment_link)) {
|
||||
uni.showToast({ title: '支付链接获取失败', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
await openAlipayPayment(payData.payment_link, props.paymentRefreshTarget);
|
||||
} catch (error) {
|
||||
uni.hideLoading();
|
||||
console.error('订单支付失败', error);
|
||||
uni.showToast({ title: error.msg || error.message || '支付失败,请稍后重试', icon: 'none' });
|
||||
} finally {
|
||||
submitting.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
defineExpose({ open, openOrderPayment });
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
Reference in New Issue
Block a user