<template>
  <div class="main-content market search-result content m20">
    <div class="search-box">
      <el-row>
        <el-col :span="8">
          <div class="search-field">
            <p>统一码/注册号：</p>
            <el-input v-model.trim="searchForm.searchUscc" placeholder="统一社会信用代码/注册号" @keyup.enter.native="submitSearch" />
          </div>
        </el-col>
        <el-col :span="8">
          <div class="search-field">
            <p>企业名称(模糊)：</p>
            <el-input v-model.trim="searchForm.entName" style="width:100%" placeholder="企业名称" @keyup.enter.native="submitSearch" />
          </div>
        </el-col>
        <el-col v-if="!showMore" :span="8" style="text-align:center;">
          <span class="arrow" @click="showMore = !showMore"><i class="el-icon-arrow-down" />展开</span>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="submitSearch" :loading="loading">查询</el-button>
          <el-button type="info" icon="el-icon-refresh-left" size="mini" @click="resetForm">重置</el-button>
        </el-col>
        <el-col v-else :span="8">
          <div class="search-field">
            <p>企业名称(精准)：</p>
            <el-input v-model.trim="searchForm.entNameJQ" style="width:100%" placeholder="企业名称" @keyup.enter.native="submitSearch" />
          </div>
        </el-col>
      </el-row>
      <template v-if="showMore">
        <el-row>
          <el-col :span="8">
            <div class="search-field">
              <p>管理片区：
                <!--                包括下属片区：<el-checkbox v-model="searchForm.checked" />-->
              </p>
              <el-cascader
                v-model="searchForm.regulatory"
                :show-all-levels="false"
                size="mini"
                class="custom"
                style="width: 100%"
                :options="bustypeOptions"
                :props="{ checkStrictly: true }"
                clearable
                filterable
              />
            </div>
          </el-col>
          <el-col :span="8">
            <div class="search-field">
              <p>登记机关：</p>
              <el-cascader
                v-model="searchForm.regorg"
                :show-all-levels="false"
                size="mini"
                class="custom"
                style="width: 100%"
                :options="REGORGList"
                :props="{ checkStrictly: true }"
                clearable
                filterable
              />
              <!-- <el-select v-model="searchForm.regorg" style="width: 100%" filterable clearable size="mini" placeholder="请选择" class="custom">
                <el-option
                  v-for="item in REGORGList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select> -->
            </div>
          </el-col>
          <el-col :span="8">
            <div class="search-field">
              <p>法定代表人：</p>
              <el-input v-model.trim="searchForm.name" placeholder="法定代表人" @keyup.enter.native="submitSearch" />
            </div>
          </el-col>
          <el-col :span="8">
            <div class="search-field">
              <p>主体类型：</p>
              <el-select v-model="searchForm.enttype" style="width: 100%" clearable size="mini" placeholder="请选择" class="custom">
                <el-option
                  v-for="item in ENTTYPEList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </div>
          </el-col>
          <el-col :span="8">
            <div class="search-field">
              <p>主体状态(国标):</p>
              <el-select v-model="searchForm.regstate" style="width: 100%" clearable size="mini" placeholder="请选择" class="custom">
                <el-option
                  v-for="item in REGSTATEList"
                  :key="item.code"
                  :label="item.name"
                  :value="item.code"
                />
              </el-select>
            </div>
          </el-col>
          <el-col :span="8">
            <div class="search-field">
              <p>主体状态(市标):</p>
              <el-select v-model="searchForm.entStatus" style="width: 100%" clearable size="mini" placeholder="请选择" class="custom">
                <el-option
                  v-for="item in entStatusList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </div>
          </el-col>
<!--          <el-col :span="8">-->
<!--            <div class="search-field">-->
<!--              <p>行业类别：</p>-->
<!--              <el-select v-model="searchForm.industryphy" style="width: 100%" clearable size="mini" placeholder="请选择" class="custom">-->
<!--                <el-option-->
<!--                  v-for="item in INDUSTRYPHYList"-->
<!--                  :key="item.code"-->
<!--                  :label="item.name"-->
<!--                  :value="item.code"-->
<!--                />-->
<!--              </el-select>-->
<!--            </div>-->
<!--          </el-col>-->
          <!-- <el-col :span="8">
            <div class="search-field">
              <p>管理类别：</p>
              <el-select v-model="searchForm.manageType" style="width: 100%" clearable size="mini" placeholder="请选择" class="custom">
                <el-option
                  v-for="item in manageTypeList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </div>
          </el-col> -->

          <el-col :span="8">
            <div class="search-field">
              <p>经营地址：</p>
              <el-input v-model="searchForm.dom" style="width:100%" placeholder="经营地址" @keyup.enter.native="submitSearch" />
            </div>
          </el-col>
          <el-col :span="8">
            <div class="search-field">
              <p>经营范围：</p>
              <el-input v-model="searchForm.opscope" placeholder="经营范围" @keyup.enter.native="submitSearch" />
            </div>
          </el-col>
          <!-- <el-col :span="8">
            <div class="search-field">
              <p>实际经营项目：</p>
              <el-input v-model="searchForm.businessName" placeholder="实际经营项目" @keyup.enter.native="submitSearch" />
            </div>
          </el-col> -->
          <el-col :span="8">
            <div class="search-field">
              <p>成立日期：</p>
              <el-date-picker
                v-model="searchForm.establishDate"
                size="mini"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                style="width:100%"
              />
            </div>
          </el-col>
          <el-col :span="8">
            <div class="search-field">
              <p>核准日期：</p>
              <el-date-picker
                v-model="searchForm.apprDate"
                size="mini"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                style="width:100%"
              />
            </div>
          </el-col>
          <!-- <el-col :span="8">
            <div class="search-field">
              <p>注销日期：</p>
              <el-date-picker
                v-model="searchForm.changeDate"
                size="mini"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                style="width:100%"
              />
            </div>
          </el-col> -->
          <!-- <el-col :span="8">
            <div class="search-field">
              <p>变更日期：</p>
              <el-date-picker
                v-model="searchForm.changeDate"
                size="mini"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                style="width:100%"
              />
            </div>
          </el-col> -->
          <!-- <el-col :span="8">
            <div class="search-field">
              <p>检查人员：</p>
              <el-input v-model="searchForm.checkPeople" placeholder="检查人员" @keyup.enter.native="submitSearch" />
            </div>
          </el-col> -->
<!--          <el-col :span="8">-->
<!--            <div class="search-field">-->
<!--              <p>认领情况：</p>-->
<!--              <el-select v-model="searchForm.noClaim" style="width: 100%" clearable size="mini" placeholder="请选择" class="custom">-->
<!--                <el-option-->
<!--                  v-for="item in noClaimList"-->
<!--                  :key="item.value"-->
<!--                  :label="item.label"-->
<!--                  :value="item.value"-->
<!--                />-->
<!--              </el-select>-->
<!--            </div>-->
<!--          </el-col>-->
          <!-- <el-col :span="8">
            <div class="search-field">
              <p style="width: 220px;">实际经营项目备注：</p>
              <el-input v-model="searchForm.businessNameRemark" placeholder="实际经营项目备注" @keyup.enter.native="submitSearch" />
            </div>
          </el-col> -->
          <el-col :span="8">
            <div class="search-field">
              <p>风险监管级别：</p>
              <el-select v-model="searchForm.risklevel" style="width: 100%" clearable size="mini" placeholder="请选择" class="custom">
                <el-option
                  v-for="item in risklevelList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </div>
          </el-col>
<!--          <el-col :span="8">-->
<!--            <div class="search-field">-->
<!--              <p>监管检查结果：</p>-->
<!--              <el-select v-model="searchForm.checkRs" style="width: 100%" clearable size="mini" placeholder="请选择" class="custom">-->
<!--                <el-option-->
<!--                  v-for="item in checkRsList"-->
<!--                  :key="item.code"-->
<!--                  :label="item.name"-->
<!--                  :value="item.code"-->
<!--                />-->
<!--              </el-select>-->
<!--            </div>-->
<!--          </el-col>-->
          <!-- <el-col :span="8">
            <div class="search-field">
              <p>是否年检验照：</p>
              <el-select v-model="searchForm.isnjyz" style="width: 100%" clearable size="mini" placeholder="请选择" class="custom">
                <el-option
                  v-for="item in isnjyzList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </div>
          </el-col> -->
          <!-- <el-col :span="8">
            <div class="search-field">
              <p>是否无照经营：</p>
              <el-select v-model="searchForm.iswzjy" style="width: 100%" clearable size="mini" placeholder="请选择" class="custom">
                <el-option
                  v-for="item in iswzjyList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </div>
          </el-col> -->
          <!-- <el-col :span="8">
            <div class="search-field">
              <p>是否国家局执照：</p>
              <el-select v-model="searchForm.license" style="width: 100%" clearable size="mini" placeholder="请选择" class="custom">
                <el-option
                  v-for="item in licenseList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </div>
          </el-col> -->
          <!-- <el-col :span="8">
            <div class="search-field">
              <p>是否省局执照：</p>
              <el-select v-model="searchForm.license" style="width: 100%" clearable size="mini" placeholder="请选择" class="custom">
                <el-option
                  v-for="item in licenseList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </div>
          </el-col> -->
          <el-col :span="24">
            <div class="search-field">
              <p style="width: 130px">名单类型：</p>
              <el-radio v-model="searchForm.type" label="wnbSdcw" @change="bbb">未年报且通过登记住所无法联系的</el-radio>
              <el-radio v-model="searchForm.type" label="wnb2" @change="bbb">连续两年未年报</el-radio>
              <!-- <el-radio v-model="searchForm.type" label="wnb5">连续5年未年报</el-radio> -->
              <el-radio v-model="searchForm.type" label="abn" @change="bbb">因实地查无或通过登记住所无法联系被列异超过两年的</el-radio>
            </div>
          </el-col>
          <el-col v-if="tableFlag == true" :span="16">
            <div class="search-field">
              <p style="width: 130px">企业类型：</p>
              <el-radio v-model="searchForm.isGRDZ" label="GRDZ">个人独资企业</el-radio>
              <el-radio v-model="searchForm.isGRDZ" label="NOGRDZ">除个人独资企业外</el-radio>
            </div>
          </el-col>
        </el-row>

        <!-- 信用修复查询条件-->
        <el-row>
<!--          <el-col :span="8">-->
<!--            <div class="search-field">-->
<!--              <p>信用修复日期</p>-->
<!--              <el-date-picker-->
<!--                v-model="searchForm.searchRemDate"-->
<!--                size="mini"-->
<!--                value-format="yyyy-MM-dd"-->
<!--                type="daterange"-->
<!--                range-separator="至"-->
<!--                start-placeholder="开始日期"-->
<!--                end-placeholder="结束日期"-->
<!--                style="width:100%"-->
<!--              />-->
<!--            </div>-->
<!--          </el-col>-->
          <!-- 5.30 316-330添加  -->
          <el-col :span="8">
            <div class="search-field">
              <p>是否年报： </p>
              <el-select clearable v-model="searchForm.isnb">
                <el-option value="y" label="是"></el-option>
                <el-option value="n" label="否"></el-option>
              </el-select>
              <el-date-picker
                v-model="searchForm.nbyear"
                value-format="yyyy"
                type="year"
                placeholder="选择年">
              </el-date-picker>
              <!--              <div v-if="showReportYear">-->
              <!--                <el-select v-model="searchForm.yearReport"  size="small"  >-->
              <!--                  <el-option v-for="(item,i) in searchForm.years" :key="i" :label="item.label" :value="item.value" />-->
              <!--                </el-select>-->
              <!--              </div>-->
            </div>
          </el-col>
          <el-col :span="8">
            <div class="search-field">
              <p>是否经营异常： </p>
              <el-select clearable v-model="searchForm.isabn">
                <el-option value="1" label="是"></el-option>
                <el-option value="0" label="否"></el-option>
              </el-select>
            </div>
          </el-col>
        </el-row>
      </template>
    </div>
    <div v-if="showMore" class="func-box">
      <div class="btn-box">
        <span v-if="showMore" class="arrow" @click="showMore = !showMore"><i class="el-icon-arrow-up" />隐藏</span>
        <span v-if="!showMore" class="arrow" @click="showMore = !showMore"><i class="el-icon-arrow-down" />展开</span>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="submitSearch"  :loading="loading">查询</el-button>
        <el-button type="info" icon="el-icon-refresh-left" size="mini" @click="resetForm">重置</el-button>
      </div>
    </div>
    <el-table
      v-loading="loading"
      :data="tableData"
      :row-class-name="tableRowClassName"
      :header-cell-style="{background:'#8cc3fb',color:'#fff'}"
      @row-click="rowClick"
    >
      <el-table-column label="序号" prop="index" min-width="50" />
      <el-table-column label="统一社会信用代码/注册号" min-width="100" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.uniscid && scope.row.uniscid.length > 0 ? scope.row.uniscid: scope.row.regno }}
        </template>
      </el-table-column>
      <el-table-column label="主体名称" prop="entname" min-width="120" show-overflow-tooltip />
      <el-table-column label="法定代表人/负责人" prop="name" show-overflow-tooltip />
      <el-table-column label="经营地址" prop="dom" show-overflow-tooltip />
      <el-table-column label="企业类型" prop="enttypeCn" show-overflow-tooltip />
      <!-- <el-table-column label="经营期限" prop="opto" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.opto ? scope.row.opto: '长期' }}
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="信用等级" /> -->
      <el-table-column label="风险等级" prop="level" min-width="60" show-overflow-tooltip />
    </el-table>
    <div class="page-box">
      <el-row>
        <el-col :span="6">
          <el-button type="primary" @click="$router.back()">返回</el-button>
          <el-button v-if="this.$util.isNotEmpty(searchType) && searchType !== undefined" :disabled="tableData.length == 0" type="primary" @click="revokeEntListExport">导出Excel</el-button>
          <el-button v-else type="primary" @click="openDialog">导出Excel</el-button>
        </el-col>
        <el-col :span="18" style="text-align:right">
          <el-pagination
            :disabled="loading"
            :page-size="pageParam.pageSize"
            :total="pageParam.total"
            :page-sizes="[10, 20, 30, 40,50,100,200]"
            :current-page="pageParam.curPage"
            layout="slot,total, sizes, prev, pager, next, jumper"
            @size-change="pageSizeChange"
            @current-change="pageIndexChange"
          >
            <!-- <batchFunction :options="options" style="float:left" /> -->
            <span>
              第 {{ pageParam.curPage }} 页 /
              共 {{ (pageParam.total !== 0 ? parseInt((pageParam.total + pageParam.pageSize - 1)/pageParam.pageSize) : 1) }} 页
            </span>
          </el-pagination>
        </el-col>
      </el-row>
    </div>
    <el-dialog title="请选择需要导出的字段" :visible.sync="isExport" width="90%">
      <el-checkbox v-model="checkAll" :indeterminate="isIndeterminate" @change="handleCheckAllChange">全选</el-checkbox>
      <el-checkbox-group v-model="checkedfields" @change="handleCheckedCitiesChange">
        <el-checkbox v-for="each in fields" :key="each" style="margin: 15px;" :label="each">{{ each }}</el-checkbox>
      </el-checkbox-group>
      <el-button v-loading="exportLoading" type="primary" @click="exportData">确认导出</el-button>
    </el-dialog>
  </div>
</template>

<script>
import { getBaseCodeList } from '@/api/constant'
import { getConstant, getOrgTreeList, getSliceTreeList } from '@/api/system'
import { comprehensiveQuery, revokeEntListExport, exportInfo, checkExportNum } from '@/api/entBase'
export default {
  data() {
    return {
      value: '',
      exportLoading: false,
      isIndeterminate: false,
      checkAll: false,
      checkedfields: [],
      fields: ['统一社会信用代码', '主体名称', '注册号', '市场主体类型', '成立日期', '登记机关', '登记状态', '住所', '经营范围', '法人名称',
        '属地监管所', '联络人', '联络人电话', '最新年报申报时间', '资产总营业', '营业收入', '利润总额', '净利润',
        '是否列严', '是否列异', '是否地址列异', '是否年报', '注册资金', '信用风险等级','主营项目类别'],
      isExport: false,
      // 搜索条件
      showMore: false,
      bustypeOptions: [],
      searchForm: {
        specause: '',
        searchDate: '',
        checked: '',
        regulatory: '',
        searchUscc: '',
        entName: '',
        entNameJQ: '',
        dom: '',
        name: '',
        checkPeople: '',
        opscope: '',
        businessName: '',
        businessNameRemark: '',
        industryphy: '',
        regorg: '',
        manageType: '',
        isnjyz: '',
        noClaim: '',
        risklevel: '',
        checkRs: '',
        establishDate: '',
        apprDate: '',
        changeDate: '',
        enttype: '',
        regstate: '',
        entStatus: '',
        license: '',
        iswzjy: '',
        type: '',
        searchRemDate: '',
        nbyear: '',
        isnb: '',
        isabn: ''
      },
      INDUSTRYPHYList: [],
      regOrgOptions: [],
      REGORGList: [],
      reasonList: [],
      manageTypeList: [],
      isnjyzList: [{
        value: '0',
        label: '否'
      }, {
        value: '1',
        label: '是'
      }],
      noClaimList: [{
        value: '0',
        label: '未认领'
      }, {
        value: '1',
        label: '已认领'
      }],
      risklevelList: [{
        value: '高风险',
        label: '高风险'
      }, {
        value: '较高风险',
        label: '较高风险'
      }, {
        value: '中风险',
        label: '中风险'
      }, {
        value: '低风险',
        label: '低风险'
      }],
      checkRsList: [],
      ENTTYPEList: [{
        value: 'individual',
        label: '个体工商户'
      }, {
        value: 'farmer',
        label: '农民专业合作社'
      }, {
        value: 'company',
        label: '企业'
      }],
      REGSTATEList: [],
      licenseList: [{
        value: '0',
        label: '否'
      }, {
        value: '1',
        label: '是'
      }],
      iswzjyList: [{
        value: '0',
        label: '否'
      }, {
        value: '1',
        label: '是'
      }],
      // 搜索结果
      tableData: [],
      pageParam: {
        curPage: 1,
        pageSize: 10,
        total: 0,
        customParamMap: {}
      },
      loading: false,
      searchType: '',
      tableFlag: false,
      exportQueryData: {}, // 导出excel的查询条件, 用于导出excel, 每轮查询成功后赋值
      entStatusList: []
    }
  },
  mounted() {
    // this.getYear()
    this.getCache()
    // this.pageParam.customParamMap = {
    //   ...this.$route.query
    // }
    // if (this.$route.query.type) {
    //   this.searchForm.type = this.$route.query.type
    // }
    if (this.$route.query.pripid) {
      var pid = this.$route.query.pripid
      var shrink = this.$route.query.shrink
      this.$router.push({
        path: '/comprehensive/details', query: { pripid: pid, shrink: shrink } // 少带了shrink参数
      })
    }
    getSliceTreeList().then(res => {
      if (res.code === 0) {
        this.bustypeOptions = res.data
      }
    })
    getOrgTreeList().then(res => {
      if (res.code === 0) {
        // this.REGORGList= res.data
        this.REGORGList.push({
          id: '001019001',
          label: '广州市市场监督管理局',
          value: '440101',
          children: res.data
        })
      }
    })
    // 获取登记机关
    // getRegOrgList().then(res => {
    //   if (res.code === 0) {
    //     this.REGORGList = res.data
    //   }
    // })
    // getDataType('registration').then(res => {
    //   if (res.code === 0) {
    //     this.REGORGList = res.data
    //   }
    // })
    // 获取行业门类
    getBaseCodeList('CA05').then(res => {
      if (res.code === 0) {
        this.INDUSTRYPHYList = res.data
      }
    })
    // 监管检查结果
    getBaseCodeList('CD29').then(res => {
      if (res.code === 0) {
        this.checkRsList = res.data
      }
    })
    // 监管业务状态
    getBaseCodeList('CA19').then(res => {
      if (res.code === 0) {
        this.REGSTATEList = res.data
      }
    })
    this.entStatusList=this.$util.getEntstatusList();
    // 获取列异原因
    this.getDifferList()

    this.pageParam.customParamMap = this.$route.query
    // this.searchType = this.pageParam.customParamMap.type
    // this.isGRDZ = this.pageParam.customParamMap.isGRDZ
    // this.submitSearch()
  },
  methods: {
    bbb() {
      if (this.searchForm.type != '') {
        this.tableFlag = true
      }
    },
    getCache() {
      const pageParam = sessionStorage.getItem('pageParam-ztcx')
      const tableData = sessionStorage.getItem('tableData-ztcx')
      if (pageParam) {
        this.pageParam = JSON.parse(pageParam)
        this.searchForm = this.pageParam.customParamMap
      }
      if (tableData) {
        this.tableData = JSON.parse(tableData)
      }
    },
    // getYear() {
    //   var y = new Date().getFullYear()
    //   for (let i = 0; i <= 5; i++) {
    //     if (i < 5) {
    //       this.searchForm.years.unshift({ value: (y - i), label: (y - i) })
    //     } else {
    //       for (let i = 1; i < 6; i++) {
    //         this.searchForm.years.push({ value: (y + i), label: (y + i) })
    //       }
    //     }
    //   }
    // },
    download2(data, fileName) {
      if (!data) {
        return
      }
      const url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel;charset=utf-8' }))
      // window.open(url)
      const link = document.createElement('a')
      link.style.display = 'none'
      link.href = url
      link.setAttribute('download', fileName)
      // document.body.appendChild(link)
      link.click()
    },
    exportData() {
      // if (this.checkedfields.length === 0) return this.$message.warning('导出的列不能为空')
      // const pripids = []
      // this.tableData.forEach(each => {
      //   pripids.push(each.pripid)
      // })
      this.exportLoading = true
      //this.searchForm.filedList = this.checkedfields
      // this.pageParam.customParamMap = this.searchForm
      // this.searchType = this.pageParam.customParamMap.type
      // this.isGRDZ = this.pageParam.customParamMap.isGRDZ
      // if (this.$util.isNotEmpty(this.searchType)) {
      //   if (this.$util.isEmpty(this.isGRDZ)) {
      //     this.loading = false
      //     return this.$message.warning('请选择企业类型')
      //   }
      // }
      // if (this.$util.isNotEmpty(this.isGRDZ)) {
      //   if (this.$util.isEmpty(this.searchType)) {
      //     this.loading = false
      //     return this.$message.warning('请选择名单类型')
      //   }
      // }
      // if (!this.showReportYear) {
      //   this.searchForm.yearReport = ''
      // }
      const data = JSON.parse(JSON.stringify(this.exportQueryData))
      data.customParamMap.filedList = this.checkedfields
      checkExportNum(data).then(res => {
        const num = res.data
        if (num > 50000) {
          this.exportLoading = false
          return this.$message.warning('导出数量不能大于5万')
        } else {
          exportInfo(data).then(res => {
            this.exportLoading = false
            this.download2(res, '主体名单.xlsx')
          }).catch(req => {
            this.exportLoading = false
          })
        }
      })
    },
    openDialog() {
      if (this.tableData.length === 0) {
        return this.$message.warning('没有可导出的数据')
      }
      this.isExport = true
    },
    handleCheckAllChange(val) {
      this.checkedfields = val ? this.fields : []
      this.isIndeterminate = false
    },
    handleCheckedCitiesChange(value) {
      const checkedCount = value.length
      this.checkAll = checkedCount === this.fields.length
      this.isIndeterminate = checkedCount > 0 && checkedCount < this.fields.length
    },
    // 批吊相关条件类型企业清单导出
    revokeEntListExport() {
      if (this.searchType === 'wnb2') {
        this.openDialog()
      } else {
        this.$confirm('是否确认导出', '提示', {
          closeOnClickModal: false,
          showClose: false,
          beforeClose: (action, instance, done) => {
            if (action === 'confirm') {
              const data = JSON.parse(JSON.stringify(this.exportQueryData))
              instance.confirmButtonLoading = true
              instance.confirmButtonText = '正在导出，请稍后。'
              revokeEntListExport(data).then((res) => {
                if (instance.confirmButtonLoading) {
                  const { data, headers } = res
                  let filename = '查询结果.xlsx'
                  try {
                    filename = decodeURIComponent(headers['content-disposition'].match(/filename=(.*?)$/)[1])
                  } catch (e) {
                    console.log(e)
                  }
                  const element = document.createElement('a')
                  element.href = URL.createObjectURL(data)
                  element.download = filename
                  element.target = '_blank'
                  element.click()
                  done()
                }
              }).finally(() => {
                instance.confirmButtonText = '确认'
                instance.confirmButtonLoading = false
              })
            } else if (action === 'cancel') {
              instance.confirmButtonLoading = false
              done()
            }
          }
        })
      }
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 === 1) {
        return 'warning-row'
      }
    },
    rowClick(row, column, event) {
      this.$router.push({ path: '/comprehensive/details', query: { pripid: row.pripid }})
      // const { href } = this.$router.resolve({ path: '/market/search/result/detail', query: { pripid: row.pripid }})
      // window.open(href)
    },
    // 当前分页改变
    pageIndexChange(curPage) {
      this.pageParam.curPage = curPage
      this.loadPage()
    },
    // 分页大小改变
    pageSizeChange(pageSize) {
      this.pageParam.pageSize = pageSize
      this.loadPage()
    },
    submitSearch() {
      this.exportQueryData = null
      this.pageParam.curPage = 1
      this.loadPage()
    },
    // 加载分页
    loadPage() {

      if (this.loading) return
      let data = {}
      if(this.exportQueryData != null && Object.keys(this.exportQueryData).length != 0){   //是否存在查询参数
        this.exportQueryData.curPage = this.pageParam.curPage
        this.exportQueryData.pageSize = this.pageParam.pageSize
        data = JSON.parse(JSON.stringify(this.exportQueryData))
      }else{
        this.pageParam.customParamMap = this.searchForm
        this.searchType = this.pageParam.customParamMap.type
        this.isGRDZ = this.pageParam.customParamMap.isGRDZ
        if (this.$util.isNotEmpty(this.searchForm.isnb)) {
          if (this.$util.isEmpty(this.searchForm.nbyear)) {
            this.loading = false
            return this.$message.warning('请选择年报年份')
          }
        }
        if (this.$util.isNotEmpty(this.searchType)) {
          if (this.$util.isEmpty(this.isGRDZ)) {
            this.loading = false
            return this.$message.warning('请选择企业类型')
          }
        }
        if (this.$util.isNotEmpty(this.isGRDZ)) {
          if (this.$util.isEmpty(this.searchType)) {
            this.loading = false
            return this.$message.warning('请选择名单类型')
          }
        }
        if (!this.showReportYear) {
          this.searchForm.yearReport = ''
        }
        data = JSON.parse(JSON.stringify(this.pageParam))
      }
      // 判断是否填写了条件
      let flag = false
      // obj的遍历
      Object.keys(data.customParamMap).forEach(key => {
        if (key === 'regorg' || key === 'regulatory') {
          if (data.customParamMap[key].length > 0) {
            flag = true
          }
        } else {
          if (data.customParamMap[key] !== '' && data.customParamMap[key] !== null) {
            flag = true
          }
        }
      })
      if (!flag) {
        this.$message({
          message: '请至少填写一个查询条件！',
          type: 'warning'
        })
        return
      }
      this.loading = true
      comprehensiveQuery(data).then(res => {
        this.loading = false
        this.exportQueryData = JSON.parse(JSON.stringify(data))
        if (res.code === 0) {
          const data = res.data
          const list = []
          let index = (this.pageParam.curPage - 1) * this.pageParam.pageSize
          data.records.forEach(each => {
            each.index = ++index
            list.push(each)
          })
          this.tableData = list
          this.pageParam.total = data.total
          //this.pageParam.curPage = 1
          sessionStorage.setItem('pageParam-ztcx', JSON.stringify(this.pageParam))
          sessionStorage.setItem('tableData-ztcx', JSON.stringify(this.tableData))
        }
      })
    },
    getDifferList() {
      getConstant('CD71').then(res => {
        if (res.code === 0) {
          const list = []
          res.data.forEach(each => {
            list.push({
              value: each.code,
              label: each.name
            })
          })
          this.reasonList = list
        }
      })
    },

    resetForm() {
      this.tableFlag = false
      for (const key in this.searchForm) {
        this.$set(this.searchForm, key, '')
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.content{
  background: #fff;
  .el-table .warning-row {
    background: #eaf4fe!important;
  }
}
/* 搜索条件 */
  .main-content{
    >div:not(:first-child){
      margin-top:16px;
    }
    .search-box{
      padding:10px 0;
      .search-field{
        display:flex;
        width:100%;
        >p{
          margin:3px 16px 10px 0;
          font-family: Microsoft YaHei, Microsoft YaHei-Bold;
          color: #666;
          font-size:16PX;
          width:200px;
          text-align: right;
        }
      }
      .el-col{
        margin-bottom:15px;
      }
    }
    .btn-box{
      text-align:right;
    }
    .main-body{
      padding:16px 0;
      border-top: 1px dashed #70AEFF;
      .header{
        .header-label{
          font-size: 20PX;
          font-family: Microsoft YaHei, Microsoft YaHei-Bold;
          font-weight: bold;
          color: #243668;
          line-height: 32px;
        }
      }
    }
  }
  /deep/.el-input__inner{
    height: 28px;
  }
  /deep/.el-input__icon{
    line-height: 28px;
  }
  .arrow{
    color: #3296FA;
    cursor: pointer;
    margin-right: 16px;
  }
  .market.search-result{
    .el-table__row{
      cursor: pointer;
    }
  }
</style>
