<template>
  <div class="formout">
    <el-form
      :inline="true"
      :model="formInline"
      label-width="0px"
      :rules="rules"
      ref="ruleForm"
      class="demo-form-inline"
    >
      <el-form-item>
        <p class="formname">申请部门：</p>
        <el-input disabled v-model="formInline.depart" placeholder="申请部门"></el-input>
      </el-form-item>
      <el-form-item prop="preson">
        <p class="formname">部门联系人：</p>
        <el-input v-model="formInline.preson" placeholder="联系人"></el-input>
      </el-form-item>
      <el-form-item prop="phone">
        <p class="formname">联系电话：</p>
        <el-input v-model="formInline.phone" placeholder="联系电话"></el-input>
      </el-form-item>
      <el-form-item prop="date">
        <p class="formname">申请使用期限</p>
        <el-date-picker
          v-model="formInline.date"
          type="daterange"
          range-separator="至"
          value-format="yyyy-MM-dd"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item prop="sqly" class="all_box">
        <p class="formname">申请理由</p>
        <el-input v-model="formInline.sqly" placeholder="请输入申请理由" type="textarea"></el-input>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  props: {
    formInline: {
      type: Object,
      default: function () {
        return {};
      },
    },
  },
  components: {},
  data() {
    var check_phone = (rule, value, callback) => {
      var phone_ruler = /^(?:(?:\+|00)86)?1[3-9]\d{9}$/;
      setTimeout(() => {
        if (!phone_ruler.test(value)) {
          callback(new Error("请输入正确电话号码"));
        } else {
          callback();
        }
      });
    };

    return {
      rules: {
        preson: [
          { required: true, message: "请输入部门联系人", trigger: "blur" },
          { max: 16, message: "不能超过16个字符", trigger: "blur" },
        ],
        phone: [
          { required: true, message: "请输入联系电话", trigger: "blur" },
          { validator: check_phone, trigger: "blur" },
        ],
        date: [
          { required: true, message: "请选择使用期限", trigger: "change" },
        ],
        sqly: [
          { required: true, message: "请输入申请理由", trigger: "blur" },
          { max: 240, message: "不能超过240个字符", trigger: "blur" },
        ],
      },
    };
  },
  watch: {},
  computed: {},
  created() {},
  mounted() {
    this.formInline.depart = this.$store.state.userInfo&&this.$store.state.userInfo.department_name || "";
  },
  methods: {
    submitForm() {
      var flag = null;
      this.$refs.ruleForm.validate((valid) => {
        console.log(valid);
        if (valid) {
          flag = true;
        } else {
          flag = false;
        }
      });
      return flag;
    },
  },
};
</script>

<style>
.formout .el-input__inner {
  width: 550px;
}
</style>
<style scoped>
.formout {
  width: 100%;
  overflow: hidden;
  background-color: rgba(255, 255, 255, 1);
  box-shadow: 0px 3px 6px 0px rgba(195, 202, 248, 0.25);
  border-radius: 12px;
  padding: 30px;
}
.formout .formname {
  width: 520px;
  color: rgba(88, 97, 122, 1);
}
.formout .el-form-item {
  margin-right: 20px;
}
.formout .el-form-item:nth-of-type(even) {
  margin-right: 0px;
}
.formout .el-form-item:nth-of-type(5) {
  margin-right: 0px;
  width: 100%;
}
.formout .all_box /deep/.el-form-item__content {
  width: 100%;
}
</style>
