<template>
  <div style="height:100%;max-height:100%;overflow-y:hidden;display:flex;flex-direction:column;justify-content:space-between;">
    <div class="box-card" style="background-color: #ECF8FF; height: 40px; font-size: small; line-height: 30px; display: flex; justify-content: space-between; align-items: center;">
      <div style="display:flex;" class="checkbox_left">
        <a-checkbox :checked="checked" @change="onChecked">本级</a-checkbox>
        <a-input-search
          v-model="input5"
          placeholder="请输入对象名称"
          enter-button
          @search="searchDcryResult"
          allow-clear
          style="width: 200px; margin-left: 30px;"/>
      </div>
      <a-button
        v-if="dczId && dczId.length==12"
        v-show="showEdit"
        @click="editHandler"
        type="primary"
        icon="edit"
        size="small"
        ghost
        style="float: right; margin-right: 10px; height: 30px;">添加对象</a-button>
    </div>
    <component
      :is="curComponent"
      :tableData="tableData"
      :objType="objType"
      :pageIndex="pageIndex"
      :loading="loading"
      :pageSize="pageSize"
      :total="total"
      @handleCurrentChange="handleCurrentChange"
      @deleteHandler="deleteHandler"></component>
  </div>
</template>

<script>
import { Modal } from 'ant-design-vue';
import { deleteDcdxByObjid, getDcdxList } from '../../../api/duChaPlan';
import common from './duChaDuiXiangSingle/common.vue';
import diFangGongCheng from './duChaDuiXiangSingle/diFangGongCheng.vue';
import difanggongchengduxun from './duChaDuiXiangSingle/difanggongchengduxun.vue';
import dike2022 from './duChaDuiXiangSingle/dike2022.vue';
import fanghonggongchengfuchazhenggai from './duChaDuiXiangSingle/fanghonggongchengfuchazhenggai.vue';
import hehuweishi from './duChaDuiXiangSingle/hehuweishi.vue';
import ncgsgc from './duChaDuiXiangSingle/ncgsgc.vue';
import nongcunyinshuianquan from './duChaDuiXiangSingle/nongcunyinshuianquan.vue';
import nongyin from './duChaDuiXiangSingle/nongyin.vue';
import quShuiGongCheng from './duChaDuiXiangSingle/quShuiGongCheng.vue';
import renyin from './duChaDuiXiangSingle/renyin.vue';
import shuihui from './duChaDuiXiangSingle/shuihui.vue';
import shuikufanghongdiaodu from './duChaDuiXiangSingle/shuikufanghongdiaodu.vue';
import shuilitisunian from './duChaDuiXiangSingle/shuilitisunian.vue';
import shuixingzhengzhifa from './duChaDuiXiangSingle/shuixingzhengzhifa.vue';
import shuiyuandi from './duChaDuiXiangSingle/shuiyuandi.vue';
import shuiZiYuanJieShui from './duChaDuiXiangSingle/shuiZiYuanJieShui.vue';
import shuizha from './duChaDuiXiangSingle/shuizha.vue';
import shujunshashi from './duChaDuiXiangSingle/shujunshashi.vue';
import siLuanQianYi from './duChaDuiXiangSingle/siLuanQianYi.vue';
import sjzhdcjh from './duChaDuiXiangSingle/sjzhdcjh.vue';
import slaqscdpc from './duChaDuiXiangSingle/slaqscdpc.vue';
import villsaf from './duChaDuiXiangSingle/villsaf.vue';
import xiaoshuidian from './duChaDuiXiangSingle/xiaoshuidian.vue';
import xiaoshuiku from './duChaDuiXiangSingle/xiaoshuiku.vue';
import yingjibeiyongshuiyuan from './duChaDuiXiangSingle/yingjibeiyongshuiyuan.vue';
import zhongDianShuiHuiGongCheng from './duChaDuiXiangSingle/zhongDianShuiHuiGongCheng.vue';
import zhongDianShuiLi from './duChaDuiXiangSingle/zhongDianShuiLi.vue';
export default {
  props: ['dczId', 'zuName', 'objType', 'plnaId', 'activeContent'], // objType业务类型
  data() {
    return {
      input5: '',
      objTypeName: '小水电',
      xsk: true,
      ncys: false,
      shgc: false,
      dxs: false,
      sz: false,
      jsh: false,
      yx: false,
      showEdit: true,
      tableData: [],
      currentShowList: [],
      pageIndex: 1,
      pageSize: 10,
      total: 0,
      loading: true,
      tableHeight: window.innerHeight - 200,
      tableHeight1: window.innerHeight - 355,
      checked: false,
      isAll: '1',
      curComponent: 'xiaoshuidian',
    };
  },
  components: {
    xiaoshuiku,
    renyin,
    shuihui,
    shuizha,
    hehuweishi,
    shujunshashi,
    shuilitisunian,
    xiaoshuidian,
    diFangGongCheng,
    shuiZiYuanJieShui,
    quShuiGongCheng,
    zhongDianShuiHuiGongCheng,
    siLuanQianYi,
    shuiyuandi,
    nongyin,
    zhongDianShuiLi,
    shuixingzhengzhifa,
    yingjibeiyongshuiyuan,
    shuikufanghongdiaodu,
    nongcunyinshuianquan,
    difanggongchengduxun,
    fanghonggongchengfuchazhenggai,
    slaqscdpc,
    ncgsgc,
    common,
    dike2022,
    villsaf,
    sjzhdcjh,
  },
  mounted() {
    this.input5 = '';
    this.getDcdxList1();
    this.judgeCurCom();
  },
  methods: {
    // 根据objType初始化展示对象
    // 1 小水库  2 人饮  3 水毁  6 水闸 36 大中型水库 24江西小水库标准化
    judgeCurCom() {
      if (this.objType == '1' || this.objType == '36' || this.objType == '24') {
        this.curComponent = 'xiaoshuiku';
      } else if (this.objType == '2') {
        this.curComponent = 'renyin';
      } else if (this.objType == '3') {
        this.curComponent = 'shuihui';
      } else if (this.objType == '6') {
        this.curComponent = 'shuizha';
      } else if (this.objType == '50') {
        this.curComponent = 'hehuweishi';
      } else if (this.objType == '52') {
        this.curComponent = 'shujunshashi';
      } else if (this.objType == '51') {
        this.curComponent = 'shuilitisunian';
      } else if (this.objType == '59') {
        this.curComponent = 'xiaoshuidian';
      } else if (this.objType == '58') {
        // 堤防工程
        this.curComponent = 'diFangGongCheng';
      } else if (this.objType == '60') {
        // 水资源节水
        this.curComponent = 'shuiZiYuanJieShui';
      } else if (this.objType == '64') {
        // 取水工程
        this.curComponent = 'quShuiGongCheng';
      } else if (this.objType == '66') {
        // 66 重点水毁工程
        this.curComponent = 'zhongDianShuiHuiGongCheng';
      } else if (this.objType == '61') {
        this.curComponent = 'shuiyuandi';
      } else if (this.objType == '63') {
        this.curComponent = 'nongyin';
      } else if (this.objType == '18') {
        // 18 四乱迁移
        this.curComponent = 'siLuanQianYi';
      } else if (this.objType == '65') {
        // 65 重点水利
        this.curComponent = 'zhongDianShuiLi';
      } else if (this.objType == '85') {
        // 85 水行政执法
        this.curComponent = 'shuixingzhengzhifa';
      } else if (this.objType == '86') {
        // 86 水库防洪调度
        this.curComponent = 'shuikufanghongdiaodu';
      } else if (this.objType == '87') {
        // 87 应急备用水源
        this.curComponent = 'yingjibeiyongshuiyuan';
      } else if (this.objType == '88') {
        // 88 农村饮水安全
        this.curComponent = 'nongcunyinshuianquan';
      } else if (this.objType == '90') {
        // 90 堤防工程度汛
        this.curComponent = 'difanggongchengduxun';
      } else if (this.objType == '92') {
        // 92 防洪工程复查整改
        this.curComponent = 'fanghonggongchengfuchazhenggai';
      } else if (this.objType == '107') {
        // 107 水利安全生产大排查
        this.curComponent = 'slaqscdpc';
      } else if (this.objType == '109') {
        // 109 农村供水工程
        this.curComponent = 'ncgsgc';
      } else if (this.objType == '111') {
        // 111 通用督查
        this.curComponent = 'common';
      } else if (this.objType == '114') {
        // 114 堤防工程2022
        this.curComponent = 'dike2022';
      } else if (this.objType == '117') {
        // 114 堤防工程2022
        this.curComponent = 'villsaf';
      } else if (this.objType == '1110') {
        // 1110 省级综合督查计划
        this.curComponent = 'sjzhdcjh';
      }
    },
    getDcdxList1() {
      if (!this.dczId) {
        this.loading = false;
        return;
      }
      this.loading = true;
      const type = this.objType == '1110' ? '111' : this.objType;
      getDcdxList(
        this.dczId,
        type,
        this.pageSize,
        this.pageIndex,
        this.isAll,
        this.input5,
        this.input5,
        this.input5,
      ).then((response) => {
        var res = response.data;
        this.tableData = res.list;
        this.total = res.total;
        this.loading = false;
        this.tableData.forEach((element, index) => {
          element['index'] = this.pageSize * (this.pageIndex - 1) + index + 1;
        });
      });
    },
    onChecked(e) {
      this.checked = e.target.checked;
    },
    searchDcryResult(val) {
      this.input5 = val;
      this.pageIndex = 1;
      this.getDcdxList1();
    },
    editHandler(item) {
      this.$emit('showEditDialog_dx');
    },
    handleCurrentChange(item) {
      this.pageIndex = item;
      this.getDcdxList1();
    },
    deleteHandler(item) {
      const type = this.objType == '1110' ? '111' : this.objType;
      Modal.confirm({
        title: '提示',
        content: '是否确认删除?',
        okType: 'warning',
        onOk: () => {
          if (type == '111') {
            deleteDcdxByObjid(item.objId, type, '1').then((res) => {
              if (res.success) {
                this.getDcdxList1();
                this.$message.success('删除成功');
              } else {
                if (res.message == '请先删除登记表') {
                  this.$message.warning('请联系管理员，删除登记表！');
                } else {
                  this.$message.error('请删除失败');
                }
              }
            });
          } else {
            deleteDcdxByObjid(item.objId, type).then((res) => {
              if (res.success) {
                this.getDcdxList1();
                this.$message.success('删除成功');
              } else {
                if (res.message == '请先删除登记表') {
                  this.$message.warning('请联系管理员，删除登记表！');
                } else {
                  this.$message.error('请删除失败');
                }
              }
            });
          }
          return Promise.resolve();
        },
        onCancel: () => {
          this.$message.info('已取消删除');
        },
      });
    },
  },
  computed: {
    isAdmin: () =>
      localStorage.getItem('isAdmin') ? localStorage.getItem('isAdmin') : '',
  },
  watch: {
    objType(n, o) {
      this.judgeCurCom();
    },
    objTypeName(n, o) {
      this.$emit('emitCurrentObjSelectName', n);
    },
    dczId: {
      immediate: true,
      handler(n, o) {
        this.getDcdxList1();
      },
    },
    checked(n, o) {
      if (n == true) {
        this.isAll = '0';
      } else {
        this.isAll = '1';
      }
      this.pageIndex = 1;
      this.getDcdxList1();
    },
    // 为了删除区域点回对象列表后更新列表
    activeContent(val) {
      if (val == 'second') {
        this.getDcdxList1();
      }
    },
  },
};
</script>

<style lang='less' scoped>
.checkbox_left{
  margin-left: 20px;
}
:deep(.ant-checkbox-wrapper) {
  white-space: nowrap;
}
</style>
