<script setup lang="ts">
import { ref } from "vue";
import contentConfig from "./config/content.config";
import searchConfig from "./config/search.config";
import CapitalModal from "./components/capital-modal.vue";
import { usePageSearch, type PageHooks, type PageEvents } from "/@/hooks/page";
import { useRenderIcon } from "/@/components/ReIcon/src/hooks";
import { usePermission } from "/@/hooks/core/usePermission";
import { httpWithdraw } from "/@/api/InvoiceSales/capitalClaim";
import { useAsync } from "/@/hooks/core/useAsync";
import { useRouter } from "vue-router";

const PageName = "capitalPool";
const capitalModalRef = ref<InstanceType<typeof CapitalModal> | null>(null);
const { hasPermissionWithCode } = usePermission("capitalClaim");
const pageContentRef = ref(null)

const { run: withDraw } = useAsync({
  success: () => pageContentRef.value.onSearch()
});

const handleWithDraw = data => withDraw(httpWithdraw(data));

const router = useRouter();

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

const events: PageEvents = {
  content: {
    preview: ({ logNo }) => router.push('/InvoiceSales/capitalDetail?id=' + logNo + "&back=capitalPool")
  }
};
</script>

<template>
  <PageAuth :pageName="PageName">
    <PageContainer :hooks="hooks" :events="events" :get-content-ref="ref => pageContentRef = ref"  :contentConfig="contentConfig" :search-config="searchConfig">
      <template #content_action="row">
        <el-popconfirm
          v-if="hasPermissionWithCode('009') && String(row.status) === '1'" placement="top"
          title="是否确认撤销资金认领?"    @confirm="() => handleWithDraw({ logNo: row.logNo })">
          <template #reference>
            <el-button :icon="useRenderIcon('refresh-right')" type="primary" link />
          </template>
        </el-popconfirm>
      </template>
    </PageContainer>
    <CapitalModal ref="capitalModalRef" />
  </PageAuth>
</template>
