Browse Source

fix(account): keep actionable traffic orders after payment start

main
xiaosi 3 weeks ago
parent
commit
dd45413f34
  1. 20
      src/views/AccountView/AccountView.vue

20
src/views/AccountView/AccountView.vue

@ -87,18 +87,18 @@
<template #content="{ row }">{{ orderContentLabel(row) }}</template> <template #content="{ row }">{{ orderContentLabel(row) }}</template>
<template #unitPrice="{ row }">{{ money(row.unitPrice) }}</template> <template #unitPrice="{ row }">{{ money(row.unitPrice) }}</template>
<template #totalPrice="{ row }"><strong>{{ money(row.totalPrice) }}</strong></template> <template #totalPrice="{ row }"><strong>{{ money(row.totalPrice) }}</strong></template>
<template #payStatus="{ row }"><em :class="{ processing: row.payStatus === 'unpaid' }">{{ payStatusName(row.payStatus) }}</em></template>
<template #payStatus="{ row }"><em :class="{ processing: row.payStatus === 'unpaid' || row.payStatus === 'processing' }">{{ payStatusName(row.payStatus) }}</em></template>
<template #createdAt="{ row }">{{ fmtTime(row.createdAt) }}</template> <template #createdAt="{ row }">{{ fmtTime(row.createdAt) }}</template>
<template #actions="{ row }"> <template #actions="{ row }">
<t-button <t-button
v-if="row.payStatus === 'unpaid'"
v-if="isTrafficOrderActionable(row)"
variant="text" variant="text"
theme="primary" theme="primary"
:loading="payingOrderId === row.id" :loading="payingOrderId === row.id"
@click="payTrafficOrder(row)" @click="payTrafficOrder(row)"
>去支付</t-button> >去支付</t-button>
<t-button <t-button
v-if="row.payStatus === 'unpaid'"
v-if="isTrafficOrderActionable(row)"
variant="text" variant="text"
theme="danger" theme="danger"
@click="cancelTrafficOrder(row.id)" @click="cancelTrafficOrder(row.id)"
@ -344,11 +344,15 @@ function sourceName(type) { return ({ live: '直播', replay: '回放', download
function payStatusName(status) { function payStatusName(status) {
return ({ return ({
unpaid: '待支付', unpaid: '待支付',
processing: '支付中',
paid: '已支付', paid: '已支付',
cancelled: '已取消', cancelled: '已取消',
closed: '已关闭' closed: '已关闭'
})[status] || status || '--' })[status] || status || '--'
} }
function isTrafficOrderActionable(row) {
return row?.payStatus === 'unpaid' || row?.payStatus === 'processing'
}
function describePayment(payment) { function describePayment(payment) {
if (!payment) return '支付已创建' if (!payment) return '支付已创建'
const amount = moneyFromFen(payment.totalFeeFen) const amount = moneyFromFen(payment.totalFeeFen)
@ -412,18 +416,24 @@ async function createTrafficOrderAndPay() {
return return
} }
trafficOrdering.value = true trafficOrdering.value = true
let orderCreated = false
try { try {
const order = await request.post(urls.TRAFFIC_ORDERS, { const order = await request.post(urls.TRAFFIC_ORDERS, {
packageId: Number(selectedTrafficPackageId.value) packageId: Number(selectedTrafficPackageId.value)
}) })
orderCreated = true
orderPageNum.value = 1
const payment = await createPayment('traffic_order', order.id) const payment = await createPayment('traffic_order', order.id)
ui.toast(describePayment(payment)) ui.toast(describePayment(payment))
orderPageNum.value = 1
await Promise.all([loadOrders(), request.get(urls.TRAFFIC_BALANCE).then((data) => { await Promise.all([loadOrders(), request.get(urls.TRAFFIC_BALANCE).then((data) => {
balance.value = data?.balanceGb == null ? '--' : Number(data.balanceGb).toFixed(1) balance.value = data?.balanceGb == null ? '--' : Number(data.balanceGb).toFixed(1)
})]) })])
} catch (error) { } catch (error) {
ui.toast(error.message || '购买失败') ui.toast(error.message || '购买失败')
if (orderCreated) {
orderPageNum.value = 1
await loadOrders()
}
} finally { } finally {
trafficOrdering.value = false trafficOrdering.value = false
} }
@ -441,7 +451,7 @@ async function payTrafficOrder(row) {
} }
} }
async function cancelTrafficOrder(id) { async function cancelTrafficOrder(id) {
const ok = await ui.confirm('取消该流量订单?', '仅未支付订单可取消。', ['订单将关闭', '可重新选择套餐下单'])
const ok = await ui.confirm('取消该流量订单?', '仅待支付/支付中订单可取消。', ['订单将关闭', '可重新选择套餐下单'])
if (!ok) return if (!ok) return
try { try {
await request.delete(urls.TRAFFIC_ORDER(id)) await request.delete(urls.TRAFFIC_ORDER(id))

Loading…
Cancel
Save