diff --git a/src/utils/dept.js b/src/utils/dept.js new file mode 100644 index 0000000..ebac9c7 --- /dev/null +++ b/src/utils/dept.js @@ -0,0 +1,39 @@ +/** + * 业务部门下拉规范化。 + * rawLabel 保留原始部门名供落库;展示名优先追加所属公司,缺省时用上级组织。 + * + * @param {Array} list 业务部门原始列表 + * @param {{ alwaysShowCompany?: boolean }} [options] + * alwaysShowCompany=true 时始终展示「部门(公司)」;默认仅同名时追加 + */ +export function normalizeBusinessDeptOptions(list, options = {}) { + const alwaysShowCompany = !!options.alwaysShowCompany; + const source = Array.isArray(list) ? list : []; + const nameCount = {}; + source.forEach(item => { + const name = String(item?.deptName || item?.fullName || '').trim(); + if (!name) return; + nameCount[name] = (nameCount[name] || 0) + 1; + }); + return source + .map(item => { + const id = item?.id == null || item?.id === '' ? '' : String(item.id); + if (!id) return null; + const rawLabel = item.deptName || item.fullName || id; + const companyName = String(item.belongCompanyName || item.parentName || '').trim(); + const label = + companyName && (alwaysShowCompany || nameCount[rawLabel] > 1) + ? `${rawLabel}(${companyName})` + : rawLabel; + return { + id, + value: id, + label, + rawLabel, + parentName: String(item.parentName || '').trim(), + belongCompanyName: String(item.belongCompanyName || '').trim(), + kingdeeDeptCode: item.kingdeeDeptCode || '', + }; + }) + .filter(Boolean); +} diff --git a/src/views/business/contract-manage.vue b/src/views/business/contract-manage.vue index 4b56676..cbf6ec0 100644 --- a/src/views/business/contract-manage.vue +++ b/src/views/business/contract-manage.vue @@ -1205,7 +1205,8 @@ import { getDetail as getCustomerArchiveDetail, getList as getCustomerArchiveList, } from '@/api/vehicle/customer-archive'; -import { getBusinessDeptSelect, getDeptTree } from '@/api/system/dept'; +import { getBusinessDeptSelect, getDeptTree, getPlatformCompanySelect } from '@/api/system/dept'; +import { normalizeBusinessDeptOptions } from '@/utils/dept'; import { getDictionary as getSystemDictionary } from '@/api/system/dict'; import { getDictionary as getBizDictionary } from '@/api/system/dictbiz'; import { config, option } from '@/option/business/contract-manage'; @@ -2678,28 +2679,55 @@ export default { applyProjectPlatformCompanies(project, autoSelect = false) { const ids = this.parseUndertakeDeptIds(project?.undertakeDeptId); const names = this.parseUndertakeDeptNames(project?.undertakeDeptName); - this.platformCompanyOptions = ids.map((id, index) => ({ + // 项目可能仍挂旧组织 ID(已删/非平台公司),按名称映射到现行「是否平台公司=是」的组织 + return this.resolveProjectPlatformCompanyOptions(ids, names).then(options => { + this.platformCompanyOptions = options; + if (!autoSelect) { + this.syncCurrentPlatformCompanyOption(); + return options; + } + if (this.platformCompanyOptions.length === 1) { + this.form.platformCompanyId = this.platformCompanyOptions[0].id; + this.form.platformCompanyName = this.platformCompanyOptions[0].label; + } else if ( + !this.platformCompanyOptions.some( + item => String(item.id) === String(this.form.platformCompanyId) + ) + ) { + this.form.platformCompanyId = ''; + this.form.platformCompanyName = ''; + } else { + this.handlePlatformCompanyChange(this.form.platformCompanyId); + } + if (this.formMode === 'add') this.refreshPreviewContractNo(); + return options; + }); + }, + resolveProjectPlatformCompanyOptions(ids, names) { + const fallback = ids.map((id, index) => ({ id: String(id), label: names[index] || String(id), })); - if (!autoSelect) { - this.syncCurrentPlatformCompanyOption(); - return; - } - if (this.platformCompanyOptions.length === 1) { - this.form.platformCompanyId = this.platformCompanyOptions[0].id; - this.form.platformCompanyName = this.platformCompanyOptions[0].label; - } else if ( - !this.platformCompanyOptions.some( - item => String(item.id) === String(this.form.platformCompanyId) - ) - ) { - this.form.platformCompanyId = ''; - this.form.platformCompanyName = ''; - } else { - this.handlePlatformCompanyChange(this.form.platformCompanyId); - } - if (this.formMode === 'add') this.refreshPreviewContractNo(); + if (!ids.length) return Promise.resolve([]); + return getPlatformCompanySelect() + .then(res => { + const liveList = (res.data?.data || []).map(item => ({ + id: String(item.id), + label: item.deptName || item.fullName || String(item.id), + })); + return ids.map((id, index) => { + const name = String(names[index] || '').trim(); + const byId = liveList.find(item => String(item.id) === String(id)); + if (byId) return byId; + const byName = name ? liveList.find(item => item.label === name) : null; + if (byName) return byName; + return { + id: String(id), + label: name || String(id), + }; + }); + }) + .catch(() => fallback); }, handlePlatformCompanyChange(value) { const matched = this.platformCompanyOptions.find(item => String(item.id) === String(value)); @@ -3093,11 +3121,8 @@ export default { this.businessDeptLoading = true; getBusinessDeptSelect() .then(res => { - this.businessDeptOptions = (res.data?.data || []).map(item => ({ - id: String(item.id), - label: item.deptName || item.fullName || String(item.id), - rawLabel: item.deptName || item.fullName || String(item.id), - })); + // 同名业务部门(不同上级公司)展示「部门(上级)」;落库仍用 rawLabel 原始部门名 + this.businessDeptOptions = normalizeBusinessDeptOptions(res.data?.data || []); this.syncCurrentBusinessDeptOption(); }) .finally(() => { @@ -3113,6 +3138,7 @@ export default { } this.businessDeptOptions.unshift({ id: String(this.form.organizationId), + value: String(this.form.organizationId), label: this.form.organizationName, rawLabel: this.form.organizationName, }); diff --git a/src/views/business/project-apply.vue b/src/views/business/project-apply.vue index ced8d78..ed68327 100644 --- a/src/views/business/project-apply.vue +++ b/src/views/business/project-apply.vue @@ -1094,6 +1094,7 @@ import { getDetail as getCustomerArchiveDetail, } from '@/api/vehicle/customer-archive'; import { getBusinessDeptSelect, getPlatformCompanySelect } from '@/api/system/dept'; +import { normalizeBusinessDeptOptions } from '@/utils/dept'; import { getDictionary as getSystemDictionary } from '@/api/system/dict'; import { getDictionary as getBizDictionary } from '@/api/system/dictbiz'; import { getList as getUserList } from '@/api/system/user'; @@ -2979,19 +2980,8 @@ export default { loadDeptOptions() { getBusinessDeptSelect() .then(res => { - const bizList = res.data.data || []; - // 仅展示「是否业务部门=是」的本级部门,扁平下拉 - this.deptOptions = bizList - .map(item => { - const value = item.id == null || item.id === '' ? '' : String(item.id); - const label = item.deptName || item.fullName || item.title || item.name || value; - return { - label, - rawLabel: label, - value, - }; - }) - .filter(item => item.value); + // 仅展示「是否业务部门=是」;同名部门追加上级组织名区分 + this.deptOptions = normalizeBusinessDeptOptions(res.data.data || []); this.fillDefaultBusinessDept(); this.ensureCurrentBusinessDeptOption(); }) diff --git a/src/views/system/business-dept-config.vue b/src/views/system/business-dept-config.vue index 01f00a7..bf5baec 100644 --- a/src/views/system/business-dept-config.vue +++ b/src/views/system/business-dept-config.vue @@ -93,6 +93,7 @@