🐛 业务部门下拉展示所属公司,并映射项目旧平台公司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);
}