fix(pl): 优化证件行内绑定并保护已关联数据免于误改
This commit is contained in:
1 parent
ed22f7df4e
commit
d30a406aa6
12 files changed
+300
-54
No files matched your search
@@ -51,6 +51,7 @@ export interface QuotaCert extends Omit<CertBody, 'status'> {
|
||||
id: string
|
||||
status: 'draft' | 'active' | 'suspended' | 'void'
|
||||
bindingsEditable?: boolean
|
||||
referencesEditable?: boolean
|
||||
revision: number
|
||||
reservedQty: string | number
|
||||
usedQty: string | number
|
||||
@@ -347,6 +348,7 @@ export const quotaAdjustmentApi = {
|
||||
|
||||
export type QuotaQuantity = string | number
|
||||
export interface CertificateContractBinding {
|
||||
editLocked?: boolean
|
||||
id?: string
|
||||
contractId: string
|
||||
linkStatus?: 'active' | 'inactive'
|
||||
|
||||
@@ -220,10 +220,23 @@
|
||||
@change="edited.add('vehicleNumbersJson')"
|
||||
/></el-form-item>
|
||||
<h3 class="dialog-section-title">证面引用</h3>
|
||||
<el-button
|
||||
class="mb-3"
|
||||
type="primary"
|
||||
:disabled="saving || form.referencesEditable === false"
|
||||
@click="addReference"
|
||||
><el-icon><Plus /></el-icon>添加引用</el-button
|
||||
>
|
||||
<p v-if="form.referencesEditable === false" class="form-tip"
|
||||
>已有用证关联,不能编辑或移除证面引用,请联系管理员。</p
|
||||
>
|
||||
<el-table :data="form.purchaseRefs" row-key="id" stripe>
|
||||
<el-table-column label="引用类型" min-width="160"
|
||||
><template #default="{ row }"
|
||||
><el-select v-model="row.referenceType" @change="edited.add('purchaseRefs')"
|
||||
><el-select
|
||||
v-model="row.referenceType"
|
||||
:disabled="saving || form.referencesEditable === false"
|
||||
@change="edited.add('purchaseRefs')"
|
||||
><el-option
|
||||
v-for="(label, value) in refLabels"
|
||||
:key="value"
|
||||
@@ -234,12 +247,14 @@
|
||||
><template #default="{ row }"
|
||||
><el-input
|
||||
v-model="row.referenceNo"
|
||||
:disabled="saving || form.referencesEditable === false"
|
||||
@input="edited.add('purchaseRefs')" /></template
|
||||
></el-table-column>
|
||||
<el-table-column label="对应购买证档案" min-width="200"
|
||||
><template #default="{ row }"
|
||||
><el-select
|
||||
v-model="row.purchaseCertId"
|
||||
:disabled="saving || form.referencesEditable === false"
|
||||
filterable
|
||||
clearable
|
||||
@change="edited.add('purchaseRefs')"
|
||||
@@ -251,58 +266,75 @@
|
||||
></el-table-column>
|
||||
<el-table-column label="操作" min-width="260" fixed="right"
|
||||
><template #default="{ $index }"
|
||||
><el-button @click="removeReference($index)"
|
||||
><el-button
|
||||
:disabled="saving || form.referencesEditable === false"
|
||||
@click="removeReference($index)"
|
||||
><el-icon><Delete /></el-icon>移除引用</el-button
|
||||
></template
|
||||
></el-table-column
|
||||
>
|
||||
</el-table>
|
||||
<el-button @click="addReference"
|
||||
><el-icon><Plus /></el-icon>添加引用</el-button
|
||||
>
|
||||
</section>
|
||||
<section class="view-section">
|
||||
<h3 class="dialog-section-title">绑定合同产品</h3>
|
||||
<p v-if="form.bindingsEditable === false" class="form-tip">
|
||||
当前仅展示可见合同,绑定范围不可编辑;证面信息仍可保存。
|
||||
</p>
|
||||
<el-select
|
||||
<el-button
|
||||
v-if="form.bindingsEditable !== false"
|
||||
:model-value="undefined"
|
||||
filterable
|
||||
remote
|
||||
clearable
|
||||
placeholder="搜索合同编号或名称,添加合同"
|
||||
:remote-method="searchBindingContracts"
|
||||
:loading="bindingSearching"
|
||||
class="mb-3"
|
||||
type="primary"
|
||||
:disabled="saving"
|
||||
@visible-change="(open: boolean) => open && searchBindingContracts('')"
|
||||
@change="addContractBinding"
|
||||
@click="addContractBinding()"
|
||||
><el-icon><Plus /></el-icon>添加合同</el-button
|
||||
>
|
||||
<el-option
|
||||
v-for="contract in bindingContracts"
|
||||
:key="contract.id"
|
||||
:value="contract.id"
|
||||
:label="contract.contractNo + ' · ' + contract.contractName"
|
||||
:disabled="
|
||||
form.contractBindings?.some(
|
||||
(b: CertificateContractBinding) => b.contractId === contract.id
|
||||
)
|
||||
"
|
||||
/>
|
||||
</el-select>
|
||||
<el-table :data="form.contractBindings || []" stripe>
|
||||
<el-table-column label="合同" min-width="220">
|
||||
<template #default="{ row }">{{ bindingContractLabel(row.contractId) }}</template>
|
||||
<template #default="{ row, $index }">
|
||||
<el-select
|
||||
:model-value="row.contractId"
|
||||
filterable
|
||||
remote
|
||||
placeholder="请选择合同"
|
||||
:remote-method="searchBindingContracts"
|
||||
:loading="bindingSearching"
|
||||
:disabled="saving || form.bindingsEditable === false || row.editLocked"
|
||||
@visible-change="(open: boolean) => open && searchBindingContracts('')"
|
||||
@change="(id: string) => changeBindingContract($index, id)"
|
||||
>
|
||||
<el-option
|
||||
v-for="contract in bindingContracts"
|
||||
:key="contract.id"
|
||||
:value="contract.id"
|
||||
:label="contract.contractNo + ' · ' + contract.contractName"
|
||||
:disabled="
|
||||
form.contractBindings.some(
|
||||
(b: CertificateContractBinding, i: number) =>
|
||||
i !== $index && b.contractId === contract.id
|
||||
)
|
||||
"
|
||||
/>
|
||||
<el-option
|
||||
v-if="row.contractId && !bindingContracts.some((c) => c.id === row.contractId)"
|
||||
:value="row.contractId"
|
||||
label="合同信息不可用"
|
||||
/>
|
||||
</el-select>
|
||||
<p v-if="row.editLocked" class="form-tip"
|
||||
>已有用证关联,不能编辑或移除,请联系管理员。</p
|
||||
>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="适用合同产品" min-width="360">
|
||||
<template #default="{ row, $index }">
|
||||
<el-select
|
||||
multiple
|
||||
:model-value="row.products.map((p: any) => p.contractProductId)"
|
||||
:disabled="saving || form.bindingsEditable === false"
|
||||
:disabled="
|
||||
saving || form.bindingsEditable === false || row.editLocked || !row.contractId
|
||||
"
|
||||
:loading="bindingProductLoading[row.contractId]"
|
||||
placeholder="勾选适用产品"
|
||||
:placeholder="row.contractId ? '勾选适用产品' : '请先选择合同'"
|
||||
style="width: 100%"
|
||||
@change="(ids: string[]) => setBindingProducts($index, ids)"
|
||||
@visible-change="(open: boolean) => open && loadBindingProducts(row.contractId)"
|
||||
@@ -334,8 +366,10 @@
|
||||
min-width="260"
|
||||
fixed="right"
|
||||
>
|
||||
<template #default="{ $index }"
|
||||
><el-button :disabled="saving" @click="removeContractBinding($index)"
|
||||
<template #default="{ row, $index }"
|
||||
><el-button
|
||||
:disabled="saving || row.editLocked"
|
||||
@click="removeContractBinding($index)"
|
||||
><el-icon><Delete /></el-icon>移除合同</el-button
|
||||
></template
|
||||
>
|
||||
@@ -615,12 +649,6 @@
|
||||
const bindingProductLoading = ref<Record<string, boolean>>({})
|
||||
const removedBindings = new Map<string, CertificateContractBinding>()
|
||||
const originalScopes = new Map<string, CertificateContractBinding['products']>()
|
||||
function bindingContractLabel(id: string) {
|
||||
const contract = bindingContracts.value.find((item) => item.id === id)
|
||||
return contract
|
||||
? [contract.contractNo, contract.contractName].filter(Boolean).join(' · ')
|
||||
: '合同信息不可用'
|
||||
}
|
||||
function bindingProductOptions(binding: CertificateContractBinding): ContractProduct[] {
|
||||
const options = bindingProducts.value[binding.contractId] || []
|
||||
return [
|
||||
@@ -676,26 +704,66 @@
|
||||
if (isCurrent()) bindingProductLoading.value[contractId] = false
|
||||
}
|
||||
}
|
||||
function addContractBinding(contractId: string) {
|
||||
function addContractBinding(contractId = '') {
|
||||
if (
|
||||
!contractId ||
|
||||
saving.value ||
|
||||
form.value.bindingsEditable === false ||
|
||||
form.value.contractBindings?.some(
|
||||
(b: CertificateContractBinding) => b.contractId === contractId
|
||||
)
|
||||
(contractId &&
|
||||
form.value.contractBindings?.some(
|
||||
(b: CertificateContractBinding) => b.contractId === contractId
|
||||
))
|
||||
)
|
||||
return
|
||||
form.value.contractBindings ||= []
|
||||
form.value.contractBindings.push(
|
||||
removedBindings.get(contractId) || { contractId, linkStatus: 'active', products: [] }
|
||||
)
|
||||
void loadBindingProducts(contractId).catch(() => {})
|
||||
if (contractId) void loadBindingProducts(contractId).catch(() => {})
|
||||
}
|
||||
function changeBindingContract(index: number, contractId: string) {
|
||||
const previous = form.value.contractBindings[index] as CertificateContractBinding
|
||||
if (
|
||||
saving.value ||
|
||||
form.value.bindingsEditable === false ||
|
||||
!previous ||
|
||||
previous.contractId === contractId
|
||||
)
|
||||
return
|
||||
if (previous.editLocked) {
|
||||
ElMessage.warning('已有用证关联,不能编辑或移除,请联系管理员')
|
||||
return
|
||||
}
|
||||
if (
|
||||
form.value.contractBindings.some(
|
||||
(b: CertificateContractBinding, i: number) => i !== index && b.contractId === contractId
|
||||
)
|
||||
) {
|
||||
ElMessage.warning('该合同已添加,请在原行选择产品')
|
||||
return
|
||||
}
|
||||
if (previous.contractId) {
|
||||
removedBindings.set(previous.contractId, previous)
|
||||
bindingProductEpochs.set(
|
||||
previous.contractId,
|
||||
(bindingProductEpochs.get(previous.contractId) || 0) + 1
|
||||
)
|
||||
delete bindingProductLoading.value[previous.contractId]
|
||||
}
|
||||
form.value.contractBindings[index] = removedBindings.get(contractId) || {
|
||||
contractId,
|
||||
linkStatus: 'active',
|
||||
products: []
|
||||
}
|
||||
if (contractId) void loadBindingProducts(contractId).catch(() => {})
|
||||
}
|
||||
function removeContractBinding(index: number) {
|
||||
if (saving.value || form.value.bindingsEditable === false) return
|
||||
if (form.value.contractBindings[index]?.editLocked) {
|
||||
ElMessage.warning('已有用证关联,不能编辑或移除,请联系管理员')
|
||||
return
|
||||
}
|
||||
const [removed] = form.value.contractBindings.splice(index, 1)
|
||||
removedBindings.set(removed.contractId, removed)
|
||||
if (removed.contractId) removedBindings.set(removed.contractId, removed)
|
||||
bindingProductEpochs.set(
|
||||
removed.contractId,
|
||||
(bindingProductEpochs.get(removed.contractId) || 0) + 1
|
||||
@@ -706,7 +774,11 @@
|
||||
function setBindingProducts(index: number, ids: string[]) {
|
||||
if (saving.value || form.value.bindingsEditable === false) return
|
||||
const binding = form.value.contractBindings[index] as CertificateContractBinding
|
||||
if (bindingProductLoading.value[binding.contractId]) return
|
||||
if (binding.editLocked) {
|
||||
ElMessage.warning('已有用证关联,不能编辑或移除,请联系管理员')
|
||||
return
|
||||
}
|
||||
if (!binding.contractId || bindingProductLoading.value[binding.contractId]) return
|
||||
const previous = [...binding.products, ...(originalScopes.get(binding.contractId) || [])]
|
||||
binding.products = ids.map(
|
||||
(id) =>
|
||||
@@ -752,7 +824,8 @@
|
||||
...b,
|
||||
products: b.products.map((p) => ({ ...p }))
|
||||
})),
|
||||
bindingsEditable: cert.bindingsEditable !== false
|
||||
bindingsEditable: cert.bindingsEditable !== false,
|
||||
referencesEditable: cert.referencesEditable !== false
|
||||
}
|
||||
: { ...newCert(targetKind), contractBindings: [], bindingsEditable: true }
|
||||
const contracts = row ? await quotaCertApi.certificateContracts(targetKind, row.id) : []
|
||||
@@ -848,6 +921,13 @@
|
||||
}
|
||||
async function save() {
|
||||
if (saving.value) return
|
||||
if (
|
||||
form.value.bindingsEditable !== false &&
|
||||
form.value.contractBindings?.some((b: CertificateContractBinding) => !b.contractId)
|
||||
) {
|
||||
ElMessage.warning('请选择每行绑定的合同,或移除未填写行')
|
||||
return
|
||||
}
|
||||
if (certAttachments.value?.hasUploading()) {
|
||||
ElMessage.warning('请等待附件上传完成')
|
||||
return
|
||||
@@ -915,7 +995,13 @@
|
||||
if (session === editSession) recognizing.value = false
|
||||
}
|
||||
}
|
||||
function referencesLocked() {
|
||||
if (form.value.referencesEditable !== false) return false
|
||||
ElMessage.warning('已有用证关联,不能编辑或移除证面引用,请联系管理员')
|
||||
return true
|
||||
}
|
||||
function addReference() {
|
||||
if (saving.value || referencesLocked()) return
|
||||
form.value.purchaseRefs.push({
|
||||
referenceType: 'unknown',
|
||||
referenceNo: '',
|
||||
@@ -924,6 +1010,7 @@
|
||||
edited.add('purchaseRefs')
|
||||
}
|
||||
function removeReference(index: number) {
|
||||
if (saving.value || referencesLocked()) return
|
||||
form.value.purchaseRefs.splice(index, 1)
|
||||
edited.add('purchaseRefs')
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user