index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <script setup lang="ts">
  2. import { reactive, ref } from "vue";
  3. import { useRouter } from "vue-router";
  4. import { usePageSearch, type PageHooks, type PageEvents } from "/@/hooks/page";
  5. import NotOrderImportModal from "./components/NotOrderImportModal/index.vue"
  6. import OrderImportModal from "./components/OrderImportModal/index.vue"
  7. import { notOrderTemplate } from "./components/NotOrderImportModal/columns-config"
  8. import { orderTemplate } from "./components/OrderImportModal/columns-config"
  9. import { useRenderIcon } from "/@/components/ReIcon/src/hooks"
  10. import contentConfig from "./config/content.config";
  11. import searchConfig from "./config/search.config";
  12. import { utils, writeFile } from "xlsx";
  13. import { useUserInfo } from "/@/hooks/core/useUser";
  14. import { httpDelete } from "/@/api/invoiceInOut/inOutManager";
  15. import { useTask } from "/@/hooks/core";
  16. import { ElMessage } from "element-plus";
  17. const PageName = "inOutManager";
  18. const router = useRouter();
  19. const state = reactive({ orderImportVisible: false, notOrderImportVisible: false })
  20. const hooks: PageHooks = { pageSearchHook: () => usePageSearch(undefined, undefined, searchConfig) };
  21. const pageContentRef = ref(null)
  22. const deleteTask = useTask({
  23. success() {
  24. ElMessage.success('取消成功')
  25. pageContentRef?.value.onSearch()
  26. }
  27. })
  28. const { isSuperUser } = useUserInfo()
  29. const events: PageEvents = {
  30. content: {
  31. create: () => router.push('/invoiceInOut/outManagerDetail'),
  32. preview: ({ id }) => router.push("/invoiceInOut/outManagerDetail?id=" + id)
  33. }
  34. };
  35. function onDownload(type = 'notOrder'){
  36. const data = type === 'notOrder' ? notOrderTemplate : orderTemplate
  37. const title = type === 'notOrder' ? '非订单商品模板.xlsx' : '订单商品模板.xlsx'
  38. const workBook = utils.book_new();
  39. const workSheet = utils.json_to_sheet(data);
  40. utils.book_append_sheet(workBook, workSheet, "sheet");
  41. writeFile(workBook, title, { bookType: "xlsx" });
  42. }
  43. function handleRefresh(row) {
  44. deleteTask.run(httpDelete({ id: row.id }))
  45. }
  46. </script>
  47. <template>
  48. <PageAuth :pageName="PageName">
  49. <PageContainer :hooks="hooks" :events="events" :searchConfig="searchConfig" :contentConfig="contentConfig"
  50. :get-content-ref="ref => pageContentRef = ref">
  51. <template #content_header>
  52. <ElDropdown v-if="!isSuperUser">
  53. <ElButton size="small" type="primary" style="margin-right: 10px;margin-top:1px"
  54. :icon="useRenderIcon('arrow-up-line')">商品导入
  55. </ElButton>
  56. <template #dropdown>
  57. <ElDropdownMenu>
  58. <ElDropdownItem @click="state.orderImportVisible = true">订单商品</ElDropdownItem>
  59. <ElDropdownItem @click="state.notOrderImportVisible = true">非订单商品</ElDropdownItem>
  60. </ElDropdownMenu>
  61. </template>
  62. </ElDropdown>
  63. <ElDropdown>
  64. <ElButton size="small" style="margin-right: 10px;margin-top:1px" :icon="useRenderIcon('arrow-down-line')">
  65. 商品导入模板下载</ElButton>
  66. <template #dropdown>
  67. <ElDropdownMenu>
  68. <ElDropdownItem @click="onDownload('order')">订单商品</ElDropdownItem>
  69. <ElDropdownItem @click="onDownload('notOrder')">非订单商品</ElDropdownItem>
  70. </ElDropdownMenu>
  71. </template>
  72. </ElDropdown>
  73. </template>
  74. <template #content_action="row">
  75. <ElTooltip content="取消操作" placement="top" v-if="row.status == '1'">
  76. <ElButton :icon="useRenderIcon('refresh')" @click="handleRefresh(row)" type="danger" link />
  77. </ElTooltip>
  78. </template>
  79. </PageContainer>
  80. <OrderImportModal v-model:visible="state.orderImportVisible" @refresh="pageContentRef?.onSearch()" />
  81. <NotOrderImportModal v-model:visible="state.notOrderImportVisible" @refresh="pageContentRef?.onSearch()" />
  82. </PageAuth>
  83. </template>