Files
cz-web/src/views/project/cpns/ProjectFinance.vue
2026-10-01 17:24:57 +08:00

401 lines
9.0 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 type { FileInfo } from '@/types/api'
import type { ProjectBill } from '@/types/business/project'
import { fileLabelOf, fileToneOf } from '@/utils/fileMeta'
import { formatFileSize, formatMoney } from '@/utils/format'
interface Props {
paymentPlans: ProjectBill[]
invoiceRecords: FileInfo[]
contractFile?: FileInfo
}
defineProps<Props>()
const emit = defineEmits<{
pay: [billId: string]
preview: [file: FileInfo]
download: [file: FileInfo]
}>()
function canPay(bill: ProjectBill): boolean {
return bill.status === '待支付' && /^\d+$/.test(bill.id)
}
const TONE_CLASS: Record<ProjectBill['status'], string> = {
'已支付': 'is-paid',
'待支付': 'is-pending',
'未到期': 'is-idle',
}
function fileMeta(file: FileInfo): string {
const size = file.size ? formatFileSize(file.size) : ''
const time = file.uploadTime ? `上传于 ${file.uploadTime}` : ''
return [size, time].filter(Boolean).join(' · ')
}
</script>
<template>
<section class="project-finance">
<h2 class="project-finance__title">
付款计划
</h2>
<div class="project-finance__plans">
<article
v-for="bill in paymentPlans"
:key="bill.id || bill.planName"
class="project-finance__plan"
:class="TONE_CLASS[bill.status]"
>
<div class="project-finance__plan-head">
<span class="project-finance__plan-name">
{{ bill.planName }}<template v-if="bill.periodRatio"> 比例{{ bill.periodRatio }}%</template>
</span>
<span class="project-finance__badge">{{ bill.status }}</span>
</div>
<div class="project-finance__plan-body">
<div class="project-finance__fields">
<p v-if="bill.status === '已支付' && bill.tradeNo" class="project-finance__field">
交易流水号:{{ bill.tradeNo }}
</p>
<p class="project-finance__field">
账单号:{{ bill.billNo || '—' }}
</p>
<p class="project-finance__field">
关联项目:{{ bill.projectName || '—' }}
</p>
</div>
<div class="project-finance__amount">
¥{{ formatMoney(bill.amount) }}
</div>
</div>
<button
v-if="canPay(bill)"
class="project-finance__pay"
type="button"
@click="emit('pay', bill.id)"
>
立即支付
</button>
</article>
<p v-if="paymentPlans.length === 0" class="project-finance__empty text-secondary">
暂无付款计划
</p>
</div>
<h2 class="project-finance__title">
发票记录
</h2>
<ul class="project-finance__files">
<li
v-for="(file, index) in invoiceRecords"
:key="`invoice-${index}`"
class="project-finance__file"
>
<span
class="project-finance__file-badge"
:style="{ color: fileToneOf(file), backgroundColor: `${fileToneOf(file)}1a` }"
>
{{ fileLabelOf(file) }}
</span>
<div class="project-finance__file-info">
<span class="project-finance__file-name" :title="file.name">{{ file.name }}</span>
<span class="project-finance__file-meta">{{ fileMeta(file) }}</span>
</div>
<div class="project-finance__file-actions">
<button class="project-finance__act" type="button" @click="emit('preview', file)">
预览
</button>
<button class="project-finance__act" type="button" @click="emit('download', file)">
下载
</button>
</div>
</li>
<li v-if="invoiceRecords.length === 0" class="project-finance__empty text-secondary">
暂无发票记录
</li>
</ul>
<h2 class="project-finance__title">
合同文件
</h2>
<div v-if="contractFile" class="project-finance__file">
<span
class="project-finance__file-badge"
:style="{ color: fileToneOf(contractFile), backgroundColor: `${fileToneOf(contractFile)}1a` }"
>
{{ fileLabelOf(contractFile) }}
</span>
<div class="project-finance__file-info">
<span class="project-finance__file-name" :title="contractFile.name">{{ contractFile.name }}</span>
<span class="project-finance__file-meta">{{ fileMeta(contractFile) }}</span>
</div>
<div class="project-finance__file-actions">
<button class="project-finance__act" type="button" @click="emit('preview', contractFile)">
预览
</button>
<button class="project-finance__act" type="button" @click="emit('download', contractFile)">
下载
</button>
</div>
</div>
<p v-else class="project-finance__empty text-secondary">
暂无合同文件
</p>
</section>
</template>
<style lang="less" scoped>
.project-finance {
.flex(column, flex-start, stretch);
padding: 0;
&__title {
.section-title();
margin-top: 22px;
padding-left: 12px;
font-size: 15px;
font-weight: 700;
line-height: 20px;
&::before {
width: 4px;
height: 20px;
}
}
&__title:first-child + &__plans {
margin-top: 21px;
}
&__plans + &__title,
&__files + &__title {
margin-top: 31px;
}
&__title + &__files,
&__title + &__file {
margin-top: 21px;
}
&__plans {
.flex(column, flex-start, flex-start);
gap: 14px;
}
&__plan {
.flex(column, flex-start, stretch);
position: relative;
width: 372px;
padding: 17px 19px 17px;
border: 1px solid @project-divider;
border-radius: 13px;
background: @white;
box-sizing: border-box;
gap: 0;
&:has(.project-finance__pay) {
padding-bottom: 0;
}
&:not(:has(.project-finance__field:nth-child(3))):not(:has(.project-finance__pay)) {
padding-bottom: 17px;
}
&:has(.project-finance__field:nth-child(3)):not(:has(.project-finance__pay)) {
padding-bottom: 15px;
}
&.is-paid {
.project-finance__badge {
color: @finance-paid;
}
.project-finance__amount {
color: @finance-paid;
}
}
&.is-pending {
.project-finance__badge {
color: @tag-warning-text;
}
.project-finance__amount {
color: @finance-pending-amount;
}
}
&.is-idle {
.project-finance__badge {
color: @project-label;
}
.project-finance__amount {
color: @finance-idle;
}
}
}
&__plan-head {
.flex(row, space-between, flex-start);
gap: @spacing-sm;
}
&__plan-name {
font-size: 14px;
font-weight: 700;
line-height: 19px;
color: @project-ink;
.ellipsis();
}
&__badge {
.flex(row, center, center);
flex-shrink: 0;
margin-top: 2px;
font-size: 11px;
line-height: 15px;
white-space: nowrap;
}
&__plan-body {
.flex(row, space-between, flex-start);
position: relative;
margin-top: 8px;
gap: @spacing-base;
}
&__fields {
position: relative;
flex: 0 0 auto;
min-width: 0;
height: 53px;
&:has(> :nth-child(3)) {
height: 78px;
}
}
&__field {
position: absolute;
left: 0;
right: 0;
font-size: 11px;
line-height: 15px;
color: @project-label;
.ellipsis();
&:nth-child(1) { top: 0; }
&:nth-child(2) { top: 23px; }
&:nth-child(3) { top: 61px; }
}
&__amount {
position: absolute;
top: 29px;
right: 0;
flex-shrink: 0;
font-size: 20px;
font-weight: 700;
line-height: 26px;
white-space: nowrap;
}
&__pay {
height: 34px;
margin: 11px -19px 0;
border: none;
border-radius: 0 0 13px 13px;
background: @finance-pending;
color: @white;
font-size: 12px;
line-height: 34px;
cursor: pointer;
transition: background 0.2s;
&:hover {
background: @finance-cta-hover;
}
}
&__files {
.flex(column, flex-start, stretch);
gap: 10px;
margin: 0;
padding: 0;
list-style: none;
}
&__file {
.flex(row, space-between, center);
gap: @spacing-base;
height: 55px;
box-sizing: border-box;
padding: 0 5.7px 0 16px;
border-radius: 8px;
background: @finance-row-bg;
}
&__file-badge {
.flex(row, center, center);
flex-shrink: 0;
width: 33px;
height: 21px;
border-radius: @radius-sm;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.2px;
}
&__file-info {
.flex(column, flex-start, stretch);
flex: 1;
gap: 3px;
min-width: 0;
}
&__file-name {
max-width: 1410px;
font-size: 13px;
line-height: 17px;
color: @project-ink;
.ellipsis();
}
&__file-meta {
font-size: 11px;
line-height: 15px;
color: @project-muted;
}
&__file-actions {
.flex(row, flex-end, center);
gap: 14px;
flex-shrink: 0;
}
&__act {
flex-shrink: 0;
font-size: 12px;
line-height: 16px;
color: @project-label;
cursor: pointer;
transition: color 0.2s;
&:hover {
color: @primary-color;
}
}
&__empty {
font-size: @font-size-body;
}
}
</style>