<template>
  <div class="app-container enterprises">
    <div class="flex-box eco-header">
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="本地企业" name="first"></el-tab-pane>
        <el-tab-pane label="异地备案" name="second"></el-tab-pane>
      </el-tabs>
      <div class="location"><i class="el-icon-location"></i>{{province}}</div>
    </div>
    <div class="content">
      <div class="search">
        <el-cascader
          ref="aptitudeCode"
          :options="aptitudeCodeList"
          :props="props"
          v-model="queryParams.codeStr"
          @change="handleChange"
          placeholder="资质资格"
          collapse-tags
          clearable></el-cascader>
        <el-input placeholder="输入企业名称关键词" v-model="queryParams.ename" clearable @clear="handleSearch()">
          <el-button slot="append" @click="handleSearch()">搜索</el-button>
        </el-input>
        <span class="total">共{{tableDataTotal}}条</span>
      </div>
      <div class="table-item">
        <el-table
          v-loading="tableLoading"
          :data="tableData"
          element-loading-text="Loading"
          border
          fit
          @sort-change="sortChange"
          highlight-current-row
          v-if="tableDataTotal > 0"
          :default-sort = "{prop: 'skyCount', order: 'descending'}"
        >
          <el-table-column label="序号" width="60" align="left" fixed>
            <template slot-scope="scope">{{ pageIndex * pageSize - pageSize + scope.$index + 1 }}</template>
          </el-table-column>
          <el-table-column label="公司名称" align="left" fixed width="350">
            <template slot-scope="scope">
              <router-link v-if="scope.row.jskEid"  :to="`/company/${encodeStr(scope.row.jskEid)}`" tag="a" class="a-link" v-html="scope.row.name" ></router-link>
              <span v-else v-html="scope.row.name" ></span>
            </template>
          </el-table-column>
          <el-table-column label="注册地址" prop="domicile" width="200" :formatter="formatStatus"/>
          <el-table-column label="资质资格" prop="aptitudeCountNew" sortable="custom" width="120" :formatter="formatStatus"/>
          <el-table-column label="专业人员" prop="persionCount" sortable="custom" width="120" :formatter="formatStatus"/>
          <el-table-column label="中标业绩" prop="recentlyCount" sortable="custom" width="120" :formatter="formatStatus"/>
          <el-table-column label="最大中标金额（万元）" prop="bidMaxAmount" sortable="custom" width="170" :formatter="formatStatus"/>
          <el-table-column label="中标总金额（万元）" prop="bidSumAmount" sortable="custom" width="170" :formatter="formatStatus"/>
          <el-table-column label="四库业绩" prop="skyCount" sortable="custom" width="120" :formatter="formatStatus"/>
          <el-table-column label="公路业绩" prop="roadConservancy" sortable="custom" width="100" :formatter="formatStatus"/>
          <el-table-column label="水利业绩" prop="waterConservancy" sortable="custom" width="100" :formatter="formatStatus"/>
          <el-table-column label="常合作业主" prop="topCustomer" width="150" :formatter="formatStatus"/>
          <el-table-column label="客户（个）" prop="customerCount" sortable="custom" width="120" :formatter="formatStatus"/>
          <el-table-column label="供应商（个）" prop="supplierCount" sortable="custom" width="150" :formatter="formatStatus"/>
          <el-table-column label="常合作供应商" prop="topSupplier" width="200" :formatter="formatStatus"/>
        </el-table>
        <div class="empty" v-if="tableDataTotal === 0">
          <img class="img" src="@/assets/images/project/empty.png">
          <div class="p1">抱歉，没找到相关数据</div>
          <div class="p2">建议调整关键词或筛选条件，重新搜索</div>
        </div>
      </div>
      <div class="pagination-box" v-if="tableDataTotal>pageSize">
        <el-pagination background :current-page="pageIndex" :page-size="pageSize" :total="tableDataTotal" layout="prev, pager, next, jumper" @current-change="handleCurrentChange" @size-change="handleSizeChange" />
      </div>
    </div>
    <!--<LocalEnterprises v-if="activeName === 'first'"></LocalEnterprises>-->
    <!--<Offsite v-if="activeName === 'second'"></Offsite>-->
  </div>
</template>

<script>

  // import LocalEnterprises from './component/localEnterprises'
  // import Offsite from './component/offsite'
  import {encodeStr} from "@/assets/js/common.js"
  import aptitudeCode from '@/assets/json/aptitudeCode'
  import { enterprise,location } from '@/api/macro/macro'
export default {
  name: 'Enterprises',
  // components: {LocalEnterprises,Offsite},
  data() {
    return {
      encodeStr,
      activeName: 'first',
      queryParams:{
        ename:'',
        codeStr:'',
      },
      props: {
        value: 'id',
        multiple: true,
        checkStrictly:true,
        label:'name',
        children:'list',
        expandTrigger:'hover'
      },
      tableData: [],
      tableLoading: false,
      pageIndex: 1,
      pageSize: 20,
      tableDataTotal: null,
      aptitudeCodeList:[],
      aptitudeType:'',
      province:'',
      provinceId:''
    }
  },
  created() {
    location({}).then(res => {
      this.province=res.data.province;
      this.provinceId=res.data.provinceId;
      this.querySubmit()
    })
    this.aptitudeCode()

  },
  methods: {
//资质Json
    async aptitudeCode() {
      // await axios.post("https://files.jiansheku.com/file/json/common/aptitudeCode.json", {}, {
      //   headers: {
      //     'Content-Type': 'application/json'
      //   }
      // }).then(res => {
      //   if (res.data.code == 200) {
      //     console.log(res.data.data)
      //   }
      // })
      this.aptitudeCodeList=aptitudeCode
    },
    async querySubmit(){
      const params = { pageNum: this.pageIndex, pageSize: this.pageSize}
      if(this.queryParams.field){
        params.field=this.queryParams.field
      }
      if(this.queryParams.order){
        params.order=this.queryParams.order
      }
      params.aptitudeQueryDto={
        filePlaceType:this.activeName === 'first' ? 3 : 2,
        aptitudeSource:'new',
        aptitudeQueryType:'or',
        filePlaceCode:this.provinceId
      }
      if(this.queryParams.ename){
        params.aptitudeQueryDto.ename=this.queryParams.ename
      }
      if(this.aptitudeType){
        let aptitudeType=[];
        aptitudeType.push({
          codeStr:this.aptitudeType,
          queryType: "and",
          aptitudeType: "qualification"
        })
        params.aptitudeQueryDto.aptitudeDtoList=aptitudeType
      }
      enterprise(params).then(res => {
        if(res.code === 200){
          this.tableData=res.data.list;
          this.tableDataTotal=res.data.total;
        }
      })
    },
    // 重置页数
    handleSizeChange(val) {
      this.pageIndex = 1
      this.pageSize = val
      this.querySubmit()
    },
    // 跳转指定页数
    handleCurrentChange(val) {
      this.pageIndex = val
      this.querySubmit()
    },
    handleChange(){
      // console.log(this.queryParams.codeStr)
      let codeStr=this.queryParams.codeStr;
      let arr=[]
      for(let i=0; i<codeStr.length; i++){
        arr.push(codeStr[i][codeStr[i].length - 1])
      }
      this.aptitudeType=arr.join(',')
      this.$refs.aptitudeCode.toggleDropDownVisible(false)
      this.pageIndex=1;
      this.querySubmit()
    },
    handleClick(){
      console.log(this.activeName)
      this.queryParams.codeStr=[]
      this.aptitudeType='';
      this.queryParams={
        ename:'',
        codeStr:'',
      }
      this.pageIndex=1;
      this.querySubmit()
    },
    handleSearch(){
      this.pageIndex=1;
      this.querySubmit()
    },
    formatStatus: function(row, column, cellValue) {
      return cellValue? cellValue : '-'
    },
    sortChange({ column, prop, order }){
      if(prop === 'aptitudeCountNew'){
        this.queryParams.field ='aptitudeCountNew'
      }else {
        this.queryParams.field = prop
      }
      if(column.order === "ascending"){
        this.queryParams.order = 'asc'
      }else if(column.order === "descending"){
        this.queryParams.order = 'desc'
      }else {
        this.queryParams.order=''
        this.queryParams.field=''
      }
      this.pageIndex = 1;
      this.querySubmit()
    },
  }
}
</script>

<style lang="scss" scoped>
  .app-container{
    padding: 0;
  }
  .enterprises{
    .eco-header{
      justify-content: space-between;
      height: 48px;
      background: #FFFFFF;
      border-radius: 4px;
      padding:0 16px;
      color: #232323;
      ::v-deep .el-tabs{
        height: 48px;
        line-height: 48px;
        .el-tabs__nav-wrap::after {
          position: static !important;
        }
        .el-tabs__header{
          margin: 0;
          .el-tabs__item{
            padding: 0 16px;
            font-size: 16px;
          }
          .is-active{
            font-weight: bold;
          }
        }
        .el-tabs__content{
          width: 100%;
        }
      }
      .location{
        font-size: 14px;
        color: #0081FF;
        i{
          margin-right: 6px;
          font-size: 16px;
        }
      }
    }
    .content{
      background: #FFFFFF;
      border-radius: 4px;
      margin-top: 12px;
      padding: 16px;
      .search{
        ::v-deep .el-cascader{
          width: 180px;
          margin-right: 12px;
          height: 32px;
          .el-input{
            width: 100%;
            height: 32px;
            .el-input__inner{
              height: 32px !important;
            }
          }
          .el-cascader__tags{
            flex-wrap: inherit;
            .el-tag{
              max-width: 100px;
              margin: 5px 0 2px 6px;
            }
          }
        }
        ::v-deep .el-input{
          width: 250px;
          height: 32px;
          .el-input__inner{
            height: 32px;
          }
          .el-input-group__append{
            width: 59px;
            background: #F5F5F5;
            color:#0081FF;
            border-left: 0;
          }
        }
        .total{
          float: right;
          color: #3D3D3D;
          font-size: 12px;
          line-height: 36px;
        }
      }
      .table-item{
        margin-top: 14px;
        .empty{
          margin: 0 auto;
          height: 600px;
          text-align: center;
          border-top: 1px solid #EFEFEF;
          .img{
            width: 108px;
            height: 108px;
            margin-bottom: 24px;
            margin-top: 150px;
          }
          .p1{
            color: #333333;
            font-size: 16px;
          }
          .p2{
            color: #999999;
            font-size: 14px;
            margin-top: 8px;
          }
        }
      }
    }
  }

</style>
