<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"
      :isExcel="true"
      @handle-search="handleSearch"
    />

    <tables
      :indexFixed="true"
      :tableLoading="tableLoading"
      :tableData="tableData"
      :forData="forData"
      :tableDataTotal="tableDataTotal"
      :queryParams="queryParams"
      @handle-current-change="handleCurrentChange"
    >
      <template slot="investName" slot-scope="scope">
        <router-link :to="scope.row.uipId?`/enterprise/${encodeStr(scope.row.id)}`:`/company/${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" :class="labelArr.includes(scope.row.businessStatus)?'style2':'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>
      <template slot="proportion">
        <div class="tab-header">股权占比 <el-popover placement="top-start" width="280" trigger="hover">
          <div style="font-size: 12px;">
            控股67%：绝对控制权67%，相当于100%的权力，修改公司章程/分立、合并、变更主营项目、重大决策<br />
            控股51%：相对控制权51%，控制线，绝对控制公司<br />
            控股34%：安全控制权，一票否决权</div>
          <img src="@/assets/images/detail/overview/zbph_question.png" slot="reference">
        </el-popover></div>
      </template>
      <template slot="stockPercentage" slot-scope="scope">
        <span>{{scope.row.stockPercentage?parseFloat(Number(scope.row.stockPercentage*100).toFixed(4))+'%':'--'}}</span>
      </template>
    </tables>
  </div>
</template>

<script>
import mixin from '../mixins/mixin'
import {investment} from '@/api/detail/party-a/overview'
export default {
  name: 'Overseas',
  props: ['companyId'],
  mixins: [mixin],
  data() {
    return {
      queryParams: {
        cid: this.companyId,
        pageNum: 1,
        pageSize: 20
      },
      forData: [
        {label: '被投资企业名称', prop: 'investName', minWidth: '180', slot: true},
        {label: '法定代表人', prop: 'investOperName'},
        {label: '注册资本', prop: 'investRegistCapi'},
        {label: '成立日期', prop: 'investStartDate'},
        {label: '股权占比', prop: 'stockPercentage', slot: true, slotHeader: true, slotName: 'proportion'},
        {label: '认缴出资额（万元）', prop: 'shouldCapi'}
      ],
      formData: [
        { type: 1, fieldName: 'hasBid', value: '', placeholder: '招标公告', options: [
          {name:'不限',value:'noLimit'},
          {name:'有招标公告',value:1},
          {name:'无招标公告',value:0}
          ],
          width: 130
        },
        { type: 1, fieldName: 'proportion', value: '', placeholder: '股权占比', options: [
            {name:'不限',value:'noLimit'},
            {name:'100%',value:'1~1'},
            {name:'66.66%以上',value:'0.6666~1'},
            {name:'50%以上',value:'0.5~1'},
            {name:'33.33%以上',value:'0.3333~1'},
            {name:'25%以上',value:'0.25~1'},
            {name:'不到5%',value:'0~0.05'}
          ],
          width: 130
        },
        { type: 3, fieldName: 'keyword', value: '', placeholder: '输入企业名称查询'},
      ],
      //列表
      tableLoading:false,
      tableData:[],
      tableDataTotal:0,
      labelArr:['失信联合惩戒企业','严重行政处罚','司法纠纷','注销', '注销企业'],
    }
  },
  created() {
    this.handleQuery()
  },
  methods: {
    async handleQuery(params) {
      this.isSkeleton = true;
      this.tableLoading = true
      let param = params?params:this.queryParams
      let res = await investment(param)
      this.tableLoading = false
      if(res.code==200){
        this.isSkeleton = false;
        this.tableData = res.rows
      }
      this.tableDataTotal = res.total
    },
    handleSearch(){
      let params = this.formParams()
      if(params.proportion){
        if(params.proportion!='noLimit'){
          params.stockPercentageMin = parseFloat(params.proportion.split('~')[0])
          params.stockPercentageMax = parseFloat(params.proportion.split('~')[1])
        }
        delete params.proportion
      }
      if(params.hasBid=='noLimit'){
        delete params.hasBid
      }
      params.pageNum = 1
      this.queryParams.pageNum = 1
      this.handleQuery(params)
    }
  }
}
</script>

<style lang="scss" scoped>
.detail-container{
  margin: 0;
  padding: 16px;
  background: #FFFFFF;
  border-radius: 4px;
  .tab-header{
    img{
      margin-bottom: 2px;
      width: 14px;
      height: 14px;
      cursor: pointer;
    }
  }
  .tags{
    .tag{
      display: inline-block;
      border-radius: 2px;
      padding: 1px 7px;
      margin: 4px 8px 0 0;
      &.style1{
        background: #E4F3FD;
        color: #41A1FD;
      }
      &.style2{
        background: #FFF1F1;
        color: #FF3C3C;
      }
    }
  }
}
</style>
