<template xmlns="http://www.w3.org/1999/html">
  <skeleton style="margin-left:16px;" v-if="isSkeleton"></skeleton>
  <div class="app-container detail-container" v-else>
    <el-tabs v-model="activeName" @tab-click="handleClick" class="detail-tab">
      <el-tab-pane label="工商信息" name="first"></el-tab-pane>
      <el-tab-pane label="工商变更" :disabled="tableDataTotal>0" name="second"></el-tab-pane>
    </el-tabs>


    <info-table class="info-tab" :list="defaultList" :obj="forInfo" :labelWidth="labelWidth" v-if="activeName=='first'">
      <template slot="provinceCode" slot-scope="scope">
        <span>{{showRegion(scope.data.provinceCode)}}</span>
      </template>
      <template slot="term" slot-scope="scope">
        <span v-if="scope.data.termStart&&scope.data.termEnd">{{ scope.data.termStart }} ~ {{ scope.data.termEnd }}</span>
        <span v-else-if="scope.data.termStart&&!scope.data.termEnd">{{ scope.data.termStart }}起</span>
        <span v-else-if="!scope.data.termStart&&scope.data.termEnd">{{ scope.data.termEnd }}止</span>
        <span v-else>--</span>
      </template>
      <template slot="actualCapi" slot-scope="scope">
        <span>
          {{ scope.data.actualCapi?scope.data.actualCapi+'万元人民币':'--' }}
        </span>
      </template>
      <template slot="colleguesNum" slot-scope="scope">
        <span>
          {{ scope.data.colleguesNum?scope.data.colleguesNum+'人':'--' }}
        </span>
      </template>
    </info-table>
    <tables
      :tableLoading="tableLoading"
      :tableData="tableData"
      :forData="forData"
      :queryParams="queryParams"
      v-if="activeName=='second'"
    />
  </div>
</template>

<script>
import mixin from '../mixins/mixin'
import dataRegion from '@/assets/json/dataRegion'
import InfoTable from '../component/infoTable'
import {icInfo, changeInfo} from "@/api/detail/party-a/overview"
export default {
  name: 'Businfo',
  props: ['companyId'],
  components: {
    InfoTable
  },
  mixins: [mixin],
  data() {
    return {
      activeName: 'first',
      baseParams: {
        cid: this.companyId
      },
      queryParams: {
        cid: this.companyId,
        pageNum: 1,
        pageSize: 20
      },
      labelWidth: 250,
      forInfo: {},
      defaultList: [
        { name: '企业名称', prop: 'name' },
        { name: '社会信用代码', prop: 'creditNo' },
        { name: '法定代表人', prop: 'operName' },
        { name: '登记状态', prop: 'status' },
        { name: '成立日期', prop: 'startDate' },
        { name: '注册资本', prop: 'registCapi' },
        { name: '实缴资本', prop: 'actualCapi', slot: true },
        { name: '核准日期', prop: 'checkDate' },
        { name: '组织机构代码', prop: 'orgNo' },
        { name: '工商注册号', prop: 'regNo' },
        { name: '纳税人识别号', prop: 'creditNo' },
        { name: '企业类型', prop: 'econKind' },
        { name: '营业期限', prop: 'term', slot: true },
        { name: '纳税人资质', prop: 'qualification' },
        { name: '所属地区', prop: 'provinceCode', slot: true },
        { name: '登记机关', prop: 'belongOrg' },
        { name: '人员规模', prop: 'colleguesNum', slot: true },
        { name: '参保人数', prop: 'colleguesNum', slot: true },
        { name: '经营范围', prop: 'scope', style: true }
      ],
      forData: [
        {label: '变更日期', prop: 'changeDate', width: '100'},
        {label: '变更事项', prop: 'type'},
        {label: '变更前', prop: 'beforeContent'},
        {label: '变更后', prop: 'afterContent'}
      ],
      //列表
      tableLoading:false,
      tableData:[],
      tableDataTotal:0
    }
  },
  created() {
    this.handleQuery();
    this.handleQuery1();
  },
  methods: {
    handleClick(){
      this.handleQuery()
    },
    async handleQuery() {
      this.isSkeleton = true;
      this.tableLoading = true
      let param = this.baseParams;
      let res = await icInfo(param);
      this.tableLoading = false
      if(res.code==200){
        this.isSkeleton = false;
        this.forInfo = res.data
      }
    },
    async handleQuery1() {
      let param = this.queryParams
      let res = await changeInfo(param)
      if(res.code==200){
        this.tableData = res.rows;
        this.tableDataTotal = res.total
      }
    },
    showRegion(region){
      if(region) {
        let list = dataRegion
        let areaText = ''
        list.forEach(item => {
          if(item.id == region) {
            areaText = item.regionName
          }
        })
        return areaText
      }else {
        return '--'
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.detail-container{
  margin: 0;
  padding: 16px;
  background: #FFFFFF;
  border-radius: 4px;
  .detail-tab{
    margin: 0 0 0 -16px;
    ::v-deep .el-tabs__nav-wrap::after{
      display: none;
    }
    ::v-deep .el-tabs__item{
      font-size: 16px;
      height: 30px;
      line-height: 30px;
      padding: 0 16px;
      &.is-active{
        font-weight: bold;
      }
    }
  }
}
</style>
