<template>
  <div class="app-container">
    <page-search
      :searchFormConfig="searchFormConfig"
      :dictId = "route.params.dictId"
      @resetBtnClick="handleResetClick"
      @queryBtnClick="handleQueryClick"
    />
    <page-content
      ref="pageContentRef"
      :contentTableConfig="contentTableConfig"
      pageName="/system/dict/data/type"
      @newBtnClick="handleNewData"
      @editBtnClick="handleEditData"
    ></page-content>
    <page-modal
      :defaultInfo="defaultInfo"
      ref="pageModalRef"
      pageName="/system/dict/data/type"
      :modalConfig="modalConfig"
    ></page-modal>
  </div>
</template>

<script>
import { defineComponent } from 'vue'

import PageSearch from '@/components/page-search'
import PageContent from '@/components/page-content'
import PageModal from '@/components/page-modal'

import { searchFormConfig } from './configdata/search.config'
import { contentTableConfig } from './configdata/content.config'
import { modalConfig } from './configdata/modal.config'

import { usePageSearch } from '@/hooks/use-page-search'
import { usePageModal } from '@/hooks/use-page-modal'
import useSelectStore from '@/store/commonSelect/common'
export default defineComponent({
  name: 'users',
  components: {
    PageSearch,
    PageContent,
    PageModal
  },
  setup() {
    const [pageContentRef, handleResetClick, handleQueryClick] = usePageSearch()
    const route = useRoute()
    console.log(route.params.dictId,'route.params.dictId')
    // 1.处理逻辑
    const newCallback = () => {}
    const editCallback = () => {}

    //动态获取搜索数据
    const searchFormConfigRef = computed(() => {
      const DictItem = searchFormConfig.formItems.find(
        (item) => item.field === 'dictType'
      )
      DictItem.options = useSelectStore().dictList
      return searchFormConfig
    })
    usePageSearch()

    // 3.调用hook获取公共变量和函数
    const [pageModalRef, defaultInfo, handleNewData, handleEditData] =
      usePageModal(newCallback, editCallback)
    return {
      searchFormConfig,
      searchFormConfigRef,
      contentTableConfig,
      pageContentRef,
      handleResetClick,
      handleQueryClick,
      modalConfig,
      pageModalRef,
      defaultInfo,
      handleNewData,
      handleEditData,
      route
    }
  }
})
</script>
