<template>
  <div id="form-1">
    <el-row>
      <el-col :span="24" class="main">
        <el-col :span="24" class="one">
          <el-form :model="form" :rules="rules" ref="form" label-width="140px">
            <el-col :span="12">
              <el-form-item label="审核结果" prop="status">
                <el-select v-model="form.status" clearable placeholder="请选择" style="width: 100%" @change="changeS">
                  <el-option v-for="(item, index) in statusList" :key="index" :label="item.label" :value="item.value"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <!-- <el-col :span="12">
              <el-form-item label="备案状态" prop="status_two" v-if="form.status == '2'">
                <el-select v-model="form.status_two" clearable placeholder="请选择" style="width: 100%" @change="changeS">
                  <el-option label="建档并补充资料" value="0"></el-option>
                  <el-option label="通过" value="1"></el-option>
                </el-select>
              </el-form-item>
            </el-col> -->
            <el-col :span="12">
              <el-form-item label="审核人" prop="examine_prsonal">
                <el-input v-model="form.examine_prsonal" placeholder="请输入审核人" disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="审核时间" prop="examine_date">
                <el-date-picker
                  v-model="form.examine_date"
                  type="datetime"
                  placeholder="选择日期时间"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  format="yyyy-MM-dd HH:mm:ss"
                  style="width: 100%"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="审核意见" prop="resaon">
                <el-input v-model="form.resaon" type="textarea" rows="2" placeholder="请输入审核意见"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24" class="btn">
              <el-button type="danger" size="small" @click="toReset('form')">取消提交</el-button>
              <el-button type="primary" size="small" @click="onSubmit('form')">提交保存</el-button>
            </el-col>
          </el-form>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex';
const moment = require('moment');
export default {
  name: 'form-1',
  props: {
    form: { type: Object },
    info: { type: Object },
    statusList: { type: Array },
  },
  components: {},
  data: function () {
    return {
      rules: {
        status: [{ required: true, message: '请选择', trigger: 'change' }],
        resaon: [{ required: true, message: '请输入审核意见', trigger: 'blur' }],
        examine_date: [{ required: true, message: '请选择', trigger: 'change' }],
      },
    };
  },
  created() {},
  mounted() {
    this.$set(this.form, `examine_date`, moment().format('YYYY-MM-DD HH:mm:ss'));
    this.$set(this.form, `examine_prsonal`, this.user.name);
  },
  methods: {
    toReset() {
      this.$emit('toReset');
    },
    onSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('onSubmit', { data: this.form });
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    // 选择备案状态
    changeS(value) {
      if (this.info.status && this.info.status == '1') {
        if (value == 0) this.$set(this.form, `resaon`, '');
        else if (value == 2) this.$set(this.form, `resaon`, '建档，需要后期完善相关保安资料');
        else if (value == 3) this.$set(this.form, `resaon`, '通过');
      }
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  .one {
    .btn {
      text-align: center;
    }
  }
}
</style>
