<template>
  <el-dialog :title="title" :visible.sync="visible" v-dialogDrag width="40%" :close-on-click-modal="false"
    :before-close="cancel">
    <div class="dia-box">
      <el-form :model="form" :rules="rules" ref="ruleForm" label-width="110px">
        <el-form-item label="年度" prop="year">
          <el-input-number v-model="form.year" controls-position="right" placeholder="请输入年度"></el-input-number>
        </el-form-item>
        <el-form-item label="单位名称" prop="unitName">
          <el-input v-model.trim="form.unitName" placeholder="请输入单位名称"></el-input>
        </el-form-item>
        <el-form-item label="单位类别代码" prop="unitCode">
          <el-input v-model.trim="form.unitCode" placeholder="请输入单位类别代码"></el-input>
        </el-form-item>
        <el-form-item label="单位负责人" prop="unitPerson">
          <el-input v-model.trim="form.unitPerson" placeholder="请输入单位负责人"></el-input>
        </el-form-item>
        <el-form-item label="填表人" prop="completed">
          <el-input v-model.trim="form.completed" placeholder="请输入填表人"></el-input>
        </el-form-item>
        <el-form-item label="报出时间" prop="outTime">
          <el-date-picker
            v-model="form.outTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button :loading="btnloading" type="primary" size="mini" @click="submit('ruleForm')">
            保存
          </el-button>
          <el-button size="mini" @click="cancel">取消</el-button>
        </el-form-item>
      </el-form>
    </div>
  </el-dialog>
</template>

<script>
  
  export default {
    props: {
      visible: {
        type: Boolean,
        default: () => false
      },
    },
    data() {
      return {
        title: '新增年度',
        btnloading: false,
        form: {
          year: undefined,
          unitName: "",
          unitCode: "",
          unitPerson: "",
          completed: "",
          outTime: "",
        },
        rules: {
          year: [{ required: true,message: "请输入年度",trigger: "blur"}],
          unitName: [{required: true,message: "请输入单位名称",trigger: "blur"}],
          unitCode: [{required: true,message: "请输入单位类别代码",trigger: "blur"}],
          unitPerson: [{required: true,message: "请输入单位负责人",trigger: "blur"}],
          completed: [{required: true,message: "请输入填表人",trigger: "blur"}],
          outTime: [{required: true, message: '请选择报出时间',trigger: "blur" }],
        }
      };
    },
    methods: {
      cancel() {
        this.$refs.ruleForm.resetFields();
        this.$emit("cancel");
      },
      submit(formName) {
        this.$refs[formName].validate(valid => {
          if (valid) {
            this.btnloading = true;
            this.$emit("submit", this.form);
          } else {
            return false;
          }
        });
      }
    }
  };

</script>
