<template>
  <div class="create-container">
    <div class="create-body" v-loading="loading" style="width: 100%">
      <div class="title" v-if="this.type == 0">测评机构信息</div>
      <div class="title" v-else>入驻品牌机构信息</div>
      <el-form :model="authentication" ref="authentication" label-width="12%" class="demo-report">
        <el-form-item prop="agencyPhoto" label="机构logo">
          <span>
          <el-image
            style="width: 100px;"
            :src="authentication.agencyPhoto==null?defaultValue.image:authentication.agencyPhoto"
            fit="scale-down"></el-image>
        </span>
        </el-form-item>
        <el-form-item label="机构名称" prop="evaluationAgencyName">
          <span>{{authentication.evaluationAgencyName}}</span>
        </el-form-item>
        <el-form-item label="法人名称" prop="legalPersonName">
          <span>{{authentication.legalPersonName}}</span>
        </el-form-item>
        <!--        <el-form-item  label="认证状态" prop="name">-->
        <!--          <el-tag :type="authentication.authStatus.style">{{authentication.authStatus.text}}</el-tag>-->
        <!--        </el-form-item>-->
        <el-form-item label="地址" prop="address"
                      v-if="this.authentication.address != null &&  this.authentication.address != ''">
          <span>{{authentication.address}}</span>
        </el-form-item>
        <!--        <el-form-item label="测评机构能力" prop="evaluationAgencyAbilityList">-->
        <!--          <span  v-for="(item,index) in authentication.evaluationAgencyAbilityList"-->
        <!--                :key="index"><span class="badge">{{item}}</span></span>-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="测评机构资源" prop="evaluationAgencyResourceList">-->
        <!--          <span  v-for="item in authentication.evaluationAgencyResourceList" :key="item.id">-->
        <!--            资源类型：{{item.type}}；&nbsp;&nbsp;资源名称：{{item.name}}；&nbsp;&nbsp;资源总量：{{item.totalNum}}；&nbsp;&nbsp;可用资源：{{item.availableNum}}<br/>-->
        <!--          </span>-->
        <!--        </el-form-item>-->

        <el-form-item label="接包数量" prop="taskCount" v-if="this.type == 0">
          <span>{{authentication.taskCount}}</span>
        </el-form-item>
        <el-form-item label="认证时间" prop="checkTime">
          <span>{{dateFormat(new Date(authentication.checkTime),'yyyy-MM-dd HH:mm:ss')}}</span>
        </el-form-item>

        <el-form-item>
          <div class="btn btn-medium btn-info" @click="back()">返回</div>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
  import Http from '@/js/http.js'
  import Apis from '@/js/api.js'
  import {notify} from '@/constants/index'
  import {
    getAllReportTypes,
    defaultValue,
    storageGet,
    getAgencyAuthInfoCommon,
    getAllAgencyResourceTypes,
    getAllServiceTypes,
  } from '@/js/index'

  export default {
    name: 'AgencyDetail',
    components: {},
    data() {
      return {
        user: {},
        loading: false,
        type: 0,
        userId: 0,
        resourceTypes: [],
        serviceTypes: [],
        defaultValue:defaultValue,
        authentication: {
          mobile: '',
          evaluationAgencyName: '',
          // bankAccount: '',
          address: '',
          evaluationAgencyAbilityList: [],
          evaluationAgencyResourceList: [],
          authStatus: {},
          legalPersonName: '',
          checkTime: '',
          agencyPhoto: defaultValue.image,
          explain: '',
          taskCount: 0
        },
      }
    },
    mounted() {
      this.$nextTick(() => {
        this.init()
      })
    },
    methods: {
      init() {
        this.userId = this.$route.params.id
        this.type = this.$route.params.type
        this.setServiceTypes()
        this.setResourceTypes()
        this.getAuthInfo()
      },
      back() {
        this.$router.go(-1);
      },
      //加载数据
      getAuthInfo() {
        this.showLoading()
        getAgencyAuthInfoCommon(this.userId, this.getAuthInfoSuccess, this.getAuthInfoFail)
      },
      getAuthInfoSuccess(res) {
        this.hideLoading()
        this.authentication.agencyPhoto = res.data.agencyPhoto == null ? defaultValue.image : res.data.agencyPhoto
        this.authentication.evaluationAgencyName = res.data.evaluationAgencyName == null ? '暂未填写' : res.data.evaluationAgencyName
        this.authentication.evaluationAgencyAbilityList = res.data.evaluationAgencyAbilityList == null ? [] : res.data.evaluationAgencyAbilityList
        this.authentication.evaluationAgencyResourceList = res.data.evaluationAgencyResourceList == null ? [] : res.data.evaluationAgencyResourceList
        // this.authentication.bankAccount = res.data.bankAccount == null ? '暂未填写' : res.data.bankAccount
        this.authentication.address = res.data.address == null ? '暂未填写' : res.data.address
        this.authentication.authStatus = res.data.authStatus
        this.authentication.legalPersonName = res.data.legalPersonName == null ? '暂未填写' : res.data.legalPersonName
        // this.authentication.explain = res.data.explain
        this.authentication.taskCount = res.data.taskCount
        this.authentication.checkTime = res.data.checkTime
      },
      getAuthInfoFail(error) {
        this.hideLoading()
        notify('error', '加载认证信息失败：' + error.data)
      },
      //设置测试类型
      setServiceTypes() {
        getAllServiceTypes().then((res) => {
          this.serviceTypes = res
        }).catch((error) => {
          notify('error', '机构能力加载失败')
        })
      },
      //设置机构资源类型
      setResourceTypes() {
        this.resourceTypes = getAllAgencyResourceTypes()
      },
      setUserInfo() {
        this.user = storageGet('user')
      },
      showLoading() {
        this.loading = true
      },
      hideLoading() {
        this.loading = false
      },
      dateFormat (date, format) {
        date = new Date(date)
        let o = {
          'M+' : date.getMonth() + 1, //month
          'd+' : date.getDate(), //day
          'H+' : date.getHours(), //hour+8小时
          'm+' : date.getMinutes(), //minute
          's+' : date.getSeconds(), //second
          'q+' : Math.floor((date.getMonth() + 3) / 3), //quarter
          'S' : date.getMilliseconds() //millisecond
        }
        if (/(y+)/.test(format)){
          format = format.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
        }

        for (let k in o)
          if (new RegExp('(' + k + ')').test(format))
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length));

        return format;
      }
    },
    watch: {
      agencyType(val) {
        this.agencyType = val
      }
    }
  }
</script>

<style>
  .demo {
    font-size: 32px;
  }

</style>
