<!-- * @Description: * @Autor: renchao * @LastEditTime: 2023-07-19 16:04:43 --> <template> <dialogBox title="新增法律法规" @submitForm="submitForm" saveButton="保存" :isFullscreen="false" width="50%" @closeDialog="closeDialog" v-model="value"> <el-form ref="ruleForm" :model="ruleForm" label-width="100px" :rules="rules"> <el-row> <el-col :span="12"> <el-form-item label="标题:" prop="noticeTitle"> <el-input v-model="ruleForm.noticeTitle"></el-input> </el-form-item> </el-col> </el-row> <el-row> <el-col :span="8"> <el-form-item label="附件:" prop="noticeFileUrl"> <el-upload action="" :file-list="fileList" multiple :auto-upload="false" :limit="1" :on-change="handleChange" :before-upload="beforeUpload"> <el-button icon="el-icon-upload" type="primary">上传</el-button> <div slot="tip" class="el-upload__tip">支持上传doc、docx、xls、xlsx、pdf文件,大小不超过20MB</div> </el-upload> </el-form-item> </el-col> </el-row> </el-form> </dialogBox> </template> <script> import { addSysNotice } from "@/api/sysNotice.js" import { upload } from "@/api/file.js" export default { props: { value: { type: Boolean, default: false }, }, data () { return { ruleForm: { noticeTitle: '', noticeContent: '', noticeFileUrl: '', noticeType: '2' }, rules: { noticeTitle: [ { required: true, message: '请输入法律法规标题', trigger: 'blur' } ] }, } }, methods: { /** * @description: submitForm * @author: renchao */ submitForm () { let that = this; that.$refs.ruleForm.validate(valid => { if (valid) { addSysNotice(this.ruleForm).then(res => { if (res.code == 200) { this.$message.success('保存成功') this.$emit("input", false); this.resetRuleForm(); this.$parent.queryClick(); } else { this.$message.error(res.message) } }) } else { // console.log('error submit!!'); return false; } }); }, //关闭窗口 /** * @description: 关闭窗口 * @author: renchao */ closeDialog () { this.$emit("input", false); this.resetRuleForm(); }, /** * @description: resetRuleForm * @author: renchao */ resetRuleForm () { this.$refs['ruleForm'].resetFields(); this.ruleForm.noticeType = '2' }, /** * @description: beforeUpload * @param {*} file * @author: renchao */ beforeUpload (file) { return true; }, /** * @description: handleChange * @param {*} file * @author: renchao */ async handleChange (file) { var formdata = new FormData(); formdata.append("file", file.raw); upload(formdata).then(res => { this.ruleForm.noticeFileUrl = res.message }) }, } } </script> <style scoped lang="scss"> </style>