<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="120px">
|
<el-row :gutter="35">
|
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
|
<el-form-item label="项目名称" prop="projectName">
|
<el-input v-model.trim="form.projectName" 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="contractorId">
|
<el-select v-model="form.contractorId" filterable placeholder="请选择承包商" clearable>
|
<el-option v-for="(item,index) in contractorList" :key="index" :label="item.contractorName" :value="item.uuid"/>
|
</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="qualificationList">
|
<el-button type="primary" style="margin-bottom: 10px" @click="addFile">新增</el-button>
|
<el-table :data="form.qualificationList" style="width: 100%" border>
|
<el-table-column prop="qulificationName" label="资质名称"></el-table-column>
|
<el-table-column prop="filePath" label="资质文件"></el-table-column>
|
<el-table-column fixed="right" label="操作">
|
<template #default="scope">
|
<el-button @click="delFile(scope.$index)" type="text" size="small">删除</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
</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 v-model="addVisible" @open="startAdd" width="30%">
|
<el-form :model="addForm" label-width="170px" ref="addFormRef" :rules="addFormRules">
|
<el-row :gutter="20">
|
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
|
<el-form-item label="资质名称" prop="qulificationName">
|
<el-input
|
v-model="addForm.qulificationName"
|
placeholder="请输入资质名称"
|
/>
|
</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" multiple :action="uploadUrl" :headers="header" method="post" :on-exceed="showTip" :on-preview="handlePictureCardPreview" :on-success="handleAvatarSuccess" :limit='1' v-model:file-list="fileList" :before-upload="picSize" :on-remove="handleRemove" :before-remove="beforeRemove">
|
<el-button size="small" type="primary">点击上传</el-button>
|
<div slot="tip" class="el-upload__tip">支持上传pdf,尺寸小于5M,最多可上传1份</div>
|
<!-- <template #tip>-->
|
<!-- <div class="el-upload__tip">上传图片尺寸小于4M,最多可上传1张</div>-->
|
<!-- </template>-->
|
</el-upload>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
</el-form>
|
<template #footer>
|
<span class="dialog-footer">
|
<el-button type="primary" @click="confirmAdd(addFormRef)">新增</el-button>
|
</span>
|
</template>
|
</el-dialog>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script lang="ts">
|
import { reactive, toRefs, onMounted, defineComponent, ref } from 'vue';
|
import {ElMessageBox, ElMessage, FormRules, FormInstance} from 'element-plus';
|
import axios from "axios";
|
import {contractorApi} from "/@/api/dataUpload/contractorManage";
|
import Cookies from "js-cookie";
|
|
// 定义接口来定义对象的类型
|
interface DataState {
|
title: string
|
isShowDialog: boolean
|
form: {
|
uuid: string
|
projectName: string
|
contractorId: string
|
qualificationList: Array<any>
|
deleted: string
|
}
|
rules:{}
|
addVisible: boolean
|
fileList: [],
|
uploadUrl: string,
|
header: {},
|
imgDialog: boolean,
|
imageUrl: string
|
addForm: {}
|
contractorList: []
|
}
|
|
export default defineComponent({
|
name: 'reportDialog',
|
setup(props, context) {
|
const formRef = ref()
|
const addFormRef = ref()
|
const checkList = (rule: any, value: any, callback: any) => {
|
if(state.form.qualificationList.length == 0){
|
callback(new Error("请完善资质信息"))
|
} else {
|
callback();
|
}
|
}
|
const state = reactive<DataState>({
|
title: '',
|
isShowDialog: false,
|
form: {
|
uuid: '',
|
projectName: '',
|
contractorId: '',
|
qualificationList: [],
|
deleted: '0'
|
},
|
rules:{
|
projectName: [{ required: true, message: '请填写项目名称', trigger: 'blur' }],
|
contractorId: [{ required: true, message: '请选择承包商', trigger: 'blur' }],
|
qualificationList: [{ required: true,validator: checkList, trigger: 'blur' }]
|
},
|
contractorList: [],
|
addVisible: false,
|
fileList: [],
|
uploadUrl: import.meta.env.VITE_API_URL + '/account/file/upload',
|
header: {
|
uid: Cookies.get('uid'),
|
Authorization: Cookies.get('token')
|
},
|
imgDialog: false,
|
imageUrl: '',
|
addForm: {
|
qulificationName: '',
|
filePath: ''
|
}
|
})
|
|
const checkFile = (rule: any, value: any, callback: any) => {
|
if(state.fileList.length == 0){
|
callback(new Error("请上传附件"))
|
} else {
|
callback();
|
}
|
}
|
|
const addFormRules = reactive<FormRules>({
|
qulificationName: [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
|
filePath: [{ required: true,validator: checkFile, trigger: 'blur' }]
|
})
|
// 页面加载时
|
onMounted(() => {
|
|
})
|
// 打开弹窗
|
const open = (type: string, data: object) => {
|
state.isShowDialog = true;
|
getDataList()
|
if (type === 'add') {
|
state.title = '新增上报';
|
state.form = {
|
uuid: '',
|
projectName: '',
|
contractorId: '',
|
qualificationList: [],
|
deleted: '0'
|
}
|
}else{
|
state.title = '重新上报';
|
state.form = {
|
uuid: data.uuid,
|
projectName: data.projectName,
|
contractorId: data.contractorId,
|
qualificationList: data.qualificationList,
|
deleted: '0'
|
}
|
}
|
};
|
|
const getDataList = async ()=>{
|
const res = await contractorApi().getContractorList({searchParams: {}, pageIndex: 1, pageSize: 999})
|
if(res.data.code == 200){
|
state.contractorList = res.data.data
|
}else{
|
ElMessage({
|
type: 'warning',
|
message: res.data.msg
|
})
|
}
|
}
|
|
// 新增修改
|
const onSubmit = async () => {
|
formRef.value.validate(async (valid:Boolean) => {
|
if(valid){
|
const res = await contractorApi().addProjectInfo([state.form])
|
if(res.data.code == 200){
|
ElMessage({
|
type:'success',
|
message:'数据上报成功'
|
})
|
state.isShowDialog = false
|
}else{
|
ElMessage({
|
type:'warning',
|
message:res.data.msg
|
})
|
}
|
context.emit('refresh');
|
}else{
|
ElMessage({
|
type:'warning',
|
message:'请完善基本信息'
|
})
|
}
|
})
|
}
|
|
const delFile = (index:number)=>{
|
state.form.qualificationList.splice(index,1)
|
}
|
|
const addFile = ()=>{
|
state.addVisible = true
|
}
|
|
const startAdd =()=>{
|
state.addForm={
|
qulificationName: '',
|
filePath: '',
|
}
|
state.fileList = []
|
}
|
|
const confirmAdd=async (formEl: FormInstance | undefined)=>{
|
if (!formEl) return
|
await formEl.validate(async (valid, fields) => {
|
if (valid) {
|
state.form.qualificationList.push(state.addForm)
|
state.addVisible = false
|
} else {
|
ElMessage({
|
type: 'warning',
|
message: '有表单内容未完成,请再次检查完善'
|
})
|
}
|
})
|
}
|
|
// 图片上传
|
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.addForm.filePath = res
|
}else{
|
ElMessage({
|
type: 'warning',
|
message: '文件上传失败'
|
})
|
}
|
}
|
|
const handlePictureCardPreview = (uploadFile) => {
|
state.imageUrl = uploadFile.url
|
state.imgDialog = true;
|
}
|
|
const handleRemove = (file, uploadFiles,type) => {
|
state.fileList = uploadFiles
|
}
|
|
return {
|
formRef,
|
addFormRef,
|
addFormRules,
|
delFile,
|
startAdd,
|
showTip,
|
picSize,
|
addFile,
|
confirmAdd,
|
handleAvatarSuccess,
|
handlePictureCardPreview,
|
handleRemove,
|
open,
|
onSubmit,
|
...toRefs(state)
|
};
|
}
|
});
|
</script>
|