diff --git a/components/RenewalPaymentPopup.vue b/components/RenewalPaymentPopup.vue index d4a57bc..d5e5ee1 100644 --- a/components/RenewalPaymentPopup.vue +++ b/components/RenewalPaymentPopup.vue @@ -2,13 +2,13 @@ - 立即续费 + {{ popupTitle }} × - 续费套餐 - {{ packageNamesText }} + {{ summaryLabel }} + {{ summaryName }} @@ -33,7 +33,7 @@ @@ -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 }); diff --git a/pages/package-order/package-order.vue b/pages/package-order/package-order.vue index 6f13c9e..d01f9b9 100644 --- a/pages/package-order/package-order.vue +++ b/pages/package-order/package-order.vue @@ -28,7 +28,7 @@ - 可用流量 + 套餐流量 {{ formatData(item.data_allowance, item.data_unit) }} @@ -36,7 +36,6 @@ {{ formatPackagePrice(item.retail_price) }} - {{ item.description }} 立即订购 @@ -56,7 +55,7 @@ ¥{{ formatPackagePrice(currentPackage?.retail_price) }} - 可用流量 + 套餐流量 {{ formatData(currentPackage?.data_allowance, currentPackage?.data_unit) }} @@ -672,13 +671,6 @@ } } - .package-desc { - font-size: 24rpx; - color: var(--text-secondary); - line-height: 1.5; - margin-bottom: 22rpx; - } - .package-footer { display: block; padding-top: 22rpx; diff --git a/static/wallet.png b/static/wallet.png index 0bd448f..76d8542 100644 Binary files a/static/wallet.png and b/static/wallet.png differ diff --git a/static/微信支付.png b/static/微信支付.png index b8b4b8a..32b33e7 100644 Binary files a/static/微信支付.png and b/static/微信支付.png differ diff --git a/static/支付宝支付.png b/static/支付宝支付.png index 2e94c13..ab982d0 100644 Binary files a/static/支付宝支付.png and b/static/支付宝支付.png differ diff --git a/static/有效期.png b/static/有效期.png new file mode 100644 index 0000000..c599f1f Binary files /dev/null and b/static/有效期.png differ diff --git a/static/流量.png b/static/流量.png new file mode 100644 index 0000000..5fdbf29 Binary files /dev/null and b/static/流量.png differ