🐛 业务部门下拉展示所属公司,并映射项目旧平台公司ID

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-09 12:44:44 +08:00
parent d3ba0ce38b
commit 748214a4b6
4 changed files with 119 additions and 42 deletions
+39
View File
@@ -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);
}
+51 -25
View File
@@ -1205,7 +1205,8 @@ import {
getDetail as getCustomerArchiveDetail, getDetail as getCustomerArchiveDetail,
getList as getCustomerArchiveList, getList as getCustomerArchiveList,
} from '@/api/vehicle/customer-archive'; } 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 getSystemDictionary } from '@/api/system/dict';
import { getDictionary as getBizDictionary } from '@/api/system/dictbiz'; import { getDictionary as getBizDictionary } from '@/api/system/dictbiz';
import { config, option } from '@/option/business/contract-manage'; import { config, option } from '@/option/business/contract-manage';
@@ -2678,28 +2679,55 @@ export default {
applyProjectPlatformCompanies(project, autoSelect = false) { applyProjectPlatformCompanies(project, autoSelect = false) {
const ids = this.parseUndertakeDeptIds(project?.undertakeDeptId); const ids = this.parseUndertakeDeptIds(project?.undertakeDeptId);
const names = this.parseUndertakeDeptNames(project?.undertakeDeptName); 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), id: String(id),
label: names[index] || String(id), label: names[index] || String(id),
})); }));
if (!autoSelect) { if (!ids.length) return Promise.resolve([]);
this.syncCurrentPlatformCompanyOption(); return getPlatformCompanySelect()
return; .then(res => {
} const liveList = (res.data?.data || []).map(item => ({
if (this.platformCompanyOptions.length === 1) { id: String(item.id),
this.form.platformCompanyId = this.platformCompanyOptions[0].id; label: item.deptName || item.fullName || String(item.id),
this.form.platformCompanyName = this.platformCompanyOptions[0].label; }));
} else if ( return ids.map((id, index) => {
!this.platformCompanyOptions.some( const name = String(names[index] || '').trim();
item => String(item.id) === String(this.form.platformCompanyId) const byId = liveList.find(item => String(item.id) === String(id));
) if (byId) return byId;
) { const byName = name ? liveList.find(item => item.label === name) : null;
this.form.platformCompanyId = ''; if (byName) return byName;
this.form.platformCompanyName = ''; return {
} else { id: String(id),
this.handlePlatformCompanyChange(this.form.platformCompanyId); label: name || String(id),
} };
if (this.formMode === 'add') this.refreshPreviewContractNo(); });
})
.catch(() => fallback);
}, },
handlePlatformCompanyChange(value) { handlePlatformCompanyChange(value) {
const matched = this.platformCompanyOptions.find(item => String(item.id) === String(value)); const matched = this.platformCompanyOptions.find(item => String(item.id) === String(value));
@@ -3093,11 +3121,8 @@ export default {
this.businessDeptLoading = true; this.businessDeptLoading = true;
getBusinessDeptSelect() getBusinessDeptSelect()
.then(res => { .then(res => {
this.businessDeptOptions = (res.data?.data || []).map(item => ({ // 同名业务部门(不同上级公司)展示「部门(上级)」;落库仍用 rawLabel 原始部门名
id: String(item.id), this.businessDeptOptions = normalizeBusinessDeptOptions(res.data?.data || []);
label: item.deptName || item.fullName || String(item.id),
rawLabel: item.deptName || item.fullName || String(item.id),
}));
this.syncCurrentBusinessDeptOption(); this.syncCurrentBusinessDeptOption();
}) })
.finally(() => { .finally(() => {
@@ -3113,6 +3138,7 @@ export default {
} }
this.businessDeptOptions.unshift({ this.businessDeptOptions.unshift({
id: String(this.form.organizationId), id: String(this.form.organizationId),
value: String(this.form.organizationId),
label: this.form.organizationName, label: this.form.organizationName,
rawLabel: this.form.organizationName, rawLabel: this.form.organizationName,
}); });
+3 -13
View File
@@ -1094,6 +1094,7 @@ import {
getDetail as getCustomerArchiveDetail, getDetail as getCustomerArchiveDetail,
} from '@/api/vehicle/customer-archive'; } from '@/api/vehicle/customer-archive';
import { getBusinessDeptSelect, getPlatformCompanySelect } from '@/api/system/dept'; import { getBusinessDeptSelect, getPlatformCompanySelect } from '@/api/system/dept';
import { normalizeBusinessDeptOptions } from '@/utils/dept';
import { getDictionary as getSystemDictionary } from '@/api/system/dict'; import { getDictionary as getSystemDictionary } from '@/api/system/dict';
import { getDictionary as getBizDictionary } from '@/api/system/dictbiz'; import { getDictionary as getBizDictionary } from '@/api/system/dictbiz';
import { getList as getUserList } from '@/api/system/user'; import { getList as getUserList } from '@/api/system/user';
@@ -2979,19 +2980,8 @@ export default {
loadDeptOptions() { loadDeptOptions() {
getBusinessDeptSelect() getBusinessDeptSelect()
.then(res => { .then(res => {
const bizList = res.data.data || []; // 仅展示「是否业务部门=是」;同名部门追加上级组织名区分
// 仅展示「是否业务部门=是」的本级部门,扁平下拉 this.deptOptions = normalizeBusinessDeptOptions(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.fillDefaultBusinessDept(); this.fillDefaultBusinessDept();
this.ensureCurrentBusinessDeptOption(); this.ensureCurrentBusinessDeptOption();
}) })
+26 -4
View File
@@ -93,6 +93,7 @@
<script> <script>
import { getList, getDetail, submit, remove } from '@/api/system/business-dept-config'; import { getList, getDetail, submit, remove } from '@/api/system/business-dept-config';
import { getBusinessDeptSelect, getPlatformCompanySelect } from '@/api/system/dept'; import { getBusinessDeptSelect, getPlatformCompanySelect } from '@/api/system/dept';
import { normalizeBusinessDeptOptions } from '@/utils/dept';
import { mapGetters } from 'vuex'; import { mapGetters } from 'vuex';
export default { export default {
@@ -154,8 +155,9 @@ export default {
{ {
label: '业务部门', label: '业务部门',
prop: 'businessDeptName', prop: 'businessDeptName',
minWidth: 160, minWidth: 260,
display: false, display: false,
formatter: row => this.formatBusinessDeptLabel(row),
}, },
{ {
label: '平台公司', label: '平台公司',
@@ -277,11 +279,16 @@ export default {
Promise.all([getPlatformCompanySelect(), getBusinessDeptSelect()]).then( Promise.all([getPlatformCompanySelect(), getBusinessDeptSelect()]).then(
([platformRes, businessRes]) => { ([platformRes, businessRes]) => {
this.platformCompanyOptions = this.normalizeDeptOptions(platformRes?.data?.data); this.platformCompanyOptions = this.normalizeDeptOptions(platformRes?.data?.data);
this.businessDeptOptions = this.normalizeDeptOptions(businessRes?.data?.data); // 业务部门配置页始终展示「部门(所属公司)」,便于与平台公司配对
this.businessDeptOptions = normalizeBusinessDeptOptions(businessRes?.data?.data, {
alwaysShowCompany: true,
});
const platformColumn = this.findColumn(this.option.column, 'platformCompanyId'); const platformColumn = this.findColumn(this.option.column, 'platformCompanyId');
if (platformColumn) platformColumn.dicData = this.platformCompanyOptions; if (platformColumn) platformColumn.dicData = this.platformCompanyOptions;
const businessColumn = this.findColumn(this.option.column, 'businessDeptId'); const businessColumn = this.findColumn(this.option.column, 'businessDeptId');
if (businessColumn) businessColumn.dicData = this.businessDeptOptions; if (businessColumn) businessColumn.dicData = this.businessDeptOptions;
// 下拉选项就绪后刷新列表展示名(避免列表先于选项返回时只显示裸部门名)
this.refreshBusinessDeptLabels();
} }
); );
}, },
@@ -292,6 +299,19 @@ export default {
kingdeeDeptCode: item.kingdeeDeptCode || '', kingdeeDeptCode: item.kingdeeDeptCode || '',
})); }));
}, },
/** 列表业务部门列:部门名(所属公司) */
formatBusinessDeptLabel(row) {
if (!row) return '-';
const matched = this.businessDeptOptions.find(
item => String(item.value) === String(row.businessDeptId)
);
if (matched?.label) return matched.label;
return row.businessDeptName || '-';
},
refreshBusinessDeptLabels() {
if (!this.data?.length) return;
this.data = this.data.map(row => ({ ...row }));
},
formatSerial(value) { formatSerial(value) {
// Avue number 空值常落成 -1,历史脏数据也按空展示 // Avue number 空值常落成 -1,历史脏数据也按空展示
if (value === null || value === undefined || value === '' || value === -1 || value === '-1') { if (value === null || value === undefined || value === '' || value === -1 || value === '-1') {
@@ -317,13 +337,15 @@ export default {
}, },
handleBusinessDeptChange(value) { handleBusinessDeptChange(value) {
const matched = this.businessDeptOptions.find(item => String(item.value) === String(value)); const matched = this.businessDeptOptions.find(item => String(item.value) === String(value));
this.form.businessDeptName = matched ? matched.label : ''; this.form.businessDeptName = matched ? matched.rawLabel || matched.label : '';
}, },
beforeOpen(done, type) { beforeOpen(done, type) {
const loadOptions = Promise.all([getPlatformCompanySelect(), getBusinessDeptSelect()]).then( const loadOptions = Promise.all([getPlatformCompanySelect(), getBusinessDeptSelect()]).then(
([platformRes, businessRes]) => { ([platformRes, businessRes]) => {
this.platformCompanyOptions = this.normalizeDeptOptions(platformRes?.data?.data); this.platformCompanyOptions = this.normalizeDeptOptions(platformRes?.data?.data);
this.businessDeptOptions = this.normalizeDeptOptions(businessRes?.data?.data); this.businessDeptOptions = normalizeBusinessDeptOptions(businessRes?.data?.data, {
alwaysShowCompany: true,
});
const platformColumn = this.findColumn(this.option.column, 'platformCompanyId'); const platformColumn = this.findColumn(this.option.column, 'platformCompanyId');
if (platformColumn) platformColumn.dicData = this.platformCompanyOptions; if (platformColumn) platformColumn.dicData = this.platformCompanyOptions;
const businessColumn = this.findColumn(this.option.column, 'businessDeptId'); const businessColumn = this.findColumn(this.option.column, 'businessDeptId');