<template>
  <el-dialog
    title="总部企业" 
    :visible.sync="infoVisible"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    @close="infoClose"
    custom-class="headquarterEnterprise-dialog"
    append-to-body
    width="75%"
  >
    <div class="headquarterEnterprise-box">
      <el-form :inline="true" :model="formInline" size="small" class="headquarterEnterprise-form" ref="queryFrom">
        <el-col :span="21">
          <el-form-item label="企业名称：">
            <el-input v-model.trim="formInline.qymc" placeholder="请输入内容"></el-input>
          </el-form-item>
          <el-form-item label="统一社会信用代码："> <!-- 申报单位 -->
            <el-input v-model.trim="formInline.tyshxydm" placeholder="请输入统一社会信用代码"></el-input>
          </el-form-item>
          <el-form-item label="总部类型：">
            <el-select class="ignoreElement" v-model="formInline.type" placeholder="请选择总部类型">
              <el-option
                v-for="dict in dict.type.head_quarter_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item>
            <el-button size="mini" @click="resetQuery('queryFrom')">重置</el-button>
            <el-button size="mini" type="primary" @click="handleQuery('queryFrom')">查询</el-button>
          </el-form-item>
        </el-col>
      </el-form>
      <!-- <el-row class="radio_btn"> -->
      <el-col class="radio_btn">
        <el-radio-group v-model="projectSmallType" @change="toggleOptionsEnter" fill="#134EE6">
          <el-radio-button label="">全部({{ countData.count1 + countData.count2 + countData.count3 }})</el-radio-button>
          <el-radio-button label="1">省级总部({{ countData.count1 }})</el-radio-button>
          <el-radio-button label="2">市级总部({{ countData.count2 }})</el-radio-button>
          <el-radio-button label="3">区级总部({{ countData.count3 }})</el-radio-button>
        </el-radio-group>
      </el-col>
      <!-- </el-row> -->
      <section>
        <el-table 
          v-loading="loading" 
          class="dataMap-two-table" 
          :data="tableData" 
          :row-class-name="tableRowClassName" 
          :header-cell-style="{background:'#D1D9E6'}"
          height="500px"
        >  <!-- :max-height="tabHeader" -->
          <el-table-column label="序号" type="index" align="center" width="50"/>
          <el-table-column label="企业名称" prop="qymc" align="center"/>
          <el-table-column label="统一信用代码" prop="tyshxydm" align="center" />
          <el-table-column label="总部类型" prop="type" align="center" width="200">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.head_quarter_type" :value="scope.row.type"/>
            </template>
          </el-table-column>
          <el-table-column label="税收(亿元)" prop="taxation" align="center" width="100">
            <!-- <template slot-scope="scope">
              <div>{{ scope.row.taxation == '-0.0' ? '-' : scope.row.taxation == '0.0' ? '-' : scope.row.taxation }}</div>
            </template> -->
          </el-table-column>
          <el-table-column label="产值(亿元)" prop="output" align="center" width="100">

          </el-table-column>
          <el-table-column label="营收(亿元)" prop="revenue" align="center" width="100">

          </el-table-column>
          <el-table-column label="销售额(亿元)" prop="sales" align="center" width="100">

          </el-table-column>
          <el-table-column label="操作" align="center" width="100">
            <template slot-scope="scope">
              <div class="project-trace-table-number" @click="enterpriseInfo(scope.row)">企业详情</div>
            </template>
          </el-table-column>
        </el-table>
        <my-pagination 
          :total="total"
          :page="pagination.current"
          :limit="pagination.size"
          @pagination="getPagination"
          :current-page.sync="pagination.current" 
        ></my-pagination>
      </section>
    </div>
  </el-dialog>
</template>
<script>
import myPagination from "@/views/components/Pagination/index.vue"
import { selectZbCount, headquartersRevenue } from "@/api/jin_ji_hu/dataCloudMap"
import { getUserId } from "@/api/jin_ji_hu/project/index"
export default {
  components:{myPagination},
  dicts: ["head_quarter_type"],
  name: "honorDialog",
  data() {
    return {
      infoVisible: false,
      loading: false,
      tableData:[],
      formInline:{
        qymc:"",
        tyshxydm:"",
        type:"",
        projectSmallType:""
      },
      projectSmallType:"",
      pagination: {
        current:1,
        size:10,
      },
      total:40,
      countData: {
        count1:0,
        count2:0,
        count3:0,
      },
    }
  },
  methods:{
    open(){
      this.infoVisible = true;
      selectZbCount().then(res=>{
        this.countData = res.data;
      })
      this.getList();
    },
    infoClose(){
      this.infoVisible = false;
    },
    getList(){
      this.loading = true;
      headquartersRevenue(this.pagination).then(res=>{
        this.loading = false;
        this.total = res.data.total;
        this.tableData = res.data.records
      })
    },
    // 获取页码
    getPagination(pages) {
      this.pagination.current = pages.page;
      this.pagination.size = pages.limit;
      this.getList();
    },
    // 重置
    resetQuery(){
      this.pagination = {
        current: 1,
        size: 10
      }
      this.formInline = {
        qymc:"",
        tyshxydm:"",
        type:"",
        projectSmallType: this.projectSmallType,
      },
      this.pagination = { ...this.pagination,...this.formInline };
      this.getList();
    },
    // 查询
    handleQuery(){
      this.pagination = {
        current: 1,
        size: 10
      }
      this.pagination = { ...this.pagination,...this.formInline };
      this.getList();
    },
    // 企业详情
    enterpriseInfo(row){
      getUserId({getCreditCode : row.tyshxydm}).then(res=>{
        if(res.data?.id) {
          this.$router.push({
            name: 'enterpriselibraryInfo',
            query: { userId: res.data.id, creditCode: row.tyshxydm }
          })
        } else {
          this.$message.error("该企业未在企业库");
        }
      })
    },
    // tab切换
    toggleOptionsEnter(val){
      this.projectSmallType = val;
      this.pagination = {
        current: 1,
        size: 10
      }
      this.formInline = {
        qymc:"",
        tyshxydm:"",
        type: "",
        projectSmallType: val,
      },
      this.pagination = { ...this.pagination,...this.formInline };
      this.getList();
    },
    // 修改table背景色
    tableRowClassName({row, rowIndex}){
      if (rowIndex % 2 !== 0) {
        return 'evenNumber-row';
      }
      return '';
    },
  },
}
</script>
<style lang="scss" scoped>
::v-deep .headquarterEnterprise-dialog {
  margin-top: 10vh !important;
}
</style>