🐛 业务部门下拉展示所属公司,并映射项目旧平台公司ID
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
@@ -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,
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
})
|
||||
|
||||
@@ -93,6 +93,7 @@
|
||||
<script>
|
||||
import { getList, getDetail, submit, remove } from '@/api/system/business-dept-config';
|
||||
import { getBusinessDeptSelect, getPlatformCompanySelect } from '@/api/system/dept';
|
||||
import { normalizeBusinessDeptOptions } from '@/utils/dept';
|
||||
import { mapGetters } from 'vuex';
|
||||
|
||||
export default {
|
||||
@@ -154,8 +155,9 @@ export default {
|
||||
{
|
||||
label: '业务部门',
|
||||
prop: 'businessDeptName',
|
||||
minWidth: 160,
|
||||
minWidth: 260,
|
||||
display: false,
|
||||
formatter: row => this.formatBusinessDeptLabel(row),
|
||||
},
|
||||
{
|
||||
label: '平台公司',
|
||||
@@ -277,11 +279,16 @@ export default {
|
||||
Promise.all([getPlatformCompanySelect(), getBusinessDeptSelect()]).then(
|
||||
([platformRes, businessRes]) => {
|
||||
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');
|
||||
if (platformColumn) platformColumn.dicData = this.platformCompanyOptions;
|
||||
const businessColumn = this.findColumn(this.option.column, 'businessDeptId');
|
||||
if (businessColumn) businessColumn.dicData = this.businessDeptOptions;
|
||||
// 下拉选项就绪后刷新列表展示名(避免列表先于选项返回时只显示裸部门名)
|
||||
this.refreshBusinessDeptLabels();
|
||||
}
|
||||
);
|
||||
},
|
||||
@@ -292,6 +299,19 @@ export default {
|
||||
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) {
|
||||
// Avue number 空值常落成 -1,历史脏数据也按空展示
|
||||
if (value === null || value === undefined || value === '' || value === -1 || value === '-1') {
|
||||
@@ -317,13 +337,15 @@ export default {
|
||||
},
|
||||
handleBusinessDeptChange(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) {
|
||||
const loadOptions = Promise.all([getPlatformCompanySelect(), getBusinessDeptSelect()]).then(
|
||||
([platformRes, businessRes]) => {
|
||||
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');
|
||||
if (platformColumn) platformColumn.dicData = this.platformCompanyOptions;
|
||||
const businessColumn = this.findColumn(this.option.column, 'businessDeptId');
|
||||
|
||||
Reference in New Issue
Block a user