<template>
  <div class="app-container rela-container">
    <div class="common-title">关系企业</div>
    <el-tabs v-model="activeName" @tab-click="handleClick" class="tabpane selfTab">
      <el-tab-pane label="股东" name="first"></el-tab-pane>
      <el-tab-pane label="对外投资" name="second"></el-tab-pane>
    </el-tabs>
    <div class="table-item">
      <div class="rela-person" v-show="activeName=='first'">实际控制人：{{financial&&financial.actualController || '--'}}</div>
      <el-table :data="holderData" border style="width: 100%" v-show="activeName=='first'">
        <el-table-column label="序号" width="55" align="left" fixed>
          <template slot-scope="scope">{{ holderParams.pageNum * holderParams.pageSize - holderParams.pageSize + scope.$index + 1 }}</template>
        </el-table-column>
        <el-table-column min-width="140" label="股东名称">
          <template slot-scope="scope">
            <router-link :to="`/enterprise/${encodeStr(scope.row.stockId)}`" tag="a" class="a-link" v-if="scope.row.stockId&&scope.row.stockName" v-html="scope.row.stockName"></router-link>
            <div v-else v-html="scope.row.stockName  || '--'"></div>
          </template>
        </el-table-column>
        <el-table-column prop="shouldCapiConv" label="应缴金额"></el-table-column>
        <el-table-column prop="stockPercent" label="持股比例"></el-table-column>
        <el-table-column prop="" label="法定代表人">
          <template slot-scope="scope">
            <span>{{scope.row.corporatePerson || '--'}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="成立日期">
          <template slot-scope="scope">
            <span>{{scope.row.registeredDate || '--'}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="企业状态">
          <template slot-scope="scope">
            <span>{{scope.row.businessStatus || '--'}}</span>
          </template>
        </el-table-column>
      </el-table>
      <el-table :data="shipData" border style="width: 100%" v-show="activeName=='second'">
        <el-table-column label="序号" width="55" align="left" fixed>
          <template slot-scope="scope">{{ shipParams.pageNum * shipParams.pageSize - shipParams.pageSize + scope.$index + 1 }}</template>
        </el-table-column>
        <el-table-column min-width="140" label="被投资企业名称">
          <template slot-scope="scope">
            <router-link :to="`/enterprise/${encodeStr(scope.row.id)}`" tag="a" class="a-link" v-if="scope.row.id&&scope.row.investName" v-html="scope.row.investName"></router-link>
            <div v-else v-html="scope.row.investName  || '--'"></div>
            <div class="tags" v-if="scope.row.businessStatus || scope.row.biddingAnnouncement">
              <span class="tag style1" v-if="scope.row.businessStatus">{{scope.row.businessStatus}}</span>
              <span class="tag style1" v-if="scope.row.biddingCount">招标数{{scope.row.biddingCount}}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="investOperName" label="法定代表人"></el-table-column>
        <el-table-column label="注册资本">
          <template slot-scope="scope">
            <span>{{scope.row.investRegistCapi || '--'}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="investStartDate" label="成立日期"></el-table-column>
        <el-table-column prop="stockPercentage" label="股权占比"></el-table-column>
        <el-table-column prop="shouldCapi" label="认缴出资额（万元）"></el-table-column>
      </el-table>
      <div class="rela-more" v-show="activeName=='second'&& shipTotal>shipParams.pageSize"><span class="a-link" @click="handlePath">查看更多数据 ></span></div>
    </div>
  </div>
</template>

<script>
import {encodeStr, changePath} from "@/assets/js/common"
import {bestStockPage, investment} from '@/api/detail/party-a/overview'
export default {
  name: 'Relationship',
  props: ['companyId', 'financial'],
  data() {
    return {
      encodeStr,
      activeName:'first',
      //表格数据
      holderData:[],
      holderParams: {
        cid: this.companyId,
        isHistory: 0,
        pageNum: 1,
        pageSize: 100
      },
      shipData:[],
      shipParams: {
        cid: this.companyId,
        pageNum: 1,
        pageSize: 5
      },
      shipTotal: 0
    }
  },
  created() {
    this.handleQuery()
    this.handleInvest()
  },
  mounted() {
  },
  methods: {
    async handleQuery(){
      let res = await bestStockPage(this.holderParams)
      if(res.code==200){
        if(res.rows&&res.rows.length>0){
          res.rows.forEach(item => {
            item.stockPercent?item.stockPercent = parseFloat(Number(item.stockPercent*100).toFixed(4))+'%':''
          })
        }
        this.holderData = res.rows
      }
    },
    async handleInvest(){
      let res = await investment(this.shipParams)
      if(res.code==200){
        if(res.rows&&res.rows.length>0){
          res.rows.forEach(item => {
            item.stockPercentage?item.stockPercentage = parseFloat(Number(item.stockPercentage*100).toFixed(4))+'%':''
          })
        }
        this.shipData = res.rows
        this.shipTotal = res.total
      }
    },
    handleClick(){
    },
    handlePath(){
      changePath(this, 'overseas')
    }
  }
}
</script>

<style lang="scss" scoped>
  .rela-container{
    margin: 0;
    padding: 24px 16px;
    background: #FFFFFF;
    border-radius: 4px;
    .selfTab{
      margin: 24px 0 0 -12px;
      ::v-deep .el-tabs__nav-wrap::after{
        display: none;
      }
      ::v-deep .el-tabs__item{
        height: 30px;
        line-height: 30px;
        padding: 0 12px;
      }
    }
    .table-item{
      margin-top: 16px;
      .tags{
        .tag{
          display: inline-block;
          border-radius: 2px;
          padding: 1px 7px;
          margin: 4px 8px 0 0;
          &.style1{
            background: #E4F3FD;
            color: #41A1FD;
          }
        }
      }
      ::v-deep .el-table--border .el-table__cell{
        border-bottom: 0;
      }
    }
    .rela-person{
      width: 100%;
      height: 24px;
      line-height: 24px;
      font-size: 12px;
      color: #3D3D3D;
      padding: 0 8px;
      background: #FDF8E9;
    }
    .rela-more{
      padding-top: 16px;
      text-align: center;
      span{
        cursor: pointer;
      }
    }
  }
</style>
