<template>
  <a-row :gutter="10">
    <a-col :span="11">
      <a-radio-group v-model:value="modeTp" button-style="solid" @change="modeTpChange" style="margin: 5px">
        <a-radio-button :value="1">标准库管理</a-radio-button>
        <a-radio-button :value="2">控制项查询</a-radio-button>
        <a-radio-button :value="5">管理要求</a-radio-button>
        <a-radio-button :value="3">文档库</a-radio-button>
        <a-radio-button :value="4">生成检查表</a-radio-button>
        <!-- <a-radio-button :value="6">内控要求库</a-radio-button> -->
        <!-- <a-radio-button :value="6">任务分配</a-radio-button>
        <a-radio-button :value="7">报告填写</a-radio-button> -->
      </a-radio-group>
    </a-col>
    <a-col :span="13">
      <span style="line-height: 30px">全表搜索：</span>
      <a-select v-if="modeTp == 1" v-model:value="srhContentTp" style="width: 15%" :options="srhColOptions" />
      <vxe-input v-model="srhContent" type="search" placeholder="请输入" clearable @keyup.enter="handleSearch()" style="width: 35%; margin: 0px" />
      <a-button type="link" @click="handleSearch()">搜索</a-button>
      <a-button type="link" @click="refresh()">刷新</a-button>
    </a-col>
  </a-row>

  <LibIndex v-if="modeTp == 1" ref="refLibIndex" @callback="callback" @callBackAct="callBackAct" @setSearchTp="setSearchTp" />
  <ActIndex v-if="modeTp == 2" ref="refActIndex" @callback="callback" />
  <DocFilesList v-if="modeTp == 3" ref="refDocFilesList" @callback="callback" />
  <ReportIndex v-if="modeTp == 4" ref="refReportIndex" @callback="callback" />
  <RuleIndex v-if="modeTp == 5" ref="refRuleIndex" @callback="callback" @callBackAct="callBackAct" />
  <InnerCtrlIndex v-if="modeTp == 6" ref="refInnererCtrlIndex" @callback="callback" @callBackAct="callBackAct" />
</template>
<script lang="ts" setup>
  import { ref, nextTick, useAttrs } from 'vue';
  import LibIndex from './LibIndex.vue';
  import ActIndex from './ActIndex.vue';
  import ReportIndex from './ReportIndex.vue';
  import RuleIndex from './RuleIndex.vue';
  import DocFilesList from './components/doc/DocFilesIndex.vue';
  import InnerCtrlIndex from './InnerCtrlIndex.vue';

  import { useRoute } from 'vue-router';

  const route = useRoute();
  const paramid = route.query.id as string | undefined;
  const paramtp = route.query.tp as string | undefined;

  const srhContentTp = ref('');
  const srhContent = ref('');
  const modeTp = ref(1);
  const refLibIndex = ref();
  const refActIndex = ref();
  const refReportIndex = ref();
  const refRuleIndex = ref();

  const refInnererCtrlIndex = ref();

  const srhColOptions = ref([]);

  function handleSearch() {
    if (modeTp.value == 1) {
      refLibIndex.value.handleSearch(srhContent.value, srhContentTp.value);
    } else if (modeTp.value == 2) {
      refActIndex.value.handleSearch(srhContent.value);
    } else if (modeTp.value == 4) {
      refReportIndex.value.handleSearch(srhContent.value);
    } else if (modeTp.value == 5) {
      refRuleIndex.value.handleSearch(srhContent.value);
    } else if (modeTp.value == 6) {
      refInnererCtrlIndex.value.handleSearch(srhContent.value);
    }
  }

  async function modeTpChange() {
    await nextTick();
    if (modeTp.value == 1) {
      if (paramtp) {
        let tp = Number(paramtp);
        let id = Number(paramid);
        refLibIndex.value.paramLibList(tp, id);
      } else {
        refLibIndex.value.iniLibList();
      }
    } else if (modeTp.value == 2) {
      refActIndex.value.iniActList();
    } else if (modeTp.value == 4) {
      refReportIndex.value.iniActList();
    } else if (modeTp.value == 5) {
      refRuleIndex.value.iniLeftData();
    } else if (modeTp.value == 6) {
      refInnererCtrlIndex.value.iniData();
    }
  }

  function callback(srcTxt) {
    srhContent.value = srcTxt || '';
  }

  function setSearchTp(options) {
    srhContentTp.value = '';
    srhColOptions.value = options;
  }

  async function refresh() {
    srhContent.value = '';
    if (modeTp.value == 1) {
      refLibIndex.value.iniLibList();
    } else if (modeTp.value == 2) {
      refActIndex.value.iniActList();
    } else if (modeTp.value == 4) {
      refReportIndex.value.refresh();
    } else if (modeTp.value == 5) {
      refRuleIndex.value.refresh();
    } else if (modeTp.value == 6) {
      refInnererCtrlIndex.value.iniData();
    }
  }

  async function callBackAct(srhTxt, stp) {
    if (stp == 1) {
      srhContent.value = srhTxt;
      modeTp.value = 1;
      await handleSearch();
    } else if (stp == 5) {
      srhContent.value = srhTxt;
      modeTp.value = 5;
      await handleSearch();
    } else {
      modeTp.value = 2;
      nextTick(async () => {
        await refActIndex.value.iniActList(srhTxt);
      });
    }
  }

  modeTpChange();
</script>

<style scope>
  .underline-input {
    border-left: none;
    border-top: none;
    border-right: none;
    width: 100%;
  }
  .ant-tabs-large > .ant-tabs-nav .ant-tabs-tab {
    padding: 16px 0;
    font-size: 14px;
  }

  blockquote.info {
    border-left-color: rgb(91, 192, 222);
    color: rgb(91, 192, 222);
    background-color: rgb(244, 248, 250);
  }
  blockquote {
    display: block;
    unicode-bidi: isolate;
  }

  blockquote {
    padding: 0px 5px;
    color: rgb(119, 119, 119);
    border-left: 4px solid rgb(221, 221, 221);
  }

  .layout {
    background: #fff;
    height: calc(100vh - 200px);
    margin: 0px 0px 0px 0px;
    overflow: hidden;
    min-height: 450px;
  }
</style>
