This commit is contained in:
sjl
2024-12-23 14:05:53 +08:00
parent 5f0b36b3bb
commit fdf91965d9
6 changed files with 138 additions and 105 deletions

View File

@@ -14,13 +14,7 @@
<el-table-column prop="nextId" label="序号" width="60" />
<el-table-column prop="type" label="电能质量检测指标类型" min-width="200">
<template #default="{ row }">
<el-cascader :options="options" v-model="row.type"/>
<!-- <el-select v-model="row.type" placeholder="选择指标类型" >
<el-option v-for="item in dictStore.getDictData('Pq_Test_Type')"
:key="item.id"
:label="item.name"
:value="item.id"/>
</el-select> -->
<el-cascader :options="options" v-model="row.type" :props="{ checkStrictly: false, emitPath: false }"/>
</template>
</el-table-column>
<el-table-column label="起止范围" >
@@ -64,7 +58,7 @@
v-for="item in dictStore.getDictData('Condition_Type')"
:key="item.id"
:label="item.name"
:value="item.id"
:value="Number(item.value)"
/>
</el-select>
</template>
@@ -83,7 +77,7 @@
v-for="item in dictStore.getDictData('Error_Value_Type')"
:key="item.id"
:label="item.name"
:value="item.id"
:value="Number(item.value)"
/>
</el-select>
</template>
@@ -104,61 +98,23 @@
import { useDictStore, } from '@/stores/modules/dict'
import {CirclePlus, Delete, EditPen,CopyDocument} from '@element-plus/icons-vue'
import { type CascaderOption, type FormItemRule } from 'element-plus';
import { onMounted, type PropType, Ref, ref, watch } from 'vue';
import { type PropType, type Ref, ref, watch } from 'vue';
import { defineEmits } from 'vue';
import ProTable from '@/components/ProTable/index.vue'
import {
getDictTreeList,
} from '@/api/system/dictionary/dictTree'
import { type Dict } from '@/api/system/dictionary/interface';
const emit = defineEmits(['updateTableData']);
const multipleSelection = ref<number[]>([])
const dictStore = useDictStore()
const props = defineProps({
options: {
type: Array as PropType<CascaderOption[]>,
required: true
},
tableData: {
type: Array as PropType<ErrorSystem.ErrorSystemDetail[]>,
default: () => []
}
});
const options: Ref<CascaderOption[]> = ref([]); // 修改这里
onMounted(async () => {
const dictCode = '误差体系指标项'; // 替换为实际需要的字典代码
const resDictTree: Dict.ResDictTree = {
name: dictCode,
id: '',
pid: '',
pids: '',
code: '',
sort: 0
};
const result = await getDictTreeList(resDictTree);
const allOptions = convertToOptions(result.data as Dict.ResDictTree[]);
// 提取第二层节点
const secondLevelOptions: any[] = [];
allOptions.forEach(option => {
if (option.children && option.children.length > 0) {
secondLevelOptions.push(...option.children);
}
});
// 将第二层节点赋值给 options.value
options.value = secondLevelOptions;
})
// 转换函数
const convertToOptions = (dictTree: Dict.ResDictTree[]): CascaderOption[] => {
return dictTree.map(item => ({
value: item.id,
label: item.name,
children: item.children ? convertToOptions(item.children) : undefined
}));
};
// 监听 props.tableData 的变化,确保每次数据变化时都重新设置 nextId
watch(() => props.tableData, async (newTableData) => {
for (let i = 0; i < newTableData.length; i++) {

View File

@@ -35,7 +35,7 @@
</el-tabs>
<ErrorSystemDetailTable :tableData="tableData" @updateTableData="handleTableDataUpdate" />
<ErrorSystemDetailTable :tableData="tableData" :options="options" @updateTableData="handleTableDataUpdate" />
<template #footer>
<div >
@@ -49,22 +49,25 @@
</template>
<script lang="ts" setup name="ErrorSystemDialog">
import{ElMessage, type FormInstance,type FormItemRule}from'element-plus'
import { defineProps, defineEmits, reactive,watch,ref, Ref, computed } from 'vue';
import{type CascaderOption, ElMessage, type FormInstance,type FormItemRule}from'element-plus'
import { defineProps, defineEmits, reactive,watch,ref, type Ref, computed } from 'vue';
import { dialogBig} from '@/utils/elementBind'
import { addPqErrSys,updatePqErrSys,getPqErrSysListById} from '@/api/device/error/index'
import {CirclePlus, Delete, EditPen,FolderOpened,CopyDocument} from '@element-plus/icons-vue'
import { useDictStore } from '@/stores/modules/dict'
import { type ErrorSystem } from '@/api/device/interface/error';
import ErrorSystemDetailTable from '@/views/machine/errorSystem/components/errorSystemDetailTable.vue';
import {getDictTreeList} from '@/api/system/dictionary/dictTree'
import { type Dict } from '@/api/system/dictionary/interface';
// 定义弹出组件元信息
const dialogFormRef = ref()
const dictStore = useDictStore()
const tableData = ref<ErrorSystem.ErrorSystemDetail[]>([]);
const handleTableDataUpdate = (newTableData: ErrorSystem.ErrorSystemDetail[]) => {
const options: Ref<CascaderOption[]> = ref([]); // 修改这里
const handleTableDataUpdate = (newTableData: ErrorSystem.ErrorSystemDetail[]) => {
tableData.value = newTableData;
};
};
function useMetaInfo() {
const dialogVisible = ref(false)
@@ -149,12 +152,47 @@
console.error('验证过程中出现错误', err)
}
}
// 封装提取第二层节点的逻辑
const loadSecondLevelOptions = async () => {
const dictCode = '误差体系指标项'; // 替换为实际需要的字典代码
const resDictTree: Dict.ResDictTree = {
name: dictCode,
id: '',
pid: '',
pids: '',
code: '',
sort: 0
};
const result = await getDictTreeList(resDictTree);
const allOptions = convertToOptions(result.data as Dict.ResDictTree[]);
// 提取第二层节点
const secondLevelOptions: any[] = [];
allOptions.forEach(option => {
if (option.children && option.children.length > 0) {
secondLevelOptions.push(...option.children);
}
});
// 将第二层节点赋值给 options.value
options.value = secondLevelOptions;
};
// 转换函数
const convertToOptions = (dictTree: Dict.ResDictTree[]): CascaderOption[] => {
return dictTree.map(item => ({
value: item.id,
label: item.name,
children: item.children ? convertToOptions(item.children) : undefined
}));
};
// 打开弹窗,可能是新增,也可能是编辑
const open = async (sign: string, data: ErrorSystem.ErrorSystemList) => {
titleType.value = sign
dialogVisible.value = true
// 确保每次打开弹窗时都重新加载数据
await loadSecondLevelOptions();
if (data.id) {
const result = await getPqErrSysListById(data);
if (result && result.data) {
@@ -167,6 +205,9 @@ const open = async (sign: string, data: ErrorSystem.ErrorSystemList) => {
}
// 重置表单
dialogFormRef.value?.resetFields()
dialogVisible.value = true
}