﻿<template>
  <a-form :model="queryParams" layout="inline" ref="searchForm" style="row-gap: 8px;">
    <a-form-item label="问题编号">
      <a-input v-model:value="queryParams.fileNoNumber" placeholder="问题编号或范围值(如:1-100)" allow-clear />
    </a-form-item>
    <a-form-item label="工程名称">
      <a-input v-model:value="queryParams.nm" placeholder="请输入工程名称" allow-clear />
    </a-form-item>
    <a-form-item label="问题来源">
      <a-input v-model:value="queryParams.pblmSource" placeholder="请输入问题来源" allow-clear />
    </a-form-item>
    <a-form-item label="印发文件名">
      <a-input v-model:value="queryParams.zgMemo" placeholder="请输入问题印发文件名" allow-clear />
    </a-form-item>
    <a-form-item label="责任处室">
      <a-input v-model:value="queryParams.dutyDept" placeholder="请输入责任处室（单位）" allow-clear />
    </a-form-item>
    <a-form-item label="问题归类">
      <a-input v-model:value="queryParams.objType" placeholder="请输入问题归类" allow-clear />
    </a-form-item>
    <a-form-item label="申诉审核状态">
      <a-select v-model:value="stat" allow-clear>
        <a-select-option value="0">未申诉</a-select-option>
        <a-select-option value="2">申诉成功</a-select-option>
        <a-select-option value="4">开启通道</a-select-option>
        <a-select-option value="3">驳回</a-select-option>
        <a-select-option value="4002">整改单位审核人复核</a-select-option>
        <a-select-option value="4003">市级经办人审核</a-select-option>
        <a-select-option value="4004">市级审核人审核</a-select-option>
        <a-select-option value="4005">监督处经办人初审</a-select-option>
        <a-select-option value="4006">监督处审核人归档审核</a-select-option>
        <a-select-option value="4007">厅业务处经办人审核</a-select-option>
        <a-select-option value="4008">厅业务处审核人复核</a-select-option>
        <a-select-option value="4010">监督处经办人归档复核</a-select-option>
      </a-select>
    </a-form-item>
    <a-button
        ref="queryButton"
        @click="exportExcel"
        :loading="loading"
        type="primary"
        style="color:rgba(255,255,255,1);float:right;margin-right:10px;z-index: 1;">导出</a-button>
    <a-button
      ref="queryButton"
      @click="queryByParams"
      
      :loading="loading"
      type="primary"
      style="color:rgba(255,255,255,1);float:right;margin-right:10px;z-index: 1;">查询</a-button>
  </a-form>
</template>

<script>
import moment from 'moment';
import request from '../../../utils/gw_ajax_request';
import { exportModel } from '../../../utils/gw_exportModel';
import commonUploadAutoSimple from '../../../widgets/common-upload-auto-simple.vue';
import {
  getDuChaResource,
  getDuChaYears,
  getDutyDept,
  getOrgTreeJson,
  getRectifyProcStates1,
} from '../Common/rectify_api.js';

export default {
  props: {
    showRectifyStatus: {
      type: Boolean,
      default: true,
    },
    showZgXianOrgId: {
      type: Boolean,
      default: true,
    },
    showInspPblmCate: {
      type: Boolean,
      default: false,
    },
    loading: {
      type: Boolean,
      default: false,
    },
    showAd: {
      type: Boolean,
      default: true,
    },
    isView: {
      type: Boolean,
      default: false,
    },
    isYears: {
      type: Boolean,
      default: false,
    },
    isSjdw: {
      type: Boolean,
      default: false,
    },
    isShowImport: {
      type: Boolean,
      default: false,
    },
    isAppeal: {
      type: Boolean,
      default: false,
    },
    isDataScreen: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      currentRange: [],
      pblmSourceArr: [],
      ywcsList: [],
      workflowStats: [],
      stat: '',
      queryParams: {
        fileNoNumber: '',
        nm: '',
        pblmSource: '',
        zgMemo: '',
        dutyDept: '',
        objType: '',
        stat: '',
        workflowStat: '',
      },
      rectifyProcStates: getRectifyProcStates1(), // 整改流程所有流程状态
      duChaTypes: [],
      sourceList: [],
      DuChaYears: getDuChaYears(),
      rectifyUnits: [],
      headsList: [
        { lable: '编号', value: 'fileNoNumber[编号]' },
        { lable: '问题', value: 'inspPblmDesc[问题]' },
        { lable: '问题详情', value: 'problemDetails[问题详情]' },
        { lable: '问题来源', value: 'pblmSource[问题来源]' },
        { lable: '问题来源时间', value: 'pblmSourceTm[问题来源时间]' },
        { lable: '工程名称', value: 'nm[工程名称]' },
        { lable: '设区市/直管县', value: 'upAdName[设区市/直管县]' },
        { lable: '县（市、区）', value: 'adName[县（市、区）]' },
        { lable: '问题印发文号', value: 'zgWjName[问题印发文号]' },
        { lable: '问题印发文件名', value: 'zgMemo[问题印发文件名]' },
        { lable: '问题印发时间', value: 'issuedTm[问题印发时间]' },
        { lable: '责任处室', value: 'dutyDept[责任处室]' },
        { lable: '问题归类', value: 'objType[问题归类]' },
        { lable: '整改要求', value: 'pblmSggtn[整改要求]' },
        // {lable:'初始整改时限',value:'firstZgTm[初始整改时限]'},
        { lable: '问题是否已销号', value: 'isPblmDel[问题是否已销号]' },
        { lable: '销号时间', value: 'isPdTm[销号时间]' },
        { lable: '是否按期销号', value: 'isPdSche[是否按期销号]' },
        { lable: '最新申请延期月份', value: 'psDlyTm[最新申请延期月份]' },
        { lable: '申请销号日期', value: 'applyPdTm[申请销号日期]' },
        { lable: '提交业务处室日期', value: 'applyFfcTm[提交业务处室日期]' },
        {
          lable: '当前要求整改完成时限',
          value: 'zgDate[当前要求整改完成时限]',
        },
        { lable: '年度初始整改时限', value: 'nlZgDate[年度初始整改时限]' },
        {
          lable: '整改工作开展情况（由各地填报，需具体描述）',
          value: 'zgDevelopment[整改工作开展情况（由各地填报，需具体描述）]',
        },
        {
          lable: '业务处室、单位不同意销号原因',
          value: 'deptagePdEln[业务处室、单位不同意销号原因]',
        },
        {
          lable: '重新明确整改要求（如有，由业务处室、单位填写）',
          value:
            'zgRedefineReq[重新明确整改要求（如有，由业务处室、单位填写）]',
        },
        { lable: '整改描述', value: 'zgZgxx[整改描述]' },
        { lable: '备注', value: 'note[备注]' },
        { lable: '整改时限延期说明', value: 'zgDelayEln[整改时限延期说明]' },
        { lable: '整改状态', value: 'workflowStat[整改状态]' },
        { lable: '问题超期次数', value: 'overdueCount[问题超期次数]' },
        { lable: '问题超期整改记录', value: 'overdueRecord[问题超期整改记录]' },
        { lable: '申请销号次数', value: 'auditTotal[申请销号次数]' },
        // {lable:'调度年份',value:'schdYear[调度年份]'},
        // {lable:'问题被通报次数',value:'informedNum[问题被通报次数]'},
        // {lable:'编号',value:'fileNoNumber[编号]'},
        // {lable:'问题详情',value:'inspPblmDesc[问题详情]'},
        // {lable:'问题来源',value:'pblmSource[问题来源]'},
        // {lable:'问题来源时间',value:'pblmSourceTm[问题来源时间]'},
        // {lable:'工程名称',value:'nm[工程名称]'},
        // {lable:'行政划区编码',value:'adCode[行政划区编码]'},
        // {lable:'设区市/直管县',value:'upAdName[设区市/直管县]'},
        // {lable:'行政划区名称',value:'adName[行政划区名称]'},
        // {lable:'问题印发文号',value:'zgWjName[问题印发文号]'},
        // {lable:'问题印发文件名',value:'zgMemo[问题印发文件名]'},
        // {lable:'问题印发时间',value:'issuedTm[问题印发时间]'},
        // {lable:'责任处室',value:'dutyDept[责任处室]'},
        // {lable:'问题归类',value:'objType[问题归类]'},
        // {lable:'整改要求',value:'pblmSggtn[整改要求]'},
        // {lable:'预计整改完成时间',value:'expectedZgDate[预计整改完成时间]'},
        // {lable:'当前要求整改完成时限',value:'zgDate[当前要求整改完成时限]'},
        // {lable:'问题是否已销号',value:'isPblmDel[问题是否已销号]'},
        // {lable:'销号时间',value:'isPdTm[销号时间]'},
        // {lable:'初始整改时限',value:'firstZgTm[初始整改时限]'},
        // {lable:'是否按期销号',value:'isPdSche[是否按期销号]'}
        // {lable:'编号',value:'fileNoNumber[编号]'},
        // {lable:'问题描述',value:'pblmDescBz[问题描述]'},
        // {lable:'问题来源',value:'pblmSource[问题来源]'},
        // {lable:'工程名称',value:'rsName[工程名称]'},
        // {lable:'市',value:'city[市]'},
        // {lable:'区/县',value:'country[区/县]'},
        // {lable:'印发文号',value:'zgWh[印发文号]'},
        // {lable:'印发文件名',value:'zgWjName[印发文件名]'},
        // {lable:'整改截止日期',value:'zgDate[整改截止日期]'},
        // {lable:'预计完成日期',value:'expectedZgDate[预计完成日期]'},
        // {lable:'整改状态',value:'workflowStat1[整改状态]'},
        // {lable:'实际完成整改日期',value:'finishDate[实际完成整改日期]'},
        // {lable:'是否销号',value:'workflowStat2[是否销号]'},
        // {lable:'责任处室',value:'yewsName[责任处室]'},
        // {lable:'问题归类',value:'pTypeName[问题归类]'},
      ],
      dialogFormVisible: false,
      importVisible: false,
      errorList: [],
      isOpen: false,
      isYear: null,
      moment,
      processType: '', // 流程类型
      dataScreenVisible: false, // 控制数据筛查按钮弹窗
      dataScreenList: [],
      dataScreenLoading: false,
      readOnlyRole: localStorage.getItem('readOnlyRole'),
    };
  },
  components: {
    commonUploadAutoSimple,
  },
  created() {
    console.log(this.isDataScreen, 'isDataScreen');
    this.getDuChaTypes();
    this.getDutyDept();
    this.getDuChaResource();
    this.rectifyUnits = this.getOrgTreeJson();
  },
  methods: {
    onChange() {
      this.isOpen = false;
      this.isYear = null;
    },
    handYearChange(open) {
      if (open) {
        this.isOpen = true;
      } else {
        this.isOpen = false;
      }
      this.timer = setTimeout(() => {
        this.dateYearDisabledRule();
      }, 0);
    },
    dateYearDisabledRule(type, value) {
      const typeR = type ? type : 'lteNow';
      const valueR = value ? moment(value).format('YYYY') : '';
      //获取dom元素
      const tableDom = document.querySelectorAll(
        '.ant-calendar-year-panel-body',
      );
      const prevBtn = document.querySelector(
        '.ant-calendar-year-panel-prev-decade-btn',
      );
      const nextBtn = document.querySelector(
        '.ant-calendar-year-panel-next-decade-btn',
      );
      const tdDom = tableDom[0].querySelectorAll('td');
      // 当前面板的第一个和最后一个年份类似年份翻页按钮因此和年份翻页按钮做相同处理，否则会有错误
      const prevBtnTd = tdDom[0];
      const nextBtnTd = tdDom[tdDom.length - 1];
      //定义所需对比值
      const nowDate = moment().format('YYYY');
      if (tableDom.length > 0) {
        switch (typeR) {
          //<=当前年
          case 'lteNow':
            (() => {
              tdDom.forEach((item) => {
                if (item.innerText < '2021') {
                  item.setAttribute('class', 'datepicker-year-disabled');
                } else {
                  item.classList.remove('datepicker-year-disabled');
                }
              });
              // 年份翻页按钮
              const ev = this.dateYearDisabledRule.bind(this, 'lteNow');
              prevBtn.removeEventListener('click', ev);
              nextBtn.removeEventListener('click', ev);
              prevBtn.addEventListener('click', ev);
              nextBtn.addEventListener('click', ev);

              prevBtnTd.removeEventListener('click', ev);
              nextBtnTd.removeEventListener('click', ev);
              prevBtnTd.addEventListener('click', ev);
              nextBtnTd.addEventListener('click', ev);
            })();
            break;

          //<=当前年、<=结束日期
          case 'rangeNowStart':
            (() => {
              tdDom.forEach((item) => {
                if (
                  item.innerText > nowDate ||
                  (valueR && item.innerText > valueR)
                ) {
                  item.setAttribute('class', 'datepicker-year-disabled');
                } else {
                  item.classList.remove('datepicker-year-disabled');
                }
              });

              // 年份翻页按钮
              const ev = this.dateYearDisabledRule.bind(
                this,
                'rangeNowStart',
                value,
              );
              prevBtn.removeEventListener('click', ev);
              nextBtn.removeEventListener('click', ev);
              prevBtn.addEventListener('click', ev);
              nextBtn.addEventListener('click', ev);

              prevBtnTd.removeEventListener('click', ev);
              nextBtnTd.removeEventListener('click', ev);
              prevBtnTd.addEventListener('click', ev);
              nextBtnTd.addEventListener('click', ev);
            })();
            break;

          //<=当前年、>=开始日期
          case 'rangeNowEnd':
            (() => {
              tdDom.forEach((item) => {
                if (
                  item.innerText > nowDate ||
                  (valueR && item.innerText < valueR)
                ) {
                  item.setAttribute('class', 'datepicker-year-disabled');
                } else {
                  item.classList.remove('datepicker-year-disabled');
                }
              });
              // 年份翻页按钮
              const ev = this.dateYearDisabledRule.bind(
                this,
                'rangeNowEnd',
                value,
              );
              prevBtn.removeEventListener('click', ev);
              nextBtn.removeEventListener('click', ev);
              prevBtn.addEventListener('click', ev);
              nextBtn.addEventListener('click', ev);

              prevBtnTd.removeEventListener('click', ev);
              nextBtnTd.removeEventListener('click', ev);
              prevBtnTd.addEventListener('click', ev);
              nextBtnTd.addEventListener('click', ev);
            })();
            break;
        }
      }
    },
    getDutyDept() {
      getDutyDept().then((res) => {
        this.ywcsList = res.data;
      });
    },
    getDuChaTypes() {
      request.get('/dc/insp/pblm/getListType').then((res) => {
        if (res.success) {
          this.duChaTypes = res.data;
        }
      });
    },
    getDuChaResource() {
      getDuChaResource().then((res) => {
        this.sourceList = res.data;
      });
    },
    getOrgTreeJson() {
      getOrgTreeJson().then((res) => {
        const jsonArray = [];
        const jsonStr = JSON.stringify(res.data);
        jsonArray.push(res.data);
        this.rectifyUnits = jsonArray;
      });
    },
    isNumber(val) {
      var regPos = /^[+]{0,1}(\d+)$/; // 非负浮点数
      if (regPos.test(val)) {
        return true;
      } else {
        return false;
      }
    },
    queryByParams() {
      if (this.stat && this.stat.includes('4')) {
        this.queryParams.workflowStat = this.stat;
        this.queryParams.stat = '';
      } else {
        this.queryParams.stat = this.stat;
        this.queryParams.workflowStat = '';
      }
      if (this.queryParams.fileNoNumber) {
        if (this.queryParams.fileNoNumber.indexOf('-') > -1) {
          var numList = this.queryParams.fileNoNumber.split('-');
          if (
            ((!numList[0] || !numList[1]) && numList.length != 2) ||
            !this.isNumber(numList[0]) ||
            !this.isNumber(numList[1])
          ) {
            this.$message.warning('请输入正确的编号范围！');
            return;
          }
        }
      }
      this.$emit('queryByParams', {
        queryParams: this.queryParams,
      });
    },
    async exportExcel() {
      const datas = JSON.stringify(this.queryParams);
      const url =
        '/modular-source/7446637943aa4c50b5d69c814517fca0/pdcApi/bis/insp/zg/pblm/getRepresentationsExport';
      const type = 'post';
      const exportName = '超期申诉列表.xls';
      const result = await exportModel(type, url, exportName, datas);
    },
  },
};
</script>

<style lang='less' scoped>
.data-screen {
  height: 500px;
  overflow: auto;
}
:deep(.datepicker-year-disabled) {
    pointer-events: none;
    cursor: not-allowed;
    a {
        color: rgba(0, 0, 0, 0.25);
        background: #f5f5f5;
    }
}
</style>
<style lang='less'>
    .datepicker-year-disabled {
        pointer-events: none;
        cursor: not-allowed;
        a {
            color: rgba(0, 0, 0, 0.25);
            background: #f5f5f5;
        }
    }
</style>
