🐛 修复组织类型字典非数字key导致下拉无数据,并调整用户弹窗布局
兼容 organization_type 的中文 dictKey 展示;用户弹窗所属组织与备注宽度按四列布局对齐。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+62
-16
@@ -365,7 +365,6 @@ export default {
|
||||
label: '组织类型',
|
||||
type: 'select',
|
||||
dicData: [],
|
||||
dataType: 'number',
|
||||
minWidth: 120,
|
||||
order: 90,
|
||||
prop: 'deptCategory',
|
||||
@@ -751,11 +750,8 @@ export default {
|
||||
return getDictionary({ code: ORGANIZATION_TYPE_DICT_CODE }).then(res => {
|
||||
const list = res.data.data || [];
|
||||
this.organizationTypeOptions = list
|
||||
.map(item => ({
|
||||
label: item.dictValue,
|
||||
value: Number(item.dictKey),
|
||||
}))
|
||||
.filter(item => item.label && !Number.isNaN(item.value));
|
||||
.map(item => this.normalizeOrganizationTypeOption(item))
|
||||
.filter(Boolean);
|
||||
this.resetDeptCategoryOptions();
|
||||
// 字典异步返回后触发表格组织类型标签重绘
|
||||
if (Array.isArray(this.data) && this.data.length) {
|
||||
@@ -763,6 +759,26 @@ export default {
|
||||
}
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 业务字典项转下拉选项:dictKey 为纯数字时转 number(兼容历史 deptCategory 1~6),否则保留原值。
|
||||
*/
|
||||
normalizeOrganizationTypeOption(item) {
|
||||
const label = item?.dictValue ?? item?.label;
|
||||
const rawKey = item?.dictKey ?? item?.value;
|
||||
if (label === undefined || label === null || String(label).trim() === '') {
|
||||
return null;
|
||||
}
|
||||
if (rawKey === undefined || rawKey === null || String(rawKey).trim() === '') {
|
||||
return null;
|
||||
}
|
||||
const keyText = String(rawKey).trim();
|
||||
const asNumber = Number(keyText);
|
||||
const isPureNumber = keyText !== '' && !Number.isNaN(asNumber) && String(asNumber) === keyText;
|
||||
return {
|
||||
label: String(label),
|
||||
value: isPureNumber ? asNumber : keyText,
|
||||
};
|
||||
},
|
||||
resetDeptCategoryOptions() {
|
||||
const categoryColumn = this.findColumn(this.option.column, 'deptCategory');
|
||||
if (!categoryColumn) {
|
||||
@@ -770,9 +786,37 @@ export default {
|
||||
}
|
||||
categoryColumn.dicData = [...this.organizationTypeOptions];
|
||||
},
|
||||
isSameDeptCategory(left, right) {
|
||||
if (
|
||||
left === null ||
|
||||
left === undefined ||
|
||||
left === '' ||
|
||||
right === null ||
|
||||
right === undefined ||
|
||||
right === ''
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (String(left) === String(right)) {
|
||||
return true;
|
||||
}
|
||||
const leftNumber = Number(left);
|
||||
const rightNumber = Number(right);
|
||||
return !Number.isNaN(leftNumber) && !Number.isNaN(rightNumber) && leftNumber === rightNumber;
|
||||
},
|
||||
isCarrierDeptCategory(value) {
|
||||
if (Number(value) === 6) {
|
||||
return true;
|
||||
}
|
||||
const matched = this.organizationTypeOptions.find(item => this.isSameDeptCategory(item.value, value));
|
||||
const text = matched?.label || value;
|
||||
return String(text).includes('承运商');
|
||||
},
|
||||
filterOrganizationTypeOptions(values) {
|
||||
const valueSet = new Set(values.map(Number));
|
||||
return this.organizationTypeOptions.filter(item => valueSet.has(Number(item.value)));
|
||||
const valueSet = new Set(values.map(item => String(item)));
|
||||
const filtered = this.organizationTypeOptions.filter(item => valueSet.has(String(item.value)));
|
||||
// 字典 key 非数字时无法按历史层级码过滤,回退展示全部,避免下拉无选项
|
||||
return filtered.length ? filtered : [...this.organizationTypeOptions];
|
||||
},
|
||||
updateDeptCategoryOptions() {
|
||||
const categoryColumn = this.findColumn(this.option.column, 'deptCategory');
|
||||
@@ -790,17 +834,19 @@ export default {
|
||||
dicData = this.filterOrganizationTypeOptions([2, 3]);
|
||||
} else if ([2, 3].includes(Number(parent.deptCategory))) {
|
||||
dicData = this.filterOrganizationTypeOptions([4, 5, 6]);
|
||||
} else {
|
||||
dicData = [...this.organizationTypeOptions];
|
||||
}
|
||||
categoryColumn.dicData = dicData;
|
||||
if (!dicData.some(item => Number(item.value) === Number(this.form.deptCategory))) {
|
||||
if (!dicData.some(item => this.isSameDeptCategory(item.value, this.form.deptCategory))) {
|
||||
this.form.deptCategory = dicData[0]?.value;
|
||||
}
|
||||
if (Number(this.form.deptCategory) === 6) {
|
||||
if (this.isCarrierDeptCategory(this.form.deptCategory)) {
|
||||
this.openCarrierDialog();
|
||||
}
|
||||
},
|
||||
handleDeptCategoryChange(value) {
|
||||
if (Number(value) === 6) {
|
||||
if (this.isCarrierDeptCategory(value)) {
|
||||
this.openCarrierDialog();
|
||||
}
|
||||
},
|
||||
@@ -863,10 +909,10 @@ export default {
|
||||
if (deptCategory === null || deptCategory === undefined || deptCategory === '') {
|
||||
return '-';
|
||||
}
|
||||
const matched = this.organizationTypeOptions.find(
|
||||
item => Number(item.value) === Number(deptCategory)
|
||||
const matched = this.organizationTypeOptions.find(item =>
|
||||
this.isSameDeptCategory(item.value, deptCategory)
|
||||
);
|
||||
return matched?.label || '-';
|
||||
return matched?.label || String(deptCategory);
|
||||
},
|
||||
getLeaderValue(leaderId, field) {
|
||||
// func.split 空值时返回 '',需兼容为数组,避免表格 formatter 渲染崩溃导致列错位
|
||||
@@ -906,7 +952,7 @@ export default {
|
||||
row.kingdeeDeptCode = String(row.kingdeeDeptCode || '').trim();
|
||||
row.leaderId = func.join(row.leaderId);
|
||||
this.normalizeTopParent(row);
|
||||
if (Number(row.deptCategory) === 6 && !row.carrierCustomerId) {
|
||||
if (this.isCarrierDeptCategory(row.deptCategory) && !row.carrierCustomerId) {
|
||||
this.$message.warning('请选择承运商');
|
||||
loading();
|
||||
return;
|
||||
@@ -937,7 +983,7 @@ export default {
|
||||
row.kingdeeDeptCode = String(row.kingdeeDeptCode || '').trim();
|
||||
row.leaderId = func.join(row.leaderId);
|
||||
this.normalizeTopParent(row);
|
||||
if (Number(row.deptCategory) === 6 && !row.carrierCustomerId) {
|
||||
if (this.isCarrierDeptCategory(row.deptCategory) && !row.carrierCustomerId) {
|
||||
this.$message.warning('请选择承运商');
|
||||
loading();
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user