EntryOrgList.vue
7.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
<template>
<div class="entry-org-container">
<el-table ref="tableRef" class="entry-org-table" :data="tableData" :height="tableHeight"
:highlight-current-row="true" stripe tooltip-effect="light" border>
<el-table-column label="序号" width="56" align="center" fixed="left" :formatter="formatIndex" />
<el-table-column prop="organisationName" label="所属部门" :width="columnWidths.organisationName" align="left"
:show-overflow-tooltip="true">
<template #header>
<span>所属部门</span>
<span style="color:red;margin-left: 2px;">*</span>
</template>
<template #default="scope">
<el-tree-select v-if="!isDetail" v-model="scope.row.organisationGuid" placeholder="请选择" :data="organisationList"
@node-click="(node, nodeObj) => handleTreeSelectNodeChange(node, nodeObj, scope)"
:props="{
value: 'guid',
label: 'name',
children: 'children'
}" clearable filterable :checkStrictly="true" :showAllLevels="false" class="input-width">
</el-tree-select>
<!-- <el-input v-if="!isDetail" v-model="scope.row.organisationName" placeholder="请选择" readonly
@click="openOrgSelector(scope.$index)"></el-input> -->
<span v-else>{{ scope.row.organisationName || '--' }}</span>
</template>
</el-table-column>
<el-table-column prop="isLeader" label="是否部门负责人" :width="columnWidths.isLeader" align="left"
:show-overflow-tooltip="true">
<template #header>
<span>是否部门负责人</span>
<span style="color:red;margin-left: 2px;">*</span>
</template>
<template #default="scope">
<el-select v-if="!isDetail" v-model="scope.row.isLeader" placeholder="请选择" clearable filterable>
<el-option v-for="opt in yesNoOptions" :key="opt.value" :label="opt.label" :value="opt.value" />
</el-select>
<span v-else>{{ scope.row.isLeader == 'Y' ? '是' : '否' }}</span>
</template>
</el-table-column>
<el-table-column prop="isMainOrg" label="是否主责部门" :width="columnWidths.isMainOrg" align="left"
:show-overflow-tooltip="true">
<template #header>
<span>是否主责部门</span>
<span style="color:red;margin-left: 2px;">*</span>
</template>
<template #default="scope">
<el-select v-if="!isDetail" v-model="scope.row.isMainOrg" placeholder="请选择" clearable filterable
@change="handleMainOrgChange(scope.row)">
<el-option v-for="opt in yesNoOptions" :key="opt.value" :label="opt.label" :value="opt.value" />
</el-select>
<span v-else>{{ scope.row.isMainOrg == 'Y' ? '是' : '否' }}</span>
</template>
</el-table-column>
<el-table-column v-if="!isDetail" label="操作" width="140" align="left" fixed="right">
<template #default="scope">
<span class="text_btn" @click="deleteItem(scope)" v-preReClick>删除</span>
</template>
</el-table-column>
</el-table>
</div>
<div v-if="!isDetail" class="add-btn-container">
<el-button link @click="addNewRow" :icon="CirclePlus" v-preReClick>
新增入职部门
</el-button>
</div>
</template>
<script lang="ts" setup name="EntryOrgList">
import { CirclePlus } from "@element-plus/icons-vue";
import {
getOrganisationRelTreeList
} from '@/api/modules/dataBasic';
import { isAllPropertiesEmpty } from '@/utils/common';
import useUserStore from "@/store/modules/user";
const userStore = useUserStore();
const userData = JSON.parse(userStore.userData)
const { proxy } = getCurrentInstance() as any;
// Props 定义
const props = defineProps({
disabled: {
type: Boolean,
default: false
},
organisationJson: {
type: Array as PropType<any[]>,
default: () => []
},
projectDate: {
type: Array as PropType<any[]>,
default: () => []
},
});
// 响应式数据
const tableRef = ref();
const currentIndex = ref<number>(0);
const organisationList = ref<any[]>([]);
const yesNoOptions = ref<any[]>([]);
// 表格数据计算属性
const tableData = computed(() => {
return props.organisationJson;
});
// 详情状态计算属性
const isDetail = computed((): boolean => {
return proxy.$route.query.isDetail || props.disabled;
});
// 表格高度计算
const tableHeight = computed(() => {
return 'auto';
});
// 列宽配置
const columnWidths = computed(() => {
return {
organisationName: '180px',
isLeader: '140px',
isMainOrg: '140px'
};
});
// 初始化数据
const initializeData = async () => {
try {
// 获取是否字典选项
yesNoOptions.value = [{
value: 'Y',
label: '是'
}, {
value: 'N',
label: '否'
}];
// 获取组织列表
await getOrganisationList();
} catch (error) {
console.error('初始化数据失败:', error);
}
};
// 获取组织列表
const getOrganisationList = async () => {
try {
const res: any = await getOrganisationRelTreeList({
tenantGuid: userData.tenantGuid
});
organisationList.value = res?.data || [];
} catch (error) {
console.error('获取组织列表失败:', error);
}
};
// 格式化序号
const formatIndex = (row: any, column: any, cellValue: any, index: number) => {
return String(index + 1);
};
// 处理主责部门变更
const handleMainOrgChange = (row: any) => {
// 检查是否已经有主责部门
const mainOrgCount = tableData.value.filter(item => item.isMainOrg === 'Y').length;
if (mainOrgCount > 1) {
row.isMainOrg = null;
proxy.$message.warning('只能选择一个主责部门');
}
};
// 添加新行
const addNewRow = () => {
// 检查最后一行是否填写完整
if (tableData.value.length > 0) {
const lastItem = tableData.value[tableData.value.length - 1];
const isEmpty = isAllPropertiesEmpty(lastItem, ['organisationGuid', 'isLeader', 'isMainOrg']);
if (isEmpty) {
proxy.$message.warning('请填写完整');
return;
}
}
unref(tableData).push({});
};
// 删除行
const deleteItem = (scope: any) => {
if (isDetail.value) return;
proxy.$openMessageBox('确定删除吗?', () => {
unref(tableData).splice(scope.$index, 1);
proxy.$ElMessage.success('删除成功');
}, () => {
proxy.$ElMessage.info('已取消删除');
});
};
const currentTreeNode = ref({});
const handleTreeSelectNodeChange = (node, nodeObj, scope) => {
currentTreeNode.value = node;
scope.row.organisationName = node.name;
}
// 验证数据
const validateData = (): boolean => {
const guidSet = new Set();
for (const item of tableData.value) {
if (!item.organisationGuid) {
proxy.$ElMessage.error('所属部门必填,请填写完整');
return false;
}
if (!item.isLeader) {
proxy.$ElMessage.error('是否部门负责人必填,请填写完整');
return false;
}
if (!item.isMainOrg) {
proxy.$ElMessage.error('是否主责部门必填,请填写完整');
return false;
}
if (guidSet.has(item.organisationGuid)) {
proxy.$ElMessage.error('部门不能重复');
return false;
}
guidSet.add(item.organisationGuid);
}
return true;
};
// 暴露方法
defineExpose({
tableData,
validateData,
tableRef
});
// 生命周期钩子
onBeforeMount(() => {
initializeData();
});
onMounted(() => {
// 组件挂载后的逻辑
});
</script>
<style lang="scss" scoped>
.entry-org-container {
.entry-org-table {
:deep(.el-table__row) {
.el-input.is-disabled .el-input__inner {
background-color: #f5f7fa;
cursor: not-allowed;
}
}
}
}
.add-btn-container {
.el-button--default {
padding: 4px 0px;
margin-top: 4px;
}
:deep(.el-icon) {
width: 16px;
height: 16px;
svg {
width: 16px;
height: 16px;
}
}
}
</style>