﻿<template>
  <div class="systemLog">
    <a-tabs type="card" @change="callback">
      <a-tab-pane key="1" tab="综合监督检查标准" style="padding: 0 20px;">
        <a-layout>
          <a-layout-header>
            <a-form layout="inline" :model="searchParams" class="demo-form-inline">
              <a-form-item label="督查事项" style="min-width: 19%;">
                <a-input v-model:value="searchParams.nm" placeholder="督查事项" allow-clear />
              </a-form-item>
              <a-form-item label="业务处室" style="min-width: 19%;">
                <a-select v-model:value="searchParams.dutyDept" placeholder="请选择业务处室" show-search allow-clear>
                  <a-select-option v-for="(item, index) in ywcsList" :key="index" :value="item">{{ item }}</a-select-option>
                </a-select>
              </a-form-item>
              <a-form-item label="督查对象" style="min-width: 19%;">
                <a-select v-model:value="searchParams.objname" placeholder="请选择督查对象" allow-clear>
                  <a-select-option v-for="(item, index) in objnameList" :key="index" :value="item.id">{{ item.objname }}</a-select-option>
                </a-select>
              </a-form-item>
              <a-form-item>
                <a-button type="primary" @click="getPageList">查询</a-button>
              </a-form-item>
              <a-form-item v-if="readOnlyRole == 'display'">
                <a-button type="primary" @click="addBisInspProblemRelationOpen">添加</a-button>
              </a-form-item>
            </a-form>
          </a-layout-header>
          <a-layout-content>
            <a-table
              :columns="columns"
              :data-source="pageList"
              row-key="id"
              style="width: 100%;"
              :style="{ height: tableHeight + 'px' }"
              :scroll="{ y: tableHeight - 60}"
              :pagination="false"
              bordered>
              <template #bodyCell="{ column, record, text, index }">
                <template v-if="column.dataIndex === 'nm'">
                  <a-button type="link" size="small" @click="getPblms(record)">{{ record.nm }}</a-button>
                </template>
                <template v-else-if="column.dataIndex === 'action' && readOnlyRole == 'display'">
                  <a-button type="primary" size="small" @click="updatePageList(record)">编辑</a-button>
                  <a-button type="danger" size="small" @click="deletePageList(record.id)">删除</a-button>
                  <a-button v-if="record.displayStat == '0'" type="primary" size="small" @click="disPlayBtn(record.id, '1', 1)">隐藏</a-button>
                  <a-button v-else type="primary" size="small" @click="disPlayBtn(record.id, '0', 1)">取消隐藏</a-button>
                </template>
              </template>
            </a-table>
            <a-pagination
              show-size-changer
              v-model:current="searchParams.pageNum"
              v-model:pageSize="searchParams.pageSize"
              :total="total"
              :page-size-options="['10', '20', '30', '40']"
              :show-total="total => `共${total}条`"
              @change="getPageList"
              style="margin-top: 10px;" />
          </a-layout-content>
        </a-layout>
      </a-tab-pane>
      <a-tab-pane key="2" tab="全覆盖监督检查标准" style="padding: 0 20px;" v-if="currentAdCode == '360000000000'">
        <a-layout>
          <a-layout-header>
            <a-form
              layout="inline"
              :model="searchParamsFull"
              class="demo-form-inline"
              :label-col="{span: 8}"
              :wrapper-col="{span: 16}">
              <a-form-item label="督查事项" style="min-width: 19%;">
                <a-input v-model:value="searchParamsFull.nm" placeholder="督查事项" allow-clear />
              </a-form-item>
              <a-form-item label="业务处室" style="min-width: 19%;">
                <a-select v-model:value="searchParamsFull.dutyDept" placeholder="请选择业务处室" show-search allow-clear>
                  <a-select-option v-for="(item, index) in ywcsList" :key="index" :value="item">{{ item }}</a-select-option>
                </a-select>
              </a-form-item>
              <a-form-item label="督查对象" style="min-width: 19%;">
                <a-select v-model:value="searchParamsFull.objname" placeholder="请选择督查对象" allow-clear>
                  <a-select-option
                    v-for="(item, index) in objnameList"
                    :key="index"
                    :value="item.id">{{ item.objname }}</a-select-option>
                </a-select>
              </a-form-item>
              <a-form-item label="下发状态" style="min-width: 19%;">
                <a-select v-model:value="searchParamsFull.state" placeholder="请选择下发状态" allow-clear>
                  <a-select-option value="0">未下发</a-select-option>
                  <a-select-option value="1">已下发</a-select-option>
                </a-select>
              </a-form-item>
              <a-form-item>
                <a-button type="primary" @click="getPageListFull">查询</a-button>
              </a-form-item>
              <a-form-item v-if="readOnlyRole == 'display'">
                <a-button type="primary" @click="addBisInspProblemRelationFullOpen">添加</a-button>
              </a-form-item>
            </a-form>
          </a-layout-header>
          <a-layout-content>
            <a-table
              :columns="columnsFull"
              :data-source="pageListFull"
              row-key="id"
              style="width: 100%;"
              :style="{ height: tableHeight + 'px' }"
              :scroll="{ y: tableHeight - 60}"
              :pagination="false"
              bordered>
              <template #bodyCell="{ column, record, text, index }">
                <template v-if="column.dataIndex === 'nm'">
                  <a-button type="link" size="small" @click="getPblms(record)">{{ record.nm }}</a-button>
                </template>
                <template v-else-if="column.dataIndex === 'state'">
                  <span v-if="text === '0'">未下发</span>
                  <span v-else-if="text === '1'">已下发</span>
                  <span v-else></span>
                </template>
                <template v-else-if="column.dataIndex === 'action' && readOnlyRole == 'display'">
                  <a-button type="primary" size="small" @click="updatePageListFull(record)">编辑</a-button>
                  <a-button type="danger" size="small" @click="deletePageListFull(record)">删除</a-button>
                  <a-button v-if="record.displayStat == '0'" type="primary" size="small" @click="disPlayBtn(record.id, '1', 2)">隐藏</a-button>
                  <a-button v-else type="primary" size="small" @click="disPlayBtn(record.id, '0', 2)">取消隐藏</a-button>
                </template>
              </template>
            </a-table>
            <a-pagination
              show-size-changer
              v-model:current="searchParamsFull.pageNum"
              v-model:pageSize="searchParamsFull.pageSize"
              :total="totalFull"
              :page-size-options="['10', '20', '30', '40']"
              :show-total="totalFull => `共${totalFull}条`"
              @change="getPageListFull"
              style="margin-top: 10px;" />
          </a-layout-content>
        </a-layout>
      </a-tab-pane>
    </a-tabs>
    <!-- 添加综合督查事项 -->
    <a-modal title="添加综合督查事项" :open="addBisInspProblemRelation" @cancel="addBisInspProblemRelation = false">
      <a-form
        :model="addSearch"
        :label-col="{span: 8}"
        :wrapper-col="{ span: 16 }"
        :rules="addSearchRules"
        ref="addSearchForm">
        <a-form-item label="督查事项名称" prop="nm">
          <a-input v-model:value="addSearch.nm" placeholder="督查事项名称" allow-clear />
        </a-form-item>
        <a-form-item label="对应业务处室" prop="dutyDept">
          <a-select v-model:value="addSearch.dutyDept" placeholder="请选择对应业务处室" show-search allow-clear :disabled="disabled">
            <a-select-option v-for="(item, index) in ywcsList" :key="index" :value="item">{{ item }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="关联督查对象" prop="objNum">
          <a-select v-model:value="addSearch.objNum" placeholder="请选择关联督查对象" :disabled="disabled" allow-clear>
            <a-select-option
              v-for="(item, index) in objnameList"
              :key="index"
              :value="item.objNum">{{ item.objname }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="关联全覆盖督查" v-if="currentAdCode == '360000000000'">
          <a-select v-model:value="addSearch.dictTypeNum2" placeholder="请选择关联全覆盖督查" allow-clear @change="getChange">
            <a-select-option
              v-for="(item, index) in dictTypeNum2List"
              :key="index"
              :value="item.dictTypeNum"
              :disabled="item.optionalStatus == '1'">{{ item.nm }}</a-select-option>
          </a-select>
        </a-form-item>
      </a-form>
      <template #footer>
        <a-button type="primary" size="small" @click="addBisInspProblemRelationClick">确定</a-button>
        <a-button size="small" @click="addBisInspProblemRelation=false">取消</a-button>
      </template>
    </a-modal>
    <!-- 修改综合督查事项 -->
    <a-modal title="修改综合督查事项" :open="updateBisInspProblemRelation" @cancel="updateBisInspProblemRelation = false">
      <a-form
        :model="updateSearch"
        :label-col="{span: 8}"
        :wrapper-col="{ span: 16 }"
        :rules="addSearchRules"
        ref="updateSearchForm">
        <a-form-item label="督查事项名称" prop="nm">
          <a-input v-model:value="updateSearch.nm" placeholder="督查事项名称" allow-clear />
        </a-form-item>
        <a-form-item label="对应业务处室" prop="dutyDept">
          <a-select v-model:value="updateSearch.dutyDept" placeholder="请选择对应业务处室" show-search allow-clear disabled>
            <a-select-option v-for="(item, index) in ywcsList" :key="index" :value="item">{{ item }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="关联督查对象" prop="objNum">
          <a-select v-model:value="updateSearch.objNum" placeholder="请选择关联督查对象" allow-clear disabled>
            <a-select-option v-for="(item, index) in objnameList" :key="index" :value="item.objNum">{{ item.objname
            }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="关联全覆盖督查" v-if="currentAdCode == '360000000000'">
          <a-select v-model:value="updateSearch.dictTypeNum2" placeholder="请选择关联全覆盖督查" allow-clear disabled>
            <a-select-option v-for="(item, index) in dictTypeNum2List" :key="index" :value="item.dictTypeNum" :disabled="item.optionalStatus == '1'">{{ item.nm
            }}</a-select-option>
          </a-select>
        </a-form-item>
      </a-form>
      <template #footer>
        <a-button type="primary" size="small" @click="updateBisInspProblemRelationClick">确定</a-button>
        <a-button size="small" @click="updateBisInspProblemRelation=false">取消</a-button>
      </template>
    </a-modal>
    <!-- 添加全覆盖督查事项 -->
    <a-modal title="添加全覆盖督查事项" :open="addBisInspProblemRelationFull" @cancel="addBisInspProblemRelationFull = false">
      <a-form
        :model="addSearchFull"
        :label-col="{span: 8}"
        :wrapper-col="{ span: 16 }"
        :rules="addSearchRules"
        ref="addSearchFormFull">
        <a-form-item label="督查事项id">
          {{uuid}}
        </a-form-item>
        <a-form-item label="督查事项名称" prop="nm">
          <a-input v-model:value="addSearchFull.nm" placeholder="督查事项名称" allow-clear />
        </a-form-item>
        <a-form-item label="对应业务处室" prop="dutyDept">
          <a-select v-model:value="addSearchFull.dutyDept" placeholder="请选择对应业务处室" show-search allow-clear>
            <a-select-option v-for="(item, index) in ywcsList" :key="index" :value="item">{{ item }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="关联督查对象" prop="objNum">
          <a-select v-model:value="addSearchFull.objNum" placeholder="请选择关联督查对象" allow-clear>
            <a-select-option
              v-for="(item, index) in objnameList"
              :key="index"
              :value="item.objNum"
              :title="item.objname+`(${item.id})`"
              :disabled="item.optionalStatus == '1'">{{ item.objname+`(${item.id})` }}</a-select-option>
          </a-select>
        </a-form-item>
      </a-form>
      <template #footer>
        <a-button type="primary" size="small" @click="addBisInspProblemRelationClickFull">确定</a-button>
        <a-button size="small" @click="addBisInspProblemRelationFull = false">取消</a-button>
      </template>
    </a-modal>
    <!-- 修改综合督查事项 -->
    <a-modal title="修改综合督查事项" :open="updateBisInspProblemRelationFull" @cancel="updateBisInspProblemRelationFull = false">
      <a-form
        :model="updateSearchFull"
        :label-col="{span: 8}"
        :wrapper-col="{ span: 16 }"
        :rules="addSearchRules"
        ref="updateSearchFormFull">
        <a-form-item label="督查事项名称" prop="nm">
          <a-input v-model:value="updateSearchFull.nm" placeholder="督查事项名称" allow-clear />
        </a-form-item>
        <a-form-item label="对应业务处室" prop="dutyDept">
          <a-select v-model:value="updateSearchFull.dutyDept" placeholder="请选择对应业务处室" show-search allow-clear disabled>
            <a-select-option v-for="(item, index) in ywcsList" :key="index" :value="item">{{ item }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="关联督查对象" prop="objNum">
          <a-select v-model:value="updateSearchFull.objNum" placeholder="请选择关联督查对象" allow-clear disabled>
            <a-select-option v-for="(item, index) in objnameList" :key="index" :value="item.objNum" :disabled="item.optionalStatus == '1'">{{ item.objname
            }}</a-select-option>
          </a-select>
        </a-form-item>
      </a-form>
      <template #footer>
        <a-button type="primary" size="small" @click="updateBisInspProblemRelationClickFull">确定</a-button>
        <a-button size="small" @click="updateBisInspProblemRelationFull =false">取消</a-button>
      </template>
    </a-modal>
    <!-- 问题清单维护 -->
    <a-modal
      :title="`${pblmsName}问题清单维护`"
      :open="pblmsFlag"
      @cancel="pblmsFlag = false"
      width="50%">
      <a-layout>
        <a-layout-header style="height: 45px; line-height: 45px;">
          <a-button @click="addPblmsFlag = true" type="primary" style="margin-right: 10px;">新增</a-button>
          <a-upload
            name="file"
            :multiple="false"
            action="/modular-source/6ace62b8e2bb467d98286d260aebcef2/pdcApi/dc/insp/pblm/importListOfIssues"
            :data="{ type: pblmsType }"
            :accept="'.xls,.xlsx'"
            :headers="header"
            @change="handleChange"
            :show-upload-list="false">
            <a-button type="primary">导入</a-button>
          </a-upload>
        </a-layout-header>
        <a-layout-content style="min-height: 50px;">
          <a-tree
            v-if="treeData && treeData.length"
            v-model="checkedKeys"
            checkable
            :tree-data="treeData"
            :fieldNames="{ children: 'children', title: 'name', key: 'guid'}"
            :auto-expand-parent="false"
            @check="onCheck">
            <template #title="data">
              <span style="margin-right: 10px;" class="tree_text" :title="data.name">{{ data.name }}</span>
              <span v-if="item.levelss == '3' && item.inspPblmCate == '0'" style="color:#ffc125; ">一般</span>
              <span v-if="item.levelss == '3' && item.inspPblmCate == '1'" style="color:#ff7f24; ">较重</span>
              <span v-if="item.levelss == '3' && item.inspPblmCate == '2'" style="color:#ff0000; ">严重</span>
              <a-button
                v-if="item.levelss == '1'"
                size="small"
                type="link"
                icon="plus-circle"
                style="margin-left: 10px;"
                @click="addTreeData(data)">新增</a-button>
              <a-button
                v-if="item.levelss == '2'"
                size="small"
                type="link"
                icon="plus-circle"
                style="margin-left: 10px;"
                @click="addTreeData1(data)">新增</a-button>
            </template>
          </a-tree>
          <div v-else style="text-align: center;">暂无数据</div>
        </a-layout-content>
      </a-layout>
      <template #footer>
        <a-button type="primary" @click="updatePblms">确定</a-button>
        <a-button @click="pblmsFlag = false">取消</a-button>
      </template>
    </a-modal>
    <!-- 添加问题类别 -->
    <a-modal title="添加问题类别" :open="addPblmsFlag" @cancel="addPblmsFlag = false">
      <a-form
        :model="addPblmsParams"
        class="demo-form-inline"
        :label-col="{span: 8}"
        :wrapper-col="{span: 16}"
        :rules="addPblmsRules"
        ref="addPblmsRef">
        <a-form-item label="督查事项id">
          {{dcshId}}
        </a-form-item>
        <a-form-item label="督查事项名称">
          {{pblmsName}}
        </a-form-item>
        <a-form-item label="问题类别" prop="inspPblmsName">
          <a-input v-model:value="addPblmsParams.inspPblmsName" placeholder="问题类别" allow-clear />
        </a-form-item>
        <a-form-item label="检查项目" prop="checkPoint">
          <a-input v-model:value="addPblmsParams.checkPoint" placeholder="检查项目" allow-clear />
        </a-form-item>
        <a-form-item label="问题描述" prop="pblmDesc">
          <a-input v-model:value="addPblmsParams.pblmDesc" placeholder="问题类别" allow-clear />
        </a-form-item>
        <a-form-item label="严重程度" prop="inspPblmCate">
          <a-select v-model:value="addPblmsParams.inspPblmCate" placeholder="请选择严重程度" allow-clear>
            <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>
      <template #footer>
        <a-button type="primary" @click="addPblms">确定</a-button>
        <a-button @click="addPblmsFlag=false">取消</a-button>
      </template>
    </a-modal>

    <!-- 添加问题类别 -->
    <a-modal title="添加检查项目" :open="addPointFlag" @cancel="addPointFlag = false">
      <a-form
        :model="addPointParams"
        class="demo-form-inline"
        :label-col="{span: 8}"
        :wrapper-col="{span: 16}"
        :rules="addPblmsRules"
        ref="addPointRef">
        <a-form-item label="问题类别" prop="inspPblmsName">
          <a-input v-model:value="addPointParams.inspPblmsName" placeholder="问题类别" allow-clear disabled />
        </a-form-item>
        <a-form-item label="检查项目" prop="checkPoint">
          <a-input v-model:value="addPointParams.checkPoint" placeholder="检查项目" allow-clear />
        </a-form-item>
        <a-form-item label="问题描述" prop="pblmDesc">
          <a-input v-model:value="addPointParams.pblmDesc" placeholder="问题类别" allow-clear />
        </a-form-item>
        <a-form-item label="严重程度" prop="inspPblmCate">
          <a-select v-model:value="addPointParams.inspPblmCate" placeholder="请选择严重程度" allow-clear>
            <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>
      <template #footer>
        <a-button type="primary" @click="addPoint">确定</a-button>
        <a-button @click="addPointFlag =false">取消</a-button>
      </template>
    </a-modal>

    <!-- 添加问题类别 -->
    <a-modal title="添加问题描述" :open="addDescFlag" @cancel="addDescFlag = false">
      <a-form
        :model="addDescParams"
        class="demo-form-inline"
        :label-col="{span: 8}"
        :wrapper-col="{span: 16}"
        :rules="addPblmsRules"
        ref="addDescRef">
        <a-form-item label="问题类别" prop="inspPblmsName">
          <a-input v-model:value="addDescParams.inspPblmsName" placeholder="问题类别" allow-clear disabled/>
        </a-form-item>
        <a-form-item label="检查项目" prop="checkPoint">
          <a-input v-model:value="addDescParams.checkPoint" placeholder="检查项目" allow-clear disabled/>
        </a-form-item>
        <a-form-item label="问题描述" prop="pblmDesc">
          <a-input v-model:value="addDescParams.pblmDesc" placeholder="问题类别" allow-clear />
        </a-form-item>
        <a-form-item label="严重程度" prop="inspPblmCate">
          <a-select v-model:value="addDescParams.inspPblmCate" placeholder="请选择严重程度" allow-clear>
            <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>
      <template #footer>
        <a-button type="primary" @click="addDesc">确定</a-button>
        <a-button @click="addDescFlag =false">取消</a-button>
      </template>
    </a-modal>
  </div>
</template>

<script>
import { simpleUuid } from '@/utils/uuid';
import {
  addPblms,
  BisInspProblemRelationAdd,
  BisInspProblemRelationDelete,
  BisInspProblemRelationUpdate,
  getDcDropDownBox,
  getDutyDept,
  getObjDropDownBox,
  getPageList,
  getPblmList,
  updateByParam,
} from './Common/pblmList_api';
export default {
  data() {
    return {
      uuid: simpleUuid(),
      header: {
        persId: localStorage.getItem('persId'),
        accessToken: localStorage.getItem('accessToken'),
        orgId: localStorage.getItem('orgId'),
      },
      tableHeight: window.innerHeight - 280,
      type: 'province', // 督查事项类型
      searchParams: {
        nm: '', // 督查事项名称
        dutyDept: undefined,
        objname: undefined,
        pageNum: 1,
        pageSize: 10,
      },
      searchParamsFull: {
        nm: '',
        dutyDept: undefined,
        objname: undefined,
        state: undefined,
        pageNum: 1,
        pageSize: 10,
      },
      addSearch: {
        nm: '',
        dutyDept: undefined,
        objNum: undefined,
        dictTypeNum2: undefined,
      },
      addSearchFull: {
        nm: '',
        dutyDept: undefined,
        objNum: undefined,
      },
      addBisInspProblemRelation: false,
      addBisInspProblemRelationFull: false,
      addSearchRules: {
        nm: [
          { required: true, message: '请输入督查事项名称', trigger: 'blur' },
        ],
        dutyDept: [
          { required: true, message: '请选择对应业务处室', trigger: 'change' },
        ],
        objNum: [
          { required: true, message: '请选择关联督查对象', trigger: 'change' },
        ],
        // dictTypeNum2: [{ required: true, message: '请选择关联全覆盖督查', trigger: 'change' }]
      },
      updateSearch: {
        id: '',
        nm: '',
        dutyDept: undefined,
        objNum: undefined,
        dictTypeNum2: undefined,
      },
      updateSearchFull: {
        id: '',
        nm: '',
        dutyDept: undefined,
        objNum: undefined,
      },
      updateBisInspProblemRelation: false,
      updateBisInspProblemRelationFull: false,
      total: 0,
      totalFull: 0,
      ywcsList: [],
      objnameList: [],
      dictTypeNum2List: [],
      pageList: [],
      pageListFull: [],
      columns: [
        {
          title: '督查事项',
          dataIndex: 'nm',
          // dataIndex: 'nm',
          width: 100,
          ellipsis: true,
        },
        {
          title: '对应业务处室',
          dataIndex: 'dutyDept',
          width: 100,
          ellipsis: true,
        },
        {
          title: '关联督查对象',
          dataIndex: 'objname',
          width: 100,
          ellipsis: true,
        },
        {
          title: '关联全覆盖督查',
          dataIndex: 'dictTypeNumName',
          width: 100,
          ellipsis: true,
        },
        {
          title: '操作',
          dataIndex: 'action',
          width: 150,
        },
      ],
      columnsFull: [
        {
          title: '督查事项',
          dataIndex: 'nm',
          // dataIndex: 'nm',
          width: 100,
          ellipsis: true,
        },
        {
          title: '对应业务处室',
          dataIndex: 'dutyDept',
          width: 100,
          ellipsis: true,
        },
        {
          title: '关联督查对象',
          dataIndex: 'objname',
          width: 100,
          ellipsis: true,
        },
        {
          title: '下发状态',
          dataIndex: 'state',
          width: 100,
          ellipsis: true,
        },
        {
          title: '操作',
          dataIndex: 'action',
          width: 150,
        },
      ],
      pblmsFlag: false,
      pblmsType: '',
      addPblmsFlag: false,
      addPblmsParams: {
        inspPblmsName: '',
        checkPoint: '',
        pblmDesc: '',
        inspPblmCate: undefined,
        dataStat: 1,
      },
      addPblmsRules: {
        inspPblmsName: [
          { required: true, message: '请输入问题类别', trigger: 'blur' },
        ],
        checkPoint: [
          { required: true, message: '请输入检查项目', trigger: 'blur' },
        ],
        pblmDesc: [
          { required: true, message: '请输入问题描述', trigger: 'blur' },
        ],
        inspPblmCate: [
          { required: true, message: '请选择严重程度', trigger: 'change' },
        ],
      },
      addPointFlag: false,
      addPointParams: {
        inspPblmsName: '',
        checkPoint: '',
        pblmDesc: '',
        inspPblmCate: undefined,
        dataStat: 1,
      },
      addDescFlag: false,
      addDescParams: {
        inspPblmsName: '',
        checkPoint: '',
        pblmDesc: '',
        inspPblmCate: undefined,
        dataStat: 1,
      },
      checkedKeys: [],
      treeData: [],
      disabled: false,
      pblmsName: '',
      dcshId: '',
      currentAdCode: localStorage.getItem('currentAdCode'),
      readOnlyRole: localStorage.getItem('readOnlyRole'),
    };
  },
  created() {
    this.getDutyDept();
    this.getObjDropDownBox();
    this.getDcDropDownBox();
    this.getPageList();
  },
  methods: {
    // 获取责任处室
    getDutyDept() {
      getDutyDept()
        .then((res) => {
          this.ywcsList = res.data;
        })
        .catch((error) => {
          this.$message.error(error);
        });
    },
    // 获取督查事项下拉框
    getObjDropDownBox() {
      const { type } = this;
      const params = {
        type,
        display: '0',
      };
      getObjDropDownBox(params)
        .then((res) => {
          this.objnameList = res.data;
        })
        .catch((error) => {
          this.$message.error(error);
        });
    },
    // 督查事项编辑全覆盖督查信息下拉框
    getDcDropDownBox() {
      const { type } = this;
      const params = {
        type: type == 'province' ? 'other' : 'province',
      };
      getDcDropDownBox(params)
        .then((res) => {
          this.dictTypeNum2List = res.data;
        })
        .catch((error) => {
          this.$message.error(error);
        });
    },
    // 查询
    searchBtn() {
      this.getPageList();
    },
    updatePageList(text) {
      this.updateSearch.nm = text.nm;
      this.updateSearch.dutyDept = text.dutyDept;
      this.updateSearch.objNum = text.objNum;
      this.updateSearch.dictTypeNum2 = text.dictTypeNum2;
      this.updateSearch.id = text.id;
      this.updateBisInspProblemRelation = true;
    },
    updatePageListFull(text) {
      this.updateSearchFull.nm = text.nm;
      this.updateSearchFull.dutyDept = text.dutyDept;
      this.updateSearchFull.objNum = text.objNum;
      this.updateSearchFull.id = text.id;
      this.updateBisInspProblemRelationFull = true;
    },
    // 删除
    deletePageList(id) {
      this.$confirm({
        title: '提示',
        content: '此操作将永久删除, 是否继续?',
        okType: 'warning',
        onOk: () => {
          BisInspProblemRelationDelete(id)
            .then((res) => {
              if (res.success) {
                this.$message.success('删除成功');
                this.getPageList();
              } else {
                this.$message.error(res.message);
              }
            })
            .catch((error) => {
              this.$message.error(error);
            });
        },
      });
    },
    deletePageListFull(text) {
      if (text.state == '1') {
        this.$message.warning('已下发督查事项无法删除！');
      } else {
        this.$confirm({
          title: '提示',
          content: '此操作将永久删除, 是否继续?',
          okType: 'warning',
          onOk: () => {
            BisInspProblemRelationDelete(text.id).then((res) => {
              if (res.success) {
                this.$message.success('删除成功');
                this.getPageListFull();
              } else {
                this.$message.error(res.message);
              }
            });
          },
        });
      }
    },
    // 获取列表数据
    getPageList() {
      const {
        searchParams: { nm, dutyDept, objname, pageNum, pageSize },
        type,
      } = this;
      const params = {
        type,
        nm,
        dutyDept,
        objname,
        pageNum,
        pageSize,
      };
      getPageList(params)
        .then((res) => {
          if (res.success) {
            this.total = res.data.total;
            this.pageList = res.data.list;
          }
        })
        .catch((error) => {
          this.$message.error(error);
        });
    },
    getPageListFull() {
      const {
        searchParamsFull: { nm, dutyDept, objname, pageNum, pageSize, state },
        type,
      } = this;
      const params = {
        type,
        nm,
        dutyDept,
        objname,
        pageNum,
        pageSize,
        state,
      };
      getPageList(params).then((res) => {
        if (res.success) {
          this.totalFull = res.data.total;
          this.pageListFull = res.data.list;
        }
      });
    },
    addBisInspProblemRelationOpen() {
      this.addBisInspProblemRelation = true;
      this.getObjDropDownBox();
      this.getDcDropDownBox();
    },
    // 添加综合督查事项
    addBisInspProblemRelationClick() {
      this.$refs.addSearchForm.validate((valid) => {
        if (valid) {
          const {
            addSearch: { nm, dutyDept, objNum, dictTypeNum2 },
            type,
          } = this;
          const params = {
            type,
            nm,
            dutyDept,
            objNum,
            dictTypeNum2,
          };
          BisInspProblemRelationAdd(params)
            .then((res) => {
              if (res.success) {
                this.$message.success('添加成功!');
                this.addSearch.nm = '';
                this.addSearch.dutyDept = undefined;
                this.addSearch.objNum = undefined;
                this.addSearch.dictTypeNum2 = undefined;
                this.addBisInspProblemRelation = false;
                this.getObjDropDownBox();
                this.getDcDropDownBox();
                this.getPageList();
                this.disabled = false;
              } else {
                this.$message.error(res.message);
              }
            })
            .catch((error) => {
              this.$message.error(error);
            });
        } else {
          return false;
        }
      });
    },
    addBisInspProblemRelationFullOpen() {
      this.addBisInspProblemRelationFull = true;
      this.getObjDropDownBox();
    },
    addBisInspProblemRelationClickFull() {
      this.$refs.addSearchFormFull.validate((valid) => {
        if (valid) {
          const {
            addSearchFull: { nm, dutyDept, objNum },
            type,
          } = this;
          const params = {
            type,
            nm,
            dutyDept,
            objNum,
          };
          BisInspProblemRelationAdd(params).then((res) => {
            if (res.success) {
              this.$message.success('添加成功!');
              this.addBisInspProblemRelationFull = false;
              this.addSearchFull.nm = '';
              this.addSearchFull.dutyDept = undefined;
              this.addSearchFull.objNum = undefined;
              this.getObjDropDownBox();
              this.getDcDropDownBox();
              this.getPageListFull();
            } else {
              this.$message.error(res.message);
            }
          });
        } else {
          return false;
        }
      });
    },
    updateBisInspProblemRelationClick() {
      this.$refs.updateSearchForm.validate((valid) => {
        if (valid) {
          const {
            updateSearch: { nm, dutyDept, objNum, dictTypeNum2, id },
            type,
          } = this;
          const params = {
            id,
            type,
            nm,
            dutyDept,
            objNum,
            dictTypeNum2,
          };
          BisInspProblemRelationUpdate(params)
            .then((res) => {
              if (res.success) {
                this.updateBisInspProblemRelation = false;
                this.getPageList();
              } else {
                this.$message.error('修改失败,请联系管理员!');
              }
            })
            .catch((error) => {
              this.$message.error(error);
            });
        } else {
          return false;
        }
      });
    },
    updateBisInspProblemRelationClickFull() {
      this.$refs.updateSearchFormFull.validate((valid) => {
        if (valid) {
          const {
            updateSearchFull: { nm, dutyDept, objNum, id },
            type,
          } = this;
          const params = {
            id,
            type,
            nm,
            dutyDept,
            objNum,
          };
          BisInspProblemRelationUpdate(params).then((res) => {
            if (res.success) {
              this.updateBisInspProblemRelationFull = false;
              this.getPageListFull();
            } else {
              this.$message.error('修改失败,请联系管理员!');
            }
          });
        } else {
          return false;
        }
      });
    },
    handleSizeChange(size, val) {
      this.searchParams.pageSize = val;
      this.getPageList();
    },
    handleCurrentChange(val) {
      this.searchParams.pageNum = val;
      this.getPageList();
    },
    handleSizeChangeFull(size, val) {
      this.searchParamsFull.pageSize = val;
      this.getPageListFull();
    },
    handleCurrentChangeFull(val) {
      this.searchParamsFull.pageNum = val;
      this.getPageListFull();
    },
    callback(key) {
      if (key == '1') {
        this.type = 'province';
        this.getObjDropDownBox();
        this.getDcDropDownBox();
        this.getPageList();
      } else {
        this.type = 'other';
        this.getObjDropDownBox();
        this.getDcDropDownBox();
        this.getPageListFull();
      }
    },
    getPblms(text) {
      this.pblmsName = text.nm;
      this.dcshId = text.id;
      this.treeData = [];
      this.pblmsType = text.dictTypeNum;
      this.getPblmsList();
      this.pblmsFlag = true;
    },
    getPblmsList() {
      const { pblmsType: type } = this;
      const params = {
        type,
      };
      getPblmList(params)
        .then((res) => {
          this.treeData = res.data;
          this.checkedKeys = [];
          this.treeData.forEach((item) => {
            item.slots = { title: 'custom' };
            item.children.forEach((items) => {
              items.pName = item.name;
              items.slots = { title: 'custom' };
              items.children.forEach((item2) => {
                item2.slots = { title: 'custom' };
                if (item2.display == '0') {
                  this.checkedKeys.push(item2.guid);
                }
              });
            });
          });
        })
        .catch((error) => {
          this.$message.error(error);
        });
    },
    // 添加问题类别
    addPblms() {
      this.$refs.addPblmsRef.validate((valid) => {
        if (valid) {
          const {
            addPblmsParams: {
              inspPblmsName,
              checkPoint,
              pblmDesc,
              inspPblmCate,
              dataStat,
            },
            pblmsType: type,
          } = this;
          const params = {
            type,
            inspPblmsName,
            checkPoint,
            pblmDesc,
            inspPblmCate,
            dataStat,
          };
          addPblms(params)
            .then((res) => {
              this.$message.success('添加成功!');
              this.addPblmsFlag = false;
              this.addPblmsParams.inspPblmsName = '';
              this.addPblmsParams.checkPoint = '';
              this.addPblmsParams.pblmDesc = '';
              this.addPblmsParams.inspPblmCate = undefined;
              this.getPblmsList();
            })
            .catch((error) => {
              this.$message.error(error);
            });
        } else {
          return false;
        }
      });
    },
    onCheck(checkedKeys) {
      this.checkedKeys = checkedKeys;
    },
    updatePblms() {
      const { pblmsType: type } = this;
      const ids = this.checkedKeys.filter((item) => item.length > 12).join(',');
      const params = {
        type,
        ids,
      };
      updateByParam(params)
        .then((res) => {
          if (res.success) {
            this.$message.success('修改成功!');
            this.getPblmsList();
          } else {
            this.$message.error('修改失败,请联系管理员!');
          }
        })
        .catch((error) => {
          this.$message.error(error);
        });
    },
    addTreeData(row) {
      this.addPointParams.inspPblmsName = row.name;
      this.addPointFlag = true;
    },
    addPoint() {
      this.$refs.addPointRef.validate((valid) => {
        if (valid) {
          const {
            addPointParams: {
              inspPblmsName,
              checkPoint,
              pblmDesc,
              inspPblmCate,
              dataStat,
            },
            pblmsType: type,
          } = this;
          const params = {
            type,
            inspPblmsName,
            checkPoint,
            pblmDesc,
            inspPblmCate,
            dataStat,
          };
          addPblms(params).then((res) => {
            this.addPointFlag = false;
            this.getPblmsList();
          });
        } else {
          return false;
        }
      });
    },
    addTreeData1(row) {
      this.addDescParams.inspPblmsName = row.pName;
      this.addDescParams.checkPoint = row.name;
      this.addDescFlag = true;
    },
    addDesc() {
      this.$refs.addDescRef.validate((valid) => {
        if (valid) {
          const {
            addDescParams: {
              inspPblmsName,
              checkPoint,
              pblmDesc,
              inspPblmCate,
              dataStat,
            },
            pblmsType: type,
          } = this;
          const params = {
            type,
            inspPblmsName,
            checkPoint,
            pblmDesc,
            inspPblmCate,
            dataStat,
          };
          addPblms(params).then((res) => {
            this.addDescFlag = false;
            this.getPblmsList();
          });
        } else {
          return false;
        }
      });
    },
    handleChange(info) {
      if (info.file.status === 'done') {
        if (info.file.response.success) {
          this.$message.success(`${info.file.name} 导入成功!`);
          this.getPblmsList();
        } else {
          this.$message.error(info.file.response.message);
        }
      } else if (info.file.status === 'error') {
        this.$message.error(`${info.file.name} 导入失败!`);
      }
    },
    getChange(value, e) {
      if (value) {
        this.dictTypeNum2List.forEach((item) => {
          if (item.dictTypeNum == value) {
            this.disabled = true;
            this.addSearch.dutyDept = item.dutyDept;
            this.addSearch.objNum = item.objNum;
          }
        });
      } else {
        this.disabled = false;
        this.addSearch.dutyDept = undefined;
        this.addSearch.objNum = undefined;
      }
    },
    // 隐藏 取消隐藏
    disPlayBtn(id, displayStat, flag) {
      const params = {
        id,
        displayStat,
      };
      BisInspProblemRelationUpdate(params).then((res) => {
        if (res.success) {
          if (flag == 1) {
            this.getPageList();
          } else {
            this.getPageListFull();
          }
        } else {
          this.$message.error(res.message);
        }
      });
    },
  },
};
</script>

<style lang='less' scoped>
:deep(.ant-layout-sider),
:deep(.ant-layout-header),
:deep(.ant-layout-content) {
  background: #fff;
}

.tree_text {
  display: inline-block;
  max-width: 700px;
  height: 18px;
  overflow: hidden;
  text-overflow: ellipsis;
  // white-space: nowrap;
}
</style>
