<template>
  <div class="main-content m20">
    <!--头部-查询-->
    <div class="content-header">
      <searchHeader title="查询" />
      <div class="body search-body">
        <el-row style="margin-bottom:10px">
          <el-col :span="12">
            <label class="label-name" style="width: 220px">统一社会信用代码/注册号：</label>
            <div class="search-input-box" style="width: calc(100% - 220px)">
              <el-input v-model="searchForm.searchUscc" clearable size="mini" type="text" class="search-input" placeholder="请输入统一社会信用代码/注册号" @keyup.enter.native="search" />
            </div>
          </el-col>
          <el-col :span="12">
            <label class="label-name">主体名称（模糊）：</label>
            <div class="search-input-box">
              <el-input v-model="searchForm.searchName" clearable size="mini" type="text" class="search-input" placeholder="请输入主体名称（模糊）" @keyup.enter.native="search" />
            </div>
          </el-col>
        </el-row>
        <el-row style="margin-bottom:10px">
          <el-col :span="12">
            <label class="label-name">列入原因：</label>
            <el-select v-model="searchForm.includeType" style="width: calc(100% - 220px)" clearable size="mini" placeholder="请选择列入原因">
              <el-option
                v-for="item in reasonList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-col>
          <el-col :span="12">
            <label class="label-name" style="width: 220px">监管录入人员：</label>
            <div class="search-input-box" style="width: calc(100% - 220px)">
              <el-input v-model="searchForm.regEntryUserName" clearable size="mini" type="text" class="search-input" placeholder="请输入监管录入人员姓名" @keyup.enter.native="search" />
            </div>
          </el-col>
          <!--          <el-col :span="12">-->
          <!--            <label class="label-name">管辖机关：</label>-->
          <!--            <el-cascader-->
          <!--              v-model="searchForm.regulatory"-->
          <!--              size="mini"-->
          <!--              style="width: calc(100% - 220px)"-->
          <!--              class="custom"-->
          <!--              :options="bustypeOptions"-->
          <!--              :props="{ checkStrictly: true }"-->
          <!--              clearable-->
          <!--              filterable-->
          <!--            />-->
          <!--          </el-col>-->
        </el-row>
        <!-- <el-row v-if="showMore" style="margin-bottom:10px">
          <el-col :span="12">
            <label class="label-name" style="width: 220px">经营地址：</label>
            <div class="search-input-box" style="width: calc(100% - 220px)">
              <el-input v-model="searchForm.searchDom" clearable size="mini" type="text" class="search-input" placeholder="请输入经营地址" @keyup.enter.native="search" />
            </div>
          </el-col>

        </el-row> -->
        <el-row>
          <!--          <el-col :span="12">-->
          <!--            <label class="label-name">未报年报年度：</label>-->
          <!--            <el-select v-model="searchForm.reportYear" style="width: calc(100% - 220px)" filterable clearable size="mini" @blur="selectBlur">-->
          <!--              <el-option-->
          <!--                v-for="item in reportYearList"-->
          <!--                :key="item.value"-->
          <!--                :label="item.label"-->
          <!--                :value="item.value"-->
          <!--              />-->
          <!--            </el-select>-->
          <!--          </el-col>-->
          <el-col :span="6" :offset="1">
            <div class="btn-box" style="font-size: 14px;width: 600px">
              <!-- <span v-if="!showMore" style="margin-right:20px;color:#409EFF;cursor:pointer" @click="showMoreCriteria">
                展开<i class="el-icon-d-arrow-right" />
              </span>
              <span v-if="showMore" style="margin-right:20px;color:#409EFF;cursor:pointer" @click="showMoreCriteria">
                <i class="el-icon-d-arrow-left" />隐藏
              </span> -->
              <el-button type="primary" size="mini" @click="search">查询</el-button>
              <el-button size="mini" @click="resetSearchForm" style="margin-right: 10px">重置</el-button>
              <el-radio v-model="searchForm.searchtype" label="1">查线索</el-radio>
              <el-radio v-model="searchForm.searchtype" label="2">查主体</el-radio>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
    <!--body-查询结果-->
    <div class="content-body">
      <el-row class="bl0" style="margin-bottom: 10px">
        <el-col :span="6">
          <el-button style="margin-left: 50px" size="mini" type="primary" @click="templateDialog = true">未年报批量列异</el-button>
        </el-col>
      </el-row>
      <div class="body">
        <el-table
          ref="multipleTable"
          v-loading="loading"
          :data="tableData"
          tooltip-effect="dark"
          style="width: 95%;padding: 0;margin:0 auto"
          :fit="true"
          :row-class-name="tableRowClassName"
          :header-cell-style="{background:'#8cc3fb',color:'#fff'}"
        >
          <!-- <el-table-column class="no" type="selection" width="30" /> -->
          <el-table-column prop="index" label="序号" min-width="50" align="center" />
          <el-table-column prop="uscc" label="统一社会信用代码/注册号" min-width="150" align="left" />
          <el-table-column prop="entname" :show-overflow-tooltip="true" label="主体名称" min-width="150" align="left" />
          <el-table-column prop="name" :show-overflow-tooltip="true" label="法定代表人" min-width="80" align="left" />
          <el-table-column prop="oploc" :show-overflow-tooltip="true" label="经营地址" min-width="150" align="left" />
          <el-table-column prop="regorgCn" :show-overflow-tooltip="true" label="登记机关" min-width="150" align="left" />
          <el-table-column prop="suporgCn" label="属地监管机关" min-width="150" align="left" />
          <el-table-column prop="acceptregorgCn" :show-overflow-tooltip="true" label="受理机关" min-width="150" align="left" />
          <!-- <el-table-column prop="entname" :show-overflow-tooltip="true" label="主体名称" min-width="120" align="left" /> -->
          <!-- <el-table-column prop="annCheDeptCn" label="属地监管机关" min-width="150" align="left" /> -->
          <!-- <el-table-column prop="oploc" :show-overflow-tooltip="true" label="经营地址" min-width="150" align="left" /> -->
          <!--          <el-table-column prop="enttypeCn" :show-overflow-tooltip="true" label="主体类型" min-width="100" align="left" />-->
          <!-- <el-table-column prop="name" label="法定代表人" min-width="80" align="left" /> -->
          <!-- <el-table-column prop="estdate" label="成立日期" min-width="100" align="left" /> -->
          <!-- <el-table-column prop="regulatoryName" :show-overflow-tooltip="true" label="管辖机关" min-width="100" align="left" /> -->
          <el-table-column prop="includeType" :show-overflow-tooltip="true" label="列入原因" min-width="100" align="left" :formatter="reasonFormatter" />
          <!-- <el-table-column v-if="showReprtYear" prop="reportYear" :show-overflow-tooltip="true" label="未年报年度" min-width="90" align="center" /> -->
          <el-table-column v-if="showRegEntryUserName" prop="regEntryUserName" :show-overflow-tooltip="true" label="监管录入人员" min-width="90" align="center" />
          <el-table-column label="操作" min-width="100" align="center">
            <template slot-scope="scope">
              <el-button type="primary" v-if="searchtype === '1'" :loading="scope.row.loading" size="mini" @click="startTask(scope.row.toIncludeId, 'CLUE',scope.row)">办理</el-button>
              <el-button type="primary" v-else :loading="scope.row.loading" size="mini" @click="startTaskIvd(scope.row.pripid,scope.row)">个案办理</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="page-box">
          <el-row class="bl0">
            <el-col :span="6">
              <!-- <el-button size="mini" @click="selectAll">全选</el-button>
              <el-button size="mini" @click="$util.toggleSelect($refs.multipleTable)">反选</el-button> -->
              <!-- <el-button size="mini" type="primary" @click="templateDialog1 = true">办理</el-button> -->
              <!-- <el-button size="mini" type="primary" @click="$message.info('该业务已经停止办理')">办理</el-button> -->
<!--              <el-button style="margin-left: 50px" size="mini" type="primary" @click="templateDialog = true">未年报批量列异</el-button>-->
<!--              <el-button type="primary" size="mini" @click="openAddressAbnDialog">地址批量列异</el-button>-->
            </el-col>
            <el-col :span="18">
              <el-pagination
                :disabled="loading"
                :page-size="pageParam.pageSize"
                :total="pageParam.total"
                :page-sizes="[10, 20, 30, 40,50,100,200]"
                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>
        <!--分页多选组件-->
        <!-- <pageSelector :selection="selection" :columns="selectionColumn" @removeCallback="removeCallback" /> -->
      </div>
    </div>
    <el-dialog
      title="Excel导入"
      :visible.sync="templateDialog"
      width="30%"
    >
      <!--      <span>模板下载</span>-->
      <el-link
        style="font-size: medium"
        type="primary"
        @click="downLoadTemp"
      >下载模板</el-link>
      <!--      <span>模板上传</span>-->
      <el-upload
        :action="uploadPath"
        :data="{type:'individual'}"
        :on-success="uploadCallback"
        :on-error="errorCallback"
        :before-upload="beforeUpload"
        accept=".xls,.xlsx"
        multiple
        :file-list="fileList"
        class="templateUpload"
        :show-file-list="false"
      >
        <el-link
          style="font-size: medium;margin-top: 10px"
          type="primary"
        >上传文件</el-link>
      </el-upload>
      <FakeProgress v-if="showFakeProgress" ref="FakeProgress" style="margin-top: 10px;" />
<!--      <el-row class="addRadio" style="margin-top: 15px">-->
<!--        <el-radio v-model="importType" label="address">地址批量列异</el-radio>-->
<!--      </el-row>-->
      <span slot="footer" class="dialog-footer">
        <el-button @click="templateDialog = false">取 消</el-button>
      </span>
    </el-dialog>
    <el-dialog
      title="提示"
      :visible.sync="templateDialog1"
      width="30%"
    >
      <span class="prompt">请确认已选{{ selection.length }}家企业，将发起列异流程</span>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" :loading="nextLoading" @click="startTask">确定</el-button>
        <el-button @click="templateDialog1 = false">取 消</el-button>
      </span>
    </el-dialog>
    <el-dialog
      title="地址批量列异"
      :visible.sync="addressAbnDialog"
      width="90%"
    >
      <el-row style="margin-bottom:10px">
        <el-col :span="12">
          <label style="text-align: right; display: inline-block; width:110px;">属地监管机关：</label>
          <el-cascader
            v-model="searchForm2.suporgs"
            size="mini"
            :show-all-levels="false"
            style="width: calc(100% - 220px)"
            class="custom"
            :options="orgOptions"
            :props="{ multiple: true, checkStrictly: true }"
            clearable
            filterable
          />
        </el-col>

        <el-col :span="12">
          <label style="text-align: right; display: inline-block; width:110px;">经营地址：</label>
          <div style="display: inline-block;width: calc(100% - 220px);">
            <el-input v-model="searchForm2.dom" clearable size="mini" class="search-input" type="text" placeholder="请输入经营地址" />
          </div>
        </el-col>
      </el-row>
      <el-row style="margin-bottom:10px">
        <el-col :span="12">
          <label style="text-align: right; display: inline-block; width:110px;">登记机关：</label>
          <el-cascader
            ref="DJJG"
            v-model="searchForm2.regorgs"
            size="mini"
            :show-all-levels="false"
            style="width: calc(100% - 220px)"
            class="custom"
            :options="orgOptions"
            :props="{ multiple: true, checkStrictly: true }"
            clearable
            filterable
          />
        </el-col>
        <el-col :span="12">
          <label style="text-align: right; display: inline-block; width:110px;">是否精确查询：</label>
          <el-radio v-model="searchForm2.addressSearchType" label="like">模糊</el-radio>
          <el-radio v-model="searchForm2.addressSearchType" label="eq">精确</el-radio>
        </el-col>
      </el-row>
      <el-row style="margin-bottom:10px">
        <el-col :span="12">
          <label style="text-align: right; display: inline-block; width:110px;">受理机关：</label>
          <el-cascader
            v-model="searchForm2.acceptRegorgs"
            size="mini"
            :show-all-levels="false"
            style="width: calc(100% - 220px)"
            class="custom"
            :options="orgOptions"
            :props="{ multiple: true, checkStrictly: true }"
            clearable
            filterable
          />
        </el-col>
        <el-col :span="8" :offset="4" style="text-align: right;">
          <el-button
            size="mini"
            style="margin-left: 10px;"
            type="primary"
            icon="el-icon-search"
            :loading="nextLoading"
            @click="addressBatchSearch"
          >查询</el-button>
          <el-button
            size="mini"
            style="margin-left: 10px;"
            @click="resetSearchForm2"
          >重置</el-button>
        </el-col>
      </el-row>
      <el-table
        ref="addressEntList"
        v-loading="nextLoading"
        :header-cell-style="{background:'#8cc3fb',color:'#fff'}"
        :row-class-name="tableRowClassName"
        :data="addressEntList"
        tooltip-effect="dark"
        style="width: 100%;padding: 0;margin:0 auto"
        :fit="true"
        @selection-change="handleSelectionChange"
      >
        <el-table-column class="no" type="selection" min-width="30" align="center" />
        <el-table-column prop="index" label="序号" min-width="40" align="center" />
        <el-table-column prop="uscc" label="统一社会信用代码/注册号" min-width="150" align="left" />
        <el-table-column prop="entname" :show-overflow-tooltip="true" label="主体名称" min-width="150" align="left" />
        <el-table-column prop="lerep" :show-overflow-tooltip="true" label="法定代表人" min-width="80" align="left" />
        <el-table-column prop="oploc" :show-overflow-tooltip="true" label="经营地址" min-width="150" align="left" />
        <el-table-column prop="regorgCn" :show-overflow-tooltip="true" label="登记机关" min-width="150" align="left" />
        <el-table-column prop="suporgCn" label="属地监管机关" min-width="150" align="left" />
        <el-table-column prop="acceptregorgCn" :show-overflow-tooltip="true" label="受理机关" min-width="150" align="left" />
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-row class="bl0">
          <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12" style="text-align: left">
            <el-button size="mini" @click="selectAll2">全选</el-button>
            <el-button size="mini" @click="$util.toggleSelect($refs.addressEntList)">反选</el-button>
            <el-button size="mini" type="primary" @click="startTaskAddress">办理</el-button>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
            <el-pagination
              :disabled="nextLoading"
              :page-size="pageParam2.pageSize"
              :total="pageParam2.total"
              :page-sizes="[10, 20, 30, 40,50,100,200]"
              layout="slot,total, sizes, prev, pager, next, jumper"
              @size-change="pageSizeChange2"
              @current-change="pageIndexChange2"
            >
              <span>
                第 {{ pageParam2.curPage }} 页 /
                共 {{ (pageParam2.total !== 0 ? parseInt((pageParam2.total + pageParam2.pageSize - 1)/pageParam2.pageSize) : 1) }} 页
              </span>
            </el-pagination>
          </el-col>
        </el-row>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import searchHeader from '@/components/searchHeader'
import pageSelector from '@/components/PageSelector'
import { commonPage } from '@/api/company'
import { saveAbnormalAccept, getRegulatory, validateBiz, saveBatchAbnListAccept, saveBatchAbnListAcceptByNB, removeClue, saveIvdAccept, saveAcceptBatch } from '@/api/abnormal'
import { getConstant, getOrgTreeList } from '@/api/system'
import { getBasePage } from '@/api/entBase'
import FakeProgress from '@/components/FakeProgress'
export default {
  components: {
    pageSelector: pageSelector,
    searchHeader,
    FakeProgress
  },
  data() {
    return {
      showFakeProgress: false,
      importType: 'address',
      addressEntList: [],
      addressSearchType: '',
      addressAbnDialog: false,
      fileList: [],
      orgOptions: [],
      bustypeOptions: [],
      templateDialog1: false,
      templateDialog: false,
      showMore: false,
      uploadPath: `${process.env.VUE_APP_BASE_API}/bizSpeList/fileParamExplainByNB`,
      reportYearList: [{
        value: '2020',
        label: '当前年度'
      }, {
        value: '2020,2019',
        label: '连续两年未报年报'
      }, {
        value: '2020,2019,2018',
        label: '连续三年未报年报'
      }],
      reasonList: [{
        value: '1',
        label: '个体工商户未按照《个体工商户年度报告办法》规定报送年度报告的'
      }, {
        value: '3',
        label: '个体工商户年度报告隐瞒真实情况、弄虚作假的'
      }, {
        value: '4',
        label: '工商行政管理部门在依法履职过程中通过登记的经营场所及经营者住所无法与个体工商户取得联系的'
      }],
      selection: [],
      selectionColumn: [{ label: '序号', type: 'index', minWidth: '30px' }, { label: '统一社会信用代码/注册号', prop: 'uscc', minWidth: '100px' }, { label: '主体主体名称', prop: 'entname', minWidth: '100px' }, { label: '法定代表人', prop: 'name', minWidth: '50px' }],
      searchtype: '',
      searchForm: {
        searchtype: '1',
        entertype: 'individual',
        regulatory: ''
      },
      searchForm2: {
        entertype: 'individual',
        addressSearchType: 'like'
      },
      pageParam2: {
        customParamMap: { entertype: 'individual' },
        curPage: 1,
        total: 0,
        pageSize: 10
      },
      loading: false,
      showFixed: false,
      tableData: [],
      pageParam: {
        customParamMap: { entertype: 'individual' },
        curPage: 1,
        total: 0,
        pageSize: 10
      },
      reasonOptions: [],
      showRegEntryUserName: false,
      nextLoading: false
    }
  },
  computed: {
    fixedHeader() {
      return this.$store.state.settings.fixedHeader
    }
  },
  mounted() {
    this.getbustypeOptions()
    this.getOrgOptions()
    // this.loadPage()
    window.addEventListener('scroll', this.handleScroll, true)

    // 个体工商户标记经营异常状态原因
    getConstant('CD75').then(res => {
      if (res.code === 0) {
        const list = []
        res.data.forEach(each => {
          list.push({
            value: each.code,
            label: each.name
          })
        })
        this.reasonOptions = list
      }
    })
    this.search()
  },
  methods: {
    // 上传模板格式Excel之前校验
    beforeUpload(file) {
      // this.uploadLoading = true
      this.showFakeProgress = true
      return new Promise((resolve, reject) => {
        var testmsg = file.name.substring(file.name.lastIndexOf('.') + 1)
        const extension = testmsg === 'xls'
        const extension2 = testmsg === 'xlsx'
        if (!extension && !extension2) {
          this.uploadLoading = false
          this.$message({
            message: '上传文件只能是 xls、xlsx格式！',
            type: 'warning'
          })
          reject()
        } else {
          resolve()
        }
        // 大小判断
        // const isLt10M = file.size / 1024 / 1024 < 10
        // if (!isLt10M) {
        //   this.uploadLoading = false
        //   this.$message({
        //     message: '上传文件大小不能超过 10MB！',
        //     type: 'warning'
        //   })
        //   reject()
        // }
        // if ((extension || extension2) && isLt10M) {
        //   templateValid(file, 'company').then(res => {
        //     if (res.code === 0) {
        //       resolve()
        //     } else {
        //       this.uploadLoading = false
        //       this.$message({
        //         message: '上传文件模板参数格式有误，请下载指定模板重新上传！',
        //         type: 'warning'
        //       })
        //       reject()
        //     }
        //   })
        // }
      })
    },
    // 点击地址批量列异按钮
    openAddressAbnDialog() {
      this.resetSearchForm2()
      this.addressAbnDialog = true
      this.selection = []
    },
    addressBatchSearch() {
      if (this.$util.isEmpty(this.searchForm2.dom)) {
        return this.$message.warning('请输入地址查询')
      }
      this.selection = []
      this.pageParam2.customParamMap = this.searchForm2
      this.pageParam2.curPage = 1
      this.addressLoadPage()
    },
    addressLoadPage() {
      this.nextLoading = true
      getBasePage(this.pageParam2).then(res => {
        this.nextLoading = false
        const list = []
        let i = 1
        const pageStart = (this.pageParam2.curPage - 1) * this.pageParam2.pageSize
        res.data.records.forEach(each => {
          each.index = pageStart + i++
          each.uscc = each.uniscid || each.regno
          list.push(each)
        })
        this.addressEntList = list
        this.pageParam2.total = res.data.total
        const selection = JSON.parse(JSON.stringify(this.selection))
        this.$nextTick(() => {
          for (const i in list) {
            const each = list[i]
            for (const j in selection) {
              if (each.pripid === selection[j].pripid) {
                this.$refs.addressEntList.toggleRowSelection(each, true)
              }
            }
          }
        })
      })
    },
    showMoreCriteria() {
      this.showMore = !this.showMore
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 === 1) {
        return 'warning-row'
      }
    },
    reasonFormatter(row) {
      if (row.includeType === '3') {
        return '个体工商户年度报告隐瞒真实情况、弄虚作假的'
      } else if (row.includeType === '4') {
        return '工商行政管理部门在依法履职过程中通过登记的经营场所及经营者住所无法与个体工商户取得联系的'
      }
    },
    // 重置搜索表单
    resetSearchForm2() {
      this.searchForm2 = {
        entertype: 'individual',
        addressSearchType: 'like',
        dom: '',
        regorgs: [],
        suporgs: [],
        acceptRegorgs: []

      }
    },
    getOrgOptions() {
      getOrgTreeList().then(res => {
        if (res.code === 0) {
          this.orgOptions = res.data
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    getbustypeOptions() {
      getRegulatory().then(res => {
        if (res.code === 0) {
          this.bustypeOptions = res.data
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    errorCallback(res, file) {
      this.$refs.FakeProgress.error()
      this.showFakeProgress = false
      // this.$message.warning('上传文件模板参数格式有误，请下载指定模板重新上传！')
      this.$message.warning('上传文件失败，请检查文件格式或数据，再重新上传，或联系管理员')
    },
    uploadCallback(res, file) {
      if (res.code === 0) {
        this.$refs.FakeProgress.success()
        setTimeout(() => {
          this.templateDialog = false
          this.showFakeProgress = false
          var resData = {}
          this.$confirm(`可导数量：${res.data.enableSize} 不可导数量：${res.data.disableSize}`, '导入筛选结果', {
            confirmButtonText: '继续导入',
            cancelButtonText: '保存清单',
            distinguishCancelAndClose: true,
            beforeClose: (action, instance, done) => {
              if (action === 'confirm') {
                if (res.data.enableSize === 0) {
                  return this.$message.error('可导入数量为0，请重新上传')
                }
                instance.confirmButtonLoading = true
                instance.confirmButtonText = '正在导入，请稍后。'
                saveBatchAbnListAcceptByNB(res.data.enableListId, res.data.bizseq, 'individual').then(resp => {
                  if (instance.confirmButtonLoading) {
                    if (resp.code === 0) {
                      resData = resp.data
                      instance.confirmButtonText = '完成'
                      instance.confirmButtonLoading = false
                      done()
                    }
                  }
                }).finally(() => {
                  if (instance.confirmButtonLoading === false) {
                    // 注释/individual/mark/accept,因为该页面的提交接口参数封装与企业不一致，导致页面提交报错。 经发现原来代码个体户列异在待办列表进入经办页面为企业的经办页面，因此直接改用企业经办页面 by ymc 2023.7.7
                    // this.$router.push({ path: '/abnormal/individual/mark/accept', query: { tasklistid: resData.tasklistid, bizseq: resData.bizseq, workflowId: resData.workFlowId }})
                    this.$router.push({ path: '/abnormal/company/inclusion/accept', query: { tasklistid: resData.tasklistid, bizseq: resData.bizseq, workflowId: resData.workFlowId }})
                  }
                })
              } else if (action === 'cancel') {
                if (res.data.disableSize === 0) {
                  return this.$message.error('清单数据为0，无法保存')
                }
                const url = location.origin + process.env.VUE_APP_BASE_API + `/bizSpeList/failEntAddressExport?disableListId=${encodeURIComponent(res.data.disableListId)}`
                window.open(url)
              } else if (action === 'close') {
                done()
              }
            }
          })
        }, 1000)
      } else {
        this.$refs.FakeProgress.error()
      }
      // if (res.code === 0) {
      //   this.$router.push({ path: '/abnormal/individual/mark/accept', query: { tasklistid: res.data.tasklistid, bizseq: res.data.bizseq, workflowId: res.data.workflowId }})
      // } else {
      //   this.$message.error(res.msg)
      // }
    },
    // 模板下载
    downLoadTemp() {
      const name = 'revokeImport.xls'
      window.open(process.env.NODE_ENV === '"development"' ? `/${name}` : `/aiccs/${name}`)
    },
    handleScroll() {
      var scrollTop =
        window.pageYOffset ||
        document.documentElement.scrollTop ||
        document.body.scrollTop
      if (scrollTop > 80) {
        this.showFixed = true
      } else {
        this.showFixed = false
      }
    },
    addressStartTask() {
      if (this.selection.length === 0) return this.$message.warning('请至少选择一个企业以开启待办')
      this.nextLoading = true
      this.$confirm('是否确认启动待办', '提示').then(() => {
        let ids = ''
        this.selection.forEach(each => {
          ids += (each.pripid + ';')
        })
        saveAbnormalAccept(ids.substring(0, ids.length - 1), 'individual').then(res => {
          if (res.code === 0) {
            this.$router.push({ path: '/abnormal/individual/mark/accept', query: { tasklistid: res.data.tasklistid, bizseq: res.data.bizseq, workflowId: res.data.workflowId }})
            // const { href } = this.$router.resolve({ path: '/abnormal/company/inclusion/accept', query: { tasklistid: res.data.tasklistid, bizseq: res.data.bizseq, workflowId: res.data.workflowId }})
            // window.open(href, '_blank')
          } else {
            this.$message.error(res.msg)
          }
        })
      })
    },
    startTaskIvd(pripid, row) {
      this.$set(row, 'loading', true)
      this.$confirm('是否确认启动待办', '提示').then(() => {
        saveIvdAccept(pripid).then(res => {
          this.$set(row, 'loading', false)
          if (res.code === 0) {
            this.$router.push({ path: '/abnormal/company/inclusion/accept', query: { tasklistid: res.data.tasklistid, bizseq: res.data.bizseq, workflowId: res.data.workflowId }})
          } else {
            this.$message.error(res.msg)
          }
        })
      })
    },
    // 启动待办
    startTask(toIncludeId, validType, row) {
      this.$set(row, 'loading', true)
      // 判断企业是不是已经在办了
      // validateBiz({ ids: toIncludeId, validType: validType, entertype: 'individual' }).then(res => {
      //   this.$set(row, 'loading', false)
      //   if (res.code === 0) {
      //     if (res.data.length > 0) {
      //       let str = ''
      //       for (const item of res.data) {
      //         str += item.entname + item.reason + '；'
      //       }
      //       str += '是否废弃此线索？'
      //       this.$confirm(str, '提示', {
      //         confirmButtonText: '确定',
      //         cancelButtonText: '取消',
      //         type: 'warning'
      //       }).then(() => { // 废弃线索
      //         removeClue(toIncludeId).then(res => {
      //           if (res.data === true) {
      //             this.$message({
      //               type: 'success',
      //               message: '废弃线索成功!'
      //             })
      //             this.search()
      //           } else {
      //             this.$message({
      //               type: 'error',
      //               message: '废弃线索失败!'
      //             })
      //           }
      //         })
      //       }).catch(() => {
      //       })
      //       this.templateDialog1 = false
      //       this.nextLoading = false
      //       return
      //     }
      //     this.$confirm('是否确认启动待办', '提示').then(() => {
      //       saveAbnormalAccept(toIncludeId, validType, 'individual').then(res => {
      //         this.nextLoading = false
      //         if (res.code === 0) {
      //           this.$router.push({ path: '/abnormal/company/inclusion/accept', query: { tasklistid: res.data.tasklistid, bizseq: res.data.bizseq, workflowId: res.data.workflowId }})
      //         } else {
      //           this.$message.error(res.msg)
      //         }
      //       })
      //     })
      //   }
      // })
      // 改为提示并可以进去办理
      validateBiz({ ids: toIncludeId, validType: validType, entertype: 'individual' }).then(res => {
        this.$set(row, 'loading', false)
        if (res.code === 0) {
          let str = ''
          let type = 'info'
          if (res.data.length > 0) {
            for (const item of res.data) {
              str += item.entname + item.reason + '；'
            }
            str += '是否继续启动待办？'
            type = 'warning'
          } else {
            str = '是否确认启动待办'
          }
          this.$confirm(str, '提示', { type: type }).then(() => {
            if (row.isbatch === '1') { // 动态监管批量
              saveAcceptBatch(toIncludeId, 'individual').then(res => {
                this.nextLoading = false
                if (res.code === 0) {
                  this.$router.push({ path: '/abnormal/company/inclusion/accept', query: { tasklistid: res.data.tasklistid, bizseq: res.data.bizseq, workflowId: res.data.workflowId }})
                } else {
                  this.$message.error(res.msg)
                }
              })
            } else {
              saveAbnormalAccept(toIncludeId, validType, 'individual').then(res => {
                this.nextLoading = false
                if (res.code === 0) {
                  this.$router.push({ path: '/abnormal/company/inclusion/accept', query: { tasklistid: res.data.tasklistid, bizseq: res.data.bizseq, workflowId: res.data.workflowId }})
                } else {
                  this.$message.error(res.msg)
                }
              })
            }
          })
        }
      })
    },
    // 地址查询列表批量启动待办
    startTaskAddress() {
      if (this.selection.length === 0) return this.$message.warning('请至少选择一个企业以开启待办')
      const regorgSet = new Set()
      for (const item of this.selection) {
        regorgSet.add(item.regorg)
      }
      // 判断当前勾选列表的待办是否都是一样的登记机关
      if (regorgSet.size > 1) {
        this.$message.warning('勾选的主体存在多种登记机关，请只保留一种登记机关！')
        return
      }
      this.nextLoading = true
      let ids = ''
      this.selection.forEach(each => {
        ids += (each.pripid + ';')
      })
      // 判断企业是不是已经在办了
      validateBiz({ ids: ids.substring(0, ids.length - 1), validType: 'ADDRESS', entertype: 'individual' }).then(res => {
        if (res.code === 0) {
          if (res.data.length > 0) {
            let str = ''
            for (const item of res.data) {
              str += item.entname + item.reason + '；'
            }
            this.$alert(str, '业务重复办理', {
              confirmButtonText: '确定',
              callback: action => {
              }
            })
            this.templateDialog1 = false
            this.nextLoading = false
            return
          } else {
            this.$confirm(`请确认已选${this.selection.length}家个体户，将发起列异流程`, '提示', {
              beforeClose: (action, instance, done) => {
                if (action === 'confirm') {
                  instance.confirmButtonLoading = true
                  saveAbnormalAccept(ids.substring(0, ids.length - 1), 'ADDRESS', 'individual').then(res => {
                    instance.confirmButtonLoading = false
                    if (res.code === 0) {
                      this.$router.push({ path: '/abnormal/company/inclusion/accept', query: { tasklistid: res.data.tasklistid, bizseq: res.data.bizseq, workflowId: res.data.workflowId }})
                    } else {
                      this.$message.error(res.msg)
                    }
                    done()
                  })
                } else if (!instance.confirmButtonLoading) {
                  done()
                }
                this.nextLoading = false
              }
            })
            return
          }
        }
      })
    },
    // 启动待办
    // startTask() {
    //   if (this.selection.length === 0) return this.$message.error('请至少选择一个企业以开启待办')
    //   this.nextLoading = true
    //   let ids = ''
    //   this.selection.forEach(each => {
    //     ids += (each.toIncludeId + ';')
    //   })
    //   // 判断企业是不是已经在办了
    //   validateBiz({ toIncludeIds: ids.substring(0, ids.length - 1), entertype: 'individual' }).then(res => {
    //     if (res.data.length > 0) {
    //       let str = ''
    //       for (const item of res.data) {
    //         str += item.entname + item.reason + '；'
    //       }
    //       this.$alert(str, '业务重复办理', {
    //         confirmButtonText: '确定',
    //         callback: action => {
    //         }
    //       })
    //       this.templateDialog1 = false
    //       this.nextLoading = false
    //       return
    //     }
    //     saveAbnormalAccept(ids.substring(0, ids.length - 1), 'individual').then(res => {
    //       this.nextLoading = false
    //       if (res.code === 0) {
    //         this.$router.push({ path: '/abnormal/individual/mark/accept', query: { tasklistid: res.data.tasklistid, bizseq: res.data.bizseq, workflowId: res.data.workflowId }})
    //       } else {
    //         this.$message.error(res.msg)
    //       }
    //     })
    //   })
    // },
    // 搜索
    search() {
      if (this.searchForm.searchtype === '2') {
        if (this.$util.isEmpty(this.searchForm.searchUscc) && this.$util.isEmpty(this.searchForm.searchName)) {
          return this.$message.warning('请输入统一码注册号或企业名称')
        }
      }
      this.selection = []
      this.pageParam.customParamMap = this.searchForm
      this.pageParam.curPage = 1
      if (this.$util.isNotEmpty(this.searchForm.regEntryUserName)) {
        this.showRegEntryUserName = true
      } else {
        this.showRegEntryUserName = false
      }
      this.loadPage()
    },
    // 分页多选插件回调
    removeCallback(index, row) {
      this.$refs.multipleTable.toggleRowSelection(row, false)
    },
    // 全选按钮事件
    selectAll() {
      const table = this.$refs.multipleTable
      for (const i in table.data) {
        const each = table.data[i]
        table.toggleRowSelection(each, true)
      }
    },
    // 分页多选插件回调
    removeCallback2(index, row) {
      this.$refs.addressEntList.toggleRowSelection(row, false)
    },
    // 全选按钮事件
    selectAll2() {
      const table = this.$refs.addressEntList
      for (const i in table.data) {
        const each = table.data[i]
        table.toggleRowSelection(each, true)
      }
    },
    resetSearchForm() {
      this.searchForm.searchUscc = ''
      this.searchForm.searchName = ''
      this.searchForm.includeType = ''
      this.searchForm.regEntryUserName = ''
      this.searchForm.dom = ''
    },
    // 选项变更事件
    handleSelectionChange(selectData) {
      const cancel = []
      if (selectData.length !== this.addressEntList.length) {
        // 找出没有选中的内容
        this.addressEntList.forEach(each => {
          for (const i in selectData) {
            const atom = selectData[i]
            if (atom.pripid === each.pripid) {
              return
            }
          }
          cancel.push(each)
        })
      }
      // 取消选中的内容
      for (const i in cancel) {
        const each = cancel[i]
        let index
        for (const j in this.selection) {
          const select = this.selection[j]
          if (select.pripid === each.pripid) {
            index = parseInt(j)
            break
          }
        }
        if (index !== undefined) {
          this.selection.splice(index, 1)
        }
      }
      // 增加选中内容
      for (const i in selectData) {
        const each = selectData[i]
        let exist = false
        for (const j in this.selection) {
          const select = this.selection[j]
          if (select.pripid === each.pripid) {
            exist = true
            break
          }
        }
        if (!exist) {
          this.selection.push(each)
        }
      }
    },
    // 当前分页改变
    pageIndexChange(curPage) {
      this.pageParam.curPage = curPage
      this.loadPage()
    },
    // 分页大小改变
    pageSizeChange(pageSize) {
      this.pageParam.pageSize = pageSize
      this.loadPage()
    },
    // 当前分页改变
    pageIndexChange2(curPage) {
      this.pageParam2.curPage = curPage
      this.addressLoadPage()
    },
    // 分页大小改变
    pageSizeChange2(pageSize) {
      this.pageParam2.pageSize = pageSize
      this.addressLoadPage()
    },
    // 加载分页
    loadPage() {
      this.searchtype = this.searchForm.searchtype
      if (this.loading) return
      this.loading = true
      commonPage(this.pageParam).then(res => {
        this.loading = false
        const list = []
        let i = 1
        const pageStart = (this.pageParam.curPage - 1) * this.pageParam.pageSize
        res.data.records.forEach(each => {
          each.index = pageStart + i++
          each.uscc = each.uniscid || each.regno
          list.push(each)
        })
        this.tableData = list
        this.pageParam.total = res.data.total
        // const selection = JSON.parse(JSON.stringify(this.selection))
        // this.$nextTick(() => {
        //   for (const i in list) {
        //     const each = list[i]
        //     for (const j in selection) {
        //       if (each.pripid === selection[j].pripid) {
        //         this.$refs.multipleTable.toggleRowSelection(each, true)
        //       }
        //     }
        //   }
        // })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.main-content{
  background: #fff;
  padding: 0;
  .content-header{
    background: white;
    .label-name {
      text-align: right;
      display: inline-block;
      width: 220px;
      font-size: $table-content-font-size;
    }
    .search-input-box{
      display: inline-block;
      width: calc(100% - 220px);
    }
    .search-input{
      cursor: pointer;
    }
    .body{
     padding: 20px 0;
      border-top:none;
      margin-bottom: 10PX;
    }
  }
  .content-body{
    background:white;
    margin-bottom: 100px;
  }
  .header{
    /* height:50PX; */
    /* padding:15PX 10PX; */
    .title{
      font-weight: 600;
      font-size: 1.2rem;
    }
  }
  .page-box{
    margin:10PX;
    .el-pagination{
      text-align: right;
    }
  }
}
.prompt{
  color: #F53633;
}
.fixed-bottom {
  position: fixed;
  width: 100%;
  bottom: -10px;
  right: 0;
  z-index: 99;
  padding: 10px;
  /* background: #8bbef6; */
  border-radius: 5px 5px 0 0;
  background: linear-gradient(to bottom, #fff 0%,#8bbef6 100%);
  box-shadow:  1px -4px 4px rgba(0, 21, 41, 0.08);
}
.content-body{
  background: #fff;
  /deep/.el-table .warning-row {
    background: #eaf4fe!important;
  }
}

</style>
<style lang="scss">
.content-body .el-table-column--selection .cell{
  padding-right: 0px;
}
.fixed-bottom {
  .el-pagination {
    text-align: right!important;
  }
}
</style>
