<script setup lang="ts">
import { ref , shallowRef } from "vue";
import contentConfig from "./config/content.config";
import searchFormConfig from "./config/search.config";
import { PageContent } from "/@/components/PageContent";
import { usePermission } from "/@/hooks/core/usePermission";
import PagePower from "/@/components/PagePower/PagePower.vue";
import { PageSearch, usePageSearch } from "/@/components/PageSearch";
import ExeclUploadModal from "./../_component/execl-files-upload/index.vue";
import { httpRequsetExport } from "/@/utils/export";

import { useCompany } from "/@/hooks/core/useCompany";

  const { currentCompany } = useCompany();


// const {} = useComapnt

const execlUploadModalRef = ref<InstanceType<typeof ExeclUploadModal> | null>(
  null
);

const selected = ref<any[]>([]);
const loading = shallowRef(false);
const { permissions, hasPermissionWithCode } = usePermission("abnormalProduct");
const { pageContentRef, handleResetClick, handleSearchClick } = usePageSearch(
  undefined,
  undefined,
  searchFormConfig
);

async function handleExport() { 

  //导出模板
  await httpRequsetExport({
    url: "/good/exportDiff",
    name: "商品税率异常记录",
    onStart: () => (loading.value = true),
    onSuccess: () => (loading.value = false),
    onFail: () => (loading.value = false),
    params: {
      is_diff: "1",
      companyNo:currentCompany.value.companyNo,
      ...pageContentRef.value.getBasicParams()
    }
  });
}

//  @selection-change="nodes => (selected = nodes)"
</script>

<template>
  <div class="main role">
    <PagePower :is-show="hasPermissionWithCode('001')">
      <div w-full>
        <PageSearch
          :form-config="searchFormConfig"
          @search-btn-click="handleSearchClick"
          @reset-btn-click="handleResetClick"
        />

        <PageContent
          ref="pageContentRef"
          :powers="permissions"
          :content-config="contentConfig"
        >
        <template #header>
          <ElButton 
            type="primary" 
            v-if="hasPermissionWithCode('045')" 
            @click="handleExport" 
            :loading="loading">导出</ElButton>
        </template>
       </PageContent>

        <ExeclUploadModal
          ref="execlUploadModalRef"
          @on-success="() => pageContentRef.onSearch()"
        />
      </div>
    </PagePower>
  </div>
</template>

<style scoped lang="scss">
:deep(.el-dropdown-menu__item i) {
  margin: 0;
}
</style>
