<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 { PageContent } from "/@/components/PageContent";
import { exportPageContent } from "/@/utils/export";
import ExeclUpload from "./components/execl-files-upload/index.vue";
import { usePermission } from "/@/hooks/usePermission";
import EditModel from "./components/edit-dialog.vue";
const pageName = "exchangeOrder";
const { pageContentRef, handleResetClick, handleSearchClick, getMergeParams } =
  usePageSearch(undefined, undefined, searchConfig);
const { hasPermissionWithCode, permissions } = usePermission(pageName);
const modelEditRef = ref<InstanceType<typeof EditModel>>(null);
const execlUploadRef = ref<InstanceType<typeof ExeclUpload>>(null);

function getParams() {
  exportPageContent({
    type: "http",
    url: "orderExport",
    params: getMergeParams(),
    name: "订单导出"
  });
}
</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, account_id, good_id, type }) =>
          modelEditRef.show({ id, account_id, good_id, type })
      "
    />
    <ExeclUpload ref="execlUploadRef" @onSuccess="handleResetClick" />
    <EditModel ref="modelEditRef" @reload="pageContentRef.onSearch()" />
  </PageAuth>
</template>
