调整 合同、运力、客商、项目
This commit is contained in:
+124
-31
@@ -42,12 +42,6 @@
|
||||
<template #deptCategory="{ row }">
|
||||
<el-tag>{{ getDeptCategoryLabel(row.deptCategory) }}</el-tag>
|
||||
</template>
|
||||
<template #leaderId="{ row }">
|
||||
{{ getLeaderValue(row.leaderId, 'realName') }}
|
||||
</template>
|
||||
<template #leaderPhone="{ row }">
|
||||
{{ getLeaderValue(row.leaderId, 'phone') }}
|
||||
</template>
|
||||
<template #status="{ row }">
|
||||
<el-tag :type="Number(row.status) === 1 ? 'success' : 'info'" class="status-text">
|
||||
{{ Number(row.status) === 1 ? '启用' : '停用' }}
|
||||
@@ -174,6 +168,7 @@ export default {
|
||||
searchIndex: 4,
|
||||
searchMenuPosition: 'right',
|
||||
tree: true,
|
||||
rowKey: 'id',
|
||||
border: true,
|
||||
index: true,
|
||||
selection: true,
|
||||
@@ -183,6 +178,8 @@ export default {
|
||||
dialogClickModal: false,
|
||||
labelPosition: 'right',
|
||||
labelWidth: 'auto',
|
||||
// 禁用 Avue 列状态持久化,避免增列后表头/单元格错位
|
||||
columnState: false,
|
||||
column: [
|
||||
{
|
||||
label: '组织名称',
|
||||
@@ -206,22 +203,32 @@ export default {
|
||||
maxlength: 30,
|
||||
showWordLimit: true,
|
||||
rules: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入组织编码',
|
||||
trigger: 'blur',
|
||||
},
|
||||
{
|
||||
validator: (rule, value, callback) => {
|
||||
const deptCode = String(value || '').trim();
|
||||
// 组织编码非必填,为空直接通过
|
||||
if (!deptCode) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
if (deptCode.length > 30) {
|
||||
callback(new Error('组织编码不能超过30个字符'));
|
||||
return;
|
||||
}
|
||||
if (!this.parentDeptCode) {
|
||||
const parentId = this.normalizeParentId(this.form?.parentId);
|
||||
if (!parentId) {
|
||||
callback(new Error('请先选择上级组织'));
|
||||
return;
|
||||
}
|
||||
if (!this.parentDept || String(this.parentDept.id) !== String(parentId)) {
|
||||
this.loadParentDeptCode(parentId);
|
||||
callback(new Error('正在加载上级组织编码,请稍后重试'));
|
||||
return;
|
||||
}
|
||||
if (!this.parentDeptCode) {
|
||||
callback(new Error('上级组织未配置组织编码,请先完善上级组织编码'));
|
||||
return;
|
||||
}
|
||||
const pattern = new RegExp(`^${escapeRegExp(this.parentDeptCode)}-\\d+$`);
|
||||
if (!pattern.test(deptCode)) {
|
||||
callback(new Error(`组织编码格式应为:${this.parentDeptCode}-分段数字`));
|
||||
@@ -239,6 +246,18 @@ export default {
|
||||
minWidth: 140,
|
||||
order: 60,
|
||||
},
|
||||
{
|
||||
label: '助记码',
|
||||
prop: 'mnemonicCode',
|
||||
minWidth: 120,
|
||||
order: 50,
|
||||
},
|
||||
{
|
||||
label: '拼音助记码',
|
||||
prop: 'pinyinMnemonic',
|
||||
minWidth: 140,
|
||||
order: 45,
|
||||
},
|
||||
{
|
||||
label: '组织类型',
|
||||
type: 'select',
|
||||
@@ -268,29 +287,40 @@ export default {
|
||||
label: '负责人',
|
||||
prop: 'leaderId',
|
||||
minWidth: 120,
|
||||
slot: true,
|
||||
addDisplay: false,
|
||||
editDisplay: false,
|
||||
viewDisplay: false,
|
||||
formatter: row => this.getLeaderValue(row.leaderId, 'realName'),
|
||||
},
|
||||
{
|
||||
label: '联系电话',
|
||||
prop: 'leaderPhone',
|
||||
minWidth: 140,
|
||||
slot: true,
|
||||
addDisplay: false,
|
||||
editDisplay: false,
|
||||
viewDisplay: false,
|
||||
formatter: row => this.getLeaderValue(row.leaderId, 'phone'),
|
||||
},
|
||||
{
|
||||
label: '助记码',
|
||||
prop: 'mnemonicCode',
|
||||
minWidth: 120,
|
||||
order: 40,
|
||||
},
|
||||
{
|
||||
label: '拼音助记码',
|
||||
prop: 'pinyinMnemonic',
|
||||
minWidth: 140,
|
||||
order: 50,
|
||||
label: '是否平台公司',
|
||||
prop: 'isPlatformCompany',
|
||||
type: 'select',
|
||||
dicData: [
|
||||
{ label: '否', value: 0 },
|
||||
{ label: '是', value: 1 },
|
||||
],
|
||||
dataType: 'number',
|
||||
value: 0,
|
||||
width: 120,
|
||||
order: 35,
|
||||
formatter: row => (Number(row.isPlatformCompany) === 1 ? '是' : '否'),
|
||||
rules: [
|
||||
{
|
||||
required: true,
|
||||
message: '请选择是否平台公司',
|
||||
trigger: 'change',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: '排序',
|
||||
@@ -314,6 +344,7 @@ export default {
|
||||
slot: true,
|
||||
addDisplay: false,
|
||||
editDisplay: false,
|
||||
viewDisplay: false,
|
||||
},
|
||||
{
|
||||
label: '上级组织',
|
||||
@@ -372,6 +403,20 @@ export default {
|
||||
};
|
||||
},
|
||||
created() {
|
||||
// 清除可能错乱的表格列顺序/列状态缓存,避免新增列后表头/单元格错位
|
||||
try {
|
||||
const path = this.$route?.path || '/system/dept';
|
||||
Object.keys(localStorage).forEach(key => {
|
||||
if (
|
||||
(key.startsWith('tms:table-column-order:') && key.includes(path)) ||
|
||||
(key.startsWith('AVUE_COLUMN_STATE:') && key.includes('dept'))
|
||||
) {
|
||||
localStorage.removeItem(key);
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
// ignore storage errors
|
||||
}
|
||||
this.loadLeaderOptions();
|
||||
},
|
||||
computed: {
|
||||
@@ -400,16 +445,47 @@ export default {
|
||||
});
|
||||
},
|
||||
handleParentChange(parentId) {
|
||||
this.loadParentDeptCode(parentId);
|
||||
// Avue tree 选择时可能先触发空值 change,避免把已加载的上级编码清掉
|
||||
const normalizedId = this.normalizeParentId(parentId);
|
||||
if (!normalizedId && this.form?.parentId) {
|
||||
return;
|
||||
}
|
||||
this.loadParentDeptCode(normalizedId || this.form?.parentId);
|
||||
},
|
||||
normalizeParentId(parentId) {
|
||||
if (Array.isArray(parentId)) {
|
||||
parentId = parentId[0];
|
||||
}
|
||||
if (parentId && typeof parentId === 'object') {
|
||||
parentId = parentId.value ?? parentId.id ?? parentId.key;
|
||||
}
|
||||
if (!parentId || String(parentId) === '0') {
|
||||
return '';
|
||||
}
|
||||
return parentId;
|
||||
},
|
||||
loadParentDeptCode(parentId) {
|
||||
this.parentDeptCode = '';
|
||||
this.parentDept = null;
|
||||
if (!parentId || String(parentId) === '0') return;
|
||||
getDept(parentId).then(res => {
|
||||
const normalizedId = this.normalizeParentId(parentId);
|
||||
if (!normalizedId) {
|
||||
this.parentDeptCode = '';
|
||||
this.parentDept = null;
|
||||
return;
|
||||
}
|
||||
getDept(normalizedId).then(res => {
|
||||
// 防止异步乱序:仅采纳当前表单上级对应的结果
|
||||
if (
|
||||
this.form?.parentId &&
|
||||
String(this.form.parentId) !== '0' &&
|
||||
String(this.form.parentId) !== String(normalizedId)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
this.parentDept = res.data.data || null;
|
||||
this.parentDeptCode = this.parentDept?.deptCode || '';
|
||||
this.updateDeptCategoryOptions();
|
||||
this.$nextTick(() => {
|
||||
this.$refs.crud?.clearValidate?.('deptCode');
|
||||
});
|
||||
});
|
||||
},
|
||||
updateDeptCategoryOptions() {
|
||||
@@ -496,6 +572,10 @@ export default {
|
||||
loadLeaderOptions(tenantId) {
|
||||
getLeaderList(tenantId).then(res => {
|
||||
this.leaderOptions = res.data.data || [];
|
||||
// formatter 依赖负责人字典,异步返回后触发表格重绘
|
||||
if (Array.isArray(this.data) && this.data.length) {
|
||||
this.data = [...this.data];
|
||||
}
|
||||
});
|
||||
},
|
||||
getDeptCategoryLabel(deptCategory) {
|
||||
@@ -510,7 +590,16 @@ export default {
|
||||
return categoryMap[Number(deptCategory)] || '-';
|
||||
},
|
||||
getLeaderValue(leaderId, field) {
|
||||
const values = func.split(leaderId);
|
||||
// func.split 空值时返回 '',需兼容为数组,避免表格 formatter 渲染崩溃导致列错位
|
||||
const splitResult = func.split(leaderId);
|
||||
const values = Array.isArray(splitResult)
|
||||
? splitResult
|
||||
: String(splitResult || '')
|
||||
.split(',')
|
||||
.filter(Boolean);
|
||||
if (!values.length) {
|
||||
return '-';
|
||||
}
|
||||
const result = values
|
||||
.map(id => this.leaderOptions.find(item => String(item.id) === String(id))?.[field])
|
||||
.filter(Boolean);
|
||||
@@ -660,6 +749,9 @@ export default {
|
||||
beforeOpen(done, type) {
|
||||
if (type === 'add') {
|
||||
this.form.tenantId = this.form.tenantId || this.userInfo.tenantId || website.tenantId;
|
||||
if (this.form.isPlatformCompany === undefined || this.form.isPlatformCompany === null) {
|
||||
this.form.isPlatformCompany = 0;
|
||||
}
|
||||
this.initData(this.form.tenantId);
|
||||
this.loadParentDeptCode(this.form.parentId);
|
||||
}
|
||||
@@ -676,7 +768,8 @@ export default {
|
||||
}
|
||||
this.loadParentDeptCode(this.form.parentId);
|
||||
if (this.form.hasOwnProperty('leaderId')) {
|
||||
this.form.leaderId = func.split(this.form.leaderId);
|
||||
const splitResult = func.split(this.form.leaderId);
|
||||
this.form.leaderId = Array.isArray(splitResult) ? splitResult : [];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user