<template>
|
<div class="system-add-user-container">
|
<el-dialog :title="title" v-model="isShowDialog" width="50%">
|
<el-form :model="form" size="default" ref="formRef" :rules="rules" label-width="150px">
|
<el-row :gutter="35">
|
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
|
<el-form-item label="文件名称" prop="fileName">
|
<el-input v-model.trim="form.fileName" placeholder="文件名称" clearable></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
|
<el-form-item label="文件类型" prop="fileType">
|
<el-select v-model="form.fileType" style="width: 100%">
|
<el-option
|
v-for="item in typeList"
|
:key="item.value"
|
:label="item.label"
|
:value="item.value"
|
/>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
|
<el-form-item label="附件" prop="filePath">
|
<el-upload accept=".pdf" :action="uploadUrl" :headers="header" method="post" :on-exceed="showTip" :on-success="handleAvatarSuccess" :limit='1' v-model:file-list="fileList" :before-upload="picSize" :on-remove="handleRemove" :before-remove="beforeRemove">
|
<el-button type="primary">点击上传</el-button>
|
<template #tip>
|
<div class="el-upload__tip">仅支持上传pdf文件,尺寸小于5M,最多可上传1张</div>
|
</template>
|
</el-upload>
|
</el-form-item>
|
</el-col>
|
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20" v-if="title == '新增上报'? false : true">
|
<el-form-item label="删除状态" prop="deleted">
|
<el-radio-group v-model="form.deleted">
|
<el-radio :label="0">未删除</el-radio>
|
<el-radio :label="1">已删除</el-radio>
|
</el-radio-group>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
</el-form>
|
<template #footer>
|
<span class="dialog-footer">
|
<el-button @click="isShowDialog = !isShowDialog" size="default">取 消</el-button>
|
<el-button type="primary" v-throttle @click="onSubmit" size="default">确 定</el-button>
|
</span>
|
</template>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script lang="ts">
|
import { reactive, toRefs, onMounted, defineComponent, ref } from 'vue';
|
import { ElMessageBox, ElMessage } from 'element-plus';
|
import axios from "axios";
|
import {workApplyApi} from "/@/api/specialWorkSystem/workApply";
|
import {userApi} from '/@/api/systemManage/user'
|
import Cookies from "js-cookie";
|
import {judgeReportApi} from "/@/api/dataUpload/saftyBaseInfo/judgeReport";
|
|
// 定义接口来定义对象的类型
|
interface DataState {
|
title: string;
|
isShowDialog: boolean;
|
form: {
|
uuid: string
|
fileName: string
|
filePath: string
|
deleted: number | null
|
fileType: number | null
|
}
|
rules:{},
|
fileList: [],
|
typeList: Array<any>
|
uploadUrl: string,
|
header: {}
|
}
|
|
export default defineComponent({
|
name: 'reportDialog',
|
setup(props, context) {
|
const formRef = ref()
|
const checkFile = (rule: any, value: any, callback: any) => {
|
if(state.fileList.length == 0){
|
callback(new Error("请上传文件"))
|
} else {
|
callback();
|
}
|
}
|
const state = reactive<DataState>({
|
title: '',
|
isShowDialog: false,
|
form: {
|
uuid: '',
|
fileName: '',
|
filePath: '',
|
deleted: 0,
|
fileType: null
|
},
|
rules:{
|
fileName: [{ required: true, message: '请填写文件名称', trigger: 'blur'}],
|
fileType: [{ required: true, message: '请选择文件类型', trigger: 'blur'}],
|
filePath: [{ required: true, validator: checkFile, trigger: 'blur'}],
|
},
|
fileList: [],
|
typeList: [],
|
uploadUrl: import.meta.env.VITE_API_URL + '/account/file/upload',
|
header: {
|
uid: Cookies.get('uid'),
|
Authorization: Cookies.get('token')
|
}
|
})
|
|
// 页面加载时
|
onMounted(() => {
|
|
})
|
// 打开弹窗
|
const open = (type: string, data: object,typeList: Array<any>) => {
|
state.isShowDialog = true;
|
state.typeList = typeList
|
if (type === 'add') {
|
state.title = '新增上报';
|
state.form = {
|
uuid: '',
|
fileName: '',
|
filePath: '',
|
deleted: 0,
|
fileType: null
|
}
|
state.fileList = []
|
}else{
|
state.title = '重新上报';
|
Object.keys(state.form).forEach(key => {
|
if (Object.prototype.hasOwnProperty.call(data,key)) {
|
state.form[key] = JSON.parse(JSON.stringify(data))[key];
|
}
|
})
|
if(data.filePath !== ''){
|
state.fileList = state.form.filePath.split(',').map((i,index) => {
|
return {
|
url: i,
|
name: '文件' + (index+1)
|
}
|
})
|
}else{
|
state.fileList = []
|
}
|
// state.form = {
|
// type: 1,
|
// uuid: data.uuid,
|
// fileName: '',
|
// remarks: '',
|
// evaluateTime: '',
|
// files: '',
|
// deleted: '0'
|
// }
|
}
|
};
|
|
// 图片上传
|
const showTip =()=>{
|
ElMessage({
|
type: 'warning',
|
message: '超出文件上传数量'
|
});
|
}
|
|
const picSize = async(rawFile: any) => {
|
if(rawFile.size / 1024 / 1024 > 5){
|
ElMessage({
|
type: 'warning',
|
message: '文件大小不能超过5M'
|
});
|
return false
|
}
|
}
|
|
const handleAvatarSuccess = (res:any, uploadFile: any) => {
|
if(res){
|
uploadFile.name = res
|
state.form.filePath = res
|
}else{
|
ElMessage({
|
type: 'warning',
|
message: '文件上传失败'
|
})
|
}
|
}
|
|
const handleRemove = (file, uploadFiles,type) => {
|
state.form.filePath = ''
|
}
|
|
// 新增修改
|
const onSubmit = async () => {
|
formRef.value.validate(async (valid:Boolean) => {
|
if(valid){
|
const res = await judgeReportApi().addSafeFile([state.form])
|
if(res.data.code == '200'){
|
ElMessage({
|
type:'success',
|
message:'数据上报成功'
|
})
|
state.isShowDialog = false
|
state.fileList = []
|
}else{
|
ElMessage({
|
type:'warning',
|
message:res.data.msg
|
})
|
}
|
context.emit('refresh');
|
}else{
|
ElMessage({
|
type:'warning',
|
message:'请完善基本信息'
|
})
|
}
|
})
|
}
|
|
return {
|
formRef,
|
showTip,
|
picSize,
|
handleAvatarSuccess,
|
handleRemove,
|
open,
|
onSubmit,
|
...toRefs(state)
|
};
|
}
|
});
|
</script>
|