优化操作
This commit is contained in:
@@ -257,7 +257,17 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<el-table :data="enabledMaterialTypes" border stripe height="240px" class="mt-2">
|
<el-table :data="enabledMaterialTypes" border stripe height="240px" class="mt-2">
|
||||||
<el-table-column label="选择要求" width="85" align="center">
|
<el-table-column label="选择要求" width="95" align="center">
|
||||||
|
<template #header>
|
||||||
|
<el-checkbox
|
||||||
|
:model-value="isAllMaterialsSelected"
|
||||||
|
:indeterminate="isMaterialsIndeterminate"
|
||||||
|
:disabled="!enabledMaterialTypes.length"
|
||||||
|
@change="handleSelectAllMaterials"
|
||||||
|
>
|
||||||
|
全选
|
||||||
|
</el-checkbox>
|
||||||
|
</template>
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<el-checkbox :model-value="hasMaterial(scope.row.id)"
|
<el-checkbox :model-value="hasMaterial(scope.row.id)"
|
||||||
@change="value => toggleMaterial(scope.row.id, Boolean(value))" />
|
@change="value => toggleMaterial(scope.row.id, Boolean(value))" />
|
||||||
@@ -565,6 +575,35 @@ function toggleMaterial(materialTypeId: number, checked: boolean) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isAllMaterialsSelected = computed(() => {
|
||||||
|
if (!enabledMaterialTypes.value.length) return false;
|
||||||
|
return enabledMaterialTypes.value.every(item => hasMaterial(item.id));
|
||||||
|
});
|
||||||
|
|
||||||
|
const isMaterialsIndeterminate = computed(() => {
|
||||||
|
if (!enabledMaterialTypes.value.length) return false;
|
||||||
|
const selectedCount = enabledMaterialTypes.value.filter(item => hasMaterial(item.id)).length;
|
||||||
|
return selectedCount > 0 && selectedCount < enabledMaterialTypes.value.length;
|
||||||
|
});
|
||||||
|
|
||||||
|
function handleSelectAllMaterials(checked: boolean | string | number) {
|
||||||
|
const isChecked = Boolean(checked);
|
||||||
|
if (isChecked) {
|
||||||
|
enabledMaterialTypes.value.forEach(item => {
|
||||||
|
if (!hasMaterial(item.id)) {
|
||||||
|
form.materials.push({
|
||||||
|
materialTypeId: item.id,
|
||||||
|
required: true,
|
||||||
|
sortCode: (form.materials.length + 1) * 10
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const enabledIds = new Set(enabledMaterialTypes.value.map(item => item.id));
|
||||||
|
form.materials = form.materials.filter(item => !enabledIds.has(item.materialTypeId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function openCreate() {
|
async function openCreate() {
|
||||||
await loadBaseData();
|
await loadBaseData();
|
||||||
Object.assign(form, {
|
Object.assign(form, {
|
||||||
|
|||||||
Reference in New Issue
Block a user