<template>
  <div class="page-form-container">
    <club-detail :auth-id="auditForm.authId" />
    <template v-if="type === 'audit'">
      <el-form ref="auditForm" label-width="112px" :model="auditForm" :rules="rules">
        <el-form-item label="审核：">
          <el-radio-group v-model="auditForm.auditStatus">
            <el-radio :label="1">通过</el-radio>
            <el-radio :label="0">不通过</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="auditForm.auditStatus === 0" label="原因：" prop="invalidReason">
          <el-input v-model="auditForm.invalidReason" type="textarea" :rows="3" />
        </el-form-item>
      </el-form>
      <div class="control-box">
        <el-button type="info" @click="navigateBack">返回</el-button>
        <el-button type="primary" @click="submit">提交</el-button>
      </div>
    </template>
  </div>
</template>

<script>
import { auditAuth } from '@/api/auth'
import { ClubDetail } from '@/views/components'
export default {
  components: {
    ClubDetail
  },
  data() {
    return {
      type: 'audit',
      auditForm: {
        source: 2,
        authId: '', // 机构id
        auditStatus: 1, // 审核状态
        invalidReason: '' // 审核信息
      },
      rules: {
        invalidReason: { required: true, message: '不通过原因不能为空', tigger: 'blur' }
      }
    }
  },
  created() {
    this.auditForm.authId = this.$route.query.authId
    this.type = this.$route.query.type
  },
  methods: {
    // 地图定位
    initMap() {
      this.dialogMapVisible = true
      if (this.lnglat) {
        this.$nextTick(() => {
          this.$refs.aMap.init()
        })
      }
    },

    // 提交审核信息
    async submit() {
      try {
        await this.$refs.auditForm.validate()
        this.onAudit()
      } catch (error) {
        console.log(error)
      }
    },

    // 审核
    async onAudit() {
      try {
        const res = await auditAuth(this.auditForm)
        this.$message.success(res.data)
        this.$store.dispatch('tagsView/delView', this.$route)
        this.$router.back()
      } catch (error) {
        console.log(error)
      }
    }
  }
}
</script>
