feat(crm): sync contract number date segment with sign date

Align standard contract nos on create/update (keep seq, bump on collision),
preview the change in contract forms, and sync name parentheses.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zlwuandCursor committed 2026-08-03 11:46:11 +08:00
1 parent f01057d902
commit 594e4ce38e
5 files changed
+260 -202

No files matched your search

@@ -19,7 +19,12 @@
<el-input v-model="form.contractNo" placeholder="系统自动生成,格式:SX/X-JT20250926002" maxlength="50" />
</el-form-item>
<el-form-item label="合同名称" prop="contractName">
<el-input v-model="form.contractName" placeholder="可不填,系统将自动生成" maxlength="100" show-word-limit />
<el-input
v-model="form.contractName"
placeholder="可不填,自动生成:供方简称-需方简称(合同编号)"
maxlength="100"
show-word-limit
/>
</el-form-item>
<el-form-item label="合同类型" prop="contractType" required>
<el-select v-model="form.contractType" placeholder="请选择合同类型" style="width: 100%" @change="handleContractTypeChange">
@@ -242,7 +247,7 @@
</div>
</div>
<div class="list-body list-wrap">
<el-table :data="form.products" class="list-table" stripe @selection-change="handleProductSelectionChange">
<ListTable table-key="crm-contract-components-contract-form-dialog" :data="form.products" class="list-table" stripe @selection-change="handleProductSelectionChange">
<el-table-column type="selection" min-width="55" align="center" header-align="center" />
<el-table-column label="序号" type="index" min-width="60" align="center" header-align="center" />
<el-table-column label="产品名称" min-width="160" :show-overflow-tooltip="true">
@@ -410,7 +415,7 @@
</el-button>
</template>
</el-table-column>
</el-table>
</ListTable>
</div>
</div>
@@ -427,7 +432,7 @@
</el-button>
<div class="panel dialog-list-panel mb-3">
<div class="list-body list-wrap dialog-list-body-only">
<el-table :data="prod.priceTiers || []" class="list-table" stripe empty-text="暂无调价区间">
<ListTable table-key="crm-contract-components-contract-form-dialog-2" :data="prod.priceTiers || []" class="list-table" stripe empty-text="暂无调价区间">
<el-table-column type="index" label="#" min-width="50" align="center" header-align="center" />
<el-table-column label="开始日期" min-width="150">
<template #default="scope">
@@ -468,7 +473,7 @@
</el-button>
</template>
</el-table-column>
</el-table>
</ListTable>
</div>
</div>
</div>
@@ -601,6 +606,7 @@ import {
} from '@/utils/crm-product-brand'
import { fetchProductDetail } from '@/api/crm/product'
import ApprovalDialog from './ApprovalDialog.vue'
import { omitEmptyExceptPartyFields } from '../partyFields'
import { getContactByCustomerId } from '@/api/crm/customer'
import type { CustomerVO, ContactVO } from '@/api/crm/customer/types'
import { getDefaultInvoiceInfoByCustomerId } from '@/api/crm/invoiceInfo'
@@ -1348,6 +1354,31 @@ const updateContractNoBySupplier = (newSupplierCode: string | undefined) => {
}
}
const CONTRACT_NO_STD_RE = /^([A-Z]+)\/X-JT(\d{8})(\d{3})$/
/** 签订日变更时:标准编号只换日期段,保留序号;并同步名称括号内编号 */
const syncContractNoDateFromSignDate = (signDateVal: string | null) => {
if (!signDateVal || !form.value.contractNo) return
const m = String(form.value.contractNo).match(CONTRACT_NO_STD_RE)
if (!m) return
const dateStr = signDateVal.replace(/-/g, '')
if (dateStr.length !== 8) return
if (m[2] === dateStr) return
const nextNo = `${m[1]}/X-JT${dateStr}${m[3]}`
form.value.contractNo = nextNo
if (form.value.contractName) {
const replaced = form.value.contractName.replace(/[((][^))]*[))]$/, `(${nextNo})`)
if (replaced !== form.value.contractName) {
form.value.contractName = replaced
} else {
rebuildContractName()
}
}
}
const COMMON_SUPPLIER_SHORT_NAMES = ['山峡', 'SX']
const extractContractNameParts = (contractName: string) => {
@@ -1366,7 +1397,7 @@ const isSupplierShortNamePart = (part: string, supplierShort: string) => {
return part === supplierShort || COMMON_SUPPLIER_SHORT_NAMES.some((name) => part.includes(name))
}
/** 从现有合同名称推断客户简称(切换合同类型时不能依赖新类型解析旧格式) */
/** 从现有合同名称推断客户简称(统一格式:供方简称-需方简称) */
const inferCustomerShortNameFromContractName = (): string => {
if (customerShortName.value) return customerShortName.value
if (!form.value.contractName) return ''
@@ -1383,14 +1414,13 @@ const inferCustomerShortNameFromContractName = (): string => {
return isSupplierShortNamePart(parts[0], supplierShort) ? '' : parts[0]
}
// 统一格式:供方(交易主体)-需方(客户);供方在前则取第二段为客户简称
if (isSupplierShortNamePart(parts[0], supplierShort)) return parts[1]
if (isSupplierShortNamePart(parts[1], supplierShort)) return parts[0]
if (form.value.contractType === 'purchase') return parts[0]
return parts[1]
}
/** 按合同类型重建合同名称:销售/框架=供方简称-客户简称,采购=客户简称-供方简称 */
/** 重建合同名称:统一为 {供方简称}-{需方简称}({合同编号}),不因采购反序 */
const rebuildContractName = () => {
if (!form.value.contractName) return
@@ -1400,10 +1430,7 @@ const rebuildContractName = () => {
const { contractNoInName } = extractContractNameParts(form.value.contractName)
const contractNo = form.value.contractNo || contractNoInName
const isPurchase = form.value.contractType === 'purchase'
const nameBody = isPurchase
? [customerShort, supplierShort].filter(Boolean).join('-')
: [supplierShort, customerShort].filter(Boolean).join('-')
const nameBody = [supplierShort, customerShort].filter(Boolean).join('-')
if (!nameBody) return
@@ -1534,6 +1561,7 @@ const handleSignDateChange = (val: string | null) => {
form.value.startDate = ''
form.value.endDate = ''
}
syncContractNoDateFromSignDate(val)
nextTick(() => {
formRef.value?.validateField('startDate')
})
@@ -1919,11 +1947,7 @@ const handleSaveDraft = async () => {
data.attachmentFiles = attachmentJson
}
Object.keys(data).forEach((key) => {
if (data[key] === undefined || data[key] === '') {
delete data[key]
}
})
omitEmptyExceptPartyFields(data)
if (data.contactsName) {
data.contactName = data.contactsName
@@ -2086,11 +2110,7 @@ const handleSubmit = async () => {
data.attachmentFiles = attachmentJson
}
Object.keys(data).forEach((key) => {
if (data[key] === undefined || data[key] === '') {
delete data[key]
}
})
omitEmptyExceptPartyFields(data)
if (data.contactsName) {
data.contactName = data.contactsName