<template>
  <div class="app-container">
    <page-search :searchFormConfig="searchFormConfig" @resetBtnClick="handleResetClick"
      @queryBtnClick="handleQueryClick" />
    <page-content ref="pageContentRef" :contentTableConfig="contentTableConfig" pageName="/system/task"
      @exportBtnClick="handleExportData">
      <template #taskTypeStatus="scope">
        <el-tag type="success">{{ scope.row.status == '1' ? '导入' : '导出' }}</el-tag>
      </template>
    </page-content>
    <page-modal :defaultInfo="defaultInfo" ref="pageModalRef" pageName="/system/task"
      :modalConfig="modalConfigRef"></page-modal>
  </div>
</template>

<script>
import { defineComponent, getCurrentInstance } 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: 'ImportExportLog',
  components: {
    PageSearch,
    PageContent,
    PageModal
  },
  setup() {
    const { proxy } = getCurrentInstance()
    const [pageContentRef, handleResetClick, handleQueryClick] = usePageSearch()

    // 1.处理逻辑
    const newCallback = () => { }
    const editCallback = () => { }
    const handleExportData = (e) => {
      console.log(e)
      proxy.download(
        '/system/task/downloadLocal',
        {
          taskId: e.taskId,
        },
        `post_${new Date().getTime()}.xlsx`
      )
    }
    // 2.动态添加部门和角色列表
    const modalConfigRef = computed(() => {
      return modalConfig
    })

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