<template>
  <div class="qualifications">
    <head-form
      title="集团资质"
      :form-data="formData"
      :query-params="queryParams"
      :total="tableDataTotal"
      :isExcel="false"
      @handle-search="handleSearch"
    />
    <skeleton style="margin-left:16px;" v-if="isSkeleton"></skeleton>
    <tables
      v-if="!isSkeleton"
      :indexFixed="true"
      :defaultSort="defaultSort"
      :tableLoading="tableLoading"
      :tableData="tableData"
      :forData="forData"
      :tableDataTotal="tableDataTotal"
      :queryParams="queryParams"
      @handle-current-change="handleCurrentChange"
      @sort-change="sortChange"
    >
      <template slot="companyCount" slot-scope="scope">
        <div style="cursor: pointer;color: #0081FF;" @click="handleClick($event, scope.row)" v-html="scope.row.companyCount || '--'"></div>
      </template>
    </tables>
    <qualifications-detail
      v-if="isDetails"
      :data="rowData"
      :title="title"
      @cancel="isDetails=false" />
  </div>
</template>

<script>
  import mixin from '../../party-a/mixins/mixin'
  import {certificateList,certificateCount} from '@/api/detail/groupAccount/groupAccount'
  import QualificationsDetail from './qualificationsDetail'
  export default {
    name: 'qualifications',
    props: ['companyId','companyInfo'],
    mixins: [mixin],
    components:{
      QualificationsDetail
    },
    data(){
      return{
        isSkeleton:true,
        tableLoading:false,
        isDetails: false,
        defaultSort: {prop: 'time', order: 'descending'},
        queryParams: {
          combineId:'54355f88a5b16d3e52f74931f5567853',
          pageNum: 1,
          pageSize: 10
        },
        forData: [
          {label: '资质名称', prop: 'qualificationName'},
          {label: '拥有该资质成员', prop: 'companyCount', slot: true},
        ],
        formData: [
          { type: 4, fieldName: 'combineMemberLevel', value: '', placeholder: '筛选', options:[]},
        ],
        tableData:[],
        tableDataTotal:0,
        title:'',
        rowData:''
      }
    },
    created() {
      this.handleQuery()
      this.getCertificateList()
    },
    methods: {
      handleQuery(params){
        this.isSkeleton = true
        let data = params ? params : this.queryParams
        certificateList(data).then(res=>{
          this.tableData = res.rows
          this.tableDataTotal = res.total
          this.isSkeleton = false
        })
      },
      getCertificateList(){
        certificateCount({combineId: this.queryParams.combineId}).then(res=>{
          let data = res.data
          for(let i=0; i<data.length; i++){
            this.formData[0].options.push({
              name:  data[i].qualificationName+ '（' + data[i].companyCount + '）',
              value: data[i].qualificationType,
            })
          }
        })
      },
      handleClick(e, data) {
        this.title=this.companyInfo.companyName+data.qualificationName+'（'+ data.companyCount +'）'
        this.rowData = data
        this.isDetails = true
      },
    }
  }
</script>

<style lang="scss" scoped>
  .qualifications{
    background: #ffffff;
    border-radius: 4px;
    padding: 16px;
    .headForm{
      margin-bottom: 14px;
      .common-title{
        margin-right: 24px;
      }
    }
  }
</style>
