﻿﻿﻿﻿﻿﻿<template>
  <div style="height:100%;width:100%;">
    <a-layout style="height:100%;width:100%;">
      <a-layout-sider theme="light" width="320px" style="border-right:2px solid #d5d5ff;float:left" :style="{ 'max-height': testHeight + 'px', 'height': testHeight + 'px' }">
        <a-button :class="tabType==1 ? 'skactive' : 'sknormal'" @click="tabChange('1')">当前数据</a-button>
        <a-button :class="tabType==2 ? 'skactive' : 'sknormal'" @click="tabChange('2')">历史数据</a-button>
        <a-button :class="tabType==0 ? 'skactive' : 'sknormal'" @click="tabChange('0')">全部数据</a-button>
        <div class="tree" style="height: calc(100% - 50px); width: 100%; overflow: auto; display: inline-flex;">
          <a-tree
            :tree-data="treeData"
            @select="treeNodeClickHandler"
            :fieldNames="{ children: 'children', title: 'pnm', key: 'id' }"
            :autoExpandParent="false"
            ref="jigou_tree"
            style="height:100%;">
            <template #title="data">
              <span style="float:left;" :title="data.pnm || data.title">
                <span v-if="data.id && data.id.length >=12">
                  <img src="../../assets/images/choucha.png" v-if="data.chkType=='0'" style="width: 25px;height:20px;float: left;" />
                  <img src="../../assets/images/zicha.png" v-if="data.chkType=='1'" style="width: 25px;height:20px;float: left;" />
                  &nbsp;
                </span>
                {{ (data.pnm || data.title) ? ((data.pnm || data.title).length>12?((data.pnm || data.title).substring(0,10))+"...":(data.pnm || data.title)):"" }}
              </span>
            </template>
          </a-tree>
        </div>
      </a-layout-sider>
      <a-layout-content id="dxdcListMainsk" style="padding:5px 20px;">
        <a-row>
          <a-col :span="24">
            <a-form layout="inline" class="demo-form-inline" style="padding-left: 10px; gap: 16px 24px;">
              <a-form-item label="督查状态" style="min-width: 23%;">
                <a-select v-model:value="dcType" placeholder="督查状态" allow-clear style="min-width: 200px;">
                  <a-select-option value="0">未督查</a-select-option>
                  <a-select-option value="1">督查中</a-select-option>
                  <a-select-option value="2">已督查</a-select-option>
                </a-select>
              </a-form-item>
              <a-form-item label="对象名称" style="min-width: 23%;">
                <a-input v-model:value="depName" placeholder="对象名称" />
              </a-form-item>
              <a-form-item label="督查时间" style="min-width: 23%;">
                <a-range-picker v-model:value="dateRange" format="YYYY-MM-DD" separator="至" allow-clear />
              </a-form-item>
              <a-form-item>
                <a-button type="primary" @click="onSubmit" size="small" >查询</a-button>
              </a-form-item>
            </a-form>
          </a-col>
        </a-row>
        <a-table
          ref="table"
          :columns="columns"
          :data-source="skDataList"
          :loading="expLoading"
          :pagination="false"
          row-key="rgstrId"
          style="width: 100%;"
          :style="{ height: tableHeight + 'px'}"
          :scroll="{x: 'max-content', y: tableHeight - 60}"
          bordered>
          <template #bodyCell="{ column, record }">
            <template v-if="column.dataIndex === 'nm'">
              <a-tooltip placement="top">
                <template #title><span>{{ record.nm }}</span></template>
                <span class="ellipsis100">{{ record.nm }}</span>
              </a-tooltip>
            </template>
            <template v-else-if="column.dataIndex === 'adName'">
              <a-tooltip placement="top">
                <template #title><span>{{ record.adName }}</span></template>
                <span class="ellipsis100">{{ record.adName }}</span>
              </a-tooltip>
            </template>
            <template v-else-if="column.dataIndex === 'loc'">
              <a-tooltip placement="top">
                <template #title><span>{{ record.loc }}</span></template>
                <span class="ellipsis100">{{ record.loc }}</span>
              </a-tooltip>
            </template>
            <template v-else-if="column.dataIndex === 'chkType'">
              <img src="../../assets/images/choucha.png" v-if="record.chkType=='0'" style="width: 25px;height:20px;float: left;" />
              <img src="../../assets/images/zicha.png" v-if="record.chkType=='1'" style="width: 25px;height:20px;float: left;" />
            </template>
            <template v-else-if="column.dataIndex === 'groupName'">
              <a-tooltip placement="top">
                <template #title><span>{{ record.groupName }}</span></template>
                <span class="ellipsis100">{{ record.groupName }}</span>
              </a-tooltip>
            </template>
            <template v-else-if="column.dataIndex === 'intm1'">
              <a-tooltip placement="top">
                <template #title><span>{{ record.intm1 }}</span></template>
                <span class="ellipsis100">{{ record.intm1 }}</span>
              </a-tooltip>
            </template>
            <template v-else-if="column.dataIndex === 'uptm'">
              <a-tooltip placement="top">
                <template #title><span>{{ record.uptm }}</span></template>
                <span class="ellipsis100">{{ record.uptm }}</span>
              </a-tooltip>
            </template>
            <template v-else-if="column.dataIndex === 'dictTypeCd'">
              <a-tooltip placement="top">
                <template #title><span>{{ formatType(record) }}</span></template>
                <span class="ellipsis100">{{ formatType(record) }}</span>
              </a-tooltip>
            </template>
            <template v-else-if="column.dataIndex === 'state'">
              <span style="padding:3px 10px;background:#F56C6C;border-radius:15px;color:#fff" v-if="record.state == 0">未督查</span>
              <span style="padding:3px 10px;background:#FBB56D;border-radius:15px;color:#fff" v-else-if="record.state == 1">督查中</span>
              <span style="padding:3px 10px;background:#63C25E;border-radius:15px;color:#fff" v-else-if="record.state == 2">已督查</span>
            </template>
            <template v-else-if="column.dataIndex === 'action'">
              <div style="display: flex;justify-content: center;" v-if="parseInt(prjType)>=615 && parseInt(prjType)<630">
                <div v-if="ownPriv('manage')">
                  <a-button size="small" type="primary" v-if="!record.rgstrId" ghost @click="toAddMember('填报',record)">填报</a-button>
                  <a-button type="primary" v-if="record.rgstrId" ghost @click="toAddMember('编辑',record)" :disabled="record.state == '2' && record.chkType!='1'">督查</a-button>
                  <a-button size="small" type="danger" v-if="record.rgstrId && record.chkType!='1'" ghost @click="submitHandler(record)" :disabled="record.state == '2'">提交</a-button>
                  <a-button size="small" type="danger" v-if="record.rgstrId && record.state == '2'" ghost @click="toCheck(record)">查看</a-button>
                  <a-button type="primary" size="small" v-if="record.rgstrId && (record.adjustState=='1' || record.adjustState=='0' || !record.adjustState)" @click="showEditDialog(record)">信息调整</a-button>
                  <a-button size="small" type="primary" @click="showRecord(record)">记录</a-button>
                </div>
                <div style="padding-left: 15px;" v-if="record.rgstrId && record.state!='2' && ownPriv('del')">
                  <a-button size="small" ghost type="danger" @click="deleteMember(record)">删除</a-button>
                </div>
              </div>
              <div style="display: flex;justify-content: center;" v-else>
                <a-button size="small" type="primary" v-if="record.rgstrId" ghost @click="toAddMember('编辑',record)" :disabled="record.state == '2'">督查</a-button>
                <a-button size="small" type="danger" v-if="record.rgstrId" ghost @click="deleteMember(record)" :disabled="record.state == '2'">删除</a-button>
                <a-button size="small" type="danger" v-if="record.rgstrId" ghost @click="submitHandler(record)" :disabled="record.state == '2'">提交</a-button>
                <a-button size="small" type="danger" v-if="record.rgstrId && record.state == '2'" ghost @click="toCheck(record)">查看</a-button>
                <a-button size="small" type="danger" v-if="record.rgstrId && record.state == '2'" ghost @click="revoke(record)">撤回</a-button>
              </div>
            </template>
          </template>
        </a-table>
        <a-pagination
          show-size-changer
          v-model:pageSize="pageSize"
          :total="total"
          :page-size-options="['10','20', '30', '40', '50','100']"
          :show-total="total => `共${total}条`"
          @showSizeChange="handleSizeChange"
          @change="pageIndexChange"
          style="margin-top: 10px;" />
      </a-layout-content>
      <commonTab
        v-if="showShuiKuTianBao"
        :rowData="rowData"
        :currentObjectRgstrId="currentObjectRgstrId"
        :currentResCode="currentResCode"
        :currentObjectId="currentObjectId"
        :currentObjectName="currentResName"
        :pType="pType"
        :openType="openType"
        :chkType="chkType"
        @cancelHandler="cancelHandler"
        @addShuiKuSuccess="addShuiKuSuccess">
      </commonTab>

      <a-modal :title="editTitle+'信息调整申请'" :open="isEditShow" width="30%" @cancel="isEditShow = false">
        <a-form :model="editForm" :label-col="{span: 8}" :wrapper-col="{span: 16}" class="demo-ruleForm" ref="editForm">
          <a-form-item label="调整方式" required>
            <a-select v-model:value="editForm.adjustWay">
              <a-select-option value="1">数据调整</a-select-option>
              <a-select-option value="2">逻辑删除</a-select-option>
            </a-select>
          </a-form-item>
          <a-form-item label="对象名称" required>
            <a-input v-model:value="editForm.nm" :disabled="true" />
          </a-form-item>
          <a-form-item label="所属地市" v-show="editForm.adjustWay=='1'" required>
            <addvSingle key="city" ref="city" @addvSelect="citySelect" :level="0"></addvSingle>
          </a-form-item>
          <a-form-item label="所属区县" v-show="editForm.adjustWay=='1'" required>
            <addvSingle key="country" ref="country" @addvSelect="countrySelect" :level="1"></addvSingle>
          </a-form-item>
          <a-form-item :label="editForm.adjustWay=='1'?'调整说明':'删除原因'" required>
            <a-textarea v-model:value="editForm.adjustRecord" />
          </a-form-item>
          <a-form-item label="相关文件">
            <a-upload
              :action="`/modular-source/6ace62b8e2bb467d98286d260aebcef2/pdcApi/file/insert?bizId=${this.bizId}&bizType=adjustment`"
              :file-list="fileList"
              :headers="header"
              @change="changeFileList"
              multiple
              class="upload-demo">
              <a-button type="primary" size="small">点击上传</a-button>
            </a-upload>
          </a-form-item>
        </a-form>
        <span slot="footer" class="dialog-footer" style="display: flex;justify-content: center;">
          <a-button @click="isEditShow = false">取 消</a-button>
          <a-button type="primary" @click="editSubmit" :disabled="isLoadingBtn">确 定</a-button>
        </span>
      </a-modal>

      <a-modal :title="editTitle + '数据调整记录'" :open="isEditRecordShow" width="40%" @cancel="isEditRecordShow = false" :footer="null">
        <span style="display: block;max-height:500px;overflow:auto;padding: 20px">
          <a-timeline v-if="activities && activities.length>0">
            <a-timeline-item v-for="(activity, index) in activities" :key="index" color="#3fa4ff">
              <p style="font-size: 18px;font-weight: bold;">{{ activity.timestamp }}</p>
              <p style="font-size: 18px;">{{ activity.title }}</p>
              <p style="font-size: 15px;">{{ activity.detail }}</p>
            </a-timeline-item>
          </a-timeline>
          <div style="width:100%;height:100%;display: flex;align-items: center;justify-content: center;font-size: 20px;font-weight: bold" v-else>无记录</div>
        </span>
      </a-modal>
    </a-layout>
    <!-- 添加/编辑人员弹窗 -->

    <!-- 上传模板弹窗 -->
    <shuiku-tian-bao-pl
      v-if="showShuiKuTianBaoPl"
      :showShuiKuTianBaoPl="showShuiKuTianBaoPl"
      :id="currentNodeId"
      @closePlDialog="closePlDialog"></shuiku-tian-bao-pl>
    <!-- 水库信息查看 -->
    <rsvr-info
      :currentObjectRgstrId="currentObjectRgstrId"
      :currentResCode="currentResCode"
      :currentObjectId="currentObjectId"
      :currentObjectName="currentResName"
      :isJiangXi="isJiangXi"
      v-if="showDuchaDetails"
      @cancelHandler="closeInfoDialog"></rsvr-info>
    <!-- 水库督查信息 -->
    <popupSk
      ref="xskTianBaoRef"
      v-if="xskInfoDialog"
      :currentDuchaTpe="currentDuchaTpe"
      :currentObjectRgstrId="xskRgstrId"
      :currentResCode="currentRsCode"
      :currentObjectId="currentObjId"
      :currentObjectName="currentRsName"
      @cancelHandler="skCancelHandler">
    </popupSk>
  </div>
</template>

<script>
import { getList_sxzzf } from '../../api/duChaTianBao.js';
import { curAdcode_long, curAdcode_short } from '../../utils/global_variable';
import request from '../../utils/gw_ajax_request.js';
import { dateFormat } from '../../utils/gw_date.js';
import { exportModel } from '../../utils/gw_exportModel';
import addvSearch from '../../widgets/addvSearch.vue';
import addvSingle from '../../widgets/addvSingle.vue';
import provTreeList from '../../widgets/provTreeList.vue';
import commonTab from '../duChaTianBao/commonTab.vue';
export default {
  components: {
    provTreeList: provTreeList,
    commonTab: commonTab,
    addvSearch,
    addvSingle,
  },
  data() {
    return {
      commonType: [],
      openType: false,
      chkType: '',
      tabType:
        localStorage.getItem('currentRlcode') == '350000000000' ? '1' : '0', // 0全部数据，1当前数据，2历史数据
      dateRange: [],
      lyjg: [],
      header: {
        persId: localStorage.getItem('persId'),
        accessToken: localStorage.getItem('accessToken'),
      },
      utTypeL: [
        { id: '1', name: '企业' },
        { id: '2', name: '机关' },
        { id: '3', name: '学校' },
        { id: '4', name: '2019整改' },
        { id: '5', name: '政府机关' },
      ],
      utPptL: [
        { id: '1', name: '节水型' },
        { id: '2', name: '非节水型' },
      ],
      depName: '',
      // prjType: this.$route.params.type,
      prjType: this.$route.path.substring(this.$route.path.length - 3),
      wintCode: '',
      engScale: '',
      orgName: '',
      groupName: '',
      groupId: '',
      groups: [],
      // sttm:'',
      // ettm:'',
      adName: '',
      treeData: [],
      dxdcMainHeight: window.innerHeight - 304,
      testHeight: window.innerHeight - 111,
      skDataList: [],
      pageIndex: 1,
      pageSize: 20,
      total: 0,
      tableHeight: 0,
      currentResCode: '',
      currentResName: '',
      currentObjectId: '',
      currentObjectRgstrId: '',
      currentObjectInfoObject: null,
      showShuiKuTianBao: false,
      currentAdCode: '',
      currentNodeId: '',
      rsvrName: '',
      dcType: '',
      rowData: '',
      disabled: true,
      showShuiKuTianBaoPl: false,
      downIcon: 'el-icon-download',
      expLoading: false,
      //
      repeatId: '',
      showDuchaDetails: false,
      zerenrenLabel: '"三个责任人"落实情况',
      pType: 111,
      fillTableData: [], // 根据不同省份赋值
      xskInfoDialog: false,
      currentDuchaTpe: false,
      currentRsCode: '',
      xskRgstrId: '',
      currentObjId: '',
      currentRsName: '',
      endTime: '',
      curTime: new Date().getTime(),
      flage: false,
      isEditShow: false,
      isEditRecordShow: false,
      editForm: {
        objId: '',
        nm: '',
        adjustWay: '',
        adCode: '',
        newAdCode: '',
        adjustRecord: '',
        type: '',
      },
      editTitle: '',
      activities: [],
      isLoadingBtn: false,
      bizId: '',
      fileList: [],
      fileCount: 0,
      columns: [
        {
          title: '对象名称',
          dataIndex: 'nm',
          width: 100,
          align: 'center',
        },
        {
          title: '行政区划',
          dataIndex: 'adName',
          width: 100,
          align: 'center',
        },
        {
          title: '位置',
          dataIndex: 'loc',
          width: 100,
          align: 'center',
        },
        {
          title: '督查分类',
          dataIndex: 'chkType',
          width: 100,
          align: 'center',
        },
        {
          title: '所在组',
          dataIndex: 'groupName',
          width: 100,
          align: 'center',
        },
        {
          title: '督查时间',
          dataIndex: 'intm1',
          width: 100,
          align: 'center',
        },
        {
          title: '更新时间',
          dataIndex: 'uptm',
          width: 100,
          align: 'center',
        },
        {
          title: '督查类别',
          dataIndex: 'dictTypeCd',
          width: 100,
          align: 'center',
        },
        {
          title: '督查状态',
          dataIndex: 'state',
          width: 100,
          align: 'center',
        },
      ],
    };
  },
  computed: {
    persId() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '1098101939614724096';
    },
    isAdmin: () =>
      localStorage.getItem('isAdmin') ? localStorage.getItem('isAdmin') : '',
    currentRlcode() {
      return localStorage.getItem('currentRlcode')
        ? localStorage.getItem('currentRlcode')
        : '';
    },
    isJiangXi() {
      return this.currentRlcode.indexOf('36') == '0';
    },
    curAdcode_short() {
      return curAdcode_short;
    },
    curAdcode_long() {
      return curAdcode_long;
    },
  },
  created() {
    console.log(this.prjType, 'prjType');
    this.getCommonDict();
    if (this.ownPriv('manage')) {
      this.columns.push({
        title: '操作',
        dataIndex: 'action',
        width: 450,
        fixed: 'right',
        align: 'center',
      });
    }
  },
  mounted() {
    this.getSkDataList();
    this.getAllGroup();
    this.$nextTick(function () {
      this.tableHeight =
        window.innerHeight - this.$refs.table.$el.offsetTop - 10;
      window.onresize = () => {
        this.tableHeight =
          window.innerHeight - this.$refs.table.$el.offsetTop - 10;
      };
      this.getLeftTreeData();
      this.currentNodeId = '';
      this.rsvrName = '';
      this.dcType = '';
      this.getSkDataList();
    });
  },
  // activated () {
  //   console.log('activated')
  //   this.getLeftTreeData()
  //   this.currentNodeId = ''
  //   this.rsvrName = ''
  //   this.dcType = ''
  //   this.getSkDataList()
  // },
  watch: {
    currentNodeId(n, o) {
      this.getSkDataList();
    },
    groupName(n, o) {
      if (n == '') {
        this.groupId = '';
      }
    },
    endTime(n, o) {
      this.flage = this.endTime
        ? eval(this.endTime) < eval(this.curTime)
        : false;
    },
    $route(n, o) {
      this.prjType = n.path.substring(n.path.length - 3);
      this.getLeftTreeData();
      this.currentNodeId = '';
      this.rsvrName = '';
      this.dcType = '';
      this.getSkDataList();
    },
  },
  methods: {
    showRecord(row) {
      this.editTitle = row.nm;
      this.isEditRecordShow = true;
      this.activities = [];
      var params = {
        objId: row.objId,
      };
      request
        .post('/bis/insp/gnrlRgstrAdjust/findDtoList', params)
        .then((res) => {
          if (res.success) {
            if (res.data && res.data.length > 0) {
              var data = res.data;
              var dataList = [];
              data.forEach((item) => {
                var updateContent = item.detail;
                item.auditList.forEach((item1) => {
                  var date = new Date(item1.intm);
                  var timestamp =
                    date.getFullYear() +
                    '年' +
                    (date.getMonth() + 1) +
                    '月' +
                    date.getDate() +
                    '日';
                  dataList.push({
                    title: item1.roleName + '-' + item1.auditPersName,
                    timestamp: timestamp,
                    detail: item1.opStatus + ',' + updateContent,
                  });
                });
                // var date = new Date(item.time);
                // item.timestamp = date.getFullYear()+"年"+(date.getMonth()+1)+"月"+date.getDate()+"日";
                // if(item.auditWay){
                //     item.title = "业务处室审核";
                //     item.detail = item.auditWay=="1"?("同意,"+item.detail):("驳回,"+item.detail)
                // }else{
                //     item.title = item.adjustWay=="1"?"督查单位提交申请-信息调整":"督查单位提交申请-删除";
                // }
              });
              this.activities = dataList;
            }
          } else {
            this.$message.error(res.message);
          }
        })
        .catch((res) => {
          this.$message.error('请求错误' + res.message);
        });
    },
    editSubmit() {
      if (!this.editForm.adjustWay) {
        this.$message.warning('请选择调整方式');
        return;
      }
      if (this.editForm.adjustWay == '1') {
        if (!this.editForm.adCode) {
          this.$message.warning('所属地市、区县不能为空');
          return;
        }
        if (this.editForm.newAdCode == this.editForm.adCode) {
          this.$message.warning('修改的行政区划不能跟当前区划一致');
          return;
        }
        if (!this.editForm.adjustRecord) {
          this.$message.warning('请输入调整说明');
          return;
        }
      }
      if (this.editForm.adjustWay == '2') {
        this.editForm.newAdCode = '';
        if (!this.editForm.adjustRecord) {
          this.$message.warning('请输入删除原因');
          return;
        }
      }
      this.isLoadingBtn = true;
      request
        .post('/bis/insp/gnrlRgstrAdjust', this.editForm)
        .then((res) => {
          if (res.success) {
            this.bizId = res.data.id;
            console.log(this.bizId, 'bizId');
            if (this.fileList.length > 0) {
              this.$nextTick(() => {
                this.$refs.adjustment.submit();
              });
            }
            this.isEditShow = false;
            this.isLoadingBtn = false;
            this.$message.success('申请已提交');
            this.getSkDataList();
          } else {
            this.$message.error(res.message);
          }
        })
        .catch((res) => {
          this.$message.error('请求错误' + res.message);
        });
    },
    changeFileList({ fileList }) {
      // console.log(file, '111')
      this.fileList = fileList;
    },
    // removeFileList (file, fileList) {
    //   this.fileList = fileList
    // },
    // init () {
    //   this.bizId = ''
    //   this.$refs.adjustment.clearFiles()
    //   this.fileCount = 0
    //   this.fileList = []
    // },
    // uploadSuccess (response, file, fileList) {
    //   this.fileCount++
    //   if (this.fileCount == this.fileList.length) {
    //     this.init()
    //   }
    // },
    // upError (err, file, fileList) {
    //   this.$message.error('上传出错，请修改文件！')
    //   this.init()
    // },
    citySelect(obj) {
      this.$refs.country.getAdDataList(obj);
      this.$refs.country.setCheck('', '');
      this.editForm.newAdCode = obj;
    },
    countrySelect(obj) {
      this.editForm.newAdCode = obj;
    },
    showEditDialog(row) {
      this.isLoadingBtn = false;
      this.editTitle = row.nm;
      this.editForm.nm = row.nm;
      this.editForm.objId = row.objId;
      this.editForm.adCode = row.adCode;
      this.editForm.newAdCode = row.adCode;
      // this.editForm.type = this.$route.params.type
      this.editForm.type = this.$route.path.substring(
        this.$route.path.length - 3,
      );
      this.editForm.adjustWay = '1';
      this.editForm.adjustRecord = '';
      this.isEditShow = true;
      var cityCode = '';
      var countryCode = '';
      if (row.adCode.indexOf('00000000') > -1) {
        cityCode = row.adCode;
        this.editForm.adCode = cityCode;
      } else {
        cityCode = row.adCode.substring(0, 4) + '00000000';
        countryCode = row.adCode;
        this.editForm.adCode = countryCode;
      }
      this.$nextTick(() => {
        this.$refs.city.getAdDataList();
        this.$refs.city.setCheck(cityCode, row.city);
        this.$refs.country.getAdDataList(cityCode);
        this.$refs.country.setCheck(countryCode, row.country);
      });
    },
    getCommonDict() {
      request
        .get('/dict/type/by/gnrl')
        .then((res) => {
          if (res.success) {
            this.commonType = res.data;
          } else {
            this.$message.error(res.message);
          }
        })
        .catch((res) => {
          this.$message.error('请求错误' + res.message);
        });
    },
    tabChange(tabType) {
      this.tabType = tabType;
      this.currentNodeId = '';
      this.getAllGroup();
      this.getLeftTreeData();
      this.getSkDataList();
    },
    // 获取所有的组
    getAllGroup() {
      request
        .get('/dc/user/getGroupByPersid', {
          params: { persid: this.persId, ptype: '111', tabType: this.tabType },
        })
        .then((res) => {
          if (res.success) {
            this.groups = res.data;
          }
        });
    },
    querySearchAsync(queryString, cb) {
      var restaurants = this.groups;
      var results = queryString
        ? restaurants.filter(this.createStateFilter(queryString))
        : restaurants;

      clearTimeout(this.timeout);
      this.timeout = setTimeout(() => {
        cb(results);
      }, 1500 * Math.random());
    },
    createStateFilter(queryString) {
      return (state) => {
        return state.nm.toLowerCase().indexOf(queryString.toLowerCase()) != -1;
      };
    },
    handleSelect(item) {
      console.log(item);
      this.groupId = item.id;
    },
    getLeftTreeData() {
      this.lyjg = [];
      request
        .get('/dc/organization/base/getAllNode', {
          params: {
            userId: this.persId,
            orgType: '111',
            tabType: this.tabType,
          },
        })
        .then((res) => {
          let data = res.data;
          data.forEach((ele) => {
            if (ele.pid == null || ele.pid == '') {
              ele.pid = '111';
            }
            if (ele.id.length == 6) {
              this.lyjg.push(ele);
            }
          });
          data = this.getTrees(data);
          this.treeData = data;
          this.endTime = data[0]['entm'];
        });
    },
    // 格式化树形数据
    getTrees(list) {
      // @wxcwater重写方法 适应多个树
      let highLevelLength = 99; // 预设最大节点id长度，目前最大应该为12，所以设置为99保证正常
      list.forEach((item, index) => {
        item['pidLength'] = item.pid && item.pid != '' ? item.pid.length : 0;
        if (highLevelLength > item.pidLength) {
          highLevelLength = item.pidLength;
        }
      });
      console.log(highLevelLength);
      const heightLevelNode = [];
      list.forEach((item, index) => {
        if (highLevelLength >= item.pidLength) {
          heightLevelNode.push(item);
        }
      });

      list.forEach((item, index) => {
        heightLevelNode.forEach((pItem) => {
          this.addTreeNode(pItem, item);
        });
      });
      console.log(heightLevelNode);
      return heightLevelNode;
    },

    addTreeNode: function (treeNode, leafNode) {
      if (!Object.hasOwn(treeNode, 'children')) {
        treeNode['children'] = [];
      }
      if (leafNode.pid == treeNode.id) {
        treeNode.children.push(leafNode);
        return;
      }
      treeNode.children.forEach((item) => {
        this.addTreeNode(item, leafNode);
      });
    },
    treeNodeClickHandler: function (data, node, tree) {
      this.endTime = data['entm'];
      this.currentNodeId = data.id;
    },
    provTreeSelectChangeHandler: function (params) {
      this.currentAdCode = params.likeCode;
      this.getSkDataList();
    },
    formatDate(row, column) {
      if (row.uptm) {
        return dateFormat(row.uptm, 'yyyy-MM-dd');
      }
    },
    formatType(row, column) {
      if (row.type) {
        var obj = this.commonType.find((obj) => obj.dictTypeCd == row.type);
        if (obj) {
          return obj.dictTypeDesc;
        }
      }
      return '';
    },
    formatEngScal(row, column) {
      const engScal = row.engScal;
      let _engScal = '其他';
      switch (engScal) {
        case '1':
          _engScal = '大（1）型';
          break;
        case '2':
          _engScal = '大（2）型';
          break;
        case '3':
          _engScal = '中型';
          break;
        case '4':
          _engScal = '小（1）型';
          break;
        case '5':
          _engScal = '小（2）型';
          break;
        case '9':
          _engScal = '其他';
          break;
      }
      return _engScal;
    },
    getSkDataList: function () {
      let paramStartDate = '';
      let paramEndDate = '';
      if (
        this.dateRange &&
        this.dateRange.length > 1 &&
        this.dateRange[0] != '' &&
        this.dateRange[1] != ''
      ) {
        paramStartDate = this.dateRange[0];
        paramEndDate = this.dateRange[1];
      }
      const params = {
        prjType: this.prjType,
        presId: this.persId,
        pType: '111',
        pageSize: this.pageSize,
        pageNum: this.pageIndex,
        plnaId: this.currentNodeId,
        groupId: this.groupId, // 分组
        state: this.dcType,
        nm: this.depName,
        adName: this.adName,
        sttm: paramStartDate,
        entm: paramEndDate,
      };
      request.post(`/dc/insp/rsvrRgstr/list/type`, params).then((res) => {
        if (res.success) {
          res.data.list.forEach((item) => {
            if (item.intm) {
              item.intm1 = dateFormat(item.intm, 'yyyy-MM-dd');
            }
          });
          this.skDataList = res.data.list;
          this.total = res.data.total;
          // this.$nextTick(() => {
          // this.$refs.table.doLayout()
          // })
        }
      });
      // let paramsData = {
      //   'presId': this.persId,
      //   "pType": "110",
      //   "pageSize": this.pageSize,
      //   'pageNum': this.pageIndex,
      //   'id': this.currentNodeId,
      //   'nm': this.depName,
      //   'state': this.dcType,
      //   'adName': this.adName,
      //   'sttm': paramStartDate,
      //   'entm': paramEndDate,
      //   'riverId': this.orgName,
      //   'wintCode': this.wintCode,
      //   'groupId': this.groupId,
      //   'tabType': this.tabType
      // }
      // if(this.currentRlcode.indexOf('36') == '0'){
      //   paramsData['repeatId'] = this.repeatId
      // }
      // getList_sxzzf(paramsData).then(
      //   (res) => {
      //     console.log(res);
      //     res.data.list.forEach((item)=>{
      //       if(item.intm){
      //         item.intm1 = dateFormat(item.intm,'yyyy-MM-dd');
      //       }
      //     })
      //     this.skDataList = res.data.list;
      //     this.total = res.data.total;
      //       this.$nextTick(() => {
      //           this.$refs.table.doLayout();
      //       });
      //   }
      // );
    },
    onSubmit() {
      this.getSkDataList();
    },
    skCancelHandler() {
      this.xskInfoDialog = false;
    },
    toCheck(rowData) {
      this.rowData = rowData;
      // ;
      console.log(rowData, '1');
      // getrgstrIdObject(rowData.code,rowData.objId,_self.pageIndex).then(
      //   (res) =>{
      //     console.log(res);
      this.currentResCode = this.rowData.code;
      this.currentObjectId = this.rowData.objId;
      this.currentObjectRgstrId = this.rowData.rgstrId;
      this.currentResName = this.rowData.nm;
      this.showShuiKuTianBao = true;
      this.openType = false;
      this.chkType = this.rowData.chkType;
      this.$nextTick(() => {
        if (this.$refs['xskTianBaoRef']) {
          this.$refs['xskTianBaoRef'].showDialog();
        }
      });
    },
    toAddMember(type, rowData) {
      console.log(rowData, '2');
      this.rowData = rowData;
      this.currentResCode = this.rowData.code;
      this.currentObjectId = this.rowData.objId;
      this.currentObjectRgstrId = this.rowData.rgstrId;
      this.currentResName = this.rowData.nm;
      this.showShuiKuTianBao = true;
      this.openType = true;
      this.chkType = this.rowData.chkType;
    },
    cancelHandler() {
      this.showShuiKuTianBao = false;
      this.getSkDataList();
    },
    addShuiKuSuccess() {
      this.getSkDataList();
    },
    deleteMember(obj) {
      this.$confirm({
        title: '提示',
        content: '此操作将督查对象从列表中删除，确认删除该对象吗？',
        okType: 'warning',
        onOk: () => {
          request
            .get(
              `/supervision/plan/cleanObjDataByObjId?objType=111&objId=${obj.objId}`,
            )
            .then((res) => {
              if (res.success) {
                this.pageIndexChange();
                this.$message.success('删除成功');
              } else {
                this.$message.error(res.message);
              }
            });
        },
      });
    },
    revoke(rowData) {
      this.$confirm({
        title: '提示',
        content: '确定要撤销当前信息吗？',
        okType: 'warning',
        onOk: () => {
          const formObj = {
            rgstrId: rowData.rgstrId,
            state: '1',
          };
          request.post('/bis/insp/gnrl', formObj).then((res) => {
            if (res.success) {
              this.addShuiKuSuccess();
              this.$message.success('提交成功');
            } else {
              this.cancelHandler();
            }
          });
        },
      });
    },
    submitHandler(rowData) {
      this.$confirm({
        title: '提示',
        content: '请确认所有信息填报完毕？',
        okType: 'warning',
        onOk: () => {
          const formObj = {
            rgstrId: rowData.rgstrId,
            state: '2',
          };
          request.post('/bis/insp/gnrl', formObj).then((res) => {
            if (res.success) {
              request
                .get('/dc/insp/pblm/submit/updateState/' + rowData.objId)
                .then((res) => {
                  if (res.success) {
                    this.addShuiKuSuccess();
                    this.$message.success('提交成功');
                  } else {
                    this.cancelHandler();
                  }
                });
            } else {
              this.cancelHandler();
            }
          });
        },
      });
    },
    pageIndexChange(val) {
      console.log(val);
      this.pageIndex = val;
      this.getSkDataList();
    },
    handleSizeChange(size, val) {
      this.pageSize = val;
      this.getSkDataList();
    },
    // 下载填报模板
    async downloadTemplate() {
      const url =
        '/pdcApi/dc/impExcel/downloadTemplate/sk?userId=' +
        this.persId +
        '&id=' +
        this.currentNodeId;
      const downloadName = '小水库填报模板.xls';
      const type = 'get';
      await exportModel(type, url, downloadName);
      this.disabled = false;
    },
    showPlDialog() {
      this.showShuiKuTianBaoPl = true;
    },
    closePlDialog(val) {
      this.showShuiKuTianBaoPl = false;
    },
    // 新需求  点击复查显示以前的督查信息
    toShowDuchaDetail(row) {
      console.log(row, '3');
      this.currentResCode = row.code;
      this.currentObjectId = row.objId;
      this.currentObjectRgstrId = row.rgstrId;
      this.currentResName = row.nm;
      this.showDuchaDetails = true;
    },
    closeInfoDialog() {
      this.showDuchaDetails = false;
    },
    // 加入复查
    joinRecheck(row) {
      const data = {
        regerId: row.rgstrId,
        type: '111',
      };
      this.$confirm({
        title: '提示',
        content: '确定加入复查吗？',
        okType: 'warning',
        onOk: () => {
          request
            .post(`/bis/insp/repeat/check/log`, data)
            .then((res) => {
              if (res.success) {
                this.$message.success('已加入复查');
                this.getSkDataList();
              } else {
                this.$message.error(res.message);
              }
            })
            .catch((err) => {
              this.$message.error(err.message);
            });
        },
      });
    },
  },
};
</script>

<style lang='less' scoped>
/deep/ .ant-layout-sider,
/deep/ .ant-layout-content {
  background: #fff;
}
.skactive {
  background: #3f8eff !important;
  color: white !important;
  margin-top: 5px;
  margin-bottom: 5px;
}

.sknormal {
  background: white;
  margin-top: 5px;
  margin-bottom: 5px;
}

.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  background: #f0f9eb;
}

#dxdcListMainsk {
  overflow-y: hidden;
}
/deep/ .ant-table-pagination {
  float: left;
}

/deep/ .ant-layout-sider,
/deep/ .ant-layout-content {
  background: #fff;
}

/deep/ .ant-table-thead>tr>th,
/deep/ .ant-table-tbody>tr>td {
  padding: 0;
  height: 60px;
}

.ellipsis200 {
  display: block;
  width: 198px;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

.ellipsis120 {
  display: block;
  width: 118px;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

.ellipsis100 {
  display: block;
  width: 98px;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

/deep/ .ant-table-scroll {
  position: relative;
  z-index: 1;
}

/deep/.ant-table-fixed-left,
/deep/ .ant-table-fixed-right {
  z-index: 2;
}
</style>
