Blame view

src/views/system/flfg/components/addDialog.vue 2.65 KB
蔡俊立 committed
1 2
<template>
  <dialogBox title="新增法律法规" @submitForm="submitForm" saveButton="保存" :isFullscreen="false" width="50%"
任超 committed
3
    @closeDialog="closeDialog" v-model="value">
蔡俊立 committed
4 5 6 7 8 9 10 11 12 13
    <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">
任超 committed
14 15 16 17 18 19 20
          <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>
蔡俊立 committed
21 22 23 24 25 26 27
        </el-col>
      </el-row>
    </el-form>
  </dialogBox>
</template>

<script>
任超 committed
28
import { addSysNotice } from "@/api/system.js"
任超 committed
29
import { upload } from "@/api/system.js"
蔡俊立 committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
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 () {
任超 committed
52 53 54 55 56 57 58
      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);
59
              this.resetRuleForm();
任超 committed
60
              this.$parent.queryClick();
蔡俊立 committed
61
            } else {
任超 committed
62
              this.$message.error(res.message)
蔡俊立 committed
63
            }
任超 committed
64 65 66 67 68 69
          })
        } else {
          // console.log('error submit!!');
          return false;
        }
      });
蔡俊立 committed
70 71
    },
    //关闭窗口
任超 committed
72
    closeDialog () {
蔡俊立 committed
73 74 75 76
      this.$emit("input", false);
      this.resetRuleForm();
    },
    //
任超 committed
77 78 79
    resetRuleForm () {
      this.$refs['ruleForm'].resetFields();
      this.ruleForm.noticeType = '2'
蔡俊立 committed
80 81 82 83 84 85 86 87
    },
    beforeUpload (file) {
      return true;
    },
    async handleChange (file) {
      var formdata = new FormData();
      formdata.append("file", file.raw);
      upload(formdata).then(res => {
任超 committed
88
        this.ruleForm.noticeFileUrl = res.message
蔡俊立 committed
89 90 91 92 93 94
      })
    },
  }
}
</script>
<style scoped lang="scss">
任超 committed
95

蔡俊立 committed
96
</style>