|
|
@@ -20,11 +20,17 @@
|
|
|
<el-radio :label="3">报废</el-radio>
|
|
|
</el-radio-group>
|
|
|
</template>
|
|
|
- <template #isUseDepartment>
|
|
|
- <el-radio-group v-model="formData.isUseDepartment">
|
|
|
- <el-radio :label="1">是</el-radio>
|
|
|
- <el-radio :label="0">否</el-radio>
|
|
|
- </el-radio-group>
|
|
|
+ <template #useDepartment>
|
|
|
+ <el-cascader
|
|
|
+ v-model="useDepartmentPath"
|
|
|
+ :options="deptOptions"
|
|
|
+ :props="deptCascaderProps"
|
|
|
+ :show-all-levels="false"
|
|
|
+ placeholder="请选择使用部门"
|
|
|
+ filterable
|
|
|
+ clearable
|
|
|
+ @change="handleUseDeptChange"
|
|
|
+ />
|
|
|
</template>
|
|
|
<template #responsibilityDept>
|
|
|
<el-cascader
|
|
|
@@ -79,6 +85,7 @@
|
|
|
// 部门树(queryAllDeptTree 样式)
|
|
|
const deptOptions = ref<any[]>([]);
|
|
|
const responsibilityDeptPath = ref<number[]>([]);
|
|
|
+ const useDepartmentPath = ref<number[]>([]);
|
|
|
const deptCascaderProps = {
|
|
|
expandTrigger: 'click',
|
|
|
checkStrictly: true,
|
|
|
@@ -110,20 +117,65 @@
|
|
|
};
|
|
|
dfs(deptOptions.value, []);
|
|
|
}
|
|
|
+ // 使用部门回显:根据名称在树中查找路径
|
|
|
+ if ((formData as any).useDepartment) {
|
|
|
+ useDepartmentPath.value = getDeptPathByName(deptOptions.value, (formData as any).useDepartment);
|
|
|
+ }
|
|
|
} catch (e) {
|
|
|
console.error('获取部门树失败:', e);
|
|
|
deptOptions.value = [];
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+ /** 根据部门名称在树中查找路径(用于回显) */
|
|
|
+ const getDeptPathByName = (options: any[], name: string): number[] => {
|
|
|
+ if (!name || !options?.length) return [];
|
|
|
+ const dfs = (nodes: any[], currentPath: number[]): number[] => {
|
|
|
+ for (const n of nodes) {
|
|
|
+ const newPath = [...currentPath, n.id];
|
|
|
+ if (n.deptName === name) return newPath;
|
|
|
+ if (n.children?.length) {
|
|
|
+ const found = dfs(n.children, newPath);
|
|
|
+ if (found.length) return found;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return [];
|
|
|
+ };
|
|
|
+ return dfs(options, []);
|
|
|
+ };
|
|
|
+
|
|
|
+ /** 根据部门树路径取末级部门名称(使用部门复用责任部门) */
|
|
|
+ const getDeptNameByPath = (options: any[], pathIds: number[]): string => {
|
|
|
+ if (!pathIds?.length) return '';
|
|
|
+ let current = options;
|
|
|
+ let name = '';
|
|
|
+ for (const id of pathIds) {
|
|
|
+ const node = current.find((n: any) => n.id === id);
|
|
|
+ if (!node) return name;
|
|
|
+ name = node.deptName;
|
|
|
+ current = node.children || [];
|
|
|
+ }
|
|
|
+ return name;
|
|
|
+ };
|
|
|
+
|
|
|
const handleDeptChange = (val: number[]) => {
|
|
|
if (Array.isArray(val) && val.length) {
|
|
|
(formData as any).responsibilityDeptId = val[val.length - 1];
|
|
|
+ (formData as any).useDepartment = getDeptNameByPath(deptOptions.value, val);
|
|
|
+ useDepartmentPath.value = [...val];
|
|
|
} else {
|
|
|
(formData as any).responsibilityDeptId = undefined;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+ const handleUseDeptChange = (val: number[]) => {
|
|
|
+ if (Array.isArray(val) && val.length) {
|
|
|
+ (formData as any).useDepartment = getDeptNameByPath(deptOptions.value, val);
|
|
|
+ } else {
|
|
|
+ (formData as any).useDepartment = '';
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
const getDetail = async () => {
|
|
|
if (!id.value) {
|
|
|
ElMessage.error('缺少 id');
|
|
|
@@ -155,7 +207,6 @@
|
|
|
formData.productionDate = res.productionDate ?? '';
|
|
|
formData.inspectionCycle = res.inspectionCycle ?? undefined;
|
|
|
formData.deviceStatus = res.deviceStatus ?? 1;
|
|
|
- formData.isUseDepartment = res.isUseDepartment ?? 1;
|
|
|
formData.nextInspectionDate = res.nextInspectionDate ?? '';
|
|
|
formData.remark = res.remark ?? '';
|
|
|
}
|