<template>
  <a-modal
    title="添加督查对象"
    :open="dialogFormVisible"
    @ok="saveChange"
    @cancel="dialogFormVisible = false"
    width="80%"
  >
    <a-layout>
      <a-layout-sider
        width="200px"
        style="border:1px solid #d5d5ff; background: #fff;"
      >
        <p
          style="font-weight:bolder;background-color:#d5d5ff;padding:3px;margin: 0;"
        >
          <a-icon type="share-alt" />所属机构
        </p>
        <provTreeListQy
          ref="provTreeListQyRef"
          v-show="showLeftTree"
          :ddczId="dczId"
          rootCode="000000"
          rootType="1"
          style="max-height:485px;"
          @treeDataEmit="treeDataEmit"
          @provTreeSelectChange="provTreeSelectChangeHandler_qy"
        >
        </provTreeListQy>
        <provTreeList
          v-show="!showLeftTree"
          rootCode="000000"
          rootType="1"
          style="max-height:485px;"
          @provTreeSelectChange="provTreeSelectChangeHandler"
        ></provTreeList>
      </a-layout-sider>
      <a-layout-content
        style="border:1px solid #d5d5ff;margin-left:5px;padding:0px;"
      >
        <p
          style="font-weight:bolder;background-color:#d5d5ff;padding:3px;margin: 0;"
        >
          督查对象
        </p>
        <div v-if="objType == '1' || objType == '36'" style="padding:10px">
          <a-form :model="form" layout="inline">
            <a-form-item label="督查对象" style="display:none;">
              <a-select
                v-model:value="form.objTypeName"
                @change="selectChange"
                placeholder="请选择"
              >
                <a-select-option value="1">小水库</a-select-option>
                <a-select-option value="2">农村饮水工程</a-select-option>
                <a-select-option value="3">水毁</a-select-option>
              </a-select>
            </a-form-item>
          </a-form>
          <a-form :model="formData" layout="inline">
            <a-form-item label="注册登记码">
              <a-input
                v-model:value="formData.regCode"
                placeholder="请输入注册登记码"
                allow-clear
              />
            </a-form-item>
            <a-form-item label="工程规模">
              <a-select
                v-if="objType == '1'"
                v-model:value="formData.engScal"
                placeholder="请选择"
                allow-clear
                style="width: 110px"
              >
                <a-select-option value="4">小（1）型</a-select-option>
                <a-select-option value="5">小（2）型</a-select-option>
              </a-select>
              <a-select
                v-if="objType == '36'"
                v-model:value="formData.engScal"
                placeholder="请选择"
                allow-clear
                style="width: 110px"
              >
                <a-select-option value="1">大（1）型</a-select-option>
                <a-select-option value="2">大（2）型</a-select-option>
                <a-select-option value="3">中型</a-select-option>
              </a-select>
            </a-form-item>
            <a-form-item label="水库名称">
              <a-input
                v-model:value="formData.searchNameOfRsName"
                placeholder="请输入水库名称"
                allow-clear
              />
            </a-form-item>
            <a-form-item>
              <a-button type="primary" @click="refreshCurrentShow">
                查询
              </a-button>
              <a-button
                type="primary"
                @click="toAddNewRsvr"
                style="margin-left: 10px;"
              >
                添加新水库
              </a-button>
            </a-form-item>
            <a-form-item
            ><upload
              ref="uploadFile"
              :url="`/modular-source/6ace62b8e2bb467d98286d260aebcef2/pdcApi/dc/att/rsBase/impExcel`"
              txt="上传水库基本信息(.xls)"
            ></upload
            ></a-form-item>
          </a-form>
          <a-table
            :row-selection="{
              selectedRowKeys: selectedRowKeys,
              onChange: handleSelectionChange,
            }"
            :columns="columns"
            :data-source="currentShowList"
            @change="handleCurrentChange"
            :loading="loading"
            rowKey="index"
            :pagination="{
              total,
              defaultPageSize: pageSize,
              showTotal: (total) => `共${total}条`,
            }"
            style="width: 100%;"
          >
            <template #bodyCell="{ column, record }">
              <span v-if="column.dataIndex === 'engScal'">
                <span v-if="record.engScal == '1'">大（1）型</span>
                <span v-else-if="record.engScal == '2'">大（2）型</span>
                <span v-else-if="record.engScal == '3'">中型</span>
                <span v-else-if="record.engScal == '4'">小（1）型</span>
                <span v-else-if="record.engScal == '5'">小（2）型</span>
                <span v-else></span>
              </span>
              <span v-else-if="column.dataIndex === 'rsAdmDep'">
                <span v-if="record.rsAdmDep == 1">水利部门</span>
                <span v-else-if="record.rsAdmDep == 2">电力部门</span>
                <span v-else-if="record.rsAdmDep == 3">农业部门</span>
                <span v-else-if="record.rsAdmDep == 4">林业部门</span>
                <span v-else-if="record.rsAdmDep == 5">城建部门</span>
                <span v-else-if="record.rsAdmDep == 6">航运部门</span>
                <span v-else-if="record.rsAdmDep == 7">环保部门</span>
                <span v-else>其他部门</span>
              </span>
            </template>
          </a-table>
        </div>
        <div v-if="objType == '2'" style="padding:10px">
          <a-form :model="form" layout="inline">
            <a-form-item label="督查对象" style="display:none;">
              <a-select
                v-model:value="form.objTypeName"
                @change="selectChange"
                placeholder="请选择"
              >
                <a-select-option value="1">小水库</a-select-option>
                <a-select-option value="2">农村饮水工程</a-select-option>
                <a-select-option value="3">水毁</a-select-option>
              </a-select>
            </a-form-item>
          </a-form>
          <a-form :model="formData" layout="inline">
            <a-form-item label="行政区名称">
              <a-input
                v-model:value="formData.searchNameOfAdName"
                placeholder="请输入行政区名称"
                allow-clear
              />
            </a-form-item>
            <a-form-item>
              <a-button type="primary" @click="getTableData">
                查询
              </a-button>
            </a-form-item>
          </a-form>
          <a-table
            :row-selection="{
              selectedRowKeys: selectedRowKeys,
              onChange: handleSelectionChange,
            }"
            :columns="columns1"
            :data-source="currentShowList"
            @change="handleCurrentChange"
            :loading="loading"
            rowKey="index"
            :pagination="{
              total,
              defaultPageSize: pageSize,
              showTotal: (total) => `共${total}条`,
            }"
            style="width: 100%;"
          >
            <template #bodyCell="{ column, record }">
              <span v-if="column.dataIndex === 'adGrad'">
                <span v-if="record.adGrad == '1'">国家级</span>
                <span v-else-if="record.adGrad == '2'">省级</span>
                <span v-else-if="record.adGrad == '3'">地市级</span>
                <span v-else-if="record.adGrad == '4'">县级</span>
                <span v-else-if="record.adGrad == '5'">乡级</span>
                <span v-else-if="record.adGrad == '6'">村</span>
                <span v-else>村组</span>
              </span>
            </template>
          </a-table>
        </div>
        <div v-if="objType == '3'" style="padding:10px">
          <a-form :model="form" layout="inline">
            <a-form-item label="督查对象" style="display:none;">
              <a-select
                v-model:value="form.objTypeName"
                @change="selectChange"
                placeholder="请选择"
              >
                <a-select-option value="1">小水库</a-select-option>
                <a-select-option value="2">农村饮水工程</a-select-option>
                <a-select-option value="3">水毁</a-select-option>
              </a-select>
            </a-form-item>
          </a-form>
          <a-form :model="formData" layout="inline">
            <a-form-item label="工程类别">
              <a-input
                v-model:value="formData.wtdstType"
                placeholder="请输入工程类别"
                allow-clear
              />
            </a-form-item>
            <a-form-item label="修复状态">
              <a-select
                v-model:value="formData.engScal"
                placeholder="请选择"
                allow-clear
                style="width: 110px"
              >
                <a-select-option value="1">已修复</a-select-option>
                <a-select-option value="0">未修复</a-select-option>
              </a-select>
            </a-form-item>
            <a-form-item label="项目名称">
              <a-input
                v-model:value="formData.searchNameOfwtdstNm"
                placeholder="请输入项目名称"
                allow-clear
              />
            </a-form-item>
            <a-form-item>
              <a-button type="primary" @click="getTableData">
                查询
              </a-button>
            </a-form-item>
          </a-form>
          <a-table
            :row-selection="{
              selectedRowKeys: selectedRowKeys,
              onChange: handleSelectionChange,
            }"
            :columns="columns2"
            :data-source="currentShowList"
            @change="handleCurrentChange"
            :loading="loading"
            rowKey="index"
            :pagination="{
              total,
              defaultPageSize: pageSize,
              showTotal: (total) => `共${total}条`,
            }"
            style="width: 100%;"
          >
            <template #bodyCell="{ column, record }">
              <span v-if="column.dataIndex === 'wtdstState'">
                <span v-if="record.wtdstState == 1">已修复</span>
                <span v-else>未修复</span>
              </span>
            </template>
          </a-table>
        </div>
        <div v-if="objType == '5'" style="padding:10px">
          <a-form :model="formData" layout="inline">
            <a-form-item label="测站名称">
              <a-input
                v-model:value="formData.stnm"
                placeholder="请输入测站名称"
                allow-clear
              />
            </a-form-item>
            <a-form-item>
              <a-button type="primary" @click="refreshCurrentShow">
                查询
              </a-button>
            </a-form-item>
          </a-form>
          <a-table
            :row-selection="{
              selectedRowKeys: selectedRowKeys,
              onChange: handleSelectionChange,
            }"
            :columns="columns3"
            :data-source="currentShowList"
            @change="handleCurrentChange"
            :loading="loading"
            rowKey="index"
            :pagination="{
              total,
              defaultPageSize: pageSize,
              showTotal: (total) => `共${total}条`,
            }"
            style="width: 100%;"
          >
          </a-table>
        </div>
      </a-layout-content>
    </a-layout>
    <a-modal
      title="添加新水库"
      v-model:open="addRsvrVisible"
      @ok="addNewRsvr('formObj')"
      @cancel="addRsvrVisible = false"
      width="50%"
    >
      <a-form
        :model="formObj"
        :rules="rules"
        ref="formObj"
        :label-col="{ span: 4 }"
        style="max-width:100%"
      >
        <a-form-item label="水库名称" required>
          <a-input v-model:value="formObj.rsName" autocomplete="off" />
        </a-form-item>
        <a-form-item label="管理机构">
          <a-input v-model:value="formObj.rsAdmName" autocomplete="off" />
        </a-form-item>
        <a-form-item label="行政区域" required>
          <div>
            <a-select
              v-model:value="provName"
              @change="provChange"
              placeholder="选择省"
            >
              <a-select-option
                v-for="item in provList"
                :key="item.adCode"
                :value="item.adCode"
              >{{ item.adName }}</a-select-option
              >
            </a-select>
            <a-select
              v-model:value="cityName"
              @change="cityChange"
              placeholder="选择市"
            >
              <a-select-option
                v-for="item in cityList"
                :key="item.adCode"
                :value="item.adCode"
              >{{ item.adName }}</a-select-option
              >
            </a-select>
            <a-select
              v-model:value="countryName"
              @change="countryChange"
              placeholder="选择县"
            >
              <a-select-option
                v-for="item in countryList"
                :key="item.adCode"
                :value="item.adCode"
              >{{ item.adName }}</a-select-option
              >
            </a-select>
          </div>
        </a-form-item>
        <a-form-item label="所在地点" required>
          <a-input v-model:value="formObj.location" autocomplete="off" />
        </a-form-item>
        <a-form-item label="建成时间">
          <a-date-picker v-model:value="formObj.compDate" placeholder="选择日期" />
        </a-form-item>
        <a-form-item label="工程规模" required>
          <a-select v-model:value="formObj.engScal" placeholder="请选择">
            <a-select-option
              v-for="item in gongchengguimo"
              :key="item.value"
              :value="item.value"
            >{{ item.label }}</a-select-option
            >
          </a-select>
        </a-form-item>
        <a-form-item label="总库容(万m³)">
          <a-input v-model:value="formObj.totCap" autocomplete="off" />
        </a-form-item>
        <a-form-item label="最大坝高(m)">
          <a-input v-model:value="formObj.damSizeHig" autocomplete="off" />
        </a-form-item>
        <a-form-item label="主坝坝型">
          <a-select v-model:value="formObj.rsType" placeholder="请选择">
            <a-select-option
              v-for="item in zhubaleixing"
              :key="item.value"
              :value="item.value"
            >{{ item.label }}</a-select-option
            >
          </a-select>
        </a-form-item>
        <a-form-item label="注册登记号">
          <a-input v-model:value="formObj.regCode" autocomplete="off" />
        </a-form-item>
        <a-form-item label="经度">
          <a-input v-model:value="formObj.longitude" autocomplete="off" />
        </a-form-item>
        <a-form-item label="纬度">
          <a-input v-model:value="formObj.latitude" autocomplete="off" />
        </a-form-item>
      </a-form>
    </a-modal>
  </a-modal>
</template>

<script>
import {
  addDcAndObjRel,
  getObjListNotInspGroupId,
} from '../../api/duChaDuiXiang_xsk_API.js';
import request from '../../utils/gw_ajax_request.js';
import provTreeList from '../../widgets/provTreeList.vue';
import provTreeListQy from '../../widgets/provTreeList_quyu.vue';
import upload from '../../widgets/uploadXls.vue';

export default {
  props: ['dczId', 'dczName', 'plnaId', 'objType', 'pType'],
  data() {
    return {
      form: { objTypeName: '小水库' },
      formData: {
        regCode: '',
        engScal: undefined,
        searchNameOfRsName: '',
        searchNameOfAdName: '',
        wtdstType: '',
        wtdstState: undefined,
        searchNameOfwtdstNm: '',
      },
      selectedRowKeys: [],
      columns: [
        {
          title: '序号',
          dataIndex: 'index',
          align: 'center',
          ellipsis: true,
        },
        {
          title: '注册登记码',
          dataIndex: 'regCode',
          align: 'center',
          ellipsis: true,
        },
        {
          title: '水库名称',
          dataIndex: 'rsName',
          align: 'center',
          ellipsis: true,
        },
        {
          title: '行政区划',
          dataIndex: 'location',
          align: 'center',
          ellipsis: true,
        },
        {
          title: '工程规模',
          dataIndex: 'engScal',
          align: 'center',
          ellipsis: true,
        },
        {
          title: '归口管理部门',
          dataIndex: 'rsAdmDep',
          align: 'center',
          ellipsis: true,
        },
        {
          title: '总库容',
          dataIndex: 'totCap',
          align: 'center',
          ellipsis: true,
        },
      ],
      columns1: [
        {
          title: '序号',
          dataIndex: 'index',
          align: 'center',
          ellipsis: true,
        },
        {
          title: '行政区划名称',
          dataIndex: 'adName',
          align: 'center',
          ellipsis: true,
        },
        {
          title: '全称',
          dataIndex: 'adFullName',
          align: 'center',
          ellipsis: true,
        },
        {
          title: '行政区划编码',
          dataIndex: 'adCode',
          align: 'center',
          ellipsis: true,
        },
        {
          title: '行政区划级别',
          dataIndex: 'adGrad',
          align: 'center',
          ellipsis: true,
        },
      ],
      columns2: [
        {
          title: '序号',
          dataIndex: 'index',
          align: 'center',
          ellipsis: true,
        },
        {
          title: '项目名称',
          dataIndex: 'wtdstNm',
          align: 'center',
          ellipsis: true,
        },
        {
          title: '项目所在位置',
          dataIndex: 'locNm',
          align: 'center',
          ellipsis: true,
        },
        {
          title: '修复状态',
          dataIndex: 'wtdstState',
          align: 'center',
          ellipsis: true,
        },
        {
          title: '工程类别',
          dataIndex: 'wtdstType',
          align: 'center',
          ellipsis: true,
        },
      ],
      columns3: [
        {
          title: '序号',
          dataIndex: 'index',
          align: 'center',
          ellipsis: true,
        },
        {
          title: '测站名称',
          dataIndex: 'stnm',
          align: 'center',
          ellipsis: true,
        },
        {
          title: '测站编码',
          dataIndex: 'stcd',
          align: 'center',
          ellipsis: true,
        },
        {
          title: '所属行政区',
          dataIndex: 'adnm',
          align: 'center',
          ellipsis: true,
        },
      ],
      addOnce: false,
      objTypeName: '小水库',
      xsk: true,
      ncys: false,
      shgc: false,
      dxs: false,
      regCode: '',
      searchNameOfRsName: '',
      searchNameOfAdName: '',
      searchNameOfwtdstNm: '',
      addLevel: '',
      rsAdmDep: '',
      engScal: '',
      hstInsp: '0',
      wtdstState: '',
      engLevel: '',
      wtdstType: '',
      stnm: '',
      pageIndex: 1,
      pageSize: 10,
      total: 0,
      currentShowList: [],
      dialogFormVisible: false,
      formLabelWidth: '120',
      addArr: '',
      addName: '',
      addLttd: '',
      addLgtd: '',
      multipleSelection: [],
      searchProvTreeListCode: '',
      qyDataList: [],
      loading: false,
      showLeftTree: true,
      addRsvrVisible: false,
      formObj: {
        rsName: '',
        rsAdmName: '',
        rsLoc: '',
        location: '',
        intm: '',
        engScal: '',
        totCap: '',
        damMaxHigh: '',
        damTypeStr: '',
        damType: '',
        rsType: '',
        regCode: '',
        rsvrLong: '',
        rsvrLat: '',
        compDate: '',
        admDiv: '',
        longitude: '',
        latitude: '',
        centerXGd: '',
        centerYGd: '',
      },
      areasList: [],
      gongchengguimo: [],
      xskEngscale: [
        {
          value: '4',
          label: '小（1）型',
        },
        {
          value: '5',
          label: '小（2）型',
        },
      ],
      dskEngscale: [
        {
          value: '1',
          label: '大（1）型',
        },
        {
          value: '2',
          label: '大（2）型',
        },
        {
          value: '3',
          label: '中型',
        },
      ],
      zhubaleixing: [
        {
          value: '1',
          label: '混凝土坝',
        },
        {
          value: '2',
          label: '碾压混凝土坝',
        },
        {
          value: '3',
          label: '浆砌石坝',
        },
        {
          value: '4',
          label: '土坝',
        },
        {
          value: '5',
          label: '堆石坝',
        },
        {
          value: '6',
          label: '挡水坝',
        },
        {
          value: '7',
          label: '其他',
        },
      ],
      initLoacData: [
        {
          label: '江苏',
          cities: [],
        },
        {
          label: '浙江',
          cities: [],
        },
      ],
      props: {
        value: 'id',
        label: 'label',
        children: 'cities',
      },
      rules: {
        rsName: [
          { required: true, message: '请输入水库名称', trigger: 'blur' },
        ],
        // rsAdmName: [
        // 	{ required: true, message: '请输入管理单位', trigger: 'blur' }
        // ],
        // location: [
        //   { required: true, message: '请选择所在地', trigger: 'blur' }
        // ],
        // compDate: [
        // 	{ required: true, message: '请选择完成时间', trigger: 'blur' }
        // ]
      },
      provList: [],
      cityList: [],
      countryList: [],
      provName: '',
      cityName: '',
      countryName: '',
      provNames: '',
      cityNames: '',
      countryNames: '',
      curSelectItem: 0,
    };
  },
  components: {
    provTreeListQy,
    provTreeList,
    upload,
  },
  watch: {
    dczId: function (n, o) {
      this.searchProvTreeListCode = '';
    },
    objType: function (n, o) {
      this.searchProvTreeListCode = '';
      this.objType = n;
      if (this.objType == '1' || this.objType == '36') {
        this.getTableData_sk();
        this.getAreaList();
      } else if (this.objType == '2') {
        this.getTableData();
      } else if (this.objType == '3') {
        this.getTableData();
      } else if (this.objType == '5') {
        this.getTableData_dxs(n);
      }
    },
    qyDataList(n, o) {
      if (this.qyDataList.length == 0) {
        this.showLeftTree = false;
      } else {
        this.showLeftTree = true;
      }
      if (this.objType == '1' || this.objType == '36') {
        this.getTableData_sk();
        this.getAreaList();
      } else if (this.objType == '5') {
        this.getTableData_dxs();
      }
    },
  },
  computed: {
    userId() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '1098101939614724096';
    },
  },
  mounted() {
    if (this.objType == 1) {
      this.gongchengguimo = this.xskEngscale;
    } else if (this.objType == 36) {
      this.gongchengguimo = this.dskEngscale;
    }
  },
  methods: {
    changeCurrentObjSelectName(item) {
      this.objType = item;
    },
    selectChange(val) {
      this.objType = val;
    },
    showDialog(tableCurrentRowType = null, yqList) {
      this.tableCurrentRowType = tableCurrentRowType;
      this.dialogFormVisible = true;
      if (this.tableCurrentRowType == '1' || this.tableCurrentRowType == '36') {
        // this.getTableData_sk();
        this.xsk = true;
        this.ncys = false;
        this.shgc = false;
        this.dxs = false;
        // this.getAreaList()
      } else if (this.tableCurrentRowType == '2') {
        // this.getTableData();
        this.xsk = false;
        this.ncys = true;
        this.shgc = false;
        this.dxs = false;
      } else if (this.tableCurrentRowType == '3') {
        // this.getTableData();
        this.xsk = false;
        this.ncys = false;
        this.shgc = true;
        this.dxs = false;
      } else {
        this.xsk = false;
        this.ncys = false;
        this.shgc = false;
        this.dxs = true;
      }
      const markObjType = tableCurrentRowType || this.objType; // 添加额外参数规避watch的先后执行问题
      // if((markObjType=='1' || markObjType=='36' || markObjType=='5') && this.showLeftTree){
      this.$nextTick(() => {
        this.$refs['provTreeListQyRef'].getQyList();
      });
      // }
      if (markObjType == '1' || markObjType == '36') {
        this.getTableData_sk();
      } else if (markObjType == '2' || markObjType == '3') {
        // if(this.qyDataList && this.qyDataList.length==0){
        if (yqList && yqList.length) {
          this.qyDataList = [];
          yqList.forEach((item) => {
            this.qyDataList.push(item);
          });
        }
        // }
        this.getTableData();
      } else {
        this.getTableData_dxs();
      }
    },
    saveChange() {
      this.selectedRowKeys = [];
      this.addObjectChange();
    },
    treeDataEmit(item) {
      this.qyDataList = item;
      if (this.qyDataList.length == 0) {
        this.showLeftTree = false;
      } else {
        this.showLeftTree = true;
      }
    },
    getTableData_dxs() {
      if (this.qyDataList.length == 0) {
        this.showLeftTree = false;
      } else {
        this.showLeftTree = true;
      }
      this.loading = true;
      var str = '';
      for (var i = 0; i < this.qyDataList.length; i++) {
        str += this.qyDataList[i].adCode + ',';
      }
      str = str.substring(0, str.length - 1);
      var obj = {
        adcd: str,
        adnm: '',
        groupId: this.dczId,
        stcd: '',
        stnm: this.stnm,
        sttp: '',
        pageNum: this.pageIndex,
        pageSize: this.pageSize,
      };
      request.post('/dc/insp/obj/getGrwNotInGroup', obj).then((res) => {
        this.loading = false;
        this.currentShowList = res.data.list;
        this.currentShowList.forEach((element, index) => {
          element['index'] = this.pageSize * (this.pageIndex - 1) + index + 1;
        });
        this.total = res.data.total;
      });
    },
    getTableData_sk() {
      if (this.qyDataList.length == 0) {
        this.showLeftTree = false;
      } else {
        this.showLeftTree = true;
      }
      this.loading = true;
      var str = '';
      for (var i = 0; i < this.qyDataList.length; i++) {
        str += this.qyDataList[i].adCode + ',';
      }
      str = str.substring(0, str.length - 1);
      var obj = {
        adcd: str,
        rsName: this.searchNameOfRsName,
        engScal: this.engScal,
        id: this.userId,
        groupId: this.dczId,
        pageNum: this.pageIndex,
        pageSize: this.pageSize,
        pType: this.objType,
        regCode: this.regCode,
      };
      // request.post('/dc/insp/selarea/getResByArea',obj).then((res)=>{
      //   _self.loading = false;
      //     _self.currentShowList = res.data.list;
      //     _self.currentShowList.forEach((element, index) => {
      //       element["index"] = _self.pageSize * (_self.pageIndex - 1) + index + 1;
      //     });
      //     _self.total = res.data.total;
      // })
      request.post('/dc/insp/selarea/getResByGroup', obj).then((res) => {
        this.loading = false;
        this.currentShowList = res.data.list;
        this.currentShowList.forEach((element, index) => {
          element['index'] = this.pageSize * (this.pageIndex - 1) + index + 1;
        });
        this.total = res.data.total;
      });
    },
    getTableData: function (callBackFunction = null) {
      this.searchNameOfAdName = this.formData.searchNameOfAdName;
      this.wtdstType = this.formData.wtdstType;
      this.wtdstState = this.formData.wtdstState;
      this.searchNameOfwtdstNm = this.formData.searchNameOfwtdstNm;
      if (!this.dczId) {
        // this.dczId = 'jwW2Wihf5E9X3UC9t45fmSHyffUs2rzI';
      }
      if (this.objType == '1' || this.objType == '36' || this.objType == '5') {
        return;
      }
      let str = '';
      for (var i = 0; i < this.qyDataList.length; i++) {
        str += this.qyDataList[i].adCode + ',';
      }
      str = str.substring(0, str.length - 1);
      getObjListNotInspGroupId(
        this.dczId,
        this.objType,
        this.pageSize,
        this.pageIndex,
        this.searchNameOfRsName, // 水库名称
        this.searchNameOfAdName, // 农村饮水行政区划名称
        this.searchNameOfwtdstNm, // 水毁工程名称
        this.engScal, // 水库-工程规模
        this.rsAdmDep, // 水库-归口管理部门
        this.wtdstType, // 水毁-工程类别
        this.wtdstState, // 水毁-修复状态
        this.searchProvTreeListCode == '' ? str : this.searchProvTreeListCode,
      ).then(
        (res) => {
          this.currentShowList = [];
          res.data.list.forEach((element, index) => {
            element['index'] = this.pageSize * (this.pageIndex - 1) + index + 1;
            this.currentShowList.push(element);
          });
          this.total = res.data.total;
          if (callBackFunction && typeof callBackFunction === 'function') {
            callBackFunction();
          }
        },
        (err) => {
          if (callBackFunction && typeof callBackFunction === 'function') {
            callBackFunction();
          }
        },
      );
    },
    handleSelectionChange(val, row) {
      this.selectedRowKeys = val;
      this.multipleSelection = row;
    },
    handleCurrentChange(val) {
      this.pageIndex = val.current;
      this.refreshCurrentShow();
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.refreshCurrentShow();
    },
    refreshCurrentShow: function () {
      this.searchNameOfRsName = this.formData.searchNameOfRsName;
      this.engScal = this.formData.engScal;
      this.regCode = this.formData.regCode;
      this.stnm = this.formData.stnm;
      if (this.objType == '1' || this.objType == '36') {
        if (this.searchProvTreeListCode) {
          this.getTableData_sk1();
        } else {
          this.getTableData_sk();
        }
      } else if (this.objType == '2' || this.objType == '3') {
        this.getTableData();
      } else {
        this.getTableData_dxs();
      }
    },

    addObjectChange: function () {
      if (this.addOnce) {
        this.addOnce = false;
        return;
      }
      this.addOnce = true;
      this.addArr = '';
      this.addName = '';
      this.addLttd = '';
      this.addLgtd = '';
      const length = this.multipleSelection.length;
      if (this.objType == '1' || this.objType == '36') {
        for (let i = 0; i < length; i++) {
          this.addArr += this.multipleSelection[i].rsCode + ',';
          this.addName += this.multipleSelection[i].rsName + ',';
          this.addLttd += this.multipleSelection[i].latitude + ',';
          this.addLgtd += this.multipleSelection[i].longitude + ',';
        }
      } else if (this.objType == '2') {
        for (let i = 0; i < length; i++) {
          this.addArr += this.multipleSelection[i].adCode + ',';
          this.addName += this.multipleSelection[i].adName + ',';
          this.addLttd += this.multipleSelection[i].lttd + ',';
          this.addLgtd += this.multipleSelection[i].lgtd + ',';
        }
      } else if (this.objType == '3') {
        for (let i = 0; i < length; i++) {
          this.addArr += this.multipleSelection[i].wtdstId + ',';
          this.addName += this.multipleSelection[i].wtdstNm + ',';
          this.addLttd += this.multipleSelection[i].wtdstLttd + ',';
          this.addLgtd += this.multipleSelection[i].wtdstLgtd + ',';
        }
      } else if (this.objType == '5') {
        for (let i = 0; i < length; i++) {
          this.addArr += this.multipleSelection[i].stcd + ',';
          this.addName += this.multipleSelection[i].stnm + ',';
          this.addLttd += this.multipleSelection[i].lttd + ',';
          this.addLgtd += this.multipleSelection[i].lgtd + ',';
        }
      }

      this.addArr = this.addArr.substr(0, this.addArr.length - 1);
      this.addName = this.addName.substr(0, this.addName.length - 1);
      this.addLttd = this.addLttd.substr(0, this.addLttd.length - 1);
      this.addLgtd = this.addLgtd.substr(0, this.addLgtd.length - 1);
      try {
        // inspGroupId,objId,objType,plnaId
        const objType = this.objType;
        addDcAndObjRel(
          this.addArr,
          this.addName,
          this.addLttd,
          this.addLgtd,
          objType,
          this.dczId,
          this.plnaId,
          this.plnaId,
        ).then((response) => {
          if (response.success == true) {
            this.addOnce = false;
            this.dialogFormVisible = false;
            // this.getTableData();
            this.$message.success('添加成功');
            this.$emit('addSuccess');
            // _self.dczId = "";
            this.addArr = '';
          } else {
            this.addOnce = false;
            this.dialogFormVisible = false;
            this.$message.error(response.message);
          }
        });
      } catch (e) {
        alert('暂无数据');
      }
    },
    provTreeSelectChangeHandler: function (params) {
      this.searchProvTreeListCode = params.code;
      if (this.objType == '1' || this.objType == '36') {
        this.getTableData_sk1();
      } else if (this.objType == '2' || this.objType == '3') {
        this.getTableData();
      } else {
      }
    },
    provTreeSelectChangeHandler_qy(params) {
      this.searchProvTreeListCode = params.code;
      if (this.objType == '1' || this.objType == '36') {
        this.getTableData_sk1();
      } else if (this.objType == '5') {
        this.getTableData_dxs1();
      } else if (this.objType == '2' || this.objType == '3') {
        this.getTableData();
      }
    },
    getTableData_dxs1() {
      var obj = {
        adcd: this.searchProvTreeListCode,
        adnm: '',
        groupId: this.dczId,
        stcd: '',
        stnm: this.stnm,
        sttp: '',
        pageNum: this.pageIndex,
        pageSize: this.pageSize,
      };
      request.post('/dc/insp/obj/getGrwNotInGroup', obj).then((res) => {
        this.loading = false;
        this.currentShowList = res.data.list;
        this.currentShowList.forEach((element, index) => {
          element['index'] = this.pageSize * (this.pageIndex - 1) + index + 1;
        });
        this.total = res.data.total;
      });
    },
    getTableData_sk1() {
      const objType = this.objType;
      var obj = {
        adcd: this.searchProvTreeListCode,
        rsName: this.searchNameOfRsName,
        engScal: this.engScal,
        id: this.userId,
        groupId: this.dczId,
        pageNum: this.pageIndex,
        pageSize: this.pageSize,
        pType: objType,
        regCode: this.regCode,
      };
      request.post('/dc/insp/selarea/getResByGroup', obj).then((res) => {
        this.loading = false;
        this.currentShowList = res.data.list;
        this.currentShowList.forEach((element, index) => {
          element['index'] = this.pageSize * (this.pageIndex - 1) + index + 1;
        });
        this.total = res.data.total;
      });
    },
    toAddNewRsvr() {
      if (this.objType == 1) {
        this.gongchengguimo = this.xskEngscale;
      } else if (this.objType == 36) {
        this.gongchengguimo = this.dskEngscale;
      }
      this.addRsvrVisible = true;
      this.formObj.engScal = this.gongchengguimo[0].value;
      this.formObj.rsType = this.zhubaleixing[0].value;
    },
    addNewRsvr(formName) {
      if (!this.formObj.rsName) {
        this.$message.warning('请输入水库名称');
        return;
      }
      // if(!this.formObj.rsAdmName){
      // 	this.$message.warning('请输入管理机构名称')
      // 	return
      // }
      if (!this.formObj.location) {
        this.$message.warning('请输入所在地');
        return;
      }
      // if(!this.formObj.compDate){
      // 	this.$message.warning('请选择建成时间')
      // 	return
      // }
      if (!this.formObj.engScal) {
        this.$message.warning('请选择工程规模');
        return;
      }
      this.formObj.centerXGd = this.formObj.longitude;
      this.formObj.centerYGd = this.formObj.latitude;
      this.$refs[formName].validate((valid) => {
        if (valid) {
          request
            .post('/dc/att/rsBase', this.formObj)
            .then((res) => {
              if (res.success) {
                this.$message.success('添加成功');
                this.refreshCurrentShow();
                this.addRsvrVisible = false;
                this.formObj = {
                  rsName: '',
                  rsAdmName: '',
                  rsLoc: '',
                  location: '',
                  intm: '',
                  engScal: '',
                  totCap: '',
                  damMaxHigh: '',
                  damTypeStr: '',
                  damType: '',
                  rsType: '',
                  regCode: '',
                  rsvrLong: '',
                  rsvrLat: '',
                  compDate: '',
                  admDiv: '',
                  longitude: '',
                  latitude: '',
                  centerXGd: '',
                  centerYGd: '',
                };
              } else {
                this.$message.error(res.message);
              }
            })
            .catch((res) => {
              this.$message.error('请求错误' + res.message);
            });
        } else {
          return false;
        }
      });
    },
    getAreaList(val) {
      const areaParams = {
        adName: '',
        id: this.dczId,
        pageNum: 1,
        pageSize: 10000,
      };

      let adCode = '';
      if (!val) {
        adCode = '000000000000';
      } else {
        adCode = val;
      }
      request
        .get('/dc/ad/base/getAdData', { params: { adCode: adCode } })
        .then((res) => {
          if (res.success) {
            if (this.curSelectItem == 1) {
              this.cityList = res.data;
            } else if (this.curSelectItem == 2) {
              this.countryList = res.data;
            } else {
              this.provList = res.data;
            }
          }
        });
    },
    handleItemChange(val) {
      this.getAreaList(val);
    },
    provChange(val) {
      this.curSelectItem = 1;
      this.cityName = '';
      this.countryName = '';
      this.formObj.admDiv = val;
      this.provList.forEach((ele) => {
        if (ele.adCode == this.provName) {
          this.provNames = ele.adName;
        }
      });
      this.formObj.location = this.provNames;
      this.getAreaList(val);
    },
    cityChange(val) {
      this.curSelectItem = 2;
      if (val && val != '') {
        this.formObj.admDiv = val;
        this.countryName = '';
        this.cityList.forEach((ele) => {
          if (ele.adCode == this.cityName) {
            this.cityNames = ele.adName;
          }
        });
        this.formObj.location = this.provNames + this.cityNames;
        this.getAreaList(val);
      }
    },
    countryChange(val) {
      if (val && val != '') {
        this.formObj.admDiv = val;
        this.countryList.forEach((ele) => {
          if (ele.adCode == this.countryName) {
            this.countryNames = ele.adName;
          }
        });
        this.formObj.location =
          this.provNames + this.cityNames + this.countryNames;
      }
    },
  },
};
</script>

<style lang="less" scoped>
:deep(.ant-table-pagination) {
  float: left;
}
:deep(.ant-table-thead > tr > th),
:deep(.ant-table-tbody > tr > td) {
  padding: 0;
  height: 36px;
}
:deep(.form .ant-select) {
  width: 20%;
}
:deep(.ant-form-item) {
  margin-bottom: 10px;
}
</style>
