<el-button size="small" type="primary" @click="editFn('新增任务',1)">新增任务el-button>
<el-button size="small" type="primary" @click="editFn(row,2)">修改el-button>
<vxe-modal
ref="xModal"
v-model="formDataLayer"
row-id="id"
:title="flag == 1 ? '新增任务' : '修改'"
width="40%"
height="45%"
resize
destroy-on-close
:show-footer="true"
keep-source
:scroll-x="{ enabled: false }"
@close="closeFn('formData')"
>
<template #default>
<el-form ref="formData" :model="formData" label-width="100px" :rules="rules">
<el-form-item
label="客户名称"
prop="name"
>
<el-input v-model="formData.name" autocomplete="off" />
el-form-item>
<el-form-item
label="上传文件"
prop="fileList"
:rules="[
{
type: 'array',
required: true,
message: '请上传',
trigger: 'blur'
}
]"
>
<el-upload
class="upload-demo"
action="#"
:on-preview="handlePreview"
accept="rar, zip, doc, pdf, jpg"
:on-remove="handleRemove"
:http-request="requestUpload"
:before-remove="beforeRemove"
:before-upload="beforeUpload"
multiple
:limit="1000"
:on-exceed="handleExceed"
>
<el-button size="small" type="primary" >选择文件el-button>
<div slot="tip" class="el-upload__tip">支持扩展名:.rar、.zip、.doc、.docx、.pdf、.jpg...div>
el-upload>
el-form-item>
<el-form-item
label="截止时间"
prop="time"
>
<el-date-picker
v-model="formData.time"
type="datetime"
placeholder="选择日期时间"
default-time="12:00:00"
>el-date-picker>
el-form-item>
<el-form-item
label="任务积分"
prop="taskIntegral"
>
<el-input v-model="formData.taskIntegral" autocomplete="off" />
el-form-item>
el-form>
template>
<template #footer>
<el-button size="small" @click="formDataLayer = false">取消el-button>
<el-button size="small" @click="confirmFn(flag)" type="primary" :loading="Loading">{{flag == 1 ? '确认发布' : '确认修改'}}el-button>
template>
vxe-modal>
data(){
return {
formDataLayer: false,
flag: "",
rules: {
name: [{ required: true, message: '请输入客户名称', trigger: 'blur' }],
fileList: [
{ required: true, message: "请上传文件", trigger: "blur" },
],
time:[{ required: true, message: '请输入截止时间', trigger: 'blur' }],
taskIntegral:[{ required: true, message: '请输入任务积分', trigger: 'blur' }]
},
uploadFile: [],
formData: {
name: "",
fileList: [],
time: "",
taskIntegral: "",
},
}
}
async function putFile(fileName, file) {
try {
let result = await oss.put(fileName, file)
return result;
} catch (e) {
console.log(e);
}
}
methods: {
handlePreview(file) {
console.log(file);
},
handleRemove(file, fileList) {
this.uploadFile =
this.uploadFile.filter(list => {
return list.vueid != file.uid;
}) || [];
this.formData.fileList =
this.formData.fileList.filter(list => {
return list.vueid != file.uid;
}) || [];
},
async requestUpload(param) {
let targetRoute = `test1/${param?.file?.name}`;
let res = await putFile(targetRoute, param.file);
if (res.res.status == 200) {
let pathUrl = await get(res.name);
this.uploadFile.push({
filename: res.name,
docurl: pathUrl,
vueid: param?.file?.uid
});
this.formData.fileList.push({
name: param?.file?.name,
vueid: param?.file?.uid
});
}
},
beforeRemove(file, fileList) {
},
beforeUpload(file) {
let fileName = file.name.substring(file.name.lastIndexOf(".") + 1);
let typeInfo = ["rar", "zip", "doc", "pdf", "jpg"];
fileName = fileName.toLowerCase();
if (!typeInfo.includes(fileName)) {
this.$message({
type: "warning",
message: "请上传.rar、.zip、.doc、.docx、.pdf、.jp格式的图片"
});
return false;
}
const isLt2M = file.size < 1024 * 1024 * 3;
if (!isLt2M) {
this.$message({
type: "warning",
message: "上传图片大小不能超过3M"
});
return false;
}
},
handleExceed(files, fileList) {
},
closeFn(formName) {
this.$refs[formName].clearValidate();
},
async editFn(row, flag) {
console.log(row)
this.flag = flag;
this.formDataLayer = true;
if (flag == 1) {
console.log("新增任务");
this.formData = {
name: "",
fileList: [],
time: "",
taskIntegral: "",
}
} else {
console.log("修改");
this.formData = {
name:row.aa,
time:row.cc,
taskIntegral:row.dd,
fileList:[{name: "6666.jpg"}]
}
}
},
}