<template>
  <div class="app-container">
    <page-search
      :searchFormConfig="searchFormConfig"
      @resetBtnClick="handleResetClick"
      @queryBtnClick="handleQueryClick"
    />
    <page-content
      ref="pageContentRef"
      :contentTableConfig="contentTableConfig"
      pageName="patient/tag"
      :isExport="false"
      :isCreate="true"
      @newBtnClick="handleNewData"
      @editBtnClick="handleEditData"
    >
      <template #stateSlot="{ row }">
        <el-tag :type="row.state === 0 ? 'error' : 'success'">{{ row.state === 0 ? '关闭' : '开启' }}</el-tag>
      </template>
      <template #isSystemSlot="{ row }">
        <el-tag :type="row.isSystem === 0 ? 'success' : 'error'">{{ row.isSystem === 0 ? '否' : '是' }}</el-tag>
      </template>
      <template #tagNameSlot="{ row }">
        <span :style="[`color: ${row.color || ''}`]">{{ row.tagName }}</span>
      </template>
    
    </page-content>
    <page-modal
      :defaultInfo="defaultInfo"
      ref="pageModalRef"
      pageName="patient/tag"
      :modalConfig="modalConfigRef"
    ></page-modal>
  </div>
</template>

<script>
import { defineComponent } from 'vue'
import { userDecryptToAsterisk } from '@/utils/aes'

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 { getTimeFrame } from '@/utils/tools'
import { useRouter } from 'vue-router'

export default defineComponent({
  name: 'PatientLabel',
  components: {
    PageSearch,
    PageContent,
    PageModal
  },
  setup() {

    const router = useRouter();

    const [pageContentRef, handleResetClick, handleQueryClick] = usePageSearch()

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

    // 2.动态添加部门和角色列表
    const modalConfigRef = computed(() => {
      return modalConfig
    })

    // 3.调用hook获取公共变量和函数
    const [pageModalRef, defaultInfo, handleNewData, handleEditData] =
      usePageModal(newCallback, editCallback)

    function buttonHandle(id) {
      router.push({
        path: '/patientFile/patientDetail',
        query: {
          id,
        }
      });
    }
    return {
      userDecryptToAsterisk,
      buttonHandle,
      getTimeFrame,
      searchFormConfig,
      contentTableConfig,
      pageContentRef,
      handleResetClick,
      handleQueryClick,
      modalConfigRef,
      pageModalRef,
      defaultInfo,
      handleNewData,
      handleEditData
    }
  }
})
</script>
