<script setup lang="ts">
import contentConfig from "./config/content.config";
import searchConfig from "./config/search.config";
import { usePageSearch, type PageHooks, type PageEvents } from "/@/hooks/page";
import { useCompany } from "/@/hooks/core/useCompany";
import { ElMessage } from "element-plus";
import { shallowRef, ref } from "vue"
import Modal from "./modal.vue"


import { useRouter } from "vue-router"

const PageName = "handover";
const pageContentRef = ref<any>(null);

const hooks: PageHooks = {
  pageSearchHook: () => usePageSearch(undefined, undefined, searchConfig)
};

const visible = shallowRef(false)
const { currentCompany } = useCompany();

const { push } = useRouter()

const events: PageEvents = {
  content: {
    create: () => {
      if(!currentCompany.value.companyNo) {
        ElMessage.warning('请选择一家业务公司')
        return
      }
      visible.value = true
    },
    preview: (row) => push(`/interest/handoverDetail?id=${row.id}`)
  },
};
</script>

<template>
  <PageAuth :pageName="PageName">
    <PageContainer
      :hooks="hooks"
      :events="events"
      :contentConfig="contentConfig"
      :search-config="searchConfig"
      :get-content-ref="ref => pageContentRef = ref"
    />
    <Modal v-model:visible="visible" :companyNo="currentCompany.companyNo" @refresh="pageContentRef?.onSearch()" />
  </PageAuth>
</template>
