<template>
  <div class="uploadFile">
    <el-dialog :title="title" :visible.sync="dialogVisible" width="600px" :before-close="handleClose"
      :close-on-click-modal="false" label-width="300px">
      <el-form :model="form" status-icon :rules="rules" ref="form" label-width="120px" class="demo-ruleForm">
        <el-form-item label="文件名称：" prop="name">
          <el-input v-model="form.name" placeholder="请输入文件名称"></el-input>
        </el-form-item>
        <el-form-item label="是否为最终文件：" prop="delivery" style="width: 20px;">
          <el-switch v-model="form.delivery" active-color="#13ce66" inactive-color="#ff4949"></el-switch>
        </el-form-item>
        <el-form-item label="文件类型：">
          <el-select v-model="form.type" placeholder="请选择文件类型" style="width: 100%;">
            <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="发生时间：">
          <el-date-picker v-model="form.time" value-format="yyyy-MM-dd" type="date" placeholder="选择日期"
            style="width: 100%;">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="是否审核：" prop="delivery">
          <el-switch v-model="form.delivery2" active-color="#13ce66" inactive-color="#ff4949"></el-switch>
        </el-form-item>
        <template v-if="form.delivery2">
          <el-form-item label="审核人：">
            <el-select v-model="form.type" placeholder="请选择审核人" style="width: 100%;">
              <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="审核备注：">
            <el-input v-model="form.remark2" type="textarea" placeholder="请输入内容"></el-input>
          </el-form-item>
        </template>
        
        <el-form-item label="附件：" prop="delivery">
          <el-upload ref="upload" class="upload-file" drag action="#" :auto-upload="false" :show-file-list="true"
            :on-change="onChange" :on-remove="handleRemove" :on-preview="handlePreview">
            <i :class="fileList.length != 0 ? 'el-icon-upload' : 'el-icon-refresh'"></i>
            <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
            <div class="el-upload__tip" slot="tip"></div>
          </el-upload>
        </el-form-item>
        <el-form-item label="备注：">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose" size="small">取 消</el-button>
        <el-button @click="submit" size="small" type="primary">确 定</el-button>

      </span>
    </el-dialog>

  </div>
</template>

<script>
export default {
  components: {},
  props: {},
  data() {
    return {
      dialogVisible: false,
      title: '',
      form: {},
      rules: {
        name: [{ required: true, message: '请输入文件名称', trigger: 'blur' },],
      },
      options: [],
      value: '',
      delivery: '',
      fileList: [],
    };
  },
  watch: {},
  computed: {},
  created() { },
  mounted() { },
  methods: {
    onChange(file, fileList) { },
    handlePreview(file, fileList) { },
    handleRemove(file, fileList) { },
    // 切换按钮
    onChangeFamily(val) {
      this.btn = val
    },
    //打开弹窗
    open(row) {
      if (row.id) {
        this.title = '编辑文件'
      } else {
        this.title = '上传文件'
      }
      // this.title = '上传文件'
      this.dialogVisible = true
    },
    //关闭弹窗
    handleClose() {
      this.$refs.form.resetFields()
      this.form = {}
      this.dialogVisible = false
    },
    //提交数据
    submit() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.handleClose()
        } else {
          this.$message.error('信息未输入完整')
        }
      });
    }
  },

};
</script>
<style lang="scss">
.uploadFile {
  .el-dialog__body {
    padding: 0px 20px;
  }
}
</style>
<style lang="scss" scoped></style>