376 lines
8.6 KiB
Vue
376 lines
8.6 KiB
Vue
<script setup lang="ts">
|
||
import { computed, onMounted, watch } from 'vue'
|
||
import { storeToRefs } from 'pinia'
|
||
import { useRoute, useRouter } from 'vue-router'
|
||
import { useFinanceStore } from '@/stores/modules/finance'
|
||
import type { Bill, BillStatus } from '@/types/business/finance'
|
||
import { formatMoney } from '@/utils/format'
|
||
import { toChannelLabel } from '@/utils/payMeta'
|
||
|
||
const route = useRoute()
|
||
const router = useRouter()
|
||
const financeStore = useFinanceStore()
|
||
const { currentBill } = storeToRefs(financeStore)
|
||
|
||
const billId = computed(() => String(route.params.id))
|
||
|
||
const STATUS_CARDS: BillStatus[] = ['已支付', '待支付', '未到期']
|
||
|
||
const AMOUNT_CLASS: Record<BillStatus, string> = {
|
||
已支付: 'is-paid',
|
||
待支付: 'is-pending',
|
||
未到期: 'is-idle',
|
||
已取消: 'is-idle',
|
||
}
|
||
|
||
const cards = computed<Array<{ status: BillStatus; bill: Bill | null }>>(() =>
|
||
STATUS_CARDS.map((status) => ({
|
||
status,
|
||
bill: currentBill.value && currentBill.value.status === status ? currentBill.value : null,
|
||
})),
|
||
)
|
||
|
||
async function load(): Promise<void> {
|
||
await financeStore.fetchDetail(billId.value)
|
||
}
|
||
|
||
function onPay(id: string): void {
|
||
void router.push({ path: '/finance/checkout', query: { ids: id } })
|
||
}
|
||
|
||
watch(billId, () => {
|
||
void load()
|
||
})
|
||
|
||
onMounted(() => {
|
||
void load()
|
||
})
|
||
</script>
|
||
|
||
<template>
|
||
<div class="bill-detail">
|
||
<div class="container">
|
||
<nav class="bill-detail__breadcrumb">
|
||
<RouterLink to="/finance" class="bill-detail__breadcrumb-link">
|
||
财务中心 /
|
||
</RouterLink>
|
||
<RouterLink to="/finance/bills" class="bill-detail__breadcrumb-link">
|
||
账单明细 /
|
||
</RouterLink>
|
||
<span class="bill-detail__breadcrumb-current">账单详情</span>
|
||
</nav>
|
||
|
||
<div v-if="currentBill" class="bill-detail__cards">
|
||
<section
|
||
v-for="card in cards"
|
||
:key="card.status"
|
||
class="bill-detail__card"
|
||
>
|
||
<div class="bill-detail__head">
|
||
<span class="bill-detail__check" aria-hidden="true">✓</span>
|
||
<h3 class="bill-detail__status">
|
||
{{ card.status }}
|
||
</h3>
|
||
</div>
|
||
|
||
<div class="bill-detail__amount-row">
|
||
<span class="bill-detail__amount-label">付款金额:</span>
|
||
<span
|
||
class="bill-detail__amount"
|
||
:class="AMOUNT_CLASS[card.status]"
|
||
>¥ {{ formatMoney(card.bill?.amount ?? currentBill.amount, 0) }}</span>
|
||
</div>
|
||
|
||
<dl class="bill-detail__fields">
|
||
<div class="bill-detail__field">
|
||
<dt class="bill-detail__label">
|
||
支付方式
|
||
</dt>
|
||
<dd class="bill-detail__value">
|
||
{{ card.status === '已支付' ? toChannelLabel(currentBill.payChannel) : '—' }}
|
||
</dd>
|
||
</div>
|
||
<div class="bill-detail__field">
|
||
<dt class="bill-detail__label">
|
||
支付时间
|
||
</dt>
|
||
<dd class="bill-detail__value">
|
||
{{ card.status === '已支付' ? (currentBill.payTime ?? '—') : '—' }}
|
||
</dd>
|
||
</div>
|
||
<div class="bill-detail__field">
|
||
<dt class="bill-detail__label">
|
||
交易流水号
|
||
</dt>
|
||
<dd class="bill-detail__value">
|
||
{{ card.status === '已支付' ? (currentBill.tradeNo ?? '—') : '—' }}
|
||
</dd>
|
||
</div>
|
||
</dl>
|
||
|
||
<div class="bill-detail__order">
|
||
<span class="bill-detail__order-title">
|
||
{{ card.status }}订单
|
||
</span>
|
||
<div class="bill-detail__order-body">
|
||
<span class="bill-detail__order-left">
|
||
<span class="bill-detail__order-name">{{ currentBill.planName }}</span>
|
||
<span class="bill-detail__order-meta">账单号:{{ currentBill.billNo }}</span>
|
||
<span class="bill-detail__order-meta">关联项目:{{ currentBill.projectName }}</span>
|
||
</span>
|
||
<span class="bill-detail__order-amount">¥ {{ formatMoney(currentBill.amount, 0) }}</span>
|
||
</div>
|
||
</div>
|
||
|
||
<button
|
||
v-if="card.status === '待支付'"
|
||
class="bill-detail__cta"
|
||
@click="onPay(currentBill.id)"
|
||
>
|
||
立即支付
|
||
</button>
|
||
<button
|
||
v-else
|
||
class="bill-detail__cta"
|
||
@click="router.push('/finance/bills')"
|
||
>
|
||
返回
|
||
</button>
|
||
</section>
|
||
</div>
|
||
|
||
<p v-else class="bill-detail__empty">
|
||
账单不存在或已下线
|
||
</p>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<style lang="less" scoped>
|
||
.bill-detail {
|
||
width: 100%;
|
||
padding-bottom: 325px;
|
||
background: @contract-page-bg;
|
||
|
||
&__breadcrumb {
|
||
.flex(row, flex-start, center);
|
||
height: 86px;
|
||
padding-top: 34px;
|
||
font-size: 13px;
|
||
font-weight: 400;
|
||
line-height: 17px;
|
||
color: @project-muted;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
&__breadcrumb-link {
|
||
color: @project-muted;
|
||
|
||
&:hover {
|
||
color: @primary-strong;
|
||
}
|
||
}
|
||
|
||
&__breadcrumb-current {
|
||
margin-left: 5.5px;
|
||
color: @finance-entry-text;
|
||
font-weight: 500;
|
||
}
|
||
|
||
&__cards {
|
||
.flex(row, flex-start, flex-start);
|
||
gap: 32px;
|
||
padding-left: 453px;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
&__card {
|
||
position: relative;
|
||
width: 270px;
|
||
height: 476px;
|
||
border-radius: @radius-base;
|
||
background: @white;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
&__head {
|
||
.flex(row, flex-start, center);
|
||
gap: 0;
|
||
align-items: flex-start;
|
||
padding: 46px 0 0 16px;
|
||
height: 141px;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
&__check {
|
||
.flex(row, center, center);
|
||
width: 34px;
|
||
height: 34px;
|
||
margin-right: 30px;
|
||
border-radius: 50%;
|
||
background: @success-color;
|
||
color: @white;
|
||
font-size: 18px;
|
||
font-weight: 400;
|
||
line-height: 1;
|
||
order: 2;
|
||
flex-shrink: 0;
|
||
transform: translateX(-84.75px);
|
||
}
|
||
|
||
&__status {
|
||
order: 1;
|
||
width: 238px;
|
||
margin-top: 74px;
|
||
font-size: 16px;
|
||
font-weight: 700;
|
||
line-height: 21px;
|
||
color: @finance-ink;
|
||
}
|
||
|
||
&__amount-row {
|
||
position: relative;
|
||
width: 238px;
|
||
height: 51px;
|
||
margin: 0 0 0 16px;
|
||
}
|
||
|
||
&__amount-label {
|
||
position: absolute;
|
||
top: 16px;
|
||
left: 51.23px;
|
||
font-size: 12px;
|
||
font-weight: 400;
|
||
line-height: 16px;
|
||
color: @finance-muted-text;
|
||
}
|
||
|
||
&__amount {
|
||
position: absolute;
|
||
top: 10px;
|
||
left: 114.8px;
|
||
font-size: 18px;
|
||
font-weight: 700;
|
||
line-height: 24px;
|
||
white-space: nowrap;
|
||
|
||
&.is-paid { color: @danger-color; }
|
||
&.is-pending { color: @finance-pending; }
|
||
&.is-idle { color: @finance-idle; }
|
||
}
|
||
|
||
&__fields {
|
||
.flex(column, flex-start, stretch);
|
||
gap: 12px;
|
||
margin: 26px 0 0 24px;
|
||
width: 222px;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
&__field {
|
||
.flex(row, flex-start, flex-start);
|
||
gap: 0;
|
||
}
|
||
|
||
&__label {
|
||
flex: 0 0 77.52px;
|
||
font-size: 12px;
|
||
font-weight: 400;
|
||
line-height: 16px;
|
||
color: @finance-muted-text;
|
||
}
|
||
|
||
&__value {
|
||
flex: 1;
|
||
min-width: 0;
|
||
color: @finance-ink;
|
||
font-size: 12px;
|
||
font-weight: 700;
|
||
line-height: 16px;
|
||
word-break: break-all;
|
||
}
|
||
|
||
&__order {
|
||
.flex(column, flex-start, flex-start);
|
||
gap: 0;
|
||
margin: 17px 0 0 32.5px;
|
||
width: 205px;
|
||
}
|
||
|
||
&__order-title {
|
||
font-size: 13px;
|
||
font-weight: 700;
|
||
line-height: 17px;
|
||
color: @finance-ink;
|
||
}
|
||
|
||
&__order-body {
|
||
.flex(row, space-between, flex-start);
|
||
gap: 0;
|
||
margin-top: 6px;
|
||
width: 100%;
|
||
}
|
||
|
||
&__order-left {
|
||
.flex(column, flex-start, flex-start);
|
||
gap: 0;
|
||
min-width: 0;
|
||
}
|
||
|
||
&__order-name {
|
||
font-size: 11px;
|
||
font-weight: 400;
|
||
line-height: 15px;
|
||
color: @project-muted;
|
||
.ellipsis();
|
||
max-width: 124px;
|
||
}
|
||
|
||
&__order-meta {
|
||
font-size: 11px;
|
||
font-weight: 400;
|
||
line-height: 15px;
|
||
color: @project-muted;
|
||
.ellipsis();
|
||
max-width: 132px;
|
||
}
|
||
|
||
&__order-amount {
|
||
flex-shrink: 0;
|
||
font-size: 13px;
|
||
font-weight: 700;
|
||
line-height: 17px;
|
||
color: @finance-ink;
|
||
}
|
||
|
||
&__cta {
|
||
position: absolute;
|
||
left: 50%;
|
||
top: 428px;
|
||
width: 90px;
|
||
height: 32px;
|
||
border: none;
|
||
border-radius: 4px;
|
||
background: @primary-strong;
|
||
color: @white;
|
||
font-size: 12px;
|
||
font-weight: 500;
|
||
padding-bottom: 6px;
|
||
box-sizing: border-box;
|
||
transform: translateX(-50%);
|
||
transition: background 0.2s;
|
||
|
||
&:hover {
|
||
background: @primary-color;
|
||
}
|
||
}
|
||
|
||
&__empty {
|
||
padding: 80px 0;
|
||
color: @project-muted;
|
||
font-size: 13px;
|
||
text-align: center;
|
||
}
|
||
}
|
||
</style>
|