addDialog.vue 2.86 KB
<!--
 * @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: {
      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;
          }
        });
      },
      //关闭窗口
      closeDialog () {
        this.$emit("input", false);
        this.resetRuleForm();
      },
      //
      resetRuleForm () {
        this.$refs['ruleForm'].resetFields();
        this.ruleForm.noticeType = '2'
      },
      beforeUpload (file) {
        return true;
      },
      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>