🐛 业务部门下拉展示所属公司,并映射项目旧平台公司ID
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user