This commit is contained in:
Teo
2025-08-10 14:21:46 +08:00
parent 1ff2c759dd
commit aecff98642
5 changed files with 63 additions and 42 deletions

View File

@ -27,7 +27,12 @@
</el-card>
</el-col>
<el-col :span="19">
<el-card shadow="never">
<el-card shadow="never"
><template #header>
<el-row :gutter="10" class="mb8">
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
</template>
<el-table v-loading="loading" :data="cailiaoshebeiList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="设备材料名称" align="center" prop="name" width="110" />
@ -124,7 +129,7 @@
:fileType="['doc', 'docx']"
:autoUpload="false"
ref="fileUploadRef"
:data="{ ...form.bo }"
:data="form.bo"
uploadUrl="/cailiaoshebei/materialsorder/changeTheStatusOfTheMaterials"
:onUploadError="
(err, file, fileList) => {
@ -143,7 +148,7 @@
<template #footer>
<div class="dialog-footer">
<el-button :loading="buttonLoading" type="primary" @click="submitForm"> </el-button>
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</template>
@ -208,8 +213,8 @@ const initFormData: CailiaoshebeiForm = {
finishTime: undefined,
unit: undefined,
plan: undefined,
file: '',
realQuantity: undefined,
file: undefined,
projectId: currentProject.value.id,
bo: {
requiredTime: undefined,
@ -272,6 +277,7 @@ const getBatchList = async () => {
try {
batchTreeRef.value.setCurrentKey(res.rows[0].batchNumber);
form.value.batchNumber = res.rows[0].batchNumber;
queryParams.value.batchNumber = res.rows[0].batchNumber;
} catch (error) {
form.value.batchNumber = '';
}
@ -303,8 +309,14 @@ const cancel = () => {
/** 表单重置 */
const reset = () => {
const preservedBatchId = form.value.batchNumber; // 先保存当前的 batchNumber
form.value = { ...initFormData, batchNumber: preservedBatchId }; // 重置但保留
const preservedBatchId = form.value.batchNumber;
form.value = {
...initFormData,
bo: { ...initFormData.bo }, // 新建一个 bo 对象
batchNumber: preservedBatchId
};
cailiaoshebeiFormRef.value?.resetFields();
};
@ -341,18 +353,30 @@ const handleUpdate = async (row?: CailiaoshebeiVO) => {
operation_s.value = operation_status.value.slice(0, 2);
Object.assign(form.value.bo, row);
console.log('🚀 ~ handleUpdate ~ form.value:', form.value);
// selectValue.value = (form.value.supplierId as string).split(',');
dialog.visible = true;
dialog.title = '修改物资-材料设备';
};
/** 提交按钮 */
const submitForm = () => {
console.log('🚀 ~ submitForm ~ form.value:', form.value);
Object.keys(form.value.bo).forEach((key) => {
if (form.value.bo[key] == 'null' || form.value.bo[key] == null) {
delete form.value.bo[key];
}
});
console.log('🚀 ~ submitForm ~ form.value:', form.value.bo);
cailiaoshebeiFormRef.value?.validate(async (valid: boolean) => {
if (valid) {
buttonLoading.value = true;
fileUploadRef.value!.submitUpload();
if (fileUploadRef.value) {
fileUploadRef.value!.submitUpload();
} else {
form.value.bo.file = null;
await addCailiaoshebei(form.value.bo).finally(() => (buttonLoading.value = false));
dialog.visible = false;
getList();
}
}
});
};
@ -374,7 +398,6 @@ const handleDeleteBatch = async () => {
await delBatch(_ids);
proxy?.$modal.msgSuccess('删除成功');
queryParams.value.batchNumber = '';
await getBatchList();
};
@ -415,20 +438,6 @@ const getSupplierList = async () => {
supplierOptions.value = res.rows;
};
// 中间数组变量供 el-select 使用
const selectValue = ref<string[]>([]);
// 监听 selectValue每次变化时同步更新 form.supplierId 和 form.supplier
watch(
selectValue,
(newVal) => {
form.value.supplierId = newVal.join(',');
const selectedNames = supplierOptions.value.filter((opt) => newVal.includes(opt.id)).map((opt) => opt.name);
form.value.supplier = selectedNames.join(',');
},
{ immediate: true }
);
onMounted(() => {
getBatchList();
getSupplierList();