<template>
  <div class="main-content market">
    <el-tabs v-model="type" class="tab-card" type="border-card" @tab-click="$refs.EasyTable.reset()">
      <el-tab-pane label="新增现场核查任务" name="0" />
      <el-tab-pane label="历史记录" name="1" />
    </el-tabs>
    <div class="search-box">
      <el-row class="form" :gutter="20">
        <el-col :span="3">
          <label class="label-name" style="display: block;text-align: right;">统一社会信用代码/注册号</label>
        </el-col>
        <el-col :span="9">
          <div class="search-input-box" style="display: block;">
            <el-input v-model="searchForm.regno" size="mini" placeholder="请输入搜索统一社会信用代码/注册号" @keyup.native.enter="$refs.EasyTable.reset()" />
          </div>
        </el-col>
        <el-col :span="3">
          <label class="label-name" style="display: block;text-align: right;">主体名称</label>
        </el-col>
        <el-col :span="9">
          <div class="search-input-box" style="display: block;">
            <el-input v-model="searchForm.entname" size="mini" placeholder="请输入搜索主体名称" @keyup.native.enter="$refs.EasyTable.reset()" />
          </div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="4">
          <div class="btn-box">
            <el-button type="primary" icon="el-icon-search" size="mini" @click="$refs.EasyTable.reset()">检索</el-button>
            <!--<el-button v-if="type === '0'" type="primary" icon="el-icon-refresh-left" size="mini" :disabled="selected.length === 0" @click="removeSelected">移除选中记录</el-button>-->
            <el-button type="primary" icon="el-icon-search" size="mini" @click="searchForm.regno='';searchForm.entname='';$refs.EasyTable.reset()">重置</el-button>
            <!-- <el-radio-group v-model="sortBy" style="display: flex;margin-left: 20px;" @change="$refs.EasyTable.reset()">
              <el-radio label="dom">按地址排序</el-radio>
              <el-radio label="create_time">按到期时间排序</el-radio>
            </el-radio-group> -->
          </div>
        </el-col>

      </el-row>
    </div>
    <div class="main-body">
      <div class="header">
        <el-row>
          <el-col :span="24">
            <div style="text-align:left;">
              <el-button v-if="type === '0'" type="primary" icon="el-icon-plus" size="mini" @click="addressAbnDialog = true">新增批量现场核查</el-button>
              <!-- <el-button v-if="type === '0'" type="primary" icon="el-icon-plus" size="mini" @click="batchQueryShow">新增批量现场核查</el-button> -->
              <el-button v-if="type === '0'" type="primary" icon="el-icon-plus" size="mini" @click="openSearch">新增个案现场核查</el-button>
            </div>
          </el-col>
        </el-row>
      </div>
      <div class="content">
        <EasyTable
          ref="EasyTable"
          v-model="tableData"
          :table-config="tableConfig"
          :fields="dynamicSupervisionFields"
          :buttons="tableButtons"
          :total="tableTotal"
          :selected.sync="selected"
          :emit-current-change-on-create="true"
          @current-change="loadData"
          @size-change="loadData"
        />
      </div>
    </div>
    <el-dialog
      :visible.sync="searchFormDialog.visible"
      title="业户查询"
      width="80vw"
      :append-to-body="true"
      :modal-append-to-body="true"
    >
      <EasyForm
        ref="searchFormDialog"
        v-model="searchFormDialog.formData"
        v-loading="searchFormDialog.loading"
        :fields="searchFields"
        :form-config="searchFormDialog.config"
        :buttons="searchFormDialog.buttons"
        @cancel="searchFormDialog.visible = false"
      >
        <div slot="actualScope" slot-scope="scope" style="display: flex;">
          <el-input v-model="scope.formData.actualScope" disabled />
          <el-button type="primary">选择</el-button>
        </div>
      </EasyForm>
    </el-dialog>
    <el-dialog
      :visible.sync="searchListDialog.visible"
      title="业户列表"
      width="70vw"
    >
      <EasyTable
        ref="SearchListEasyTable"
        v-model="searchListDialog.tableData"
        :table-config="searchListDialog.tableConfig"
        :fields="searchFields"
        :total="searchListDialog.tableTotal"
        :selected.sync="searchListDialog.selected"
        @current-change="searchListLoadData"
      >
        <template slot="source" slot-scope="scope">
          <el-select v-model="scope.row.source">
            <el-option
              v-for="item in sources"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </template>
        <template slot="inspectExpireDate" slot-scope="scope">
          <el-date-picker
            v-model="scope.row.inspectExpireDate"
            type="daterange"
            value-format="yyyy-MM-dd"
            format="yyyy-MM-dd"
            style="width:100%"
          />
        </template>
      </EasyTable>
      <div style="text-align: center;margin-top: 10px;">
        <el-button
          type="primary"
          :disabled="searchListDialog.selected.length === 0"
          :loading="addTodoLoading"
          @click="addTodo"
        >
          添加到待检查列表
        </el-button>
        <el-button
          @click="searchListDialog.visible = false"
        >
          重新查找
        </el-button>
      </div>
    </el-dialog>
    <el-dialog
      :visible.sync="inputDialog.visible"
      title="检查情况"
      width="80vw"
      :append-to-body="true"
      :modal-append-to-body="true"
      @opened="showInputDialogEvent"
    >
      <EasyForm
        ref="inputDialog"
        v-model="inputDialog.formData"
        v-loading="inputDialog.loading"
        :fields="dynamicSupervisionFields"
        :form-config="inputDialog.config"
        :buttons="inputDialog.buttons"
        @cancel="inputDialog.visible = false"
      >
        <div slot="entList">
          <el-button ref="entListBtn" size="medium" type="primary" @click="showEntList = true; $refs.entListRef.reset()">查看主体名单<i class="el-icon el-icon-s-order" style="margin-left:5px" /></el-button>
        </div>
        <div slot="contactPhone" slot-scope="scope">
          <el-input
            :value="getDisplayPhone(scope)"
            readonly
            class="view-mode-input"
          >
            <template #suffix>
              <i class="el-icon-view" @click.stop="showFullPhone(scope)"></i>
            </template>
          </el-input>
        </div>
        <div slot="mobilePhone" slot-scope="scope">
          <el-input
            :value="getDisplayPhoneb(scope)"
            readonly
            class="view-mode-input"
          >
            <template #suffix>
              <i class="el-icon-view" @click.stop="showFullPhoneb(scope)"></i>
            </template>
          </el-input>
        </div>
        <div slot="opinion" slot-scope="scope">
          <el-input
            v-model="scope.formData.opinion"
            type="textarea"
            :rows="1"
          />
          <div v-if="type === '0'" style="margin-top: 10px;">
            <span style="margin-right: 10px;">常用语:</span>
            <el-select v-model="scope.formData.opinion_select" @change="(value) => {scope.formData.opinion = value}">
              <el-option v-for="item in commonList" :key="item.value" :value="item.label" :label="item.commonlanguage" />
            </el-select>
          </div>
        </div>
      </EasyForm>
      <el-dialog
        title="核查主体名单"
        :visible.sync="showEntList"
        append-to-body
        width="90%"
      >
        <EasyTable
          ref="entListRef"
          v-model="entList"
          :table-config="tableConfig_entList"
          :fields="tableFields"
          :buttons="tableButtons_entList"
          :total="tableTotal_entList"
          :selected.sync="selected"
          :emit-current-change-on-create="true"
          @current-change="loadEntListData"
        />
      </el-dialog>
    </el-dialog>
    <el-dialog
      title="批量导入"
      :visible.sync="batchQueryDialogShow"
      width="30%"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
    >
      <div>
        <el-input
          v-model="batchFileName"
          placeholder="点击选择模版文件"
          style="display:inline-block;width:calc(100% - 120px)"
          :readonly="true"
          @click.native="$refs.batchFile.click()"
        />
        <el-button style="width:100px;margin-left:10px" type="primary" @click="$refs.batchFile.click()">浏览</el-button>
        <input :ref="'batchFile'" type="file" style="display:none" accept=".xls,.xlsx" @change="fileChange">
      </div>
      <div>
        <span>来源：</span>
        <el-select v-model="batchSource">
          <el-option
            v-for="item in sources"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </div>
      <div>
        <span>检查期限：</span>
        <el-date-picker
          v-model="batchInspectExpireDate"
          type="daterange"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </div>
      <FakeProgress v-if="showFakeProgress" ref="FakeProgress" style="margin-top: 10px;" />
      <span slot="footer" class="dialog-footer">
        <el-row>
          <el-col :span="8" align="left">
            <el-button type="primary" @click="downloadFile">下载模版</el-button>
          </el-col>
          <el-col :span="16">
            <el-button :loading="loading" @click="batchQueryDialogShow = false">取 消</el-button>
            <el-button type="primary" :loading="loading" @click="batchQuery">新 增</el-button>
          </el-col>
        </el-row>
      </span>
    </el-dialog>
    <el-dialog
      title="发起多条检查任务"
      :visible.sync="openManyDialogShow"
      width="30%"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
    >
      <div>
        <span>来源：</span>
        <el-select v-model="batchSource">
          <el-option
            v-for="item in sources"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </div>
      <div>
        <span>检查期限：</span>
        <el-date-picker
          v-model="batchInspectExpireDate"
          type="daterange"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-row>
          <el-col :span="16">
            <el-button :loading="loading" @click="openManyDialogShow = false">取 消</el-button>
            <el-button type="primary" :loading="loading" @click="startManyTask">新 增</el-button>
          </el-col>
        </el-row>
      </span>
    </el-dialog>
    <el-dialog
      title="地址发起校验结果"
      :visible.sync="resultAddressDialogShow"
      width="20%"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
    >
      <div style="margin-bottom:20px; display:inline-block; width:80%">
        <span style="font-size: 20px;">可发起数量：{{canNum}}</span>
      </div>
      <div style="margin-bottom:20px; display:inline-block; width:80%">
        <span style="font-size: 20px;">不可发起数量：{{noCanNum}}</span>
        <el-link
          style="margin-left:20px; font-size: medium"
          type="primary"
          @click="exportNoCanExcel"
        >下载模板</el-link>
      </div>
      <div style="">
        <el-button :loading="loading" @click="resultAddressDialogShow = false">取 消</el-button>
        <el-button type="primary" :loading="loading" @click="batchAddressDialogShow = true">继续发起</el-button>
      </div>
    </el-dialog>
    <el-dialog
      title="输入地址"
      :visible.sync="inputAddressDialogShow"
      width="30%"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
    >
      <span style="color:red; margin-right:10px;">*</span><span>请输入地址：</span>
      <div style="display:inline-block; width:80%">
        <el-input v-model="inputAddress" clearable size="mini" class="search-input" type="text" placeholder="请输入地址" />
      </div>
      <div style="margin-top:20px; width:80%; text-align:center;">
        <span style="color:red;margin-right: 10px;">提示：该地址用于识别地址批量列异的企业是否为同一地址，输入企业地址相同的部分即可，例xxx市xxx区xxx街xxx楼xxx室 / xxx市xxx区xxx街。</span>
      </div>
      <div style="margin-top:20px; text-align:center;">
        <el-button :loading="loading" @click="inputAddressDialogShow = false">取 消</el-button>
        <el-button type="primary" :loading="loading" @click="inputAddressSave">保 存</el-button>
      </div>
    </el-dialog>
    <el-dialog
      title="发起一条检查任务"
      :visible.sync="batchAddressDialogShow"
      width="30%"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
    >
      <div>
        <span>来源：</span>
        <el-select v-model="batchSource">
          <el-option
            v-for="item in sources"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </div>
      <div>
        <span>检查期限：</span>
        <el-date-picker
          v-model="batchInspectExpireDate"
          type="daterange"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-row>
          <el-col :span="16">
            <el-button :loading="loading" @click="batchAddressDialogShow = false">取 消</el-button>
            <el-button type="primary" :loading="loading" @click="batchAddressSave">新 增</el-button>
          </el-col>
        </el-row>
      </span>
    </el-dialog>
    <el-dialog
      title="新增批量现场核查"
      :visible.sync="addressAbnDialog"
      width="90%"
    >
      <el-row style="margin-bottom:20px">
        <el-col :span="12">
          <label style="text-align: left; 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-col :span="4">
          <label style="text-align: left; 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-col :span="4" :offset="4" style="text-align: left;">
          <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-row>
        <el-col :span="20" style="text-align: left">
          <el-button size="mini" @click="selectAll2">全选</el-button>
          <el-button size="mini" @click="$util.toggleSelect($refs.addressEntList)" style="margin-right:30px">反选</el-button>
          <!-- <el-button size="mini" :loading="nextLoading" type="primary" @click="startTaskAddress">办理</el-button> -->
          <el-button size="mini" :loading="nextLoading" type="primary" @click="inputAddressDialogShow = true">发起一条检查任务</el-button>
          <el-button size="mini" :loading="nextLoading" type="primary" @click="openManyTask">发起多条检查任务</el-button>

        </el-col>
        <el-col :span="4" style="text-align: right">
          <el-button size="mini" :loading="nextLoading" type="primary" @click="batchQueryShow">导入名单</el-button>
        </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'}"
        :data="addressEntList"
        tooltip-effect="dark"
        style="width: 100%;padding: 0;margin:10px 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="dom" :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" :loading="nextLoading" 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, 400, 600, 800]"
              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 EasyTable from '../../../components/EasyTable'
import EasyForm from '../../../components/EasyForm'
import FakeProgress from '@/components/FakeProgress'
import dynamicSupervisionBase from '@/views/market/dynamicsupervision/index'
import { exportNoCanExcel, listEntInfo, tSUsualInspectSave, tSUsualInspectList, tSUsualInspectUpdate, tSUsualInspectDelete, batchSave, batchAddressSave, startManyTask, tSUsualInspectEntList, removeTSUsualInspectEntList, removeTSUsualInspect, addContactLogByEntNo } from '@/api/market'
import { areaSliceAllList } from '@/api/areaSlice'
import { getBasePage } from '@/api/entBase'
import { Eye } from 'element-ui'
export default {
  components: {
    EasyTable,
    EasyForm,
    FakeProgress,
    View: Eye
  },
  mixins: [dynamicSupervisionBase],
  data() {
    return {
      fileImportFlag: false,
      canNum: 0,
      noCanNum: 0,
      noCanList: '',
      inputAddress: '',
      resultAddressDialogShow: false,
      inputAddressDialogShow: false,
      eBaseinfoList: [],
      tableButtons_entList: [
        {
          label: '删除',
          type: 'text',
          loading: false,
          show: () => {
            return this.type === '0'
          },
          disabled: false,
          position: 'row', // header | row
          handler: (scope, button, easyTableInstance) => {
            this.delEnt(scope, button, easyTableInstance)
          }
        }
      ],
      tableConfig_entList: {
        selection: false,
        selectionWidth: '55',
        showPagination: true,
        tableProps: {
          border: true,
          headerCellStyle: { background: '#8cc3fb', color: '#fff' }
        },
        tableListeners: {
          'sort-change': ({ column, prop, order }) => {
            // this.sortBy = prop
            // this.asc = order === 'ascending'
            // this.$refs.entListRef.reset()
          }
        },
        rowKey: 'pripid'
      },
      tableFields: [
        {
          prop: 'pripid',
          type: 'string',
          label: '企业主键'
        },
        {
          prop: 'uscc',
          type: 'string',
          label: '统一社会信用代码',
          showInTable: true
        },
        {
          prop: 'entName',
          type: 'string',
          label: '企业名称',
          showInTable: true
        },
        {
          prop: 'legalName',
          type: 'string',
          label: '法定代表人',
          showInTable: true
        },
        {
          prop: 'dom',
          type: 'string',
          label: '住所',
          showInTable: true
        },
        {
          prop: 'regStateCn',
          type: 'string',
          label: '企业状态',
          showInTable: true
        },
        {
          prop: 'regOrgCn',
          type: 'string',
          label: '登记机关',
          showInTable: true
        },
        {
          prop: 'supOrgCn',
          type: 'string',
          label: '属地监管机关',
          showInTable: true
        }
      ],
      showEntList: false,
      entList: [],
      addressAbnDialog: false,
      addTodoLoading: false,
      searchForm: {
        regno: '',
        entname: ''
      },
      commonList: this.$util.getCommonWords(JSON.parse(sessionStorage.getItem('user')).primaryKey).filter((item) => {
        return item.module === '市场所协同'
      }),
      tableTotal: 0,
      tableTotal_entList: 0,
      selected: [],
      slices: [],
      user: JSON.parse(sessionStorage.getItem('user')),
      sortBy: 'create_time',
      asc: true,
      type: '0',
      batchQueryDialogShow: false,
      batchFileName: '',
      batchInspectExpireDate: '', // 批量-检查日期
      batchSource: '', // 批量-来源
      loading: false,
      showFakeProgress: false,
      currentId: '', // 当前检查任务Id
      tableData: [],
      sources: [
        {
          label: '国家',
          value: '国家'
        },
        {
          label: '省局',
          value: '省局'
        },
        {
          label: '市局',
          value: '市局'
        },
        {
          label: '批量吊销',
          value: '批量吊销'
        },
        {
          label: '其他',
          value: '其他'
        }
      ],
      searchFields: [
        {
          prop: 'sliceId',
          label: '管理片区',
          showInForm: true,
          type: 'select',
          span: 24,
          formProps: {
            clearable: true
          },
          options: () => { return this.slices }
        },
        {
          prop: 'regno',
          label: '统一社会信用代码/注册号',
          type: 'input',
          span: 12,
          showInForm: true,
          showInTable: false
        },
        {
          prop: 'uniscid',
          label: '统一社会信用代码',
          type: 'input',
          span: 12,
          showInForm: false,
          showInTable: true
        },
        {
          prop: 'entname',
          label: '主体名称',
          type: 'input',
          span: 12,
          showInForm: true,
          showInTable: true
        },
        {
          prop: 'oploc',
          label: '经营地址',
          type: 'input',
          span: 12,
          showInForm: true
        },
        {
          prop: 'name',
          label: '法定代表人/负责人',
          showInForm: true,
          span: 12,
          type: 'input',
          showInTable: true
        },
        {
          prop: 'entType',
          label: '企业类型',
          showInForm: true,
          type: 'select',
          span: 12,
          options: [
            { label: '个体户', value: 'individual' },
            { label: '农专', value: 'farmer' },
            { label: '企业', value: 'company' }

          ]
        },
        {
          prop: 'opscope',
          label: '经营范围',
          showInForm: true,
          type: 'input',
          span: 12
        },
        {
          prop: 'sortType',
          label: '排序条件',
          showInForm: false,
          type: 'radio',
          span: 24,
          options: [
            { label: '按地址排序', value: 'oploc' },
            { label: '按注册号排序', value: 'regno' }
          ]
        },
        {
          prop: 'level',
          label: '信用风险等级',
          showInForm: true,
          showInTable: false,
          type: 'radio',
          options: [
            { label: '高风险', value: '高风险' },
            { label: '较高风险', value: '较高风险' }
          ]
        },
        {
          prop: 'source',
          label: '来源',
          type: 'slot',
          slotName: 'source',
          showInForm: false,
          showInTable: true
        },
        {
          prop: 'inspectExpireDate',
          label: '检查期限',
          type: 'slot',
          slotName: 'inspectExpireDate',
          showInForm: false,
          showInTable: true
        }
      ],
      tableConfig: {
        showIndex: true,
        selection: () => {
          return false
        },
        selectionWidth: '55',
        showPagination: true,
        tableProps: {
          border: true,
          headerCellStyle: { background: '#8cc3fb', color: '#fff' }
        },
        tableListeners: {
          'sort-change': ({ column, prop, order }) => {
            this.sortBy = prop
            this.asc = order === 'ascending'
            this.$refs.EasyTable.reset()
          }
        },
        rowKey: 'regNO'
      },
      tableButtons: [
        {
          label: '录入',
          type: 'text',
          loading: false,
          show: () => {
            return this.type === '0'
          },
          disabled: false,
          position: 'row', // header | row
          handler: (scope, button, easyTableInstance) => {
            this.$router.push({
              path: '/market/marketDynamicInspect',
              query: { bizseq: scope.row.bizSeq }
            })
            // this.inputDialog.config.readOnly = false
            // this.dynamicSupervisionEvent(scope, button, easyTableInstance)
          }
        },
        {
          label: '删除',
          type: 'text',
          loading: false,
          show: () => {
            return this.type === '0'
          },
          disabled: false,
          position: 'row',
          handler: (scope) => {
            this.$confirm(`请确认是否删除 ${scope.row.entName} 检查任务`, '提示', {
              type: 'warning',
              callback: (action) => {
                if (action === 'confirm') {
                  removeTSUsualInspect(scope.row.id).then(res => {
                    if (res.code === 0) {
                      this.$message.success('操作成功')
                      this.$refs.EasyTable.reset()
                    } else {
                      this.$message.error(res.msg)
                    }
                  })
                }
              }
            })
          }
        },
        {
          label: '查看',
          type: 'text',
          loading: false,
          show: () => {
            return this.type !== '0'
          },
          disabled: false,
          position: 'row', // header | row
          handler: (scope, button, easyTableInstance) => {
            this.inputDialog.config.readOnly = true
            this.dynamicSupervisionEvent(scope, button, easyTableInstance)
          }
        }
      ],
      searchFormDialog: {
        visible: false,
        formData: {},
        loading: false,
        config: {
          labelPosition: 'right',
          labelWidth: '130px',
          // gutter: 20,
          submitPosition: 'center', // 页脚按钮位置
          showValidMessage: true // 校验失败时是否使用Message显示提示错误消息
        },
        buttons: [
          {
            label: '查询',
            type: 'primary',
            loading: false,
            handler: (formData, button, easyFormInstance) => {
              easyFormInstance.submitForm().then(() => {
                button.loading = true
              }).then(() => {
                return this.searchListLoadData({
                  pageParam: {
                    current: 1,
                    size: 10
                  }
                }).then(() => {
                  this.searchListDialog.visible = true
                })
              }).finally(() => {
                button.loading = false
              })
            }
          },
          {
            label: '重置',
            loading: false,
            handler: (formData, button, easyFormInstance) => {
              this.searchFormDialog.formData = {}
              easyFormInstance.clearValidate()
            }
          }
        ]
      },
      searchListDialog: {
        visible: false,
        tableData: [],
        selected: [],
        tableConfig: {
          selection: true,
          selectionWidth: '55',
          showPagination: true,
          tableProps: {
            border: true,
            headerCellStyle: { background: '#8cc3fb', color: '#fff' }
          },
          rowKey: 'regNO'
        },
        fields: [
          {
            prop: 'regNO',
            label: '注册号',
            showInTable: true,
            tableProps: {
              'min-width': '200px'
            }
          },
          {
            prop: 'entName',
            label: '业户名称',
            showInTable: true
          },
          {
            prop: 'legalName',
            label: '法定代表人',
            showInTable: true
          },
          {
            prop: 'address',
            label: '经营地址',
            showInTable: true
          },
          {
            prop: 'lastCheckTime',
            label: '最近检查时间',
            showInTable: true
          },
          {
            prop: 'xlevel',
            label: '信用等级',
            showInTable: true
          },
          {
            prop: 'flevel',
            label: '风险等级',
            showInTable: true
          }
        ],
        tableTotal: 0
      },
      inputDialog: {
        visible: false,
        formData: {},
        loading: false,
        config: {
          labelPosition: 'right',
          labelWidth: '130px',
          // gutter: 20,
          readOnly: false,
          submitPosition: 'center', // 页脚按钮位置
          showValidMessage: true // 校验失败时是否使用Message显示提示错误消息
        },
        buttons: [
          {
            label: '保存',
            type: 'primary',
            loading: false,
            show: (scope) => {
              // return !scope.formConfig.readOnly
              return this.type === '0'
            },
            handler: (formData, button, easyFormInstance) => {
              easyFormInstance.submitForm().then((formData) => {
                this.updateInspect(formData, button, easyFormInstance)
              })
            }
          },
          {
            label: '关闭',
            loading: false,
            show: (scope) => {
              // return !scope.formConfig.readOnly
              return this.type === '0'
            },
            handler: (formData, button, easyFormInstance) => {
              this.inputDialog.visible = false
            }
          }
        ]
      },
      // 批量地址核查变量
      searchForm2: {
        entertype: 'company',
        addressSearchType: 'like'
      },
      pageParam2: {
        customParamMap: { entertype: 'company' },
        curPage: 1,
        total: 0,
        pageSize: 10
      },
      nextLoading: false,
      batchAddressDialogShow: false,
      openManyDialogShow: false,
      addressEntList: []
      // 批量地址核查 -- end
    }
  },
  computed: {
    _currentId() {
      return this.currentId
    }
  },
  created() {
    this.getSlice()
  },
  methods: {
    // 获取脱敏显示
    getDisplayPhone(scope) {
      const phone = scope?.formData?.contactPhone || ''
      if (!phone) return ''

      // 处理手机号码 (11位数字)
      if (/^\d{11}$/.test(phone)) {
        return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
      }

      // 处理带区号的固定电话 (例如: 010-12345678 或 02112345678)
      if (/^\d{3,4}-?\d{7,8}$/.test(phone)) {
        // 提取区号和号码部分
        const parts = phone.includes('-') ? phone.split('-') : [phone.substring(0, 3), phone.substring(3)]
        const areaCode = parts[0]
        let numberPart = parts[1]

        // 隐藏号码部分的中间4位
        if (numberPart.length >= 7) {
          numberPart = numberPart.replace(/(\d{3})\d{4}(\d{0,4})/, '$1****$2')
        }

        return parts.length > 1 ? `${areaCode}-${numberPart}` : `${areaCode}${numberPart}`
      }

      // 处理其他格式的电话号码 (默认隐藏中间部分)
      const length = phone.length
      if (length > 7) {
        const start = Math.floor(length / 3)
        const end = Math.min(start + 4, length - 3)
        return phone.substring(0, start) + '****' + phone.substring(end)
      }

      // 短号码不做处理或自定义处理逻辑
      return phone
    },
    showFullPhone: function(scope) {
      this.$alert(scope?.formData?.contactPhone, '完整号码', {
        confirmButtonText: '关闭'
      })
      // eslint-disable-next-line no-empty
      if (scope?.formData?.contactPhone) {
        // 调用日志方法，传递所有必要参数
        addContactLogByEntNo({
          pripid: scope?.formData?.priPId,
          originalValue: scope?.formData?.contactPhone // 原始值
        }).then(res => {
          if (res.code === 0) {
            // 成功处理
          }
        }).catch(err => {
          console.error('记录日志失败:', err)
        })
      }
    },
    // 获取脱敏显示
    getDisplayPhoneb(scope) {
      const phone = scope?.formData?.contactPhone || ''
      if (!phone) return ''

      // 处理手机号码 (11位数字)
      if (/^\d{11}$/.test(phone)) {
        return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
      }

      // 处理带区号的固定电话 (例如: 010-12345678 或 02112345678)
      if (/^\d{3,4}-?\d{7,8}$/.test(phone)) {
        // 提取区号和号码部分
        const parts = phone.includes('-') ? phone.split('-') : [phone.substring(0, 3), phone.substring(3)]
        const areaCode = parts[0]
        let numberPart = parts[1]

        // 隐藏号码部分的中间4位
        if (numberPart.length >= 7) {
          numberPart = numberPart.replace(/(\d{3})\d{4}(\d{0,4})/, '$1****$2')
        }

        return parts.length > 1 ? `${areaCode}-${numberPart}` : `${areaCode}${numberPart}`
      }

      // 处理其他格式的电话号码 (默认隐藏中间部分)
      const length = phone.length
      if (length > 7) {
        const start = Math.floor(length / 3)
        const end = Math.min(start + 4, length - 3)
        return phone.substring(0, start) + '****' + phone.substring(end)
      }

      // 短号码不做处理或自定义处理逻辑
      return phone
    },
    showFullPhoneb(scope) {
      this.$alert(scope?.formData?.mobilePhone, '完整号码', {
        confirmButtonText: '关闭'
      })
      // eslint-disable-next-line no-empty
      if (scope?.formData?.mobilePhone) {
        // 调用日志方法，传递所有必要参数
        addContactLogByEntNo({
          pripid: scope?.formData?.priPId,
          originalValue: scope?.formData?.mobilePhone // 原始值
        }).then(res => {
          if (res.code === 0) {
            // 成功处理
          }
        }).catch(err => {
          console.error('记录日志失败:', err)
        })
      }
    },
    // 检查情况Dialog打开事件
    showInputDialogEvent() {
      if (this.type === '1') {
        setTimeout(() => {
          const entListBtnDom = this.$refs.entListBtn
          if (entListBtnDom) {
            console.log('modify btn class')
            entListBtnDom.$el.className = 'el-button el-button--primary el-button--medium'
            entListBtnDom.$el.disabled = false
          }
        }, 250)
      }
    },
    loadEntListData({ pageParam, instance }) {
      instance.loading = true
      tSUsualInspectEntList({
        'curPage': pageParam.current,
        'customParamMap': {},
        'inParamMap': {},
        'likeParamMap': {},
        'pageSize': pageParam.size,
        'paramMap': {
          bizSeq: this._currentId
        }
      }).then((res) => {
        const { code, data } = res
        if (code === 0) {
          this.entList = data.records
          this.tableTotal_entList = data.total
        }
      }).finally(() => {
        instance.loading = false
      })
    },
    getSlice() {
      areaSliceAllList().then(res => {
        if (res.code === 0) {
          this.slices = res.data.map((item) => {
            return {
              ...item,
              value: item.sliceId,
              label: item.sliceName
            }
          })
        }
      })
    },
    loadData({ pageParam, instance }) {
      // 待检查业户查询方法
      instance.loading = true
      tSUsualInspectList({
        'curPage': pageParam.current,
        'customParamMap': {
          type: this.type, // 0-待检查 1-已检查
          inspectOrg: this.user.orgId
        },
        'inParamMap': {},
        'likeParamMap': {
          entName: this.searchForm.entname ? this.searchForm.entname : undefined
        },
        'pageSize': pageParam.size,
        'paramMap': {
          uscc: (this.searchForm.regno && this.searchForm.regno.length === 18) ? this.searchForm.regno : undefined,
          regno: (this.searchForm.regno && this.searchForm.regno.length !== 18) ? this.searchForm.regno : undefined
        },
        orderField: this.sortBy,
        orderingRuleBoolean: this.asc
      }).then((res) => {
        const { code, data } = res
        if (code === 0) {
          this.tableData = data.records
          this.tableTotal = data.total
        }
      }).finally(() => {
        instance.loading = false
      })
    },
    async removeSelected() {
      this.$confirm(`确定要删除选中的${this.selected.length}条检查`, '提示', {
        type: 'warning',
        callback: (action) => {
          if (action === 'confirm') {
            // 移除选中的待检查业户
            this.$refs.EasyTable.loading = true
            Promise.all(this.selected.map((select) => {
              return tSUsualInspectDelete({
                id: select.id
              })
            })).finally(() => {
              this.$refs.EasyTable.loading = false
              this.$refs.EasyTable.reset()
            })
          }
        }
      })
    },
    openSearch() {
      this.searchFormDialog.loading = false
      this.searchFormDialog.visible = true
      this.searchFormDialog.formData = {}
      this.$nextTick(() => {
        if (this.$refs.searchFormDialog) {
          this.$refs.searchFormDialog.clearValidate()
        }
      })
    },
    isNotBlank(val) {
      if (val === undefined || val === null || val === '') {
        return false
      }
      return true
    },
    searchListLoadData({ pageParam, instance }) {
      if(!this.isNotBlank(this.searchFormDialog.formData.entType)
        && !this.isNotBlank(this.searchFormDialog.formData.sliceId)
        && !this.isNotBlank(this.searchFormDialog.formData.entname)
        && !this.isNotBlank(this.searchFormDialog.formData.oploc)
        && !this.isNotBlank(this.searchFormDialog.formData.opscope)
        && !this.isNotBlank(this.searchFormDialog.formData.regno)
        && !this.isNotBlank(this.searchFormDialog.formData.name)
        && !this.isNotBlank(this.searchFormDialog.formData.level)){
        this.$message.warning('请输入查询条件')
        return
      }
      // 根据查询条件搜索业户
      if (instance) {
        instance.loading = true
      }
      return listEntInfo({
        'curPage': pageParam.current,
        'customParamMap': {
          entname: this.searchFormDialog.formData.entname,
          entType: this.searchFormDialog.formData.entType,
          sliceId: this.isNotBlank(this.searchFormDialog.formData.sliceId) ? this.searchFormDialog.formData.sliceId : undefined
        },
        'inParamMap': {},
        'likeParamMap': {

          oploc: this.searchFormDialog.formData.oploc,
          opscope: this.searchFormDialog.formData.opscope
        },
        'pageSize': pageParam.size,
        'paramMap': {
          uniscid: (this.searchFormDialog.formData.regno && this.searchFormDialog.formData.regno.length === 18) ? this.searchFormDialog.formData.regno : undefined,
          regno: (this.searchFormDialog.formData.regno && this.searchFormDialog.formData.regno.length !== 18) ? this.searchFormDialog.formData.regno : undefined,
          name: this.isNotBlank(this.searchFormDialog.formData.name) ? this.searchFormDialog.formData.name : undefined,
          label: this.searchFormDialog.formData.label,
          level: this.searchFormDialog.formData.level
        },
        orderField: this.searchFormDialog.formData.sortType,
        orderingRuleBoolean: true
      }).then((res) => {
        const { code, data } = res
        if (code === 0) {
          this.searchListDialog.tableData = data.records
          this.searchListDialog.tableTotal = data.total
        }
      }).finally(() => {
        if (instance) {
          instance.loading = false
        }
      })
    },
    async addTodo() {
      // 把业户添加到待检查
      this.addTodoLoading = true
      for (const select of this.searchListDialog.selected) {
        if (!this.isNotBlank(select.source)) {
          this.$message.warning('请输入来源')
          this.addTodoLoading = false
          return false
        }
        if (!this.isNotBlank(select.inspectExpireDate)) {
          this.$message.warning('请输入检查期限')
          this.addTodoLoading = false
          return false
        }
        await tSUsualInspectSave({
          ...select,
          priPId: select.pripid,
          dom: select.dom || select.address,
          entName: select.entname,
          legalName: select.name,
          mobilePhone: select.phone,
          contacts: select.name,
          contactPhone: select.phone,
          regNo: select.regno,
          uscc: select.uniscid,
          scope: select.opscope,
          inspectStartDate: select.inspectExpireDate[0],
          inspectExpireDate: select.inspectExpireDate[1],
          source: select.source,
          inspector: JSON.parse(sessionStorage.user).nickname,
          inspectorId: JSON.parse(sessionStorage.user).primaryKey,
          inspectOrg: JSON.parse(sessionStorage.user).orgId,
          inspectOrgName: JSON.parse(sessionStorage.user).orgName,
          inspectType: '自定义巡查'
        }).then((res) => {
          if (res.code === 0) {
            const index = this.searchListDialog.tableData.findIndex((item) => {
              return item.pripid === select.pripid
            })
            this.searchListDialog.tableData.splice(index, 1)
          } else {
            throw res
          }
        }).catch((e) => {
          console.log(e)
        })
      }
      this.$refs.EasyTable.reset()
      this.addTodoLoading = false
      if (this.searchListDialog.tableData.length === 0) {
        this.searchListDialog.visible = false
        this.searchFormDialog.visible = false
      }
    },
    updateInspect(formData, button, easyFormInstance) {
      // 录入检查
      button.loading = true
      return tSUsualInspectUpdate(formData).then((res) => {
        const { code } = res
        if (code !== 0) {
          throw res
        }
      }).then(() => {
        this.inputDialog.visible = false
        this.$refs.EasyTable.reset()
      }).finally(() => {
        button.loading = false
      })
    },
    // 打开批量查询窗口
    batchQueryShow() {
      this.batchQueryDialogShow = true
    },
    // 下载模版
    downloadFile() {
      // const prev = process.env.NODE_ENV === '"development"' ? '' : '/aiccs'
      // window.open(prev + '/companyModel.xls')
      const name = 'companyModel.xls'
      window.open(process.env.NODE_ENV === '"development"' ? `/${name}` : `/aiccs/${name}`)
    },
    fileChange() {
      this.batchFileName = this.$refs.batchFile.files[0].name
    },
    // 市场主体批量搜索
    async batchQuery() {
      const file = this.$refs.batchFile.files
      if (!file[0]) {
        this.$message.warning('查询文件不能为空')
        return
      }
      if (!this.batchInspectExpireDate) {
        this.$message.warning('请录入检查期限')
        return
      }
      if (!this.batchSource) {
        this.$message.warning('请录入来源')
        return
      }
      const form = new FormData()
      form.append('file', file[0])
      form.append('inspectExpireDate', this.batchInspectExpireDate.join(','))
      form.append('source', this.batchSource)
      this.loading = true
      this.showFakeProgress = true
      return batchSave(form).then(async({ code, data, msg }) => {
        if (code !== 0) {
          this.$refs.FakeProgress.error()
          this.$message.error(data.message)
          this.loading = false
          this.showFakeProgress = false
        } else {
          this.eBaseinfoList = data.eBaseinfoList
          // let list = []
          // const pageStart = 0
          // let i = 1
          // data.eBaseinfoList.forEach(each =>{
          //   console.log(each)
          //   each.index = pageStart + i++
          //   each.uscc = each.uniscid || each.regno
          //   list.push(each)
          // })
          // console.log('each')
          // this.addressEntList = list
          // // for(let i = 0; i < data.eBaseinfoList.length && i < this.pageParam2.pageSize; i++){
          // //   this.addressEntList[i] = data.eBaseinfoList[i]
          // // }
          this.$refs.FakeProgress.success()
          setTimeout(() => {
            this.selection = []
            this.loading = false
            this.showFakeProgress = false
            this.batchQueryDialogShow = false
            this.$confirm(`共新增 ${data.inCheckNum} 条数据${data.noCheckNum > 0 ? ',未插入数据 ' + data.noCheckNum + ' 条' : ''}。`, data.noCheckNum > 0 ? '是否导出未查询到的记录' : '查询结果', {
              confirmButtonText: data.noCheckNum > 0 ? '导出' : '确认',
              closeOnClickModal: false,
              callback: (action) => {
                if (action === 'confirm' && data.noCheckNum > 0) {
                  window.open(`${process.env.VUE_APP_BASE_API}//market/tSUsualInspect/exportNoSearchData?id=${data.id}`, '_blank')
                }
              }
            })
            this.addressLoadPage()
          }, 1000)
          this.$refs.EasyTable.reset()
        }
        this.$refs.batchFile.value = ''
        this.batchFileName = ''
        this.fileImportFlag = true
      }).catch(() => {
        this.loading = false
        this.showFakeProgress = false
      })
    },
    // 批量地址核查 -- start
    // 选项变更事件
    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)
        }
      }
    },
    addressBatchSearch() {
      if (this.$util.isEmpty(this.searchForm2.dom)) {
        return this.$message.warning('请输入地址查询')
      }
      this.selection = []
      this.pageParam2.customParamMap = this.searchForm2
      this.$set(this.pageParam2, 'curPage', 1)
      // this.pageParam2.curPage = 1
      this.eBaseinfoList = []
      this.addressLoadPage()
    },
    addressLoadPage() {
      if(this.eBaseinfoList.length == 0 && this.fileImportFlag){
        this.showFakeProgress = false
        this.batchQueryDialogShow = false
        this.fileImportFlag = false
        return
      }
      if(this.eBaseinfoList.length > 0){
        console.log('222',this.eBaseinfoList)
        const list = []
        let startIndex = (this.pageParam2.curPage - 1) * this.pageParam2.pageSize
        for(let i = startIndex; i < this.eBaseinfoList.length && i < (startIndex + this.pageParam2.pageSize); i++){
          console.log(i,'222')
          this.eBaseinfoList[i].index = i+1
          this.eBaseinfoList[i].uscc = this.eBaseinfoList[i].uniscid || this.eBaseinfoList[i].regno
          list.push(this.eBaseinfoList[i])
        }

        this.addressEntList = list
        this.pageParam2.total = this.eBaseinfoList.length
        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)
              }
            }
          }
        })
        this.showFakeProgress = false
        this.batchQueryDialogShow = false
      }else{
        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 => {
            if(each.regstate == '1'){
              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)
                }
              }
            }
          })
        })
      }
    },
    // 重置搜索表单
    resetSearchForm2() {
      this.searchForm2 = {
        entertype: 'company',
        addressSearchType: 'like',
        dom: ''
      }
    },
    // 全选按钮事件
    selectAll2() {
      const table = this.$refs.addressEntList
      for (const i in table.data) {
        const each = table.data[i]
        table.toggleRowSelection(each, true)
      }
    },
    // 当前分页改变
    pageIndexChange2(curPage) {
      this.pageParam2.curPage = curPage
      this.addressLoadPage()
    },
    // 分页大小改变
    pageSizeChange2(pageSize) {
      this.pageParam2.pageSize = pageSize
      this.addressLoadPage()
    },
    exportNoCanExcel() {
      let ids = this.noCanList
      exportNoCanExcel(ids).then(res => {
        const url = window.URL.createObjectURL(res, { type: 'application/vnd.ms-excel;charset=utf-8' })
        const link = document.createElement('a')
        link.style.display = 'none'
        link.href = url
        link.setAttribute('download', '不可导入名单.xlsx')
        link.click()
      })
    },
    inputAddressSave() {
      if (this.inputAddress === '') return this.$message.warning('请输入地址')
      this.startTaskAddress()
    },
    //多条检查任务
    openManyTask(){
      if (this.selection.length === 0) return this.$message.warning('请至少选择一个企业')
      const regOrgSet = new Set()
      let userOrg = this.user.orgCode
      for (const item of this.selection) {
        if(userOrg != '440101'){
          if(userOrg.length == 6 &&  userOrg != item.suporg.substring(0,6)){
            this.$message.warning('勾选的主体的属地监管机关与检查人员所属的监管机关不一致')
            return
          }else if(userOrg.length == 8 && userOrg != item.suporg){
            this.$message.warning('勾选的主体的属地监管机关与检查人员所属的监管机关不一致')
            return
          }
        }
      }
      // // 判断当前勾选列表的待办是否都是一样的登记机关
      // if (regOrgSet.size > 1) {
      //   this.$message.warning('勾选的主体的属地监管机关与检查人员所属的监管机关不一致')
      //   return
      // }
      this.openManyDialogShow = true
    },
    startManyTask(){
      if (!this.batchInspectExpireDate) {
        this.$message.warning('请录入检查期限')
        return
      }
      if (!this.batchSource) {
        this.$message.warning('请录入来源')
        return
      }

      const form = new FormData()
      form.append('ids', this.selection.map(i => i.pripid).join(';'))
      form.append('inspectExpireDate', this.batchInspectExpireDate.join(','))
      form.append('source', this.batchSource)
      this.nextLoading = true
      this.loading = true
      startManyTask(form).then(async({ code, data, msg }) => {
        if (code !== 0) {
          this.$refs.FakeProgress.error()
          this.$message.error(msg)
          this.loading = false
        }
        if(code == 0 && data.msg){
          this.$message.warning(data.msg)
          this.nextLoading = false
          this.loading = false
          this.openManyDialogShow = false
        }else if(code == 0){
          this.nextLoading = false
          this.loading = false
          this.openManyDialogShow = false
          this.addressAbnDialog = false
          this.$refs.EasyTable.reset()
        }
      })
      // .finally(() => {
      //   this.nextLoading = false
      //   this.loading = false
      //   this.openManyDialogShow = false
      //   this.addressAbnDialog = false
      // })
    },
    // 启动待办
    startTaskAddress() {
      if (!this.selection) return this.$message.warning('请至少选择一个企业')
      if (this.selection.length === 0) return this.$message.warning('请至少选择一个企业')
      let userOrg = this.user.orgCode
      const regOrgSet = new Set()
      //const domSet = new Set()
      let canNum = 0
      let noCanNum = 0
      let noCanList = ''
      let list = []
      for (const item of this.selection) {
        if(userOrg != '440101'){
          if(userOrg.length == 6 && userOrg != item.suporg.substring(0,6)){
            this.$message.warning('勾选的主体的属地监管机关与检查人员所属的监管机关不一致')
            this.inputAddressDialogShow = false
            return
          }else if(userOrg.length == 8 && userOrg != item.suporg){
            this.$message.warning('勾选的主体的属地监管机关与检查人员所属的监管机关不一致')
            this.inputAddressDialogShow = false
            return
          }
        }
        if(item.dom.includes(this.inputAddress)){
          canNum++
          list.push(item)
        }else{
          noCanNum++
          noCanList = noCanList + item.pripid + ';'
        }
        //domSet.add(item.dom)
      }
      this.selection = list
      if(noCanNum > 0){
        console.log(this.resultAddressDialogShow,'sb000')
        this.canNum = canNum
        this.noCanNum = noCanNum
        this.noCanList = noCanList
        this.resultAddressDialogShow = true
        return
      }
      console.log(this.resultAddressDialogShow,'sb')

      // //地址判断
      // if (domSet.size > 1) {
      //   this.$message.warning('勾选的主体需是同一地址，才可以生成一条检查任务')
      //   return
      // }
      // 判断当前勾选列表的待办是否都是一样的登记机关
      if (regOrgSet.size > 1) {
        this.$message.warning('勾选的主体的属地监管机关与检查人员所属的监管机关不一致')
        this.inputAddressDialogShow = false
        return
      }
      this.inputAddressDialogShow = false
      this.batchAddressDialogShow = true
    },
    batchAddressSave() {
      if (!this.batchInspectExpireDate) {
        this.$message.warning('请录入检查期限')
        return
      }
      if (!this.batchSource) {
        this.$message.warning('请录入来源')
        return
      }

      const form = new FormData()
      form.append('ids', this.selection.map(i => i.pripid).join(';'))
      form.append('inspectExpireDate', this.batchInspectExpireDate.join(','))
      form.append('source', this.batchSource)
      form.append('checkAddress', this.inputAddress)
      this.nextLoading = true
      this.loading = true
      batchAddressSave(form).then(async({ code, data, msg }) => {
        if (code !== 0) {
          this.$refs.FakeProgress.error()
          this.$message.error(msg)
          this.loading = false
        }
        else if(code == 0 && data.msg){
          this.$message.warning(data.msg)
          this.nextLoading = false
          this.loading = false
          this.resultAddressDialogShow = false
          this.inputAddressDialogShow = false
          this.batchAddressDialogShow = false
        }else if(code == 0){
          this.nextLoading = false
          this.loading = false
          this.batchAddressDialogShow = false
          this.addressAbnDialog = false
          this.resultAddressDialogShow = false
          this.inputAddressDialogShow = false
          this.addressEntList = []
          this.$refs.EasyTable.reset()
          if(data.tips){
            this.$confirm(data.tips, '提示').then(() => {

            })
            //this.$message.warning(data.tips)
          }
        }
      })
      // .finally(() => {
      //   this.nextLoading = false
      //   this.loading = false
      //   this.batchAddressDialogShow = false
      //   this.addressAbnDialog = false
      // })
    }
    // 批量地址核查 -- end
  }
}
</script>

<style lang="scss" scoped>
.main-content{
  background: #fff;
    .btn-box{
        text-align:right;
        display: flex;
        align-items: center;
    }
    .main-body{
        .header{
            .header-label{
                font-size: 20PX;
                font-family: Microsoft YaHei, Microsoft YaHei-Bold;
                font-weight: bold;
                color: #243668;
                line-height: 32px;
            }
        }
    }
}
.search-box{
  background:#fff;
  padding: 0 10px;
  margin-bottom: 40px;
  .form{
    display: flex;
    align-items: center;
  }
  .el-row{
    margin-bottom: 10px;
  }
  .search-field{
      display:inline-block;
      width:80%;
      >p{
          margin:0 0 10px 0;
          font-family: Microsoft YaHei, Microsoft YaHei-Bold;
          color: #5e5e7a;
          font-size:16PX;
      }
  }
}
.view-mode-input .el-input__inner {
  background-color: transparent;
  border: none;
  padding-left: 0;
  cursor: default; /* 默认箭头 */
  color: inherit;
}
</style>
