<template>
  <div v-if="!isLoading" class="club-edit">
    <el-form ref="formRef" class="club-edit-form" label-width="120px" :model="formData" :rules="formRules">
      <el-form-item label="机构名称:">
        <span>{{ authInfo.authParty }}</span>
      </el-form-item>
      <el-form-item label="所在地区:">
        <span>{{ authInfo.area }}</span>
      </el-form-item>
      <el-form-item label="详细地址:">
        <span>{{ authInfo.address }}</span>
      </el-form-item>
      <el-form-item label="经纬度:">
        <span>{{ authInfo.lngAndLat }}</span>
      </el-form-item>
      <el-form-item label="联系方式:" prop="mobile">
        <span>{{ authInfo.mobile }}</span>
      </el-form-item>
      <el-form-item label="机构logo:">
        <el-image
          style="width: 140px; height: 140px"
          :src="authInfo.logo"
        />
      </el-form-item>
      <el-form-item label="轮播图:">
        <el-image
          v-for="(image,index) in authInfo.bannerList"
          :key="index"
          style="width: 140px; height: 140px;margin-right: 16px;"
          :src="image"
          :preview-src-list="imgList"
        />
      </el-form-item>

      <!-- 审核表单 -->
      <el-form-item label="审核状态：">
        <el-radio-group v-model="formData.auditStatus">
          <el-radio :label="1">通过</el-radio>
          <el-radio :label="0">不通过</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item v-if="formData.auditStatus!==1" prop="invalidReason" label="原因：">
        <el-input v-model="formData.invalidReason" type="textarea" placeholder="请说明原因" />
      </el-form-item>
      <el-form-item>
        <el-button type="info" @click="$_back">返回</el-button>
        <el-button type="primary" @click="submit">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
// import Location from '@/components/location'
import { getAuthFormData, auditAuth } from '@/api/auth'
import { mapGetters } from 'vuex'

export default {

  data() {
    return {
      isLoading: false,

      authId: '',

      formData: {
        auditBy: '', // 审核人id
        authId: '', // 机构id
        auditStatus: 1, // 审核状态
        invalidReason: '' // 审核信息
      },

      formRules: {
        invalidReason: { required: true, message: '不通过原因不能为空', tigger: 'blur' }
      },

      authInfo: {
        address: '',
        area: '',
        authId: '',
        authParty: '',
        bannerList: '',
        cityId: '',
        lngAndLat: '',
        logo: '',
        mobile: '',
        provinceId: '',
        townId: ''
      },

      // 预览图片
      imgList: []
    }
  },
  computed: {
    ...mapGetters(['authUserId'])
  },
  created() {
    this.authId = this.formData.authId = this.$route.query.authId
    this.getDetail()
  },
  methods: {
    // 数据回显
    getDetail() {
      getAuthFormData({ authId: this.authId }).then(res => {
        this.authInfo.address = res.data.address
        this.authInfo.area = res.data.area
        this.authInfo.authId = res.data.authId
        this.authInfo.authParty = res.data.authParty
        this.authInfo.bannerList = this.imgList = res.data.bannerList
        this.authInfo.cityId = res.data.cityId
        this.authInfo.lngAndLat = res.data.lngAndLat
        this.authInfo.logo = res.data.logo
        this.authInfo.mobile = res.data.mobile
        this.authInfo.provinceId = res.data.provinceId
        this.authInfo.townId = res.data.townId
      })
    },
    // 提交审核信息
    submit() {
      this.$refs.formRef.validate(valid => {
        if (valid) {
          this.isLoading = true
          // 指定审核人
          this.formData.auditBy = this.authUserId
          // 提交审核信息
          auditAuth(this.formData).then(res => {
            if (res.code !== 0) return
            this.$message.success(res.data)
            this.$store.dispatch('tagsView/delView', this.$route)
            this.$router.back()
          }).finally(() => {
            this.isLoading = false
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.club-edit {
  margin-bottom: 80px;
}

.club-edit-form {
  width: 600px;
  margin: 0 auto;
  margin-top: 80px;
}
.submit-btn {
  text-align: center;
  .el-button {
    width: 140px;
  }
}
</style>
