<template>
  <skeleton style="margin-left:16px;" v-if="isSkeleton"></skeleton>
  <div class="app-container detail-container" v-else>
    <head-form
      title="高管信息"
      :form-data="formData"
      :query-params="queryParams"
      :total="tableDataTotal"
    />

    <tables
      :tableLoading="tableLoading"
      :tableData="tableData"
      :tableDataTotal="tableDataTotal"
      :forData="forData"
      :isIndex="false"
      :queryParams="queryParams"
      :paging="false"
    >
      <template slot="serial" slot-scope="scope">
        <span>{{scope.row.serial}}</span>
      </template>
      <template slot="serials" slot-scope="scope">
        <span>{{scope.row.userNames?scope.row.serials:''}}</span>
      </template>
      <template slot="userNames" slot-scope="scope">
        <span>{{scope.row.userNames || ''}}</span>
      </template>
      <template slot="userJobs" slot-scope="scope">
        <span>{{scope.row.userJobs || ''}}</span>
      </template>
    </tables>
  </div>
</template>

<script>
import mixin from '../mixins/mixin'
import {keymembers} from '@/api/detail/party-a/overview'
export default {
  name: 'Execuinfo',
  props: ['companyId'],
  mixins: [mixin],
  data() {
    return {
      queryParams: {
        cid: this.companyId,
        pageNum: 1,
        pageSize: 100
      },
      forData: [
        {label: '序号', prop: 'serial', width:55, slot: true},
        {label: '姓名', prop: 'userName'},
        {label: '职位', prop: 'userJob'},
        {label: '序号', prop: 'serials', width:55, slot: true},
        {label: '姓名', prop: 'userNames', slot: true},
        {label: '职位', prop: 'userJobs', slot: true}
      ],
      formData: [],
      //列表
      tableLoading:false,
      tableData:[],
      tableDataTotal:0,
    }
  },
  created() {
    this.handleQuery()
  },
  methods: {
    async handleQuery(params) {
      this.isSkeleton = true;
      this.tableLoading = true
      let param = params?params:this.queryParams
      let res = await keymembers(param)
      this.tableLoading = false
      if(res.code==200){
        this.isSkeleton = false;
        let tempRows = []
        if(res.rows&&res.rows.length>0){
          let arrLength = res.rows.length%2==0?(res.rows.length/2):(Math.floor(res.rows.length/2)+1)
          for(let i=0; i<arrLength; i++){
            let obj = {
              serial: 2*i+1,
              userName:res.rows[2*i]?res.rows[2*i].name:'',
              userJob:res.rows[2*i]?res.rows[2*i].jobTitle:'',
              serials: 2*i+2,
              userNames:res.rows[2*i+1]?res.rows[2*i+1].name:'',
              userJobs:res.rows[2*i+1]?res.rows[2*i+1].jobTitle:''
            }
            tempRows.push(obj)
          }
        }
        this.tableData = tempRows
      }
      this.tableDataTotal = res.total
    }
  }
}
</script>

<style lang="scss" scoped>
.detail-container{
  margin: 0;
  padding: 16px;
  background: #FFFFFF;
  border-radius: 4px;
}
</style>
