<template>
  <div class="from-table">
    <a-spin :spinning="loading" style="width: 100%;height: 100%;">
      <a-row>
        <a-col :span="24">
          <div class="tb-title">
            <span>人员信息</span>
          </div>
        </a-col>
      </a-row>
      <person-info :data="personInfo" />
      <a-row>
        <a-col :span="24">
          <div class="tb-title">
            <span>审核</span>
          </div>
        </a-col>
      </a-row>
      <a-form-model ref="form" :model="formData" :rules="rules">
        <a-row type="flex">
          <a-col :span="4" class="bg-gray">
            <div class="special-middle">
              <div>审核意见</div>
            </div>
          </a-col>
          <a-col :span="20">
            <a-form-model-item prop="auditContent">
              <a-input v-model="formData.auditContent" :maxLength="30" style="width:400px" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row type="flex">
          <a-col :span="4" class="bg-gray">
            <div class="special-middle">
              <div>审核结果</div>
            </div>
          </a-col>
          <a-col :span="20">
            <a-form-model-item prop="auditResult">
              <a-radio-group v-model="formData.auditResult" @change="onChange">
                <a-radio :value="10">通过 </a-radio>
                <a-radio :value="20">不通过 </a-radio>
              </a-radio-group>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-spin>
  </div>
</template>
<script>
import personInfo from '@/views/person/components/personInfo'
import { isEmptyParams } from "@/views/utils/common"

export default {
  name: "personAudit",
  components: {
    personInfo
  },
  data () {
    return {
      formData: { id: this.value, auditResult: null, auditContent: null },
      personInfo: {},
      rules: {
        auditContent: { required: true, message: '请填写审核意见', trigger: 'blur' },
        auditResult: { required: true, message: '请选择审核结果', trigger: 'change' },
      },
      loading: false
    }
  },
  props: {
    value: {
      type: String,
      default: () => {
        return null
      }
    },
  },
  created () {
    this.getPersonById()
  },
  methods: {
    getPersonById () {
      this.loading = true
      this.$api.person.getPersonById({ id: this.value }).then(({ data = {} }) => {
        if (data) {
          this.personInfo = data
          this.formData.auditResult = data.auditResult == 1 ? null : data.auditResult
          this.formData.auditContent = data.auditContent
        }
        this.loading = false
      }).catch(() => { this.loading = false })
    },
    onChange (e) {
    },
    submit () {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.loading = true
          let pars = isEmptyParams(this.formData)
          let par = { ...pars }
          this.$api.person.audit(par).then(({ data = {} }) => {
            if (data) {
              this.$message.success('审核成功！')
              this.$emit('close', 'audit')
            }
            this.loading = false
          }).catch(() => { this.loading = false })
        }
      })
    }
  }
}
</script>