<script setup lang="ts">
import { usePageSearch, type PageHooks, type PageEvents } from "/@/hooks/page";
import { useRenderIcon } from "/@/components/ReIcon/src/hooks";
import { PageContainer } from "/@/components/PageContainer";
import { usePermission } from "/@/hooks/core/usePermission";
import { httpOldStatus } from "/@/api/purchase/orderRecord";
import { useUserInfo } from "/@/hooks/core/useUser";
import contentConfig from "./config/content.config";
import searchConfig from "./config/search.config";
import { PageAuth } from "/@/components/PageAuth";
import { useRouter } from "vue-router"
import { ElButton } from "element-plus"
import { useAsync } from "/@/hooks";
import { ref } from "vue"

const pageName = "currentcyOrderRecord";

const { push } = useRouter();
const contentRef = ref<any>(null);
const { isSuperUser } = useUserInfo();
const { hasPermissionWithCode } = usePermission(pageName);

const baseDetailPath = '/InvoiceSales/currentcyOrderRecordDetail';
const hooks: PageHooks = { pageSearchHook: () => usePageSearch(undefined, undefined, searchConfig) };

const events: PageEvents = { content: { preview: ({ payNo }) => push(`${baseDetailPath}?id=${payNo}`), create:() => push('/InvoiceSales/currentcyOrderRecordDetail') } };

const { run: revoke } = useAsync({
  success: () => contentRef.value.onSearch()
});

const handleRevoke = (payNo: string) => revoke(httpOldStatus({ payNo, status: "4" }));
</script>


<template>
  <PageAuth :pageName="pageName">
      <PageContainer
        :hooks="hooks"
        :events="events"
        :searchConfig="searchConfig"
        :contentConfig="contentConfig"
        :get-content-ref="ref => contentRef = ref"
      >
        <template #content_action="row">
          <ElTooltip placement="top" content="撤销对账申请">
           <ElButton
              v-if="
               (String(row.status) === '1' || String(row.status) === '2') &&
               hasPermissionWithCode('022') && String(row.is_comon) === '1' && 
               !isSuperUser
              "
              link
              text
              type="primary"
              :icon="useRenderIcon('refresh-right')"
              @click="() => handleRevoke(row.payNo)"
            />
          </ElTooltip>
        </template>
      </PageContainer>
    </PageAuth>
</template>
