误差体系禁用

This commit is contained in:
sjl
2024-12-24 20:22:36 +08:00
parent f17f5c9925
commit f0edeaee85
8 changed files with 368 additions and 62 deletions

View File

@@ -11,7 +11,7 @@
:style="{ height: '250px',maxHeight: '400px',overflow:'hidden'}"
@selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" />
<el-table-column prop="nextId" label="序号" width="60" />
<el-table-column prop="sort" label="序号" width="60" />
<el-table-column prop="type" label="电能质量检测指标类型" min-width="340">
<template #default="{ row }">
<el-cascader style="min-width: 350px;"
@@ -26,14 +26,14 @@
<template #default="{ row }">
<el-row type="flex" :gutter="24">
<el-col :span="12">
<el-select v-model="row.startFlag" placeholder="选择起始值" style="width: 70px;">
<el-select v-model="row.startFlag" placeholder="选择起始值" style="width: 70px;" @change="(value) => handleStartFlagChange(row, value)">
<el-option label="无" :value="2"></el-option>
<el-option label=">=" :value="1"></el-option>
<el-option label=">" :value="0"></el-option>
</el-select>
</el-col>
<el-col :span="12">
<el-input v-model= "row.startValue" style="width: 60px;"
<el-input v-model= "row.startValue" style="width: 60px;" :disabled="isStartValueDisabled[row.sort]"
/>
</el-col>
</el-row>
@@ -43,14 +43,14 @@
<template #default="{ row }">
<el-row type="flex" :gutter="24" >
<el-col :span="12">
<el-select v-model="row.endFlag" placeholder="选择结束值" style="width: 70px;">
<el-select v-model="row.endFlag" placeholder="选择结束值" style="width: 70px;" @change="(value) => handleEndFlagChange(row, value)">
<el-option label="无" :value="2"></el-option>
<el-option label="<=" :value="1"></el-option>
<el-option label="<" :value="0"></el-option>
</el-select>
</el-col>
<el-col :span="12">
<el-input v-model= "row.endValue" style="width: 60px;"/>
<el-input v-model= "row.endValue" style="width: 60px;" :disabled="isEndValueDisabled[row.sort]"/>
</el-col>
</el-row>
</template>
@@ -107,6 +107,8 @@
const emit = defineEmits(['updateTableData']);
const multipleSelection = ref<number[]>([])
const dictStore = useDictStore()
const isStartValueDisabled = ref<{ [key: number]: boolean }>({});
const isEndValueDisabled = ref<{ [key: number]: boolean }>({});
const props = defineProps({
options: {
type: Array as PropType<CascaderOption[]>,
@@ -119,43 +121,78 @@
}
});
// 监听 props.tableData 的变化,确保每次数据变化时都重新设置 nextId
// 监听 props.tableData 的变化,确保每次数据变化时都重新设置 sort
watch(() => props.tableData, async (newTableData) => {
for (let i = 0; i < newTableData.length; i++) {
newTableData[i].nextId = i + 1;
newTableData[i].sort = i + 1;
if (newTableData[i].startFlag === 2) {
newTableData[i].startValue = null; // 设置 startValue 为 null
}
if (newTableData[i].endFlag === 2) {
newTableData[i].endValue = null; // 设置 endValue 为 null
}
}
// 重新设置 isStartValueDisabled 和 isEndValueDisabled,并清空输入框
props.tableData.forEach(row => {
isStartValueDisabled.value[row.sort] = row.startFlag === 2;
});
props.tableData.forEach(row => {
isEndValueDisabled.value[row.sort] = row.endFlag === 2;
});
}, { immediate: true });
// 处理 startFlag 变化的方法
const handleStartFlagChange = (row: ErrorSystem.ErrorSystemDetail, value: number) => {
if (value === 2) {
row.startValue = null; // 清空输入框
isStartValueDisabled.value[row.sort] = true; // 禁用输入框
} else {
isStartValueDisabled.value[row.sort] = false; // 启用输入框
}
};
// 处理 endFlag 变化的方法
const handleEndFlagChange = (row: ErrorSystem.ErrorSystemDetail, value: number) => {
if (value === 2) {
row.endValue = null; // 清空输入框
isEndValueDisabled.value[row.sort] = true; // 禁用输入框
} else {
isEndValueDisabled.value[row.sort] = false; // 启用输入框
}
};
//选中
const handleSelectionChange = (selection: ErrorSystem.ErrorSystemDetail[]) => {
multipleSelection.value = selection.map(row => row.nextId); // 更新选中的行
multipleSelection.value = selection.map(row => row.sort); // 更新选中的行
};
//新增
const openAddDialog = () => {
// 获取字典数据
const conditionTypes = dictStore.getDictData('Condition_Type');
const errorValueTypes = dictStore.getDictData('Error_Value_Type');
const newRow = {
nextId: props.tableData.length + 1,
id: '',
startFlag:2,
endFlag:2,
conditionType: conditionTypes.length > 0 ? Number(conditionTypes[3].value) : 0, // 设置默认值为第一个选项的值
errorValueType:errorValueTypes.length > 0 ? Number(errorValueTypes[0].value) : 0, // 设置默认值为第一个选项的值
errorSysId: "",
type: "",
maxErrorValue: 0
const newRow = {
sort: props.tableData.length + 1,
id: '',
startFlag:2,
endFlag:2,
conditionType: conditionTypes.length > 0 ? Number(conditionTypes[3].value) : 0, // 设置默认值为第一个选项的值
errorValueType:errorValueTypes.length > 0 ? Number(errorValueTypes[0].value) : 0, // 设置默认值为第一个选项的值
errorSysId: "",
type: "",
maxErrorValue: 0
};
emit('updateTableData', [...props.tableData, newRow]);
};
const copyRow = (row: ErrorSystem.ErrorSystemDetail) => {
// 深拷贝行数据
const newRow = { ...row };
const maxNextId = Math.max(...props.tableData.map(item => item.nextId), 0);
newRow.nextId = maxNextId + 1;
const maxNextId = Math.max(...props.tableData.map(item => item.sort), 0);
newRow.sort = maxNextId + 1;
emit('updateTableData', [...props.tableData, newRow]);
};
//删除行
@@ -169,7 +206,7 @@ const deleteRow = (row:ErrorSystem.ErrorSystemDetail) => {
};
//批量删除选中行
const deleteSelectedRows = () => {
const newTableData = props.tableData.filter(row => !multipleSelection.value.includes(row.nextId));
const newTableData = props.tableData.filter(row => !multipleSelection.value.includes(row.sort));
multipleSelection.value = []; // 清空已选择的行
emit('updateTableData', newTableData);
};

View File

@@ -180,13 +180,13 @@ const handleTableDataUpdate = (newTableData: ErrorSystem.ErrorSystemDetail[]) =>
};
// 转换函数
const convertToOptions = (dictTree: Dict.ResDictTree[]): CascaderOption[] => {
return dictTree.map(item => ({
value: item.id,
label: item.name,
children: item.children ? convertToOptions(item.children) : undefined
}));
};
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) => {