forked from integrated_whb/integrated_whb_vue
163 lines
3.9 KiB
Vue
163 lines
3.9 KiB
Vue
<template>
|
|
<el-dialog
|
|
v-model="visible"
|
|
:title="type === 'edit' ? '修改' : '新增'"
|
|
:before-close="fnClose"
|
|
>
|
|
<el-form ref="formRef" :rules="rules" :model="form" label-width="150px">
|
|
<el-form-item
|
|
v-if="type === 'add'"
|
|
label="承诺书名称"
|
|
prop="COMMITMENTNAME"
|
|
clearable
|
|
>
|
|
<el-input
|
|
v-model="form.COMMITMENTNAME"
|
|
placeholder="请输入承诺书名称"
|
|
clearable
|
|
style="width: 300px"
|
|
></el-input>
|
|
</el-form-item>
|
|
<!-- <el-form-item
|
|
v-if="type === 'edit'"
|
|
label="经营企业"
|
|
prop="OPERATINGCOMPANY"
|
|
>
|
|
<span>{{ form.OPERATINGCOMPANY }}</span>
|
|
</el-form-item>-->
|
|
<el-form-item label="承诺书文件" prop="file">
|
|
<layout-upload
|
|
v-model:file-list="form.file"
|
|
accept=".pdf"
|
|
:limit="1"
|
|
:size="100"
|
|
/>
|
|
</el-form-item>
|
|
<el-form-item label="到期时间" prop="EXPIRYDATE">
|
|
<el-date-picker
|
|
v-model="form.EXPIRYDATE"
|
|
type="date"
|
|
format="YYYY-MM-DD"
|
|
value-format="YYYY-MM-DD"
|
|
placeholder="选择时间"
|
|
style="width: 200px"
|
|
clearable
|
|
/>
|
|
</el-form-item>
|
|
<el-form-item label="备注" prop="CONTENT">
|
|
<el-input
|
|
v-model="form.CONTENT"
|
|
type="textarea"
|
|
placeholder="请输入内容"
|
|
style="width: 300px"
|
|
></el-input>
|
|
</el-form-item>
|
|
</el-form>
|
|
<template #footer>
|
|
<el-button @click="fnClose">取消</el-button>
|
|
<el-button type="primary" @click="fnSubmit">确定</el-button>
|
|
</template>
|
|
</el-dialog>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { ref, toRaw } from "vue";
|
|
import { useVModels } from "@vueuse/core";
|
|
import { ElMessage } from "element-plus";
|
|
import LayoutUpload from "@/components/upload/index.vue";
|
|
import {
|
|
addCommitmentView,
|
|
editCommitmentView,
|
|
} from "@/request/traffic_safety_commitment.js";
|
|
|
|
const props = defineProps({
|
|
visible: {
|
|
type: Boolean,
|
|
required: true,
|
|
default: false,
|
|
},
|
|
form: {
|
|
type: {},
|
|
required: false,
|
|
default: false,
|
|
},
|
|
loading: {
|
|
type: Boolean,
|
|
required: true,
|
|
default: false,
|
|
},
|
|
options: {
|
|
type: Array,
|
|
required: true,
|
|
default: () => [],
|
|
},
|
|
type: {
|
|
type: String,
|
|
required: true,
|
|
default: "",
|
|
},
|
|
});
|
|
const emits = defineEmits(["update:visible", "update:form", "get-data"]);
|
|
const { visible, form } = useVModels(props, emits);
|
|
const rules = {
|
|
file: [
|
|
{ required: true, message: "请上传承诺书文件附件", trigger: "change" },
|
|
],
|
|
COMMITMENTNAME: [
|
|
{ required: true, message: "请输入承诺书名称", trigger: "blur" },
|
|
],
|
|
EXPIRYDATE: [
|
|
{ required: true, message: "请选择到期时间", trigger: "change" },
|
|
]
|
|
};
|
|
const formRef = ref(null);
|
|
const fnClose = () => {
|
|
formRef.value.resetFields();
|
|
visible.value = false;
|
|
};
|
|
|
|
const fnSubmit = async () => {
|
|
await formRef.value.validate();
|
|
|
|
const rawFormValue = toRaw(form.value);
|
|
|
|
const formData = new FormData();
|
|
|
|
// 处理文件上传
|
|
if (Array.isArray(rawFormValue.file)) {
|
|
rawFormValue.file.forEach((fileItem) => {
|
|
if (fileItem.raw) {
|
|
formData.append("FFILE", fileItem.raw);
|
|
}
|
|
});
|
|
}
|
|
Object.keys(rawFormValue).forEach((key) => {
|
|
if (key !== "file") {
|
|
formData.append(key, rawFormValue[key]);
|
|
}
|
|
});
|
|
// 执行添加或编辑操作
|
|
if (props.type === "add") {
|
|
formData.append("USER_ID", rawFormValue.USER_ID);
|
|
await addCommitmentView(formData);
|
|
} else {
|
|
formData.append(
|
|
"SECURITYCOMMITMENT_ID",
|
|
rawFormValue.SECURITYCOMMITMENT_ID
|
|
);
|
|
await editCommitmentView(formData);
|
|
}
|
|
|
|
// 操作成功提示
|
|
ElMessage.success("操作成功");
|
|
|
|
// 关闭表单对话框
|
|
fnClose();
|
|
|
|
// 触发更新数据的事件
|
|
emits("get-data");
|
|
};
|
|
</script>
|
|
|
|
<style scoped lang="scss"></style>
|