front/src/views/order/myOrders/components/OrderPayConfirmModal.vue
zzh d9185f34ed
Some checks failed
Build and Deploy Front / deploy (push) Failing after 3m53s
feat: 支付可选跳过余额,配置项提示与构建内存收敛
混合支付支持 UseBalance;微信/支付宝配置改为问号提示;Vite 堆降至 4G 并关闭 gzip 体积统计,减轻生产同机 CI 压力。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-12-04 17:19:53 +08:00

1324 lines
39 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<script setup lang="ts">
import { computed, ref, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import { Message } from '@arco-design/web-vue'
import { IconClose, IconDown, IconRight } from '@arco-design/web-vue/es/icon'
import QRCode from 'qrcode'
import { getOrderDetail, postOrderPay, type OrderPayCouponOption } from '@/api/order'
import { getDictListAll, type DictDto } from '@/api/system/dict'
import { CustomerService } from '@/api/customer'
import {
closeWeChatPay,
createOrderWeChatPay,
getWeChatPayStatus,
} from '@/api/recharge/wechatPay'
import {
closeAlipayPay,
createOrderAlipayPay,
getAlipayPayStatus,
} from '@/api/recharge/alipayPay'
import wxIcon from '@/assets/wx.png'
import zfbIcon from '@/assets/zfb.png'
import {
formatCouponBenefit,
formatPayMoney,
runWithConcurrency,
useOrderPayCoupon,
} from '@/hooks/orderPayCoupon'
interface PayOrderInput {
id: number | string
waybillNo?: string
serviceNo?: string
}
interface PayFeeRow {
costItem: string
amount: string
currency: string
chargingStage: string
}
interface PayOrderPreview {
id: number | string
key: string
waybillNo: string
customerId?: number
customerName: string
fees: PayFeeRow[]
totalText: string
totalAmount: number
error?: string
}
type PayStatus = 'paying' | 'success' | 'failed'
const DETAIL_CONCURRENCY = 4
const props = defineProps<{
visible: boolean
orders: PayOrderInput[]
}>()
const emit = defineEmits<{
'update:visible': [value: boolean]
success: []
fail: [error: unknown]
}>()
const { t } = useI18n()
const loading = ref(false)
const submitting = ref(false)
const previews = ref<PayOrderPreview[]>([])
const feeItemDictRows = ref<DictDto[]>([])
const expandedKeys = ref<Set<string>>(new Set())
const payStatus = ref<Record<string, PayStatus>>({})
const payErrors = ref<Record<string, string>>({})
const progress = ref({ done: 0, total: 0 })
/** customerId -> 余额;null 表示查询失败 */
const balances = ref<Record<number, number | null>>({})
const couponPricing = useOrderPayCoupon({
onNotApplied: () => Message.warning(t('order.myOrders.modal.payCouponNotApplied')),
onError: (msg) => Message.error(msg),
})
const columns = computed(() => [
{ title: t('order.myOrders.drawer.costItem'), dataIndex: 'costItem', width: 180 },
{ title: t('order.myOrders.drawer.amount'), dataIndex: 'amount', width: 110, align: 'right' as const },
{ title: t('order.myOrders.drawer.currency'), dataIndex: 'currency', width: 80 },
{ title: t('order.myOrders.drawer.chargingStage'), dataIndex: 'chargingStage', ellipsis: true },
])
const isMulti = computed(() => previews.value.length > 1)
const modalTitle = computed(() =>
isMulti.value
? t('order.myOrders.modal.payTitleBatch', { count: previews.value.length })
: t('order.myOrders.modal.payTitle'),
)
const customerIds = computed(() => [
...new Set(previews.value.map((p) => p.customerId).filter((id): id is number => !!id)),
])
const isMultiCustomer = computed(() => customerIds.value.length > 1)
function couponEntry(preview: PayOrderPreview) {
return couponPricing.entryOf(preview.id)
}
function pricingOf(preview: PayOrderPreview) {
return couponEntry(preview)?.pricing ?? null
}
/** 本单无法支付的原因;为空表示可支付 */
function blockReason(preview: PayOrderPreview) {
if (preview.error) return preview.error
const entry = couponEntry(preview)
if (entry?.error) return entry.error
const pricing = entry?.pricing
if (pricing && pricing.receivableSubtotal <= 0) return t('order.myOrders.modal.payInvalidAmount')
return ''
}
function isPaid(preview: PayOrderPreview) {
return payStatus.value[preview.key] === 'success'
}
const payableOrders = computed(() =>
previews.value.filter((p) => !isPaid(p) && !blockReason(p) && pricingOf(p)),
)
const blockedOrders = computed(() =>
previews.value.filter((p) => !isPaid(p) && !!blockReason(p)),
)
const failedOrders = computed(() =>
previews.value.filter((p) => payStatus.value[p.key] === 'failed'),
)
const totals = computed(() => {
let subtotal = 0
let payable = 0
let saved = 0
for (const p of payableOrders.value) {
const pricing = pricingOf(p)!
subtotal += pricing.receivableSubtotal
payable += pricing.payableAmount
saved += pricing.levelDiscountAmount + pricing.couponDiscountAmount
}
return { subtotal, payable, saved }
})
/** 按客户汇总本次应付并与余额比较(管理员批量可能跨客户) */
const balanceShortfalls = computed(() => {
const need = new Map<number, { name: string; amount: number }>()
for (const p of payableOrders.value) {
if (!p.customerId) continue
const cur = need.get(p.customerId) ?? { name: p.customerName, amount: 0 }
cur.amount += pricingOf(p)!.payableAmount
need.set(p.customerId, cur)
}
const result: { name: string; shortfall: number }[] = []
for (const [id, { name, amount }] of need) {
const balance = balances.value[id]
if (balance == null) continue
if (amount > balance + 1e-6) result.push({ name, shortfall: amount - balance })
}
return result
})
const singleBalance = computed(() => {
if (customerIds.value.length !== 1) return null
const b = balances.value[customerIds.value[0]]
return b == null ? null : b
})
const pricingLoading = computed(() => couponPricing.anyLoading.value)
/** 单客户:是否用账户余额抵扣(可关,关则全额扫码) */
const useAccountBalance = ref(true)
const canUseAccountBalance = computed(
() => !isMultiCustomer.value && singleBalance.value != null && singleBalance.value > 1e-6,
)
/** 单客户:可选余额;多客户:仅余额(不足不可确认) */
const hybridBalanceUse = computed(() => {
if (isMultiCustomer.value || singleBalance.value == null) return 0
if (!useAccountBalance.value) return 0
return Math.min(singleBalance.value, totals.value.payable)
})
const hybridWechatAmount = computed(() => {
if (isMultiCustomer.value) return 0
if (singleBalance.value == null && useAccountBalance.value) return 0
return Math.max(0, totals.value.payable - hybridBalanceUse.value)
})
const needsWechatPay = computed(() => hybridWechatAmount.value > 1e-6)
/** 在线补差渠道:微信扫码 / 支付宝扫码 */
const onlinePayChannel = ref<'wechat' | 'alipay'>('wechat')
const wxQrVisible = ref(false)
const wxQrDataUrl = ref('')
const wxOutTradeNo = ref('')
let wxPollTimer: ReturnType<typeof setInterval> | null = null
function stopWxPoll() {
if (wxPollTimer) {
clearInterval(wxPollTimer)
wxPollTimer = null
}
}
async function cancelWxPay() {
stopWxPoll()
const no = wxOutTradeNo.value
const channel = onlinePayChannel.value
wxQrVisible.value = false
wxQrDataUrl.value = ''
wxOutTradeNo.value = ''
if (!no) return
if (channel === 'alipay') {
await closeAlipayPay(no).catch(() => undefined)
} else {
await closeWeChatPay(no).catch(() => undefined)
}
}
const canConfirm = computed(
() =>
!loading.value
&& !submitting.value
&& !pricingLoading.value
&& !wxQrVisible.value
&& payableOrders.value.length > 0
&& (needsWechatPay.value || balanceShortfalls.value.length === 0),
)
const confirmText = computed(() => {
if (submitting.value && progress.value.total > 1) {
return t('order.myOrders.modal.payProgress', progress.value)
}
const amount = formatPayMoney(totals.value.payable)
return failedOrders.value.length
? t('order.myOrders.modal.payRetryFailed', { amount })
: t('order.myOrders.modal.payConfirmAmount', { amount })
})
function isCouponSelectable(preview: PayOrderPreview, coupon: OrderPayCouponOption) {
return coupon.canUse && !couponPricing.isCouponTakenByOther(preview.id, coupon.couponInstanceId)
}
function couponOptionLabel(preview: PayOrderPreview, coupon: OrderPayCouponOption) {
const name = coupon.templateName || coupon.couponCode
const benefit = formatCouponBenefit(coupon)
const base = benefit ? `${name}(${benefit})` : name
if (couponPricing.isCouponTakenByOther(preview.id, coupon.couponInstanceId)) {
return `${base} · ${t('order.myOrders.modal.payCouponUsedByOther')}`
}
if (!coupon.canUse && coupon.unavailableReason) return `${base} · ${coupon.unavailableReason}`
return base
}
function usableCouponCount(preview: PayOrderPreview) {
return (pricingOf(preview)?.availableCoupons ?? []).filter((c) => isCouponSelectable(preview, c)).length
}
function hasDiscount(preview: PayOrderPreview) {
const pricing = pricingOf(preview)
return !!pricing && pricing.payableAmount < pricing.receivableSubtotal
}
function isExpanded(preview: PayOrderPreview) {
return !isMulti.value || expandedKeys.value.has(preview.key)
}
function toggleExpand(preview: PayOrderPreview) {
if (!isMulti.value) return
const next = new Set(expandedKeys.value)
if (next.has(preview.key)) next.delete(preview.key)
else next.add(preview.key)
expandedKeys.value = next
}
const allExpanded = computed(
() => previews.value.length > 0 && previews.value.every((p) => expandedKeys.value.has(p.key)),
)
function toggleExpandAll() {
expandedKeys.value = allExpanded.value ? new Set() : new Set(previews.value.map((p) => p.key))
}
function removeOrder(preview: PayOrderPreview) {
previews.value = previews.value.filter((p) => p.key !== preview.key)
couponPricing.removeEntry(preview.id)
if (!previews.value.length) closeModal()
}
function handleCouponChange(preview: PayOrderPreview, value: unknown) {
void couponPricing.selectCoupon(preview.id, Number(value) || 0)
}
function pick(raw: Record<string, any> | undefined, ...keys: string[]) {
if (!raw) return undefined
for (const k of keys) {
const v = raw[k]
if (v !== undefined && v !== null && v !== '') return v
}
return undefined
}
function normalizeFeeType(row: any): 'receivable' | 'payable' | '' {
const raw = String(row?.type ?? row?.feeType ?? row?.FeeType ?? '').toLowerCase()
if (raw === 'receivable' || raw === 'payable') return raw
return ''
}
function sumReceivableFees(list: any[]) {
const map = new Map<string, number>()
for (const row of list) {
const currency = String(row?.currency ?? 'CNY').trim() || 'CNY'
const amount = Number(row?.amount)
if (!Number.isFinite(amount)) continue
map.set(currency, (map.get(currency) ?? 0) + amount)
}
return map
}
function formatTotals(map: Map<string, number>) {
if (!map.size) return '--'
return [...map.entries()]
.map(([currency, amount]) => `${currency} ${amount.toFixed(2)}`)
.join(' + ')
}
function getCostItemLabel(row: any) {
const fromApi = row?.costItemName ?? row?.CostItemName
if (fromApi != null && fromApi !== '') return String(fromApi)
const code = row?.costItem ?? row?.CostItem
if (code == null || code === '') return '--'
const c = String(code).trim()
const hit = feeItemDictRows.value.find(
(r) => String(r.dictCode ?? (r as any).DictCode ?? '').trim() === c,
)
if (hit?.dictName) return hit.dictName
const byName = feeItemDictRows.value.find(
(r) => String(r.dictName ?? (r as any).DictName ?? '').trim() === c,
)
return byName?.dictName || c
}
function getChargingStageLabel(stage: string) {
if (!stage) return '--'
const key = `finance.receivablePayable.chargingStage.${stage}`
const translated = t(key)
return translated !== key ? translated : stage
}
function mapFeeRows(list: any[]): PayFeeRow[] {
return list.map((row) => {
const stage = String(row?.chargingStage ?? row?.ChargingStage ?? '').trim()
const amount = Number(row?.amount)
return {
costItem: getCostItemLabel(row),
amount: Number.isFinite(amount) ? amount.toFixed(2) : '--',
currency: String(row?.currency ?? 'CNY').trim() || 'CNY',
chargingStage: getChargingStageLabel(stage),
}
})
}
async function ensureFeeItemDictLoaded() {
if (feeItemDictRows.value.length) return
try {
feeItemDictRows.value = await getDictListAll({ dictType: 'fee_item' })
} catch {
feeItemDictRows.value = []
}
}
async function loadOrderPreview(order: PayOrderInput): Promise<PayOrderPreview> {
const id = order.id
const key = String(id)
const fallbackWaybill = order.waybillNo || order.serviceNo || key
try {
const detail = await getOrderDetail(id)
const feesRaw = detail?.feeList ?? detail?.FeeList ?? detail?.orderFees ?? detail?.fees
const receivableFees = (Array.isArray(feesRaw) ? feesRaw : []).filter(
(row) => normalizeFeeType(row) === 'receivable',
)
const feeTotals = sumReceivableFees(receivableFees)
const totalAmount = [...feeTotals.values()].reduce((sum, val) => sum + val, 0)
const customerId = Number(pick(detail, 'customerId', 'CustomerId')) || undefined
return {
id,
key,
waybillNo: String(pick(detail, 'waybillNo', 'WaybillNo', 'serviceNo', 'ServiceNo') || fallbackWaybill),
customerId,
customerName: String(pick(detail, 'customerName', 'CustomerName', 'customerCode', 'CustomerCode') || ''),
fees: mapFeeRows(receivableFees),
totalText: formatTotals(feeTotals),
totalAmount,
error: totalAmount <= 0 ? t('order.myOrders.modal.payInvalidAmount') : undefined,
}
} catch (e: any) {
return {
id,
key,
waybillNo: fallbackWaybill,
customerName: '',
fees: [],
totalText: '--',
totalAmount: 0,
error: e?.message || t('order.myOrders.modal.payLoadFailed'),
}
}
}
async function loadBalances() {
const next: Record<number, number | null> = {}
await runWithConcurrency(customerIds.value, DETAIL_CONCURRENCY, async (id) => {
try {
const data: any = await CustomerService.getById(id)
const n = Number(data?.accountBalance ?? data?.balance)
next[id] = Number.isFinite(n) ? n : null
} catch {
next[id] = null
}
})
balances.value = next
}
async function loadPreviews() {
if (!props.orders.length) {
previews.value = []
return
}
loading.value = true
previews.value = []
payStatus.value = {}
payErrors.value = {}
expandedKeys.value = new Set()
try {
await ensureFeeItemDictLoaded()
const next: PayOrderPreview[] = new Array(props.orders.length)
await runWithConcurrency(props.orders, DETAIL_CONCURRENCY, async (order, index) => {
next[index] = await loadOrderPreview(order)
})
previews.value = next
await Promise.all([
couponPricing.loadAll(next.filter((x) => !x.error).map((x) => x.id)),
loadBalances(),
])
} finally {
loading.value = false
}
}
async function closeModal() {
if (submitting.value) return
if (wxQrVisible.value) {
await cancelWxPay()
}
emit('update:visible', false)
}
async function handleConfirm() {
if (!canConfirm.value) return
const queue = [...payableOrders.value]
if (!queue.length) return
// 单客户且需在线补差:一笔混合支付(微信 / 支付宝)
if (!isMultiCustomer.value && needsWechatPay.value) {
submitting.value = true
try {
const couponByOrderId: Record<number, number | null> = {}
for (const p of queue) {
couponByOrderId[Number(p.id)] = couponEntry(p)?.selectedCouponId ?? 0
}
const useAlipay = onlinePayChannel.value === 'alipay'
const created = useAlipay
? await createOrderAlipayPay({
orderIds: queue.map((p) => Number(p.id)),
couponByOrderId,
scene: 'precreate',
useBalance: useAccountBalance.value,
})
: await createOrderWeChatPay({
orderIds: queue.map((p) => Number(p.id)),
couponByOrderId,
scene: 'native',
useBalance: useAccountBalance.value,
})
if (created.paidImmediately) {
for (const p of queue) {
payStatus.value = { ...payStatus.value, [p.key]: 'success' }
}
Message.success(
queue.length > 1
? t('order.myOrders.modal.payBatchSuccess', { count: queue.length })
: t('order.myOrders.modal.paySuccess'),
)
emit('success')
emit('update:visible', false)
return
}
if (!created.codeUrl || !created.outTradeNo) {
throw new Error(
useAlipay
? t('order.myOrders.modal.payAlipayCreateFailed')
: t('order.myOrders.modal.payWxCreateFailed'),
)
}
wxOutTradeNo.value = created.outTradeNo
wxQrDataUrl.value = await QRCode.toDataURL(created.codeUrl, {
width: 200,
margin: 1,
})
wxQrVisible.value = true
stopWxPoll()
wxPollTimer = setInterval(async () => {
try {
const st = useAlipay
? await getAlipayPayStatus(created.outTradeNo!)
: await getWeChatPayStatus(created.outTradeNo!)
if (st.status === 'Success' || st.statusCode === 3) {
stopWxPoll()
wxQrVisible.value = false
wxQrDataUrl.value = ''
for (const p of queue) {
payStatus.value = { ...payStatus.value, [p.key]: 'success' }
}
Message.success(t('order.myOrders.modal.paySuccess'))
emit('success')
emit('update:visible', false)
}
} catch {
/* ignore poll errors */
}
}, 2000)
} catch (e: any) {
Message.error(e?.message || t('order.myOrders.modal.payFailed'))
emit('fail', e)
} finally {
submitting.value = false
}
return
}
// 多客户或纯余额:逐单 /order/pay
submitting.value = true
progress.value = { done: 0, total: queue.length }
let successCount = 0
let lastError: unknown = null
try {
for (const preview of queue) {
payStatus.value = { ...payStatus.value, [preview.key]: 'paying' }
try {
await postOrderPay({
id: preview.id,
couponInstanceId: couponEntry(preview)?.selectedCouponId ?? 0,
})
payStatus.value = { ...payStatus.value, [preview.key]: 'success' }
const restErrors = { ...payErrors.value }
delete restErrors[preview.key]
payErrors.value = restErrors
successCount += 1
} catch (e: any) {
lastError = e
payStatus.value = { ...payStatus.value, [preview.key]: 'failed' }
payErrors.value = {
...payErrors.value,
[preview.key]: e?.message || t('order.myOrders.modal.payFailed'),
}
}
progress.value = { ...progress.value, done: progress.value.done + 1 }
}
} finally {
submitting.value = false
}
const failedCount = queue.length - successCount
if (successCount > 0) emit('success')
if (!failedCount) {
Message.success(
queue.length > 1
? t('order.myOrders.modal.payBatchSuccess', { count: successCount })
: t('order.myOrders.modal.paySuccess'),
)
emit('update:visible', false)
return
}
if (queue.length === 1) {
Message.error(payErrors.value[queue[0].key] || t('order.myOrders.modal.payFailed'))
} else {
Message.warning(
t('order.myOrders.modal.payPartialResult', { success: successCount, failed: failedCount }),
)
}
emit('fail', lastError)
if (successCount > 0) void loadBalances()
}
watch(
() => [props.visible, props.orders] as const,
([visible]) => {
if (visible) {
useAccountBalance.value = true
onlinePayChannel.value = 'wechat'
loadPreviews()
} else {
stopWxPoll()
wxQrVisible.value = false
wxQrDataUrl.value = ''
wxOutTradeNo.value = ''
previews.value = []
submitting.value = false
couponPricing.reset()
}
},
{ immediate: true },
)
</script>
<template>
<a-modal
:visible="visible"
:title="modalTitle"
:width="860"
:mask-closable="false"
:closable="!submitting"
unmount-on-close
modal-class="order-pay-modal"
@cancel="closeModal"
>
<a-spin :loading="loading" class="pay-spin">
<div v-if="previews.length" class="pay-body">
<!-- 汇总 -->
<section class="pay-summary">
<div class="pay-summary__main">
<span class="pay-summary__label">{{ t('order.myOrders.modal.paySummaryPayable') }}</span>
<strong class="pay-summary__amount">{{ formatPayMoney(totals.payable) }}</strong>
<span v-if="totals.saved > 0" class="pay-summary__saved">
{{ t('order.myOrders.modal.paySummarySaved', { amount: formatPayMoney(totals.saved) }) }}
</span>
</div>
<dl class="pay-summary__meta">
<div>
<dt>{{ t('order.myOrders.modal.paySummaryOrders') }}</dt>
<dd>{{ t('order.myOrders.modal.payOrdersUnit', { count: payableOrders.length }) }}</dd>
</div>
<div>
<dt>{{ t('order.myOrders.modal.paySubtotal') }}</dt>
<dd>{{ formatPayMoney(totals.subtotal) }}</dd>
</div>
<template v-if="!isMultiCustomer && (needsWechatPay || canUseAccountBalance)">
<div v-if="useAccountBalance">
<dt>{{ t('order.myOrders.modal.payHybridBalanceLabel') }}</dt>
<dd>{{ formatPayMoney(hybridBalanceUse) }}</dd>
</div>
<div v-if="needsWechatPay">
<dt>{{ t('order.myOrders.modal.payHybridOnlineLabel') }}</dt>
<dd class="is-emphasis">{{ formatPayMoney(hybridWechatAmount) }}</dd>
</div>
<div v-else-if="singleBalance != null">
<dt>{{ t('order.myOrders.modal.payBalance') }}</dt>
<dd>{{ formatPayMoney(singleBalance) }}</dd>
</div>
</template>
<div v-else-if="singleBalance != null">
<dt>{{ t('order.myOrders.modal.payBalance') }}</dt>
<dd :class="{ 'is-danger': balanceShortfalls.length }">{{ formatPayMoney(singleBalance) }}</dd>
</div>
</dl>
</section>
<a-alert
v-if="balanceShortfalls.length && isMultiCustomer"
type="warning"
show-icon
class="pay-alert"
>
<div v-for="item in balanceShortfalls" :key="item.name">
{{ t('order.myOrders.modal.payBalanceShortCustomer', { name: item.name, amount: formatPayMoney(item.shortfall) }) }}
</div>
<div>{{ t('order.myOrders.modal.payMultiCustomerWxHint') }}</div>
</a-alert>
<div v-else-if="!isMultiCustomer && (canUseAccountBalance || needsWechatPay)" class="pay-method-block">
<label v-if="canUseAccountBalance" class="pay-balance-toggle">
<a-checkbox v-model="useAccountBalance" :disabled="submitting">
{{ t('order.myOrders.modal.payUseBalance') }}
</a-checkbox>
<span class="pay-balance-toggle__amt">{{ formatPayMoney(singleBalance) }}</span>
</label>
<div
v-if="needsWechatPay"
class="pay-method-row"
role="radiogroup"
:aria-label="t('order.myOrders.modal.payOnlineChannel')"
>
<span class="pay-method-row__label">{{ t('order.myOrders.modal.payOnlineChannel') }}</span>
<button
type="button"
class="pay-method-chip"
:class="{ 'is-active': onlinePayChannel === 'wechat' }"
:disabled="submitting"
role="radio"
:aria-checked="onlinePayChannel === 'wechat'"
@click="onlinePayChannel = 'wechat'"
>
<img :src="wxIcon" alt="" />
{{ t('order.myOrders.modal.payChannelWechat') }}
</button>
<button
type="button"
class="pay-method-chip"
:class="{ 'is-active': onlinePayChannel === 'alipay' }"
:disabled="submitting"
role="radio"
:aria-checked="onlinePayChannel === 'alipay'"
@click="onlinePayChannel = 'alipay'"
>
<img :src="zfbIcon" alt="" />
{{ t('order.myOrders.modal.payChannelAlipay') }}
</button>
</div>
</div>
<a-alert v-if="isMulti && blockedOrders.length" type="info" show-icon class="pay-alert">
{{ t('order.myOrders.modal.paySkipHint', { count: blockedOrders.length }) }}
</a-alert>
<!-- 订单列表 -->
<div v-if="isMulti" class="pay-list-head">
<span>{{ t('order.myOrders.modal.payOrderList') }}</span>
<a-link :hoverable="false" @click="toggleExpandAll">
{{ allExpanded ? t('order.myOrders.modal.payCollapseAll') : t('order.myOrders.modal.payExpandAll') }}
</a-link>
</div>
<div class="pay-list" :class="{ 'is-multi': isMulti }">
<article
v-for="preview in previews"
:key="preview.key"
class="pay-item"
:class="{
'is-expanded': isExpanded(preview),
'is-blocked': !!blockReason(preview) && !isPaid(preview),
'is-paid': isPaid(preview),
'is-failed': payStatus[preview.key] === 'failed',
}"
>
<header class="pay-item__head" :class="{ 'is-clickable': isMulti }" @click="toggleExpand(preview)">
<span v-if="isMulti" class="pay-item__arrow">
<icon-down v-if="isExpanded(preview)" />
<icon-right v-else />
</span>
<div class="pay-item__title">
<span class="pay-item__no">{{ preview.waybillNo }}</span>
<span v-if="isMultiCustomer && preview.customerName" class="pay-item__customer">
{{ preview.customerName }}
</span>
</div>
<div class="pay-item__coupon" @click.stop>
<template v-if="pricingOf(preview) && !blockReason(preview)">
<a-select
v-if="pricingOf(preview)!.availableCoupons.length"
:model-value="couponEntry(preview)?.selectedCouponId"
:loading="couponEntry(preview)?.loading"
:disabled="couponEntry(preview)?.loading || submitting || isPaid(preview)"
size="small"
:trigger-props="{ autoFitPopupMinWidth: true }"
class="pay-item__coupon-select"
@change="(v) => handleCouponChange(preview, v)"
>
<template #prefix>{{ t('order.myOrders.modal.payCoupon') }}</template>
<a-option :value="0">
{{ t('order.myOrders.modal.payCouponNone') }}
<template v-if="usableCouponCount(preview)">
({{ t('order.myOrders.modal.payCouponUsableCount', { count: usableCouponCount(preview) }) }})
</template>
</a-option>
<a-option
v-for="c in pricingOf(preview)!.availableCoupons"
:key="c.couponInstanceId"
:value="c.couponInstanceId"
:disabled="!isCouponSelectable(preview, c)"
>
{{ couponOptionLabel(preview, c) }}
</a-option>
</a-select>
<span v-else class="pay-item__coupon-empty">{{ t('order.myOrders.modal.payCouponEmpty') }}</span>
</template>
</div>
<div class="pay-item__amount">
<template v-if="pricingOf(preview) && !blockReason(preview)">
<s v-if="hasDiscount(preview)">{{ formatPayMoney(pricingOf(preview)!.receivableSubtotal) }}</s>
<strong>{{ formatPayMoney(pricingOf(preview)!.payableAmount) }}</strong>
</template>
<span v-else-if="!blockReason(preview)" class="pay-item__muted">{{ preview.totalText }}</span>
</div>
<div class="pay-item__state">
<a-tag v-if="isPaid(preview)" color="green" size="small">
{{ t('order.myOrders.modal.payStatusSuccess') }}
</a-tag>
<a-tag v-else-if="payStatus[preview.key] === 'paying'" color="arcoblue" size="small">
{{ t('order.myOrders.modal.payStatusPaying') }}
</a-tag>
<a-tag v-else-if="payStatus[preview.key] === 'failed'" color="red" size="small">
{{ t('order.myOrders.modal.payStatusFailed') }}
</a-tag>
<a-tag v-else-if="blockReason(preview)" color="gray" size="small">
{{ t('order.myOrders.modal.payStatusSkipped') }}
</a-tag>
<a-tooltip v-if="isMulti && !submitting && !isPaid(preview)" :content="t('order.myOrders.modal.payRemove')">
<button type="button" class="pay-item__remove" @click.stop="removeOrder(preview)">
<icon-close />
</button>
</a-tooltip>
</div>
</header>
<p v-if="!isPaid(preview) && (payErrors[preview.key] || blockReason(preview))" class="pay-item__error">
{{ payErrors[preview.key] || blockReason(preview) }}
</p>
<div v-if="isExpanded(preview) && !preview.error" class="pay-item__body">
<a-table
:columns="columns"
:data="preview.fees"
:pagination="false"
size="small"
:bordered="{ cell: true }"
class="pay-item__fees"
/>
<div v-if="pricingOf(preview)" class="pay-item__breakdown">
<span>
{{ t('order.myOrders.modal.paySubtotal') }}
<b>{{ formatPayMoney(pricingOf(preview)!.receivableSubtotal) }}</b>
</span>
<span v-if="pricingOf(preview)!.levelDiscountAmount > 0">
{{ t('order.myOrders.modal.payLevelDiscount') }}
<template v-if="pricingOf(preview)!.memberLevelName">({{ pricingOf(preview)!.memberLevelName }})</template>
<em>-{{ formatPayMoney(pricingOf(preview)!.levelDiscountAmount) }}</em>
</span>
<span v-if="pricingOf(preview)!.couponDiscountAmount > 0">
{{ t('order.myOrders.modal.payCouponDiscount') }}
<em>-{{ formatPayMoney(pricingOf(preview)!.couponDiscountAmount) }}</em>
</span>
<span class="pay-item__breakdown-total">
{{ t('order.myOrders.modal.payPayable') }}
<strong>{{ formatPayMoney(pricingOf(preview)!.payableAmount) }}</strong>
</span>
</div>
</div>
</article>
</div>
</div>
<a-empty v-else-if="!loading" :description="t('order.myOrders.modal.payEmpty')" />
<div v-if="wxQrVisible" class="pay-wx-layer">
<div class="pay-wx-card">
<h4>
{{
onlinePayChannel === 'alipay'
? t('order.myOrders.modal.payAlipayTitle')
: t('order.myOrders.modal.payWxTitle')
}}
</h4>
<p class="pay-wx-card__tip">
{{
onlinePayChannel === 'alipay'
? t('order.myOrders.modal.payAlipayTip')
: t('order.myOrders.modal.payWxTip')
}}
</p>
<img
v-if="wxQrDataUrl"
:src="wxQrDataUrl"
:alt="onlinePayChannel === 'alipay' ? 'alipay-pay-qr' : 'wx-pay-qr'"
/>
<p class="pay-wx-card__amt">
{{ t('order.myOrders.modal.payWxAmount', { amount: formatPayMoney(hybridWechatAmount) }) }}
</p>
<a-button @click="cancelWxPay">{{ t('order.myOrders.modal.payWxCancel') }}</a-button>
</div>
</div>
</a-spin>
<template #footer>
<div class="pay-footer">
<a-button :disabled="submitting" @click="closeModal">{{ t('warehouse.common.cancel') }}</a-button>
<a-button
type="primary"
:loading="submitting"
:disabled="!canConfirm"
@click="handleConfirm"
>
{{ confirmText }}
</a-button>
</div>
</template>
</a-modal>
</template>
<style scoped lang="less">
.pay-spin {
position: relative;
display: block;
width: 100%;
min-height: 160px;
}
.pay-body {
display: flex;
flex-direction: column;
gap: 12px;
}
.pay-summary {
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 16px 20px;
border-radius: 8px;
background: color-mix(in srgb, var(--app-primary-color) 6%, var(--color-bg-2));
border: 1px solid color-mix(in srgb, var(--app-primary-color) 18%, transparent);
}
.pay-summary__main {
display: flex;
align-items: baseline;
gap: 10px;
min-width: 0;
}
.pay-summary__label {
color: var(--color-text-2);
font-size: 13px;
}
.pay-summary__amount {
color: var(--app-primary-color);
font-size: 28px;
font-weight: 700;
line-height: 1.1;
font-variant-numeric: tabular-nums;
}
.pay-summary__saved {
padding: 1px 8px;
border-radius: 10px;
background: rgb(var(--danger-1));
color: rgb(var(--danger-6));
font-size: 12px;
}
.pay-summary__meta {
display: flex;
gap: 28px;
margin: 0;
div {
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 2px;
}
dt {
color: var(--color-text-3);
font-size: 12px;
}
dd {
margin: 0;
color: var(--color-text-1);
font-size: 15px;
font-weight: 600;
font-variant-numeric: tabular-nums;
&.is-danger {
color: rgb(var(--danger-6));
}
&.is-emphasis {
color: var(--app-primary-color);
}
}
}
.pay-alert {
margin: 0;
}
.pay-method-block {
display: flex;
flex-direction: column;
gap: 10px;
}
.pay-balance-toggle {
display: inline-flex;
align-items: center;
gap: 10px;
min-height: 32px;
cursor: pointer;
user-select: none;
}
.pay-balance-toggle__amt {
font-size: 13px;
color: var(--color-text-3);
font-variant-numeric: tabular-nums;
}
.pay-method-row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
.pay-method-row__label {
margin-right: 4px;
font-size: 13px;
color: var(--color-text-2);
}
.pay-method-chip {
display: inline-flex;
align-items: center;
gap: 6px;
height: 32px;
padding: 0 12px;
border-radius: 4px;
border: 1px solid var(--color-border-2);
background: #fff;
color: var(--color-text-1);
font-size: 13px;
cursor: pointer;
transition: border-color 0.15s, background 0.15s, color 0.15s;
img {
width: 18px;
height: 18px;
object-fit: contain;
}
&:hover:not(:disabled) {
border-color: color-mix(in srgb, var(--app-primary-color) 40%, var(--color-border-2));
}
&.is-active {
border-color: var(--app-primary-color);
color: var(--app-primary-color);
background: color-mix(in srgb, var(--app-primary-color) 8%, #fff);
}
&:disabled {
opacity: 0.55;
cursor: not-allowed;
}
}
.pay-list-head {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 4px;
color: var(--color-text-2);
font-size: 13px;
}
.pay-list {
display: flex;
flex-direction: column;
gap: 8px;
&.is-multi {
max-height: min(52vh, 520px);
overflow-y: auto;
padding-right: 4px;
}
}
.pay-item {
border: 1px solid var(--color-border-2);
border-radius: 8px;
background: var(--color-bg-2);
transition: border-color 0.2s, box-shadow 0.2s;
&.is-expanded {
border-color: var(--color-border-3);
}
&.is-blocked {
background: var(--color-fill-1);
.pay-item__no {
color: var(--color-text-3);
}
}
&.is-failed {
border-color: rgb(var(--danger-3));
}
&.is-paid {
opacity: 0.65;
}
}
.pay-item__head {
display: grid;
grid-template-columns: auto minmax(0, 1fr) 260px 120px auto;
align-items: center;
gap: 12px;
min-height: 52px;
padding: 8px 12px;
&.is-clickable {
cursor: pointer;
}
}
.pay-item__arrow {
display: inline-flex;
color: var(--color-text-3);
font-size: 12px;
}
.pay-item__title {
display: flex;
flex-direction: column;
gap: 2px;
min-width: 0;
}
.pay-item__no {
color: var(--color-text-1);
font-weight: 600;
font-variant-numeric: tabular-nums;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.pay-item__customer {
color: var(--color-text-3);
font-size: 12px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.pay-item__coupon {
min-width: 0;
cursor: default;
}
.pay-item__coupon-select {
width: 100%;
}
.pay-item__coupon-empty,
.pay-item__muted {
color: var(--color-text-3);
font-size: 12px;
}
.pay-item__amount {
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 1px;
font-variant-numeric: tabular-nums;
s {
color: var(--color-text-4);
font-size: 12px;
}
strong {
color: var(--color-text-1);
font-size: 15px;
font-weight: 600;
}
}
.pay-item__state {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 6px;
min-width: 28px;
}
.pay-item__remove {
display: inline-flex;
align-items: center;
justify-content: center;
width: 24px;
height: 24px;
padding: 0;
border: none;
border-radius: 4px;
background: transparent;
color: var(--color-text-3);
cursor: pointer;
&:hover {
background: var(--color-fill-2);
color: rgb(var(--danger-6));
}
}
.pay-item__error {
margin: -2px 12px 10px;
padding: 6px 10px;
border-radius: 4px;
background: rgb(var(--warning-1));
color: rgb(var(--warning-7));
font-size: 12px;
line-height: 1.5;
}
.pay-item.is-failed .pay-item__error {
background: rgb(var(--danger-1));
color: rgb(var(--danger-6));
}
.pay-item__body {
padding: 0 12px 12px;
border-top: 1px dashed var(--color-border-2);
padding-top: 12px;
}
.pay-item__breakdown {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
align-items: baseline;
gap: 20px;
margin-top: 10px;
color: var(--color-text-2);
font-size: 13px;
font-variant-numeric: tabular-nums;
b {
color: var(--color-text-1);
font-weight: 500;
}
em {
font-style: normal;
color: rgb(var(--danger-6));
}
}
.pay-item__breakdown-total strong {
color: var(--app-primary-color);
font-size: 15px;
}
.pay-footer {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 8px;
width: 100%;
}
.pay-wx-layer {
position: absolute;
inset: 0;
z-index: 5;
display: flex;
align-items: center;
justify-content: center;
background: rgba(255, 255, 255, 0.92);
}
.pay-wx-card {
display: flex;
flex-direction: column;
align-items: center;
gap: 10px;
padding: 20px 24px;
border-radius: 12px;
border: 1px solid var(--color-border-2);
background: #fff;
box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
h4 {
margin: 0;
font-size: 15px;
}
img {
width: 200px;
height: 200px;
}
}
.pay-wx-card__tip {
margin: 0;
font-size: 12px;
color: var(--color-text-3);
}
.pay-wx-card__amt {
margin: 0;
font-size: 14px;
font-weight: 600;
color: var(--app-primary-color, #1d7281);
}
</style>