Files
shanxia2.0/web-admin/src/views/pl/quota-statistics/StatisticsDetail.vue
T
wuzilongandCursor 522b4be705 feat(pl): 装送货段增加同市标记,并同步额度证件与计划表单。
同市易制毒段只校验购买证;同步 Web/H5 表单、额度统计展示与相关回归测试。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 16:34:58 +08:00

500 lines
18 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.
<template>
<div class="view-section">
<template v-if="mode === 'contract'">
<el-tabs v-model="certTab">
<el-tab-pane
v-for="cert in contract?.certificates || []"
:key="certKey(cert)"
:name="certKey(cert)"
>
<template #label>
<span class="quota-cert-tab-label">
<el-tag size="small" :type="certKindTagType(cert.certType)">{{
certKindLabel(cert.certType)
}}</el-tag>
<span>{{ cert.certNo }}</span>
</span>
</template>
<section class="quota-cert-summary">
<header class="quota-cert-summary__head">
<strong>{{ cert.certNo }}</strong>
<span>{{ cert.productNameOnCert || '未填写证面品名' }}</span>
<span class="quota-cert-summary__meta">
有效期:{{ cert.validFrom || '—' }} 至 {{ cert.validTo || '—' }}
</span>
<div class="quota-cert-summary__tags">
<el-tag size="small" :type="certKindTagType(cert.certType)">{{
certKindLabel(cert.certType)
}}</el-tag>
<el-tag size="small" :type="cert.linkStatus === 'active' ? 'success' : 'info'">{{
linkLabel(cert.linkStatus)
}}</el-tag>
<el-tag size="small" :type="cert.status === 'active' ? 'success' : 'info'">{{
certStatusLabel(cert.status)
}}</el-tag>
</div>
</header>
<dl class="quota-cert-summary__metrics">
<div v-for="item in certMetrics(cert)" :key="item.label">
<dt>{{ item.label }}</dt>
<dd :class="{ 'is-wrap': item.wrap }">
<el-tag v-if="item.alert" type="danger" size="small">{{ item.value }}</el-tag>
<template v-else>{{ item.value }}</template>
</dd>
</div>
</dl>
<div v-if="canEdit && cert.bindingId" class="quota-cert-summary__actions">
<el-button v-if="!cert.referenced" @click="emit('edit', cert)">
<el-icon><Edit /></el-icon>编辑
</el-button>
<el-button v-if="!cert.referenced" @click="emit('remove', cert)">
<el-icon><Delete /></el-icon>删除
</el-button>
<el-button
v-if="cert.referenced && cert.linkStatus === 'active'"
@click="emit('disable', cert)"
>
<el-icon><CircleClose /></el-icon>设为不可用
</el-button>
<el-button
v-if="
cert.referenced &&
cert.linkStatus !== 'active' &&
cert.status !== 'void' &&
cert.status !== 'closed'
"
@click="emit('enable', cert)"
>
<el-icon><RefreshRight /></el-icon>恢复可安排
</el-button>
</div>
<p
v-if="cert.bindingId && cert.referenced && cert.linkStatus === 'active'"
class="form-tip"
>
这份关联已有运输计划用证,不能删除,也不能改产品。设为不可用后,不能再安排新的用证,已经发生的用量仍保留。
</p>
<p v-else-if="cert.bindingId && cert.referenced" class="form-tip">
这份关联已有运输计划用证,目前不可用,不能再安排新的用证。已经发生的用量仍保留。
</p>
<p v-else-if="!cert.bindingId" class="form-tip"
>这条关联已经不在当前绑定里,历史用量仍可查看。</p
>
<StatisticsProducts
:products="cert.products"
:quantity-unit="unitLabel(cert.quantityUnit)"
/>
</section>
</el-tab-pane>
<el-tab-pane label="按产品" name="by-product">
<el-table
:data="productStatRows"
stripe
class="list-table"
row-key="key"
empty-text="暂无绑定产品"
>
<el-table-column prop="productName" label="产品" min-width="160" />
<el-table-column prop="model" label="规格" min-width="120" />
<el-table-column prop="unit" label="产品单位" min-width="100" />
<el-table-column label="证件类型" min-width="110">
<template #default="{ row }">
<el-tag size="small" :type="certKindTagType(row.certType)">{{
row.certKind
}}</el-tag>
</template>
</el-table-column>
<el-table-column prop="certNo" label="证件编号" min-width="160" />
<el-table-column prop="certUnit" label="证面单位" min-width="100" />
<el-table-column label="产品预占" min-width="120"
><template #default="{ row }">{{
formatCertQty(row.reservedQty)
}}</template></el-table-column
>
<el-table-column label="产品已用" min-width="120"
><template #default="{ row }">{{
formatCertQty(row.usedQty)
}}</template></el-table-column
>
<el-table-column label="全证核定" min-width="120"
><template #default="{ row }">{{
formatCertQty(row.totalQty)
}}</template></el-table-column
>
<el-table-column label="全证预占" min-width="120"
><template #default="{ row }">{{
formatCertQty(row.certReservedQty)
}}</template></el-table-column
>
<el-table-column prop="salePartyName" label="销售单位" min-width="160" />
<el-table-column prop="buyPartyName" label="购买单位" min-width="160" />
<el-table-column prop="validUseText" label="有效次数" min-width="110" />
<el-table-column label="是否预警" min-width="120"
><template #default="{ row }"
><el-tag v-if="row.expiryAlert" type="danger" size="small">{{
row.expiryAlert
}}</el-tag
><span v-else>—</span></template
></el-table-column
>
<el-table-column label="全证已用" min-width="120"
><template #default="{ row }">{{
formatCertQty(row.certUsedQty)
}}</template></el-table-column
>
<el-table-column label="共享余额" min-width="120"
><template #default="{ row }">{{
formatCertQty(row.availableQty)
}}</template></el-table-column
>
<el-table-column label="范围状态" min-width="110"
><template #default="{ row }"
><el-tag size="small" :type="row.scopeStatus === 'active' ? 'success' : 'info'">{{
scopeStatusLabel(row.scopeStatus)
}}</el-tag></template
></el-table-column
>
</el-table>
</el-tab-pane>
</el-tabs>
</template>
<template v-else-if="certificate">
<el-descriptions :column="2">
<el-descriptions-item label="期初已用(独立记录)">{{
qtyText(certificate.openingUsedQty, certificate.quantityUnit)
}}</el-descriptions-item>
<el-descriptions-item label="未归属合同已用">{{
qtyText(certificate.unattributedUsedQty, certificate.quantityUnit)
}}</el-descriptions-item>
</el-descriptions>
<el-empty v-if="!linkedContractTabs.length" description="暂无关联合同" :image-size="64" />
<el-tabs v-else v-model="contractTab">
<el-tab-pane
v-for="tab in linkedContractTabs"
:key="tab.key"
:name="tab.key"
:label="tab.label"
>
<section class="quota-cert-summary">
<header class="quota-cert-summary__head">
<strong>{{ tab.item.contractNo || '合同信息不可用' }}</strong>
<span>{{ tab.item.contractName || '未填写合同名称' }}</span>
<div class="quota-cert-summary__tags">
<el-tag size="small" :type="tab.item.linkStatus === 'active' ? 'success' : 'info'">
{{ linkLabel(tab.item.linkStatus) }}
</el-tag>
</div>
</header>
<dl class="quota-cert-summary__metrics is-pair">
<div>
<dt>本合同预占</dt>
<dd>{{ qtyText(tab.item.contractReservedQty, certificate.quantityUnit) }}</dd>
</div>
<div>
<dt>本合同已用</dt>
<dd>{{ qtyText(tab.item.contractUsedQty, certificate.quantityUnit) }}</dd>
</div>
</dl>
<StatisticsProducts
:products="tab.item.products"
:quantity-unit="unitLabel(certificate.quantityUnit)"
/>
</section>
</el-tab-pane>
</el-tabs>
<h3>计划段产品用量追踪</h3>
<el-table :data="usageRows" stripe class="list-table" row-key="id">
<el-table-column prop="planNo" label="计划编号" min-width="180" />
<el-table-column label="段次" min-width="150"
><template #default="{ row }"
><el-tag size="small">{{ row.stopType === 'load' ? '装货' : '送货' }}</el-tag>
</template></el-table-column
>
<el-table-column prop="productName" label="产品" min-width="160" />
<el-table-column prop="contractNo" label="合同编号" min-width="180" />
<el-table-column prop="productModel" label="规格" min-width="140" />
<el-table-column prop="partyName" label="装货 / 送货主体" min-width="180" />
<el-table-column prop="address" label="装货 / 送货地址" min-width="200" />
<el-table-column label="单位" min-width="90"
><template #default="{ row }">{{
unitLabel(row.quantityUnit) || '—'
}}</template></el-table-column
>
<el-table-column label="预占" min-width="120"
><template #default="{ row }">{{
formatCertQty(row.reservedQty)
}}</template></el-table-column
>
<el-table-column label="已用" min-width="120"
><template #default="{ row }">{{ formatCertQty(row.usedQty) }}</template></el-table-column
>
<el-table-column label="状态" min-width="120"
><template #default="{ row }"
><el-tag size="small">{{ statusLabel(row.itemStatus) }}</el-tag></template
></el-table-column
>
</el-table>
</template>
</div>
</template>
<script setup lang="ts">
import { CircleClose, Delete, Edit, RefreshRight } from '@element-plus/icons-vue'
import type { ContractStatistics, CertificateStatistics } from '@/api/pl/quota-cert'
import { useDictStore } from '@/store/modules/dict'
import { getProductUnitLabel } from '@/utils/crm-product-display'
import { formatCertQty } from '../quota-cert/model'
import {
certFaceFields,
certKindLabel,
certKindTagType,
expiryWarning
} from '../quota-cert/cert-list-face'
import StatisticsProducts from './StatisticsProducts.vue'
import { statusLabel } from './labels'
const props = withDefaults(
defineProps<{
mode: 'contract' | 'certificate'
detail: ContractStatistics | CertificateStatistics
canEdit?: boolean
}>(),
{ canEdit: false }
)
const emit = defineEmits<{
edit: [cert: ContractStatistics['certificates'][number]]
remove: [cert: ContractStatistics['certificates'][number]]
disable: [cert: ContractStatistics['certificates'][number]]
enable: [cert: ContractStatistics['certificates'][number]]
}>()
const certTab = ref('')
const contractTab = ref('')
function certKey(cert: { certType: string; certId: string }) {
return `${cert.certType}:${cert.certId}`
}
watch(
() =>
props.mode === 'contract'
? (props.detail as ContractStatistics).certificates.map(certKey).join('|')
: '',
() => {
if (props.mode !== 'contract') return
const names = (props.detail as ContractStatistics).certificates.map(certKey)
if (certTab.value !== 'by-product' && !names.includes(certTab.value))
certTab.value = names[0] || 'by-product'
},
{ immediate: true }
)
const contract = computed(() =>
props.mode === 'contract' ? (props.detail as ContractStatistics) : undefined
)
const certificate = computed(() =>
props.mode === 'certificate' ? (props.detail as CertificateStatistics) : undefined
)
const productStatRows = computed(() =>
(contract.value?.certificates || []).flatMap((cert) =>
(cert.products || []).map((product) => ({
key: `${certKey(cert)}:${product.contractProductId || product.id}`,
productName: product.productName || '—',
model: product.model || '—',
unit: unitLabel(product.unit) || '—',
certType: cert.certType,
certKind: certKindLabel(cert.certType),
certNo: cert.certNo || '—',
certUnit: unitLabel(cert.quantityUnit) || '—',
reservedQty: product.reservedQty,
usedQty: product.usedQty,
totalQty: cert.totalQty,
certReservedQty: cert.reservedQty,
salePartyName: certFaceFields(cert)[0].value,
buyPartyName: certFaceFields(cert)[1].value,
validUseText: cert.validUseText || '—',
expiryAlert: expiryWarning(cert.validTo)?.label || '',
certUsedQty: cert.usedQty,
availableQty: cert.availableQty,
scopeStatus: product.scopeStatus
}))
)
)
function scopeStatusLabel(status?: string | null) {
return status === 'active' ? '有效' : status === 'inactive' ? '停用' : '历史解绑'
}
const linkedContractTabs = computed(() => {
const rows = certificate.value?.contracts || []
const seen = new Map<string, number>()
return rows.map((item, index) => {
const count = (seen.get(item.id) || 0) + 1
seen.set(item.id, count)
const total = rows.filter((row) => row.id === item.id).length
const no = item.contractNo || '合同信息不可用'
return {
key: `${item.bindingId || 'none'}:${item.id}:${index}`,
label: total > 1 ? `${no}(${count})` : no,
item
}
})
})
watch(
() => linkedContractTabs.value.map((tab) => tab.key).join('|'),
() => {
if (props.mode !== 'certificate') return
const names = linkedContractTabs.value.map((tab) => tab.key)
if (!names.includes(contractTab.value)) contractTab.value = names[0] || ''
},
{ immediate: true }
)
function linkLabel(status?: string | null) {
return status === 'active' ? '可安排用证' : '停止新增使用'
}
function certStatusLabel(status?: string | null) {
return (
{ draft: '待核对', active: '证件已启用', suspended: '证件已停用', closed: '证件已核销', void: '证件已作废' }[
status || ''
] ||
statusLabel(status || '') ||
'—'
)
}
function unitLabel(unit?: string | null) {
const label = getProductUnitLabel(useDictStore().getLabel, unit)
return !label || label === '—' ? '' : label
}
function qtyText(value: unknown, unit?: string | null) {
const text = formatCertQty(value)
const name = unitLabel(unit)
return name ? `${text} ${name}` : text
}
function certMetrics(cert: ContractStatistics['certificates'][number]) {
const unit = cert.quantityUnit
const face = certFaceFields(cert).map((item) => ({
...item,
wrap: item.label === '销售单位' || item.label === '购买单位'
}))
const quantities = [
['全证核定', cert.totalQty],
['全证预占', cert.reservedQty],
['全证已用', cert.usedQty],
['全证共享余额', cert.availableQty],
['本合同预占', cert.contractReservedQty],
['本合同已用', cert.contractUsedQty]
].map(([label, value]) => ({ label: String(label), value: qtyText(value, unit), alert: false, wrap: false }))
return [...quantities.slice(0, 2), ...face, ...quantities.slice(2)]
}
const usageRows = computed(() =>
(certificate.value?.usageItems || []).map((item) => {
const contract = certificate.value?.contracts.find((row) => row.id === item.contractId)
const product = contract?.products.find(
(row) => row.contractProductId === item.contractProductId
)
return {
...item,
contractNo: contract?.contractNo || '—',
productModel: product?.model || '—',
partyName: item.partyName || '—',
address: item.address || '—'
}
})
)
</script>
<style scoped lang="scss">
.quota-cert-summary {
padding: 14px 16px;
border: 1px solid var(--border, #d9e8e2);
border-radius: 10px;
background: #fff;
& + & {
margin-top: 12px;
}
&__head {
display: flex;
align-items: center;
gap: 12px;
min-width: 0;
strong {
flex: none;
color: #1e293b;
font-size: 15px;
line-height: 1.4;
}
> span {
flex: none;
color: var(--mint-text-muted, #64748b);
font-size: 13px;
line-height: 1.4;
white-space: nowrap;
}
}
&__tags {
display: flex;
flex: none;
align-items: center;
gap: 6px;
margin-left: auto;
}
&__meta {
flex: none;
color: var(--mint-text-muted, #64748b);
font-size: 13px;
line-height: 1.4;
white-space: nowrap;
}
&__actions {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin: 0 0 12px;
}
&__metrics {
display: grid;
grid-template-columns: repeat(6, minmax(0, 1fr));
&.is-pair {
grid-template-columns: repeat(2, minmax(180px, 240px));
}
gap: 8px 16px;
margin: 14px 0 16px;
div {
min-width: 0;
}
dt {
margin: 0 0 4px;
color: var(--mint-text-muted, #64748b);
font-size: 13px;
font-weight: 400;
line-height: 1.4;
white-space: nowrap;
}
dd {
margin: 0;
color: #1e293b;
font-size: 14px;
font-weight: 600;
line-height: 1.5;
white-space: nowrap;
&.is-wrap {
font-weight: 500;
white-space: normal;
overflow-wrap: anywhere;
}
}
}
}
.quota-cert-tab-label {
display: inline-flex;
gap: 6px;
align-items: center;
}
</style>