<template>
|
<el-dialog v-model="centerDialogVisible" title="文档管理" width="500" center>
|
<el-form
|
ref="ruleFormRef"
|
style="max-width: 600px"
|
:model="ruleForm"
|
:rules="rules"
|
label-width="auto"
|
>
|
<el-form-item label="名称" prop="name">
|
<el-input v-model="ruleForm.name" placeholder="请输入文档名称" />
|
</el-form-item>
|
<el-form-item label="请输入文档类型" prop="type">
|
<el-select v-model="ruleForm.type" placeholder="请输入文档类型">
|
<el-option label="合同" value="合同" />
|
<el-option label="报告" value="报告" />
|
</el-select>
|
</el-form-item>
|
<el-form-item label="请输入文档状态" prop="status">
|
<el-select v-model="ruleForm.status" placeholder="请输入文档状态">
|
<el-option
|
v-for="option in options"
|
:key="option.value"
|
:label="option.label"
|
:value="option.value"
|
/>
|
</el-select>
|
</el-form-item>
|
</el-form>
|
<template #footer>
|
<el-row>
|
<el-col :span="24" style="text-align: right">
|
<el-button @click="centerDialogVisible = false">取 消</el-button>
|
<el-button type="primary" @click="submit"> 确 定 </el-button>
|
</el-col>
|
</el-row>
|
</template>
|
<fileUpload
|
v-model="ruleForm.file"
|
:fileSize="1024"
|
:fileType="['pdf', 'docx', 'txt', 'xlsx', 'pptx....']"
|
:limit="10"
|
/>
|
</el-dialog>
|
</template>
|
|
<script setup>
|
import { ref, watch } from "vue";
|
import { addOrEditArchive } from "@/api/archiveManagement";
|
import fileUpload from "@/components/FileUpload/index.vue";
|
|
const centerDialogVisible = defineModel("centerDialogVisible", {
|
type: Boolean,
|
default: false,
|
});
|
|
const props = defineProps({
|
row: {
|
type: Object,
|
default: () => ({}),
|
},
|
});
|
const copyFormData = (data) => {
|
return JSON.parse(JSON.stringify(data));
|
};
|
// 初始化表单数据的辅助函数
|
const initFormData = (rowData) => {
|
if (rowData && rowData.id) {
|
return copyFormData(rowData);
|
}
|
return {
|
name: "",
|
type: "",
|
status: "",
|
};
|
};
|
|
// 初始化表单数据
|
const ruleFormRef = ref(null);
|
const ruleForm = ref(initFormData(props.row));
|
const copyForm = ref();
|
// 监听 row 的变化,更新 ruleForm
|
watch(
|
() => props.row,
|
(newRow) => {
|
copyForm.value = initFormData(newRow);
|
ruleForm.value = JSON.parse(JSON.stringify(copyForm.value));
|
},
|
{ deep: true }
|
);
|
const rules = {
|
name: [{ required: true, message: "请输入文档名称", trigger: "blur" }],
|
type: [{ required: true, message: "请选择文档类型", trigger: "blur" }],
|
status: [{ required: true, message: "请选择文档状态", trigger: "blur" }],
|
};
|
|
const options = [
|
{ value: "有效", label: "有效" },
|
{ value: "无效", label: "无效" },
|
{ value: "作废", label: "作废" },
|
];
|
const emit = defineEmits(["submitForm"]);
|
const submit = async () => {
|
// 验证表单
|
if (!ruleFormRef.value) return;
|
|
try {
|
const valid = await ruleFormRef.value.validate();
|
if (!valid) {
|
return;
|
}
|
|
// 调用 API
|
let res = await addOrEditArchive(ruleForm.value);
|
console.log("API 响应:", res);
|
|
// 发送 emit 事件
|
emit("submitForm", res);
|
console.log("emit submitForm 已发送");
|
|
// 关闭对话框
|
centerDialogVisible.value = false;
|
} catch (error) {
|
console.error("表单验证失败或API调用失败:", error);
|
}
|
};
|
</script>
|
|
<style lang="less" scoped></style>
|