| | |
| | | <ElButton :loading="templateDownloading" @click="handleDownloadTemplate" v-ripple> |
| | | {{ t('pages.basicInfo.whMat.actions.downloadTemplate') }} |
| | | </ElButton> |
| | | <ListExportPrint |
| | | class="inline-flex" |
| | | :preview-visible="previewVisible" |
| | | @update:previewVisible="handlePreviewVisibleChange" |
| | | :report-title="reportTitle" |
| | | :selected-rows="selectedRows" |
| | | :query-params="reportQueryParams" |
| | | :columns="columns" |
| | | :preview-rows="previewRows" |
| | | :preview-meta="resolvedPreviewMeta" |
| | | :total="pagination.total" |
| | | :disabled="loading" |
| | | @export="handleExport" |
| | | @print="handlePrint" |
| | | /> |
| | | <ElButton :loading="exporting" :disabled="loading" @click="handleExport" v-ripple> |
| | | {{ t('common.actions.export') }} |
| | | </ElButton> |
| | | <ElButton |
| | | v-auth="'manager:matnrPrintTemplate:list'" |
| | | :loading="printLoading" |
| | | :disabled="loading || selectedRows.length === 0" |
| | | @click="handlePrint()" |
| | | v-ripple |
| | | > |
| | | {{ t('common.actions.print') }} |
| | | </ElButton> |
| | | </ElSpace> |
| | | </template> |
| | | </ArtTableHeader> |
| | |
| | | :loading="detailLoading" |
| | | :detail="detailData" |
| | | /> |
| | | |
| | | <WhMatPrintDialog v-model:visible="printDialogVisible" :rows="printRows" /> |
| | | </div> |
| | | </template> |
| | | |
| | |
| | | import { computed, onMounted, reactive, ref } from 'vue' |
| | | import { ElMessage } from 'element-plus' |
| | | import { useI18n } from 'vue-i18n' |
| | | import ListExportPrint from '@/components/biz/list-export-print/index.vue' |
| | | import { buildListExportPayload } from '@/components/biz/list-export-print/list-export-print.helpers.js' |
| | | import { useAuth } from '@/hooks/core/useAuth' |
| | | import { useTableColumns } from '@/hooks/core/useTableColumns' |
| | | import { useUserStore } from '@/store/modules/user' |
| | |
| | | import { defaultResponseAdapter } from '@/utils/table/tableUtils' |
| | | import { guardRequestWithMessage } from '@/utils/sys/requestGuard' |
| | | import { useCrudPage } from '@/views/system/common/useCrudPage' |
| | | import { usePrintExportPage } from '@/views/system/common/usePrintExportPage' |
| | | import { |
| | | fetchBatchUpdateMatnr, |
| | | fetchBindMatnrGroup, |
| | |
| | | import WhMatBindLocDialog from './modules/wh-mat-bind-loc-dialog.vue' |
| | | import WhMatDialog from './modules/wh-mat-dialog.vue' |
| | | import WhMatDetailDrawer from './modules/wh-mat-detail-drawer.vue' |
| | | import WhMatPrintDialog from './modules/wh-mat-print-dialog.vue' |
| | | import { createWhMatTableColumns } from './whMatTable.columns' |
| | | import { |
| | | WH_MAT_REPORT_STYLE, |
| | |
| | | buildMatnrGroupTreeQueryParams, |
| | | buildMatnrPageQueryParams, |
| | | buildWhMatDialogModel, |
| | | buildWhMatPrintRows, |
| | | buildWhMatReportMeta, |
| | | buildWhMatSavePayload, |
| | | createWhMatSearchState, |
| | | getWhMatDynamicFieldKey, |
| | |
| | | const { t } = useI18n() |
| | | const { hasAuth } = useAuth() |
| | | const userStore = useUserStore() |
| | | const canPrintMatnr = hasAuth('manager:matnrPrintTemplate:list') |
| | | |
| | | const showBatchActionButtons = false |
| | | const loading = ref(false) |
| | |
| | | const bindLocDialogVisible = ref(false) |
| | | const bindLocOptionsLoading = ref(false) |
| | | const importing = ref(false) |
| | | const exporting = ref(false) |
| | | const printLoading = ref(false) |
| | | const printDialogVisible = ref(false) |
| | | const templateDownloading = ref(false) |
| | | const tableData = ref([]) |
| | | const groupTreeData = ref([]) |
| | | const detailData = ref({}) |
| | | const printRows = ref([]) |
| | | const enabledFields = ref([]) |
| | | const serialRuleOptions = ref([]) |
| | | const areaOptions = ref([]) |
| | |
| | | handleViewDetail: openDetailDrawer, |
| | | handleEdit: hasAuth('update') ? openEditDialog : null, |
| | | handleDelete: hasAuth('delete') ? (row) => handleDeleteAction?.(row) : null, |
| | | handlePrint: (row) => handlePrint({ ids: [row.id] }), |
| | | handlePrint: canPrintMatnr ? (row) => handlePrint({ ids: [row.id] }) : null, |
| | | canEdit: hasAuth('update'), |
| | | canDelete: hasAuth('delete'), |
| | | t |
| | |
| | | } |
| | | } |
| | | |
| | | const resolvePrintRecords = async (payload) => { |
| | | if (Array.isArray(payload?.ids) && payload.ids.length > 0) { |
| | | return defaultResponseAdapter(await fetchGetMatnrMany(payload.ids)).records |
| | | } |
| | | return tableData.value |
| | | } |
| | | |
| | | const { |
| | | previewVisible, |
| | | previewRows, |
| | | previewMeta, |
| | | handlePreviewVisibleChange, |
| | | handleExport, |
| | | handlePrint |
| | | } = usePrintExportPage({ |
| | | downloadFileName: 'matnr.xlsx', |
| | | requestExport: (payload) => |
| | | fetchExportMatnrReport(payload, { |
| | | headers: { |
| | | Authorization: userStore.accessToken || '' |
| | | } |
| | | }), |
| | | resolvePrintRecords, |
| | | buildPreviewRows: (records) => buildWhMatPrintRows(records, t), |
| | | buildPreviewMeta |
| | | }) |
| | | |
| | | const resolvedPreviewMeta = computed(() => |
| | | buildWhMatReportMeta({ |
| | | previewMeta: previewMeta.value, |
| | | count: previewRows.value.length, |
| | | orientation: previewMeta.value?.reportStyle?.orientation || WH_MAT_REPORT_STYLE.orientation |
| | | }) |
| | | ) |
| | | |
| | | async function downloadFile(response, fallbackName) { |
| | | if (!response?.ok) { |
| | | throw new Error( |
| | |
| | | } |
| | | } |
| | | |
| | | async function handleExport() { |
| | | exporting.value = true |
| | | try { |
| | | const payload = buildListExportPayload({ |
| | | reportTitle, |
| | | selectedRows: selectedRows.value, |
| | | queryParams: reportQueryParams.value, |
| | | columns, |
| | | meta: buildPreviewMeta(tableData.value) |
| | | }) |
| | | const response = await guardRequestWithMessage( |
| | | fetchExportMatnrReport(payload, { |
| | | headers: { |
| | | Authorization: userStore.accessToken || '' |
| | | } |
| | | }), |
| | | null, |
| | | { |
| | | timeoutMessage: t('message.exportTimeoutStopped') |
| | | } |
| | | ) |
| | | if (!response) { |
| | | return |
| | | } |
| | | await downloadFile(response, 'matnr.xlsx') |
| | | ElMessage.success(t('crud.messages.exportSuccess')) |
| | | } catch (error) { |
| | | ElMessage.error(error?.message || t('crud.messages.exportFailed')) |
| | | } finally { |
| | | exporting.value = false |
| | | } |
| | | } |
| | | |
| | | async function handlePrint(payload = {}) { |
| | | const ids = |
| | | Array.isArray(payload?.ids) && payload.ids.length > 0 ? payload.ids : getSelectedIds() |
| | | |
| | | if (!ids.length) { |
| | | ElMessage.warning(t('pages.basicInfo.whMat.messages.selectAtLeastOne')) |
| | | return |
| | | } |
| | | |
| | | printLoading.value = true |
| | | try { |
| | | const records = await guardRequestWithMessage(fetchGetMatnrMany(ids), [], { |
| | | timeoutMessage: t('message.printTimeoutStopped') |
| | | }) |
| | | const normalizedRecords = defaultResponseAdapter(records).records |
| | | if (!normalizedRecords.length) { |
| | | ElMessage.warning(t('print.noData')) |
| | | return |
| | | } |
| | | printRows.value = normalizedRecords.map((record) => |
| | | normalizeMatnrRow(record, t, enabledFields.value) |
| | | ) |
| | | printDialogVisible.value = true |
| | | } catch (error) { |
| | | ElMessage.error(error?.message || t('crud.messages.printFailed')) |
| | | } finally { |
| | | printLoading.value = false |
| | | } |
| | | } |
| | | |
| | | async function handleDownloadTemplate() { |
| | | templateDownloading.value = true |
| | | try { |