<template>
  <div class="app-container">
    <page-search
      :searchFormConfig="searchFormConfig"
      @resetBtnClick="handleResetClick"
      @queryBtnClick="handleQueryClick"
    />
    <page-content
      ref="pageContentRef"
      rowKey="dictId"
      :contentTableConfig="contentTableConfig"
      pageName="/system/dict/type"
      @newBtnClick="handleNewData"
      @editBtnClick="handleEditData"
    >
    <template #dictype="scope">
      <router-link :to="'/system/dict-data/index/' + scope.row.dictId" class="link-type">
        <span>{{ scope.row.dictType }}</span>
      </router-link>
    </template>
    <template #dicstatus="scope">
      <el-tag :type="scope.row.status == '0' ? 'success' : 'danger'">{{
        scope.row.status == '0' ? '正常' : '停用'
      }}</el-tag>
    </template>
    </page-content>
    <page-modal
      :defaultInfo="defaultInfo"
      ref="pageModalRef"
      :mainKey="'dictId'"
      pageName="/system/dict/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 './config/search.config'
import { contentTableConfig } from './config/content.config'
import { modalConfig } from './config/modal.config'

import { usePageSearch } from '@/hooks/use-page-search'
import { usePageModal } from '@/hooks/use-page-modal'

export default defineComponent({
  name: 'Dict',
  components: {
    PageSearch,
    PageContent,
    PageModal
  },
  setup() {
    const [pageContentRef, handleResetClick, handleQueryClick] = usePageSearch()

    // 1.处理逻辑
    const newCallback = () => {}
    const editCallback = () => {}

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