<template>
  <div>
  <div v-if="!switchFlag" class="jeecg-basic-table-form-container">
    <div v-if="searchFlag" class="stm-query" @keyup.enter="handlerStandSearch">
    <a-row :gutter="24">
      <a-col class="gutter-row" :lg="6">
      </a-col>
      <a-col class="gutter-row" :lg="6">
      </a-col>
      <a-col class="gutter-row" :lg="6">
      </a-col>
      <a-col class="gutter-row" :lg="2">
      </a-col>
      <a-col class="gutter-row" :lg="2">
      </a-col>
      <!-- <a-col class="gutter-row" :lg="2">
        <a-button type="link" @click="handlerStandardlibSwitch">管理后台</a-button>
      </a-col> -->
    </a-row>
    <a-form style="margin-top: 10%;margin-bottom: 20%;">
      <a-row :gutter="24">
        <a-col :lg="4"></a-col>
        <a-col :lg="16">
          <a-typography-title class="stm-typography">标准库综合查询</a-typography-title>
        </a-col>
        <a-col :lg="3"></a-col>
      </a-row>
      <a-row :gutter="24">
      <a-col :lg="4"></a-col>
      <a-col :lg="14">
        <a-form-item  >
          <a-input-search ref="stminput1" size="large" placeholder="请输入" v-model:value="queryParam.name" 
            enter-button="搜索"
            autofocus="autofocus"
            @search="handlerStandSearch"/>
        </a-form-item>
      </a-col>
            <!--
      <a-col :lg="6">

      <a-form-item>
        <a-button type="primary" size="large" @click="handlerStandSearch">搜索</a-button>
      </a-form-item>
      </a-col>
      -->
    </a-row>
    <a-row :gutter="24">
      <a-col :lg="4"></a-col>
      <a-col :lg="16">
        <a-radio-group v-model:value="queryParam.sctype" :options="standardlibQueryRadioArr" name="radioGroup" />
      </a-col>
    </a-row>
    </a-form>
  </div>
  <div v-else class="stm-query">
    <a-form>
    <a-row :gutter="24">
      <a-col :lg="12">
        <a-form-item  >
          <a-input-search ref="stminput2" size="large" placeholder="请输入" v-model:value="queryParam.name" 
            enter-button="搜索"
            @search="handlerStandSearch"/>
        </a-form-item>
      </a-col>
      <!-- <a-col class="gutter-row" :span="2" :offset="10">
        <a-button type="link" @click="handlerStandardlibSwitch">管理后台</a-button>
      </a-col> -->
    </a-row>
    <a-row :gutter="24">
      <a-col :lg="18">
        <a-radio-group v-model:value="queryParam.sctype" :options="standardlibQueryRadioArr" name="radioGroup" @change="handlerRadioChange" />
      </a-col>
    </a-row>
    </a-form>
    <a-list item-layout="horizontal" :data-source="dataList">
      <template #renderItem="{ item }">
        <a-list-item>
          <a-list-item-meta
            :description="item.scdesc"
          >
            <template #title>
              <a style="color: #1890ff;font-size: 1.4em;" @click="handlerGotoPage(item)">
                <span v-html="item.name"></span>
                <Tag style="margin-left: 10px;">{{ item.tag }}</Tag>
                <Tag v-if="item.lableNames && item.lableNames.length>0" v-for="(t,i) in item.lables" 
                  :key="i" 
                  :color="t.color"
                  >
                  {{t.name}}
                </Tag>
              </a>
            </template>
          </a-list-item-meta>
        </a-list-item>
      </template>
  </a-list>
  <Pagination style="text-align: center;" v-model:current="pagination.current" show-quick-jumper :total="pagination.total" @change="pageChange"/>
  </div>
  </div>
  <PageWrapper v-if="switchFlag">
    <Card :bordered="false">
      <template #title>
        <p style="font-weight: 650;font-size: 16px">控制活动库</p>
      </template>
      <template #extra>
        <a-button type="link" @click="handlerStandardlibSwitch">标准库查询</a-button>
      </template>
      <a-space direction="vertical" :size="24" style="width:100%">
      <a-row :gutter="48">
        <a-col :span="8">
          <ItemMenu :menuUrl="'/standardlib/controlactivity/StCaMainList'" imgsrc="resource/img/控制活动.png" :menuName="'控制活动'" :menuDesc="'控制活动的维护'" :menuNow="menuInfo.stCaMain.updateDate" :menuCount="menuInfo.stCaMain.count" />
        </a-col>
        <a-col :span="8" :hoverable="true">
          <ItemMenu :menuUrl="'/standardlib/controlactivity/StMetricList'" imgsrc="resource/img/度量指标.png" :menuName="'度量指标'" :menuDesc="'控制活动的度量指标维护'" :menuNow="menuInfo.stMetric.updateDate" :menuCount="menuInfo.stMetric.count" />
        </a-col>
        <a-col :span="8" :hoverable="true">
          <ItemMenu :menuUrl="'/standardlib/controlactivity/StCaMainCheckList'" imgsrc="resource/img/检查方法.png" :menuName="'检查方法'" :menuDesc="'控制活动的检查方法维护'" :menuNow="menuInfo.stCheck.updateDate" :menuCount="menuInfo.stCheck.count" />
        </a-col>
      </a-row>
      <a-row :gutter="48">
        <a-col :span="8" :hoverable="true">
          <ItemMenu :menuUrl="'/standardlib/controlactivity/StCaMainCollectionList'" imgsrc="resource/img/活动集合.png" :menuName="'活动集合'" :menuDesc="'控制活动集合的维护'" :menuNow="menuInfo.stCollection.updateDate" :menuCount="menuInfo.stCollection.count" />
        </a-col>
        <a-col :span="8" :hoverable="true">
          <ItemMenu :menuUrl="'/standardlib/standard/stStandardList'" imgsrc="resource/img/检查方法.png" :menuName="'行业标准'" :menuDesc="'行业标准的维护'" :menuNow="menuInfo.stStandard.updateDate" :menuCount="menuInfo.stStandard.count" />
        </a-col>
      </a-row>
      </a-space>
    </Card>
    <Card :bordered="false">
      <template #title>
        <p style="font-weight: 650;font-size: 16px">合规库</p>
      </template>
      <a-space direction="vertical" :size="24" style="width:100%">
      <a-row :gutter="48">
        <a-col :span="8">
          <ItemMenu :menuUrl="'/standardlib/compliane/fl'"  imgsrc="resource/img/法律.png" :menuName="'法律'" :menuDesc="'法律文件'" :menuNow="menuInfo.stCompliane1.updateDate" :menuCount="menuInfo.stCompliane1.count" />
        </a-col>
        <a-col :span="8" :hoverable="true">
          <ItemMenu :menuUrl="'/standardlib/compliane/fg'" imgsrc="resource/img/法规.png" :menuName="'法规'" :menuDesc="'法规文件'" :menuNow="menuInfo.stCompliane2.updateDate" :menuCount="menuInfo.stCompliane2.count" />
        </a-col>
        <a-col :span="8" :hoverable="true">
          <ItemMenu :menuUrl="'/standardlib/compliane/jg'" imgsrc="resource/img/监管.png" :menuName="'监管意见'" :menuDesc="'监管意见文件'" :menuNow="menuInfo.stCompliane3.updateDate" :menuCount="menuInfo.stCompliane3.count" />
        </a-col>
      </a-row>
      <a-row :gutter="48">
        <a-col :span="8">
          <ItemMenu :menuUrl="'/standardlib/compliane/fx'" imgsrc="resource/img/风险提示.png" :menuName="'风险提示'" :menuDesc="'风险提示文件'" :menuNow="menuInfo.stCompliane4.updateDate" :menuCount="menuInfo.stCompliane4.count" />
        </a-col>
        <a-col :span="8" :hoverable="true">
          <ItemMenu :menuUrl="'/standardlib/compliane/cf'" imgsrc="resource/img/处罚通知.png" :menuName="'处罚通知'" :menuDesc="'处罚通知文件'" :menuNow="menuInfo.stCompliane5.updateDate" :menuCount="menuInfo.stCompliane5.count" />
        </a-col>
        <a-col :span="8" :hoverable="true">
          <ItemMenu :menuUrl="'/standardlib/compliane/query'" imgsrc="resource/img/合规查询.png" :menuName="'合规查询'" :menuDesc="'合规查询文件'" :menuNow="menuInfo.stCompliane.updateDate" :menuCount="menuInfo.stCompliane.count" />
        </a-col>
      </a-row>
      </a-space>
    </Card>
    <Card :bordered="false">
      <template #title>
        <p style="font-weight: 650;font-size: 16px">内控库</p>
      </template>
      <a-row :gutter="48">
        <a-col :span="8">
          <ItemMenu :menuUrl="'/standardlib/inner/stInnerControlList'" imgsrc="resource/img/内控策略.png" :menuName="'内控策略'" :menuDesc="'内控策略维护'" :menuNow="menuInfo.stInnerControl.updateDate" :menuCount="menuInfo.stInnerControl.count" />
        </a-col>
        <a-col :span="8" :hoverable="true">
          <ItemMenu :menuUrl="'/standardlib/inner/stInnerControlOrderList'" imgsrc="resource/img/内控制度.png" :menuName="'内控制度'" :menuDesc="'内控制度维护'" :menuNow="menuInfo.stInnerControlOrder.updateDate" :menuCount="menuInfo.stInnerControlOrder.count" />
        </a-col>
        <a-col :span="8" :hoverable="true" v-show="false">
          <ItemMenu disabled :menuName="'内控检查'"  :menuDesc="'内控制度执行'" :menuNow="'2023-03-01 00:00'" :menuCount="0" />
        </a-col>
      </a-row>
    </Card>
    <Card :bordered="false">
      <template #title>
        <p style="font-weight: 650;font-size: 16px">风险库</p>
      </template>
      <a-row :gutter="48">
        <a-col :span="8">
          <ItemMenu :menuUrl="'/standardlib/risk/StRiskScenarioList'" imgsrc="resource/img/风险场景.png" :menuName="'风险场景'" :menuDesc="'风险场景维护'" :menuNow="menuInfo.stScenario.updateDate" :menuCount="menuInfo.stScenario.count" />
        </a-col>
        <a-col :span="8" :hoverable="true">
          <ItemMenu :menuUrl="'/standardlib/risk/StRiskEventList'" imgsrc="resource/img/风险事件.png" :menuName="'风险事件'" :menuDesc="'风险事件维护'" :menuNow="menuInfo.stEvent.updateDate" :menuCount="menuInfo.stEvent.count" />
        </a-col>
        <a-col :span="8" :hoverable="true" v-show="false">
          <ItemMenu disabled :menuName="'风险策略配置'" :menuDesc="'风险策略配置'" :menuNow="'2023-03-01 00:00'" :menuCount="0" />
        </a-col>
      </a-row>
    </Card>
    <Card :bordered="false">
      <template #title>
        <p style="font-weight: 650;font-size: 16px">行业实践</p>
      </template>
      <a-row :gutter="48">
        <a-col :span="8">
          <ItemMenu :menuUrl="'/standardlib/StBestCaseList'" imgsrc="resource/img/行业实践案例.png" :menuName="'行业实践案例'" :menuDesc="'行业实践案例维护'" :menuNow="menuInfo.stBestCase.updateDate" :menuCount="menuInfo.stBestCase.count" />
        </a-col>
        <a-col :span="8" :hoverable="true">
          <ItemMenu :menuUrl="'/standardlib/StBestPracticesList'" imgsrc="resource/img/行业实践应用.png" :menuName="'行业实践应用'" :menuDesc="'行业实践应用维护'" :menuNow="menuInfo.stBestPractices.updateDate" :menuCount="menuInfo.stBestPractices.count" />
        </a-col>
      </a-row>
    </Card>
    <Card :bordered="false">
      <template #title>
        <p style="font-weight: 650;font-size: 16px">问题库</p>
      </template>
      <a-row :gutter="48">
        <a-col :span="8">
          <ItemMenu :menuUrl="'/standardlib/problem'" imgsrc="resource/img/问题.png" :menuName="'问题库'" :menuDesc="'问题库维护'" :menuNow="menuInfo.stProblem.updateDate" :menuCount="menuInfo.stProblem.count" />
        </a-col>
      </a-row>
    </Card>
    <Card :bordered="false">
      <template #title>
        <p style="font-weight: 650;font-size: 16px">基础配置</p>
      </template>
      <a-space direction="vertical" :size="24" style="width:100%">
      <a-row :gutter="48">
        <a-col :span="8">
          <ItemMenu :menuUrl="'/standardlib/base/StLableList'" imgsrc="resource/img/标签.png" :menuName="'标签库'" :menuDesc="'标签库维护'" :menuNow="menuInfo.stLable.updateDate" :menuCount="menuInfo.stLable.count" />
        </a-col>
        <a-col :span="8">
          <ItemMenu :menuUrl="'/standardlib/base/StDomainList'" imgsrc="resource/img/领域.png" :menuName="'领域管理'" :menuDesc="'领域维护'" :menuNow="menuInfo.stDomain.updateDate" :menuCount="menuInfo.stDomain.count" />
        </a-col>
        <a-col :span="8">
          <ItemMenu :menuUrl="'/standardlib/base/stClassifyList'" imgsrc="resource/img/分类.png" :menuName="'标签分类管理'" :menuDesc="'标签分类维护'" :menuNow="menuInfo.stClassify.updateDate" :menuCount="menuInfo.stClassify.count" />
        </a-col>
      </a-row>
    </a-space>
    </Card>
  </PageWrapper>
</div> 
</template>
<script lang="ts" setup>
  import { Card, Pagination, Tag } from 'ant-design-vue';
import { nextTick, onMounted, ref, unref ,computed} from 'vue';
import { useRouter } from 'vue-router';
import ItemMenu from './components/ItemMenu.vue';
import { list, statistics } from './index.api';
import { PageWrapper } from '/@/components/Page';
  const stminput1 = ref(null)
  const stminput2 = ref(null)
  const loading = ref(true);
  const switchFlag = ref(false)
  const searchFlag = ref(true)
  const pagination = ref({
    current: 1,
    pageSize: 10,
    total: 100,
  })
  const standardlibQueryRadioArr = ref([
    {label: '全部',value: '1'},
    {label: '控制活动',value: '2'},
    {label: '指标',value: '3'},
    {label: '合规库',value: '4'},
    {label: '内控库',value: '5'},
    {label: '风险库',value: '6'},
    {label: '问题库',value: '7'},
    {label: '检查方法',value: '8'},
    {label: '行业实践',value: '9'},
  ])
  const menuInfo = ref({
    stBestCase:{updateDate: '',count: 0,},
    stBestPractices:{updateDate: '',count: 0,},
    stCaMain:{updateDate: '',count: 0,},
    stCheck:{updateDate: '',count: 0,},
    stClassify:{updateDate: '',count: 0,},
    stCollection:{updateDate: '',count: 0,},
    stCompliane:{updateDate: '',count: 0,},
    stCompliane1:{updateDate: '',count: 0,},
    stCompliane2:{updateDate: '',count: 0,},
    stCompliane3:{updateDate: '',count: 0,},
    stCompliane4:{updateDate: '',count: 0,},
    stCompliane5:{updateDate: '',count: 0,},
    stDomain:{updateDate: '',count: 0,},
    stEvent:{updateDate: '',count: 0,},
    stInnerControl:{updateDate: '',count: 0,},
    stInnerControlOrder:{updateDate: '',count: 0,},
    stLable:{updateDate: '',count: 0,},
    stMetric:{updateDate: '',count: 0,},
    stProblem:{updateDate: '',count: 0,},
    stScenario:{updateDate: '',count: 0,},
    stStandard:{updateDate: '',count: 0,},
  })
  onMounted(()=>{
    // if(sessionStorage.getItem("stm.index.searchFlag") && sessionStorage.getItem("stm.index.switchFlag")){
    //   searchFlag.value = sessionStorage.getItem("stm.index.searchFlag")=="1"
    //   switchFlag.value = sessionStorage.getItem("stm.index.switchFlag")=="1"
    // }
    statistics().then(rep=>{
      console.log(rep)
      menuInfo.value = rep;
    })
  })
  nextTick(()=>{
    stminput1.value?.focus()
  })
  const router = useRouter()
  const queryParam = ref({
    name: '',
    sctype: '1',
    pageNo:  pagination.value.current,
    pageSize: pagination.value.pageSize
  })

  interface DataItem {
      bizNo: string;
      name: string;
      scdesc: string;
      sctype: string;
      tag: string;
      lableNames: string;
      lables: any;
  }

  const dataList: DataItem[] = ref([]);

  function handlerStandardlibSwitch() {
    if(switchFlag.value){
      searchFlag.value = true
     // sessionStorage.setItem("stm.index.searchFlag","1")
    }
    switchFlag.value = !switchFlag.value;
    // sessionStorage.setItem("stm.index.switchFlag",switchFlag.value?'1':'0')
    setTimeout(function(){
      stminput1.value?.focus()
    },100)
  }

  function handlerStandSearch(){
    searchFlag.value = false;
    sessionStorage.setItem("stm.index.searchFlag","0")
    // 重新查询重置参数
    queryParam.value.pageNo = 1
    pagination.value.current = 1
    pagination.value.total = 0
    onSearch()
    setTimeout(function(){
      stminput2.value?.focus()
    },100)
  }
  function handlerRadioChange(e) {
    handlerStandSearch();
  }
  function onSearch(){
    // let params = {}
    //   console.log(params)
    //   params['pageNo'] = pagination.value.current
    //   params['pageSize'] = pagination.value.pageSize
      list(unref(queryParam)).then(rep=>{
        dataList.value = rep.records
        pagination.value.current = rep.current
        pagination.value.total = rep.total
        pagination.value.pageSize = rep.size
      })
  }
  function pageChange(page,pageSize){
    queryParam.value.pageNo = page
    queryParam.value.pageSize = pageSize
    onSearch()
  }
  function handlerGotoPage(item) {
    console.log(item)
    if(item.sctype == '2') {
      router.push({path: 'standardlib/controlactivity/StCaMainList',query:{bizNo: item.bizNo,querName:queryParam.value.name}})
    }else if(item.sctype == '3') {
      router.push({path: 'standardlib/controlactivity/StMetricList',query:{bizNo: item.bizNo,querName:queryParam.value.name}})
    }else if(item.sctype == '4') {
      if(item.tag == '合规库-法律'){
        router.push({path: 'standardlib/compliane/fl',query:{bizNo: item.bizNo,querName:queryParam.value.name}})
      }else if(item.tag == '合规库-法规') {
        router.push({path: 'standardlib/compliane/fg',query:{bizNo: item.bizNo,querName:queryParam.value.name}})
      }else if(item.tag == '合规库-监管意见'){
        router.push({path: 'standardlib/compliane/jg',query:{bizNo: item.bizNo,querName:queryParam.value.name}})
      }else if(item.tag == '合规库-风险提示'){
        router.push({path: 'standardlib/compliane/fx',query:{bizNo: item.bizNo,querName:queryParam.value.name}})
      }else if(item.tag == '合规库-处罚通知'){
        router.push({path: 'standardlib/compliane/cf',query:{bizNo: item.bizNo,querName:queryParam.value.name}})
      }
    }else if(item.sctype == '5'){
      if(item.tag == '内控库-内控策略'){
        router.push({path: 'standardlib/inner/stInnerControlList',query:{bizNo: item.bizNo,querName:queryParam.value.name}})
      }else if(item.tag == '内控库-内控制度') {
        router.push({path: 'standardlib/inner/stInnerControlOrderList',query:{bizNo: item.bizNo,querName:queryParam.value.name}})
      }
    }else if(item.sctype == '6') {
      if(item.tag == '风险库-风险场景'){
        router.push({path: 'standardlib/risk/StRiskScenarioList',query:{bizNo: item.bizNo,querName:queryParam.value.name}})
      }else if(item.tag == '风险库-风险事件') {
        router.push({path: 'standardlib/risk/StRiskEventList',query:{bizNo: item.bizNo,querName:queryParam.value.name}})
      }
    }else if(item.sctype == '7') {
      router.push({path: 'standardlib/problem',query:{bizNo: item.bizNo,querName:queryParam.value.name}})
    }else if(item.sctype == '8') {
      router.push({path: 'standardlib/controlactivity/StCaMainCheckList',query:{bizNo: item.bizNo,querName:queryParam.value.name}})
    }else if(item.sctype == '9') {
      router.push({path: 'standardlib/StBestPracticesList',query:{bizNo: item.bizNo,querName:queryParam.value.name}})
    }
  }
  setTimeout(() => {
    loading.value = false;
  }, 500);
</script>
<style scoped>
.jeecg-basic-table-form-container {
  padding: 10px;
  position: relative;
}
.jeecg-basic-table-form-container .stm-query {
  padding: 12px 10px 6px 10px;
  margin-bottom: 8px;
  background-color: #fff;
  border-radius: 2px;
  position: relative;
}
.stm-typography{
  color: #009dff;
  font-size: 18px;
}
</style>