<script setup lang="ts">
import { ref } from "vue";
import { PageSearch, usePageSearch } from "/@/components/PageSearch";
import searchConfig from "./config/search.config";
import contentConfig from "./config/content.config";
import { PageModal, usePageModal } from "/@/components/PageModal";
import modalConfig from "./config/modal.config";
import { PageContent } from "/@/components/PageContent";
import { exportPageContent } from "/@/utils/export";
import ExeclUpload from "./cpns/execl-files-upload/index.vue";
import { httpDetail } from "/@/api/mobile/exchangeOrder";
import { useResponseHandle } from "/@/hooks/useAsync";
import { usePermission } from "/@/hooks/usePermission";
const pageName = "exchangeOrder";
const responseHandle = useResponseHandle();
const { pageContentRef, handleResetClick, handleSearchClick, getMergeParams } =
  usePageSearch(undefined, undefined, searchConfig);
const { hasPermissionWithCode, permissions } = usePermission(pageName);

const { pageModalRef, handlePreviewData, handleConfrim, defaultInfo } =
  usePageModal({
    pageContentRef
  });
const execlUploadRef = ref<InstanceType<typeof ExeclUpload>>(null);

async function handleDetailData(id) {
  const { code, data, message } = await httpDetail({ id: id });
  responseHandle({
    code,
    message,
    handler: () => {
      handlePreviewData(data);
    }
  });
  // actionModalRef.value.onShow("兑换商品库存", type, id);
}
function getParams() {
  exportPageContent({
    type: "http",
    url: "orderExport",
    params: getMergeParams(),
    name: "订单导出"
  });
  // console.log(pageContentRef);
}
</script>

<template>
  <PageAuth :pageName="pageName">
    <PageSearch
      :form-config="searchConfig"
      @search-btn-click="handleSearchClick"
      @reset-btn-click="handleResetClick"
    >
      <template #action>
        <el-button v-if="hasPermissionWithCode('019')" @click="getParams"
          >导出订单</el-button
        >

        <el-button
          v-if="hasPermissionWithCode('017')"
          type="primary"
          @click="() => execlUploadRef.onDisplay()"
          >批量发货
        </el-button>
      </template>
    </PageSearch>
    <PageContent
      ref="pageContentRef"
      :powers="permissions"
      :content-config="contentConfig"
      @preview-btn-click="({ id }) => handleDetailData(id)"
    />
    <ExeclUpload ref="execlUploadRef" @onSuccess="handleResetClick" />
    <PageModal
      ref="pageModalRef"
      :modal-config="modalConfig"
      :default-info="defaultInfo"
      @confirm-btn-click="handleConfrim"
    />
  </PageAuth>
</template>
