748214a4b6
Co-authored-by: Cursor <cursoragent@cursor.com>
40 lines
1.4 KiB
JavaScript
40 lines
1.4 KiB
JavaScript
/**
|
||
* 业务部门下拉规范化。
|
||
* 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);
|
||
}
|