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

const pageName = "currentcyOrderRecord";

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

const { isSuperUser } = useUserInfo();
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 => revoke(httpStatus({ payNo, status: "4" }));
</script>


<template>
  <PageAuth :pageName="pageName">
      <PageContainer
        :hooks="hooks"
        :events="events"
        :contentConfig="contentConfig"
        :searchConfig="searchConfig"
        :get-content-ref="ref => contentRef = ref"
      >
        <!-- <template #content_header>
           <ElButton 
              v-if="hasPermissionWithCode('002')"  
              size="small" type="primary" 
              @click="() => push('/InvoiceSales/currentcyOrderRecordDetail')"
              >
                添加
            </ElButton>
        </template> -->

        <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
              "
              type="primary"
              link
              text
              :icon="useRenderIcon('refresh-right')"
              @click="() => handleRevoke(row.payNo)"
            />
        </ElTooltip>
      </template>
      </PageContainer>
    </PageAuth>
</template>
