<template>
  <div class="app-content from-table" style="max-height:450px;overflow:auto;">
    <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>
      <unit-info :data="unitData" />
      <a-row>
        <a-col :span="24">
          <div class="tb-title">
            <span>管理员信息</span>
          </div>
        </a-col>
      </a-row>
      <unit-manager-info :data="managerData" />
      <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>
          <a-col :span="4" class="bg-gray" style="border-top: 0px">
            审核意见
          </a-col>
          <a-col :span="20" style="border-top: 0px">
            <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>
          <a-col :span="4" class="bg-gray">
            审核结果
          </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 moment from 'moment'
import unitInfo from '@/views/unit/components/unitInfo'
import unitManagerInfo from '@/views/unit/components/unitManagerInfo'
import { isEmptyParams } from "@/views/utils/common";

export default {
  name: "unitAudit",
  components: {
    unitInfo, unitManagerInfo
  },
  data () {
    return {
      loading: false,
      unitData: {},
      managerData: [],
      formData: { id: this.value, auditResult: this.auditInfo.auditResult == 1 ? null : this.auditInfo.auditResult, auditContent: this.auditInfo.auditContent },
      rules: {
        auditContent: { required: true, message: '请填写审核意见', trigger: 'blur' },
        auditResult: { required: true, message: '请选择审核结果', trigger: 'change' },
      },
      loading: false,
    }
  },
  props: {
    value: {
      type: String,
      default: () => {
        return null
      }
    },
    auditInfo: {
      type: Object,
      default: () => {
        return null
      }
    }
  },
  created () {
    this.getUnitById()
  },
  methods: {
    moment,
    getUnitById () {
      if (this.value) {
        this.loading = true
        this.$api.unit.getUnitById({ id: this.value }).then(({ data = {} }) => {
          if (data) {
            this.unitData = data
            this.managerData = data.managers
          } 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.unit.audit(par).then(({ data = {} }) => {
            if (data) {
              this.$message.success('审核成功！')
              this.$emit('close', 'audit')
            } this.loading = false
          }).catch(() => { this.loading = false })
        }
      })
    }
  }
}
</script>
