<template>
  <div class="app-container">
    <page-search
      :searchFormConfig="searchFormConfigRef"
      @resetBtnClick="handleResetClick"
      @queryBtnClick="handleQueryClick"
    />
    <page-content
      ref="pageContentRef"
      :contentTableConfig="contentTableConfig"
      pageName="/sms/record"
      :isExport="false"
      :isCreate="false"
      @newBtnClick="handleNewData"
      @editBtnClick="handleEditData"
    >
      <template #sendStatus="{ row }">
        <el-tag :type="(row.status && row.status.indexOf('失败') !== -1) ? 'error' : 'success'">{{ row.status }}</el-tag>
      </template>
    </page-content>
    <page-modal
      :defaultInfo="defaultInfo"
      ref="pageModalRef"
      pageName="/system/post"
      :modalConfig="modalConfigRef"
    ></page-modal>
  </div>
</template>

<script>
import { defineComponent,onMounted } 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'
import { getPageListData } from '@/api/main/system/system';

export default defineComponent({
  name: 'SendRecord',
  components: {
    PageSearch,
    PageContent,
    PageModal
  },
  setup() {
    const [pageContentRef, handleResetClick, handleQueryClick] = usePageSearch()
    onMounted(()=>{
      getList()
    })
    function getList(data) {
      getPageListData('/sms/template',{}).then((data) => {
        console.log(data)
      });
    }
    // 1.处理逻辑
    const newCallback = () => {}
    const editCallback = () => {
      console.log(defaultInfo.value)
    }

    // 2.动态添加部门和角色列表
    const modalConfigRef = computed(() => {
      console.log(modalConfig.formItems);
      return modalConfig
    })
    const searchFormConfigRef = computed(() => {
      return searchFormConfig
    })
    
    // 3.调用hook获取公共变量和函数
    const [pageModalRef, defaultInfo, handleNewData, handleEditData] =
      usePageModal(newCallback, editCallback)
    return {
      getList,
      contentTableConfig,
      pageContentRef,
      handleResetClick,
      handleQueryClick,
      modalConfigRef,
      searchFormConfigRef,
      searchFormConfig,
      pageModalRef,
      defaultInfo,
      handleNewData,
      handleEditData
    }
  }
})
</script>
