<template>
  <div>
    <el-form :model="searchForm" ref="queryRef" @submit="getData">
      <el-row :gutter="10">
        <el-col :lg="8" :sm="6">
          <el-form-item label="企业名称搜索">
            <el-input v-model="searchForm.enterpriseName" placeholder="请输入企业名称" clearable/>
          </el-form-item>
        </el-col>
        <el-col :lg="8" :sm="6">
          <el-form-item>
            <el-button type="primary" @click="getData">搜索</el-button>
            <el-button>重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-button plain @click="dialogFormVisible = true" type="primary">
      选择查看的数据
    </el-button>
    <el-button plain @click="exportToExcel" type="warning">导出当前页为 Excel</el-button>
    <el-table v-show="isShow" id="content-to-pdf" :data="tableData" max-height="650" style="width: 100%;" border show-summary
              :summary-method="getSummaries">
      <el-table-column prop="enterpriseName" label="企业名称" width="300" fixed/>

      <template v-for="(col, index) in needShow" :key="index">
        <el-table-column v-if="col.includes('a')" sortable :prop="col" :label="colMap.get(col)" width="180" align="right"/>
      </template>

      <template v-if="needShow.filter(key => key.includes('b')).length >= 2">
        <el-table-column label="企业产值" header-align="center">
          <template v-for="(col, index) in needShow" :key="index">
            <el-table-column v-if="col.includes('b')" sortable :prop="col" :label="colMap.get(col)" width="180" align="right">
              <template #default="{row}">
                {{toFixedWithoutRounding(row[col],2)}}
              </template>
            </el-table-column>
          </template>
        </el-table-column>
      </template>
      <template v-if="needShow.filter(key => key.includes('b')).length < 2">
        <template v-for="(col, index) in needShow" :key="index">
          <el-table-column v-if="col.includes('b')" sortable :prop="col" :label="colMap.get(col)" width="180" align="right">
            <template #default="{row}">
              {{toFixedWithoutRounding(row[col],2)}}
            </template>
          </el-table-column>
        </template>
      </template>
      <template v-if="needShow.filter(key => key.includes('b')).length >= 2">
        <el-table-column label="当前显示产值合计" width="180" align="right" prop="b5">
          <template #default="{row}">
            {{
              needShow.filter(key => key.includes('b')).reduce((acc, cur) => Number(acc) + Number(row[cur]), 0).toFixed(2)
            }}
          </template>
        </el-table-column>
      </template>

      <template v-if="needShow.filter(key => key.includes('c')).length >= 2">
        <el-table-column label="企业税收" header-align="center">
          <template v-for="(col, index) in needShow" :key="index">
            <el-table-column v-if="col.includes('c')" sortable :prop="col" :label="colMap.get(col)" width="180" align="right">
              <template #default="{row}">
                {{toFixedWithoutRounding(row[col],2)}}
              </template>
            </el-table-column>
          </template>
        </el-table-column>
      </template>
      <template v-if="needShow.filter(key => key.includes('c')).length < 2">
        <template v-for="(col, index) in needShow" :key="index">
          <el-table-column v-if="col.includes('c')" sortable :prop="col" :label="colMap.get(col)" width="180" align="right">
            <template #default="{row}">
              {{toFixedWithoutRounding(row[col],2)}}
            </template>
          </el-table-column>
        </template>
      </template>
      <template v-if="needShow.filter(key => key.includes('c')).length >= 2">
        <el-table-column label="当前显示税收合计" width="180" align="right" prop="c5">
          <template #default="{row}">
            {{
              needShow.filter(key => key.includes('c')).reduce((acc, cur) => Number(acc) + Number(row[cur]), 0).toFixed(2)
            }}
          </template>
        </el-table-column>
      </template>

      <template v-for="(col, index) in needShow" :key="index">
        <el-table-column v-if="col == 'dd'" sortable :prop="col" :label="colMap.get(col)" width="180" align="right"/>
      </template>

      <template v-for="(col, index) in needShow" :key="index">
        <el-table-column v-if="col == 'de'" sortable :prop="col" :label="colMap.get(col)" width="180" align="right"/>
      </template>

      <template v-for="(col, index) in needShow" :key="index">
        <el-table-column v-if="col == 'df'" sortable :prop="col" :label="colMap.get(col)" width="180" align="right"/>
      </template>

      <template v-for="(col, index) in needShow" :key="index">
        <el-table-column v-if="col == 'dg'" sortable :prop="col" :label="colMap.get(col)" width="180" align="right">
          <template #default="{row}">
            {{ row[col] == 0 ? '否' : '是' }}
          </template>
        </el-table-column>
      </template>

      <template v-for="(col, index) in needShow" :key="index">
        <el-table-column v-if="col.includes('dh')" sortable :prop="col" :label="colMap.get(col)" width="180" align="right">
          <template #default="{row}">
            {{ row[col] == 0 ? '否' : '是' }}
          </template>
        </el-table-column>
      </template>

      <template v-for="(col, index) in needShow" :key="index">
        <el-table-column v-if="col == 'di'" sortable :prop="col" :label="colMap.get(col)" width="180" align="right">
          <template #default="{row}">
            {{ row[col] == 0 ? '否' : '是' }}
          </template>
        </el-table-column>
      </template>

      <template v-for="(col, index) in needShow" :key="index">
        <el-table-column v-if="col == 'dj'" sortable :prop="col" :label="colMap.get(col)" width="180" align="right">
          <template #default="{row}">
            {{ row[col] == 0 ? '否' : '是' }}
          </template>
        </el-table-column>
      </template>

      <template v-for="(col, index) in needShow" :key="index">
        <el-table-column v-if="col == 'dk'" sortable :prop="col" :label="colMap.get(col)" width="180" align="right">
          <template #default="{row}">
            {{ row[col] == 0 ? '否' : '是' }}
          </template>
        </el-table-column>
      </template>

      <template v-for="(col, index) in needShow" :key="index">
        <el-table-column v-if="col == 'dl'" sortable :prop="col" :label="colMap.get(col)" width="180" align="right"/>
      </template>

      <template v-for="(col, index) in needShow" :key="index">
        <el-table-column v-if="col == 'dm'" sortable :prop="col" :label="colMap.get(col)" width="180" align="right"/>
      </template>

      <template v-for="(col, index) in needShow" :key="index">
        <el-table-column v-if="col == 'dn'" sortable :prop="col" :label="colMap.get(col)" width="180" align="right">
          <template #default="{row}">
            {{ row[col] == 0 ? '否' : '是' }}
          </template>
        </el-table-column>
      </template>

      <template v-for="(col, index) in needShow" :key="index">
        <el-table-column v-if="col == 'dp'" sortable :prop="col" :label="colMap.get(col)" width="180" align="right"/>
      </template>

      <template v-for="(col, index) in needShow" :key="index">
        <el-table-column v-if="col == 'dq'" sortable :prop="col" :label="colMap.get(col)" width="180" align="right"/>
      </template>

      <template v-for="(col, index) in needShow" :key="index">
        <el-table-column v-if="col == 'dr'" sortable :prop="col" :label="colMap.get(col)" width="180" align="right"/>
      </template>

      <template v-for="(col, index) in needShow" :key="index">
        <el-table-column v-if="col == 'dr1'" sortable :prop="col" :label="colMap.get(col)" width="180" align="right">
          <template #default="{row}">
            {{ toFixedWithoutRounding(row.dr1,2) }}
          </template>
        </el-table-column>
      </template>

      <template v-for="(col, index) in needShow" :key="index">
        <el-table-column v-if="col == 'ds'" :prop="col" :label="colMap.get(col)" width="180" align="right"/>
      </template>

      <template v-for="(col, index) in needShow" :key="index">
        <el-table-column v-if="col == 'dt'" :prop="col" :label="colMap.get(col)" width="180" align="right"/>
      </template>

      <template v-for="(col, index) in needShow" :key="index">
        <el-table-column v-if="col == 'du'" sortable :prop="col" :label="colMap.get(col)" width="180" align="right"/>
      </template>

      <template v-for="(col, index) in needShow" :key="index">
        <el-table-column v-if="col == 'dv'" sortable :prop="col" :label="colMap.get(col)" width="180" align="right"/>
      </template>

      <template v-if="needShow.filter(key => key.includes('dw')).length >= 2">
        <el-table-column label="企业用水" header-align="center">
          <template v-for="(col, index) in needShow" :key="index">
            <el-table-column v-if="col.includes('dw')" sortable :prop="col" :label="colMap.get(col)" width="180" align="right"/>
          </template>
        </el-table-column>
      </template>
      <template v-if="needShow.filter(key => key.includes('dw')).length < 2">
        <template v-for="(col, index) in needShow" :key="index">
          <el-table-column v-if="col.includes('dw')" sortable :prop="col" :label="colMap.get(col)" width="180" align="right"/>
        </template>
      </template>
      <template v-if="needShow.filter(key => key.includes('dw')).length >= 2">
        <el-table-column label="当前显示合计" width="180" align="right" prop="dw5">
          <template #default="{row}">
            {{
              needShow.filter(key => key.includes('dw')).reduce((acc, cur) => Number(acc) + Number(row[cur]), 0).toFixed(2)
            }}
          </template>
        </el-table-column>
      </template>

      <template v-if="needShow.filter(key => key.includes('dx')).length >= 2">
        <el-table-column label="企业用电" header-align="center">
          <template v-for="(col, index) in needShow" :key="index">
            <el-table-column v-if="col.includes('dx')" sortable :prop="col" :label="colMap.get(col)" width="180" align="right"/>
          </template>
        </el-table-column>
      </template>
      <template v-if="needShow.filter(key => key.includes('dx')).length < 2">
        <template v-for="(col, index) in needShow" :key="index">
          <el-table-column v-if="col.includes('dx')" sortable :prop="col" :label="colMap.get(col)" width="180" align="right"/>
        </template>
      </template>
      <template v-if="needShow.filter(key => key.includes('dx')).length >= 2">
        <el-table-column label="当前显示合计" width="180" align="right" prop="dx5">
          <template #default="{row}">
            {{
              needShow.filter(key => key.includes('dx')).reduce((acc, cur) => Number(acc) + Number(row[cur]), 0).toFixed(2)
            }}
          </template>
        </el-table-column>
      </template>

      <template v-if="needShow.filter(key => key.includes('dy')).length >= 2">
        <el-table-column label="企业营收" header-align="center">
          <template v-for="(col, index) in needShow" :key="index">
            <el-table-column v-if="col.includes('dy')" sortable :prop="col" :label="colMap.get(col)" width="180" align="right"/>
          </template>
        </el-table-column>
      </template>
      <template v-if="needShow.filter(key => key.includes('dy')).length < 2">
        <template v-for="(col, index) in needShow" :key="index">
          <el-table-column v-if="col.includes('dy')" sortable :prop="col" :label="colMap.get(col)" width="180" align="right"/>
        </template>
      </template>
      <template v-if="needShow.filter(key => key.includes('dy')).length >= 2">
        <el-table-column label="当前显示合计" width="180" align="right" prop="dy5">
          <template #default="{row}">
            {{
              needShow.filter(key => key.includes('dy')).reduce((acc, cur) => Number(acc) + Number(row[cur]), 0).toFixed(2)
            }}
          </template>
        </el-table-column>
      </template>
    </el-table>
    <div style="padding-top: 30px">
      <el-pagination
          v-model:current-page="pageNum"
          v-model:page-size="pageSize"
          :background="true"
          :page-sizes="[10, 20, 130, 200]"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="getData"
          @current-change="getData"
      />
    </div>
    <el-dialog v-model="dialogFormVisible" title="请选择需要查看的列" @close="handleClose">
      <el-form :model="form">
        <el-row :gutter="10">
          <el-col :lg="6" :sm="8">
            <el-form-item label="">
              <el-checkbox v-model="form.a" label="行政处罚" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.b1" :label="currentYear+'企业产值(第一季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.b2" :label="currentYear+'企业产值(第二季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.b3" :label="currentYear+'企业产值(第三季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.b4" :label="currentYear+'企业产值(第四季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.b6" :label="lastYear+'企业产值(第一季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.b7" :label="lastYear+'企业产值(第二季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.b8" :label="lastYear+'企业产值(第三季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.b9" :label="lastYear+'企业产值(第四季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.c1" :label="currentYear+'企业税收(第一季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.c2" :label="currentYear+'企业税收(第二季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.c3" :label="currentYear+'企业税收(第三季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.c4" :label="currentYear+'企业税收(第四季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.c6" :label="lastYear+'企业税收(第一季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.c7" :label="lastYear+'企业税收(第二季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.c8" :label="lastYear+'企业税收(第三季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.c9" :label="lastYear+'企业税收(第四季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dd" label="变更记录条数" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.de" label="行政许可条数" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.df" label="行政确认条数" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dg" label="上市企业" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dh" label="专精特精企业" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.di" label="科研企业" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dj" label="科技型中小企业" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dk" label="高新技术企业" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dl" label="软件著作权" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dm" label="专利信息" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dn" label="红名单企业" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dp" label="纳税信用等级" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dq" label="非正常纳税信息" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dr" label="社保缴纳人数信息" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dr1" label="社保缴纳金额信息" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.ds" label="环保信用等级" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dt" label="国家公共信用评价" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.du" label="评级机构评级信息" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dv" label="企业征信机构评分(天眼查)" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dw1" :label="currentYear+'用水明细(第一季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dw2" :label="currentYear+'用水明细(第二季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dw3" :label="currentYear+'用水明细(第三季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dw4" :label="currentYear+'用水明细(第四季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dw6" :label="lastYear+'用水明细(第一季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dw7" :label="lastYear+'用水明细(第二季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dw8" :label="lastYear+'用水明细(第三季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dw9" :label="lastYear+'用水明细(第四季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dx1" :label="currentYear+'用电明细(第一季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dx2" :label="currentYear+'用电明细(第二季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dx3" :label="currentYear+'用电明细(第三季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dx4" :label="currentYear+'用电明细(第四季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dx6" :label="lastYear+'用电明细(第一季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dx7" :label="lastYear+'用电明细(第二季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dx8" :label="lastYear+'用电明细(第三季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dx9" :label="lastYear+'用电明细(第四季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dy1" :label="currentYear+'企业营收(第一季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dy2" :label="currentYear+'企业营收(第二季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dy3" :label="currentYear+'企业营收(第三季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dy4" :label="currentYear+'企业营收(第四季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dy6" :label="lastYear+'企业营收(第一季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dy7" :label="lastYear+'企业营收(第二季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dy8" :label="lastYear+'企业营收(第三季度)'" size="large"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :sm="8">
            <el-form-item>
              <el-checkbox v-model="form.dy9" :label="lastYear+'企业营收(第四季度)'" size="large"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
  </div>
</template>

<script lang="ts" setup>
import {computed, ref, watch} from "vue";
import {getCheckList} from "@/api/basicData/sjtjzl"
import {getInfo} from "@/api/login"
import {toFixedWithoutRounding} from '@/utils/toFixedWithoutRounding'
import {ElMessage} from "element-plus";
import {colMap} from "./colMap";
import * as XLSX from 'xlsx';
const isShow = ref(true)

const initCheck = {
  a: true,
  b1: false,
  b2: false,
  b3: false,
  b4: false,
  b6: false,
  b7: false,
  b8: false,
  b9: false,
  c1: false,
  c2: false,
  c3: false,
  c4: false,
  c6: false,
  c7: false,
  c8: false,
  c9: false,
  dd: false,
  de: false,
  df: false,
  dg: false,
  dh: false,
  di: false,
  dj: false,
  dk: false,
  dl: false,
  dm: false,
  dn: false,
  dp: false,
  dq: false,
  dr:false,
  dr1:false,
  ds:false,
  dt:false,
  du:false,
  dv:false,
  dw1:false,
  dw2:false,
  dw3:false,
  dw4:false,
  dw6:false,
  dw7:false,
  dw8:false,
  dw9:false,
  dx1:false,
  dx2:false,
  dx3:false,
  dx4:false,
  dx6:false,
  dx7:false,
  dx8:false,
  dx9:false,
  dy1:false,
  dy2:false,
  dy3:false,
  dy4:false,
  dy6:false,
  dy7:false,
  dy8:false,
  dy9:false
};
const currentYear = ref(new Date().getFullYear());
const lastYear = ref(currentYear.value - 1)
const dialogFormVisible = ref(false)
const tableData = ref([])
const userName = ref("")
const pageNum = ref(1)
const pageSize = ref(20)
const total = ref(0)
const form = ref(JSON.parse(localStorage.getItem("sjtjzlKey")) || initCheck)
const searchForm = ref({
  enterpriseName: ""
})
const handleClose = ()=>{
  isShow.value = false
  setTimeout(()=>{isShow.value = true},0)
}
const exportToExcel = () => {
  const staticArr = ["enterpriseName", "uniCode"];
  const headers1 = staticArr.concat(needShow.value).map(key => colMap.get(key));
  const headers = staticArr.concat(needShow.value);
  const needTransformKeys = ['dg','dh','di','dj','dk','dn'];
  const wsData = [headers1, ...tableData.value.map(item => {
    return headers.map(key => {
      if(needTransformKeys.includes(key)){
        return item[key]==0 ? '否' : '是';
      }
      return  item[key]
    })
  })];


  const ws = XLSX.utils.aoa_to_sheet(wsData);

  ws['!cols'] = headers1.map(() => ({wch: 20}));

  const wb = XLSX.utils.book_new();
  XLSX.utils.book_append_sheet(wb, ws, '企业数据总览报告');

  XLSX.writeFile(wb, '企业数据总览报告.xlsx');
};
const needShow = computed(() => {
  return Object.keys(form.value).filter(key => form.value[key]);
});
const getData = async () => {
  let conditionJsonWhole = [];
  if (searchForm.value.enterpriseName != '') {
    conditionJsonWhole.push({
      column: "enterprise_name",
      type: 'like',
      value: searchForm.value.enterpriseName
    });
  }
  let s = encodeURIComponent(JSON.stringify(conditionJsonWhole));
  const res = await getCheckList(needShow.value, pageNum.value, pageSize.value, s);
  if (res.code != 200) {
    ElMessage.error("出现了问题,请联系管理员处理")
  }
  tableData.value = res.data;
  tableData.value = tableData.value.map(item => {
    let b5 = 0;
    let c5 = 0;
    let dw5 = 0;
    let dx5 = 0;
    let dy5 = 0;
    for (const k in item) {
      if(k.includes('b')){
        b5 += Number(item[k]);
      }
      if(k.includes('c')){
        c5 += Number(item[k]);
      }
      if(k.includes('dw')){
        dw5 += Number(item[k]);
      }
      if(k.includes('dx')){
        dx5 += Number(item[k]);
      }
      if(k.includes('dy')){
        dy5 += Number(item[k]);
      }
      // if (k=='b1'||k=='b2'||k=='b3'||k=='b4') {
      //   if (item[k] != null) {
      //     b5 += Number(item[k]);
      //   }
      // }
      // if (k=='b6'||k=='b7'||k=='b8'||k=='b9') {
      //   if (item[k] != null) {
      //     b5 += Number(item[k]);
      //   }
      // }
      // if (k=='c1'||k=='c2'||k=='c3'||k=='c4') {
      //   if (item[k] != null) {
      //     c5 += Number(item[k]);
      //   }
      // }
      // if (k=='c6'||k=='c7'||k=='c8'||k=='c9') {
      //   if (item[k] != null) {
      //     c5 += Number(item[k]);
      //   }
      // }
      // console.log(b5);
    }
    return {
      ...item,
      b5,
      c5,
      dw5,
      dx5,
      dy5
    }
  })
  total.value = res?.total;
}
const getSummaries = (param) => {
  const {columns, data} = param;
  const sums = [];
  columns.forEach((column, index) => {
    // console.log(column.property);
    if (index === 0) {
      sums[index] = "当前页总计";
      return;
    }
    const values = data.map(item => Number(item[column.property]));
    console.log(values);
    if (!values.every(value => isNaN(value))) {
      sums[index] = values.reduce((prev, curr) => {
        const value = Number(curr);
        if (!isNaN(value)) {
          return prev + curr;
        } else {
          return prev;
        }
      }, 0);
      let until;
      if (column.property == "a") {
        until = "条";
        sums[index] += until;
      } else if (column.property == "b1" || column.property == "b2" || column.property == "b3" || column.property == "b4" ||  column.property == "b5" ||  column.property == "b6" || column.property == "b7" || column.property == "b8" || column.property == "b9") {
        sums[index] = sums[index].toFixed(2);
        until = "万元";
        sums[index] += until;
      } else if (column.property == "c1" || column.property == "c2" || column.property == "c3" || column.property == "c4" || column.property == "c5" || column.property == "c6" || column.property == "c7" || column.property == "c8" || column.property == "c9") {
        sums[index] = sums[index].toFixed(2);
        until = "万元";
        sums[index] += until;
      } else if (column.property == "dr1") {
        sums[index] = sums[index].toFixed(2);
        until = "万元";
        sums[index] += until;
      } else if (column.property == "dd" || column.property == "de" || column.property == "df") {
        until = "条";
        sums[index] += until;
      } else if (column.property == "dg" || column.property == "dh" || column.property == "di" || column.property == "dj" || column.property == "dk" || column.property == "dn") {
        until = "家";
        sums[index] += until;
      } else if (column.property == "dl" || column.property == "dm" || column.property== "du") {
        until = "个"
        sums[index] += until;
      } else if (column.property == "dr") {
        until = "人"
        sums[index] += until;
      } else if (column.property == "dw1" || column.property == "dw2" || column.property == "dw3" || column.property == "dw4" || column.property == "dw5" || column.property == "dw6" || column.property == "dw7" || column.property == "dw8" || column.property == "dw9") {
        until = "吨"
        sums[index] += until;
      }else if (column.property == "dx1" || column.property == "dx2" || column.property == "dx3" || column.property == "dx4" || column.property == "dx5" || column.property == "dx6" || column.property == "dx7" || column.property == "dx8" || column.property == "dx9") {
        until = "度"
        sums[index] += until;
      }else if (column.property == "dy1" || column.property == "dy2" || column.property == "dy3" || column.property == "dy4" || column.property == "dy5" || column.property == "dy6" || column.property == "dy7" || column.property == "dy8" || column.property == "dy9") {
        until = "万元"
        sums[index] += until;
      } else if (column.property == "dv"){
        sums[index] = " ";
      }
    } else {
      sums[index] = " ";
    }
  });
  return sums;
};
watch(() => needShow.value, () => {
  init()
})
const init = () => {
  getInfo().then(res => {
    if (res.code != 200) {
      ElMessage.error("出现了问题,请联系管理员处理")
    }
    userName.value = res.user.userName;
  });
  localStorage.setItem("sjtjzlKey", JSON.stringify(form.value ? form.value : initCheck))
  getData()
}
init();
</script>

<style scoped>
::v-deep .el-scrollbar__bar.is-horizontal{
  height: 10px;
  display: block !important;
  position: fixed !important;
  bottom: 6.3rem !important;
  left: 15rem !important;
}
::v-deep .el-scrollbar{
  position: relative;
}
::v-deep .el-scrollbar__bar.is-vertical{
  width: 10px;
}
::v-deep .el-table__footer{
  z-index: -1;
}
</style>