<template>
  <el-dialog v-dialogDrag ref="diaFrom" :title="title" :close-on-click-modal="false" :visible.sync="isDiaBox"
    width="55%" :before-close="cancel">
    <el-form :model="form" style="padding:10px 20px" :rules='rules' label-width="100px" ref="ruleForm">
      <el-form-item label="题名：" prop="fileTitle">
        <el-input v-model="form.fileTitle" placeholder="请输入" size="mini" type="textarea" :rows="1">
        </el-input>
      </el-form-item>
      <el-row>
        <el-col :span="12">
          <el-form-item label="全宗：" prop="fondsNo">
            <el-select size="mini" v-model="form.fondsNo" placeholder="请选择" style="width:100%">
              <el-option v-for="item in fondsList" :key="item.id" :label="item.codeName" :value="item.fondscode">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="文件类型：" prop="fileType">
            <el-input v-model="form.fileType" size="mini" placeholder="请输入" clearable></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="档号：" prop="archiveNo">
            <el-input v-model="form.archiveNo" placeholder="请输入" size="mini" clearable>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="指导人：" prop="director">
            <el-input v-model="form.director" placeholder="请输入" size="mini" clearable>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="指导内容：" prop="dirContent">
        <el-input v-model="form.dirContent" placeholder="请输入" size="mini" type="textarea" :rows="3">
        </el-input>
      </el-form-item>
      <el-form-item label="  ">
        <el-button @click="submitForm('ruleForm')" type="primary" size="mini">保存</el-button>
        <el-button @click="cancel" type="info" size="mini">取消</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>
<script>
  import {
    addSupervise,
    updateSupervise
  } from "@/api/supervise-management/supervise-guide"
  import {
    clearObjValue
  } from '@/utils/common';
  export default {
    props: {
      isDiaBox: {
        type: Boolean,
        default: () => false,
      },
      title: {
        type: String,
        default: () => "",
      },
      fondsList: {
        type: Array,
        default: () => [],
      },
    },
    data() {
      return {
        form: {
          archiveNo: "",
          dirContent: "",
          director: "",
          fileDate: "",
          fileTitle: "",
          fileType: "",
          fondsNo: "",
          id: "",
        },
        rules: {
          archiveNo: [{
            required: true,
            message: '请输入档号',
            trigger: 'blur'
          }],
          dirContent: [{
            required: true,
            message: '请输入指导内容',
            trigger: 'blur'
          }],
          director: [{
            required: true,
            message: '请输入指导人',
            trigger: 'blur'
          }],
          fileTitle: [{
            required: true,
            message: '请输入题名',
            trigger: 'blur'
          }],
          fileType: [{
            required: true,
            message: '请输入文件类型',
            trigger: 'blur'
          }],
          fondsNo: [{
            required: true,
            message: '请选择全宗',
            trigger: 'change'
          }],
          fondsNo: [{
            required: true,
            message: '请选择全宗',
            trigger: 'change'
          }],
        },
      }
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            if (this.title === '新增') {
              addSupervise(this.form).then(res => {
                this.cancel()
                this.$emit('getData')
              })
            } else {
              updateSupervise(this.form).then(res => {
                this.cancel()
                this.$emit('getData')
              })
            }
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      cancel() {
        clearObjValue(this.form)
        // this.$refs['ruleForm'].resetFields();
        // console.log(this.form)
        this.$emit('cancel')
      },

    }
  }

</script>
<style lang='scss' scoped>
  ::v-deep .el-form .el-form-item .el-input__inner {
    text-align: left;
  }

</style>
