<template>
|
<div class="notice">
|
<el-dialog
|
v-model="dialogVisible"
|
:title="state.title"
|
width="550px"
|
:before-close="handleClose"
|
>
|
<el-form :model="state.form" size="default" ref="formRef" :rules="state.formRules" label-width="110px" >
|
<el-form-item label="整改时间:" prop="rectifyTime" >
|
<el-date-picker
|
style="width: 100%"
|
v-model="state.form.rectifyTime"
|
type="date"
|
value-format="YYYY-MM-DD 00:00:00"
|
placeholder="请选择日期"
|
size="large"
|
/>
|
</el-form-item>
|
<el-form-item label="整改人:" prop="rectifyPerson">
|
<el-input v-model="state.form.rectifyPerson" show-word-limit type="text" size="large" placeholder="请输入整改人" />
|
</el-form-item>
|
<el-form-item label="整改说明:" prop="reason">
|
<el-input v-model="state.form.reason" show-word-limit type="text" size="large" placeholder="请输入整改说明"/>
|
</el-form-item>
|
<el-form-item prop="fileList">
|
<el-upload accept=".pdf"
|
:action="state.uploadUrl"
|
:disabled="state.disabled"
|
:headers="state.header"
|
method="post"
|
:limit="state.imgLimit"
|
:before-upload="beforeUpload"
|
:on-success="handleAvatarSuccess"
|
v-model:file-list="state.form.fileList"
|
:on-remove="handleRemove"
|
:data="state.uploadData"
|
:on-preview="handlePreview"
|
>
|
<el-button type="primary">附件上传</el-button>
|
<template #tip>
|
<div class="el-upload__tip">
|
只能上传pdf类型,且只能上传一个
|
</div>
|
</template>
|
</el-upload>
|
|
</el-form-item>
|
</el-form>
|
<template #footer >
|
<span class="dialog-footer">
|
<el-button @click="handleClose" size="default">取 消</el-button>
|
<el-button type="primary" @click="onSubmit" size="default" v-preReClick>确认</el-button>
|
</span>
|
</template>
|
</el-dialog>
|
</div>
|
</template>
|
<script setup>
|
import {defineEmits, nextTick, reactive, ref} from "vue";
|
import {ElMessage} from "element-plus";
|
import axios from "axios";
|
import {getToken} from "@/utils/auth";
|
import {delAccessoryFile} from "@/api/projectManage/project";
|
import {addRate, addRecitification, editRecitification} from "@/api/projectManage/riskAnalysis";
|
const emit = defineEmits(["getList"]);
|
const formRef = ref(null)
|
const state = reactive({
|
title: '',
|
form: {
|
id: null,
|
},
|
formRules:{
|
rectifyTime: [{ required: true, message: '请选择整改时间', trigger: 'blur' }],
|
rectifyPerson: [{ required: true, message: '请输入整改人', trigger: 'blur' }],
|
fileList: [{ required: true, message: '请上传附件', trigger: 'blur' }],
|
reason:[{ required: true, message: '请输入整改说明', trigger: 'blur' }],
|
},
|
imgLimit: 1,
|
uploadUrl: import.meta.env.VITE_APP_BASE_API + '/manage/accessory-file/uploadFile',
|
header: {
|
Authorization: getToken()
|
},
|
uploadData: {
|
moduleType: 11
|
},
|
|
})
|
const dialogVisible = ref(false)
|
|
const openDialog = (type, value) => {
|
state.uploadData.projectId = value.projectId;
|
state.title = type === 'add' ? '新增' : '编辑' ;
|
if(state.title === '编辑'){
|
state.form = value;
|
state.form.fileList = [value.accessoryFile]
|
state.form.fileList[0].name = value.accessoryFile.originName
|
}
|
dialogVisible.value = true
|
}
|
|
const beforeUpload = (file) => {
|
let fileType = file.name.substring(file.name.lastIndexOf(".") + 1);
|
if (fileType === 'pdf') {
|
} else {
|
ElMessage.error("文件类型必须为pdf格式")
|
return false
|
}
|
}
|
const handleAvatarSuccess = (res) => {
|
if(res.code === 200){
|
console.log("file",state.form.fileList)
|
ElMessage({
|
type: 'success',
|
message: '文件上传成功'
|
})
|
}else {
|
ElMessage({
|
type: 'warning',
|
message: '文件上传失败'
|
})
|
}
|
}
|
|
const handlePreview = (file) => {
|
let path = "";
|
if(file.path){
|
path = file.path
|
}else {
|
path = file.response.data.path
|
|
}
|
const url = import.meta.env.VITE_APP_BASE_API + '/' + path
|
axios.get( url,{
|
headers:
|
{
|
'Content-Type': 'application/json',
|
'Authorization':getToken(),
|
},
|
responseType: 'blob'
|
}
|
).then(res=>{
|
if (res) {
|
const link = document.createElement('a')
|
let blob = new Blob([res.data],{type: res.data.type})
|
link.style.display = "none";
|
link.href = URL.createObjectURL(blob); // 创建URL
|
link.setAttribute("download", file.name);
|
document.body.appendChild(link);
|
link.click();
|
document.body.removeChild(link);
|
} else {
|
this.$message.error('获取文件失败')
|
}
|
})
|
}
|
const onSubmit = async () => {
|
const valid = await formRef.value.validate();
|
if(valid){
|
state.form.fileId = state.form.fileList ? state.form.fileList[0].response ? state.form.fileList[0].response.data.id : state.form.fileList[0].id : '';
|
if(state.title === '新增'){
|
const {id,fileList, ...data} = JSON.parse(JSON.stringify(state.form))
|
data.projectId = state.uploadData.projectId;
|
console.log("Add",data)
|
const res = await addRecitification(data);
|
if (res.code == 200) {
|
ElMessage.success('保存成功')
|
handleClose();
|
emit('getList');
|
} else {
|
ElMessage.warning(res.message)
|
}
|
}else if(state.title === '编辑'){
|
const {ileList, ...data} = JSON.parse(JSON.stringify(state.form))
|
data.projectId = state.uploadData.projectId;
|
const res = await editRecitification(data);
|
if (res.code == 200) {
|
ElMessage.success('编辑成功')
|
handleClose();
|
emit('getList');
|
} else {
|
ElMessage.warning(res.message)
|
}
|
}
|
}
|
}
|
const handleRemove = async (file, uploadFiles) => {
|
console.log("file",file)
|
let accessoryFileId = "";
|
if(file.id){
|
accessoryFileId = file.id
|
}else {
|
accessoryFileId = file.response.data.id
|
|
}
|
const res = await delAccessoryFile(accessoryFileId)
|
if(res.code == 200){
|
ElMessage({
|
type: 'success',
|
message: '文件已删除'
|
})
|
}else{
|
ElMessage({
|
type: 'warning',
|
message: res.message
|
})
|
}
|
}
|
|
const handleClose = () => {
|
state.form = {
|
id: null,
|
rectifyTime: '',
|
rectifyPerson: '',
|
reason: '',
|
fileList: []
|
}
|
formRef.value.clearValidate();
|
dialogVisible.value = false;
|
|
}
|
defineExpose({
|
openDialog
|
});
|
</script>
|
|
<style scoped lang="scss">
|
|
</style>
|