feat(库存报表): 列表改服务端分页并按其他接口传 pagination/sort;导出语义修正为 item=含锁定、不传=仅出入库,新增导出选中(仅出入库/全部含锁定)
This commit is contained in:
parent
e3f5c9ede5
commit
caa1b83cc8
@ -22,6 +22,15 @@ export type StockReportListItem = {
|
|||||||
[key: string]: unknown
|
[key: string]: unknown
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface StockReportPagination {
|
||||||
|
page?: number
|
||||||
|
pageSize?: number
|
||||||
|
total?: number
|
||||||
|
totalPages?: number
|
||||||
|
hasPrevious?: boolean
|
||||||
|
hasNext?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
export interface StockReportSearchBody {
|
export interface StockReportSearchBody {
|
||||||
where?: {
|
where?: {
|
||||||
start_time?: string | Date
|
start_time?: string | Date
|
||||||
@ -33,15 +42,24 @@ export interface StockReportSearchBody {
|
|||||||
}
|
}
|
||||||
sort?: {
|
sort?: {
|
||||||
sortField?: 'begin_total' | 'inbound_total' | 'outbound_total' | 'end_total'
|
sortField?: 'begin_total' | 'inbound_total' | 'outbound_total' | 'end_total'
|
||||||
sort_field?: 'begin_total' | 'inbound_total' | 'outbound_total' | 'end_total'
|
|
||||||
sortOrder?: 'ASC' | 'DESC' | 'asc' | 'desc'
|
sortOrder?: 'ASC' | 'DESC' | 'asc' | 'desc'
|
||||||
sort_order?: 'ASC' | 'DESC' | 'asc' | 'desc'
|
}
|
||||||
|
pagination?: {
|
||||||
|
page?: number
|
||||||
|
pageSize?: number
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* stock.report.export / exportStore 导出语义(与订单模块的 waybill/item 含义不同):
|
||||||
|
* - export_mode='item':变更记录 sheet 含 LOCK(锁定/解锁)记录,即「全部」
|
||||||
|
* - 不传 export_mode:变更记录 sheet 仅出入库等变动(不含 LOCK)
|
||||||
|
* 参数位置 data.export_mode(兼容驼峰 data.exportMode),export/exportStore 均支持。
|
||||||
|
* 注意:无论哪种模式,「汇总」+「变更记录」两个 sheet 都会生成。
|
||||||
|
*/
|
||||||
export interface StockReportExportBody extends StockReportSearchBody {
|
export interface StockReportExportBody extends StockReportSearchBody {
|
||||||
export_mode?: 'waybill' | 'item'
|
export_mode?: 'item'
|
||||||
exportMode?: 'waybill' | 'item'
|
exportMode?: 'item'
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface StockReportExportTaskResponse {
|
export interface StockReportExportTaskResponse {
|
||||||
@ -78,8 +96,10 @@ export interface StockReportSearchResult {
|
|||||||
message?: string
|
message?: string
|
||||||
data?: {
|
data?: {
|
||||||
list?: StockReportListItem[]
|
list?: StockReportListItem[]
|
||||||
|
pagination?: StockReportPagination
|
||||||
}
|
}
|
||||||
list?: StockReportListItem[]
|
list?: StockReportListItem[]
|
||||||
|
pagination?: StockReportPagination
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 不传或传 `{}` 表示无业务参数(与页面首次打开一致) */
|
/** 不传或传 `{}` 表示无业务参数(与页面首次打开一致) */
|
||||||
|
|||||||
@ -17,13 +17,15 @@
|
|||||||
<div class="toolbar">
|
<div class="toolbar">
|
||||||
<div class="toolbar-left">
|
<div class="toolbar-left">
|
||||||
<el-button size="small" @click="loadData">刷新</el-button>
|
<el-button size="small" @click="loadData">刷新</el-button>
|
||||||
<ExportModeDropdown :loading="exportLoading" @action="handleExportAction" />
|
<ExportModeDropdown
|
||||||
|
:loading="exportLoading"
|
||||||
|
label="导出"
|
||||||
|
default-action="handleExportOnlyInOut"
|
||||||
|
:items="exportDropdownItems"
|
||||||
|
@action="handleExportAction"
|
||||||
|
/>
|
||||||
<el-button size="small" @click="openColumnConfigPanel">字段设置</el-button>
|
<el-button size="small" @click="openColumnConfigPanel">字段设置</el-button>
|
||||||
<el-button size="small" @click="toggleDetailVisible">{{ detailVisible ? '隐藏详情' : '显示详情' }}</el-button>
|
<el-button size="small" @click="toggleDetailVisible">{{ detailVisible ? '隐藏详情' : '显示详情' }}</el-button>
|
||||||
<template v-if="pagination.total > 0">
|
|
||||||
<el-tag size="small" effect="plain">入库合计 {{ formatNumber(sumInbound) }}</el-tag>
|
|
||||||
<el-tag size="small" effect="plain">出库合计 {{ formatNumber(sumOutbound) }}</el-tag>
|
|
||||||
</template>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -41,9 +43,11 @@
|
|||||||
:table-size="tableSize"
|
:table-size="tableSize"
|
||||||
:pagination="pagination"
|
:pagination="pagination"
|
||||||
:show-index="true"
|
:show-index="true"
|
||||||
|
show-selection
|
||||||
:loading="loading"
|
:loading="loading"
|
||||||
:query-time="queryTime"
|
:query-time="queryTime"
|
||||||
@current-change="handleRowClick"
|
@current-change="handleRowClick"
|
||||||
|
@selection-change="handleSelectionChange"
|
||||||
@sort-change="handleSortChange"
|
@sort-change="handleSortChange"
|
||||||
@page-change="handlePageChange"
|
@page-change="handlePageChange"
|
||||||
@page-size-change="handlePageSizeChange"
|
@page-size-change="handlePageSizeChange"
|
||||||
@ -111,6 +115,7 @@ import dayjs from 'dayjs'
|
|||||||
import ScanBox from '@/components/ScanBox/index.vue'
|
import ScanBox from '@/components/ScanBox/index.vue'
|
||||||
import UpperTable from '@/components/UpperTable/index.vue'
|
import UpperTable from '@/components/UpperTable/index.vue'
|
||||||
import ExportModeDropdown from '@/components/ExportModeDropdown.vue'
|
import ExportModeDropdown from '@/components/ExportModeDropdown.vue'
|
||||||
|
import type { ExportDropdownItem } from '@/components/ExportModeDropdown.vue'
|
||||||
import AsyncExportProgressDialog from '@/components/AsyncExportProgressDialog.vue'
|
import AsyncExportProgressDialog from '@/components/AsyncExportProgressDialog.vue'
|
||||||
import { useAsyncExportTask } from '@/composables/useAsyncExportTask'
|
import { useAsyncExportTask } from '@/composables/useAsyncExportTask'
|
||||||
import {
|
import {
|
||||||
@ -182,6 +187,7 @@ const {
|
|||||||
exportProgressPercent,
|
exportProgressPercent,
|
||||||
exportProgressStatus,
|
exportProgressStatus,
|
||||||
exportStatusLabel,
|
exportStatusLabel,
|
||||||
|
submitExportTask,
|
||||||
submitExportTaskWithMode,
|
submitExportTaskWithMode,
|
||||||
resumeExportTaskFromStorage,
|
resumeExportTaskFromStorage,
|
||||||
hasPendingExportTask
|
hasPendingExportTask
|
||||||
@ -191,7 +197,6 @@ const {
|
|||||||
queryProgress: (params) => getExportTaskProgress(params)
|
queryProgress: (params) => getExportTaskProgress(params)
|
||||||
})
|
})
|
||||||
|
|
||||||
const fullList = ref<any[]>([])
|
|
||||||
const list = ref<any[]>([])
|
const list = ref<any[]>([])
|
||||||
const columns = ref(buildReportTableColumns([]))
|
const columns = ref(buildReportTableColumns([]))
|
||||||
|
|
||||||
@ -208,7 +213,7 @@ const currentSort = reactive<{ prop: string; order: '' | 'ascending' | 'descendi
|
|||||||
const selectedRid = ref<string | null>(null)
|
const selectedRid = ref<string | null>(null)
|
||||||
const currentConditionRaw = ref<any>({})
|
const currentConditionRaw = ref<any>({})
|
||||||
|
|
||||||
const selectedRow = computed(() => fullList.value.find((r) => r.__rid === selectedRid.value) || null)
|
const selectedRow = computed(() => list.value.find((r) => r.__rid === selectedRid.value) || null)
|
||||||
|
|
||||||
const detailKeys = computed(() => {
|
const detailKeys = computed(() => {
|
||||||
if (!selectedRow.value) return []
|
if (!selectedRow.value) return []
|
||||||
@ -216,17 +221,6 @@ const detailKeys = computed(() => {
|
|||||||
return sortReportDetailKeys(keys)
|
return sortReportDetailKeys(keys)
|
||||||
})
|
})
|
||||||
|
|
||||||
const sumInbound = computed(() =>
|
|
||||||
fullList.value.reduce((a, r) => a + Number((r as any).inbound_total ?? 0), 0)
|
|
||||||
)
|
|
||||||
const sumOutbound = computed(() =>
|
|
||||||
fullList.value.reduce((a, r) => a + Number((r as any).outbound_total ?? 0), 0)
|
|
||||||
)
|
|
||||||
|
|
||||||
function formatNumber(n: number) {
|
|
||||||
return Number.isFinite(n) ? n.toLocaleString('zh-CN') : '--'
|
|
||||||
}
|
|
||||||
|
|
||||||
function fieldLabel(key: string) {
|
function fieldLabel(key: string) {
|
||||||
return reportFieldLabels[key] || key
|
return reportFieldLabels[key] || key
|
||||||
}
|
}
|
||||||
@ -253,13 +247,6 @@ function isWideKey(key: string) {
|
|||||||
return detailValue(key).length > 80
|
return detailValue(key).length > 80
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractReportList(res: any): any[] {
|
|
||||||
if (!res) return []
|
|
||||||
if (res.data != null && Array.isArray(res.data.list)) return res.data.list
|
|
||||||
if (Array.isArray(res.list)) return res.list
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
|
|
||||||
function withRowIds(rows: any[]) {
|
function withRowIds(rows: any[]) {
|
||||||
return rows.map((row, idx) => ({
|
return rows.map((row, idx) => ({
|
||||||
...row,
|
...row,
|
||||||
@ -267,27 +254,17 @@ function withRowIds(rows: any[]) {
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyClientPage() {
|
|
||||||
const total = fullList.value.length
|
|
||||||
pagination.total = total
|
|
||||||
const start = (pagination.currentPage - 1) * pagination.pageSize
|
|
||||||
list.value = fullList.value.slice(start, start + pagination.pageSize)
|
|
||||||
}
|
|
||||||
|
|
||||||
const SORTABLE_FIELDS = new Set(['begin_total', 'inbound_total', 'outbound_total', 'end_total'])
|
const SORTABLE_FIELDS = new Set(['begin_total', 'inbound_total', 'outbound_total', 'end_total'])
|
||||||
|
|
||||||
|
/** 排序参数(与其他列表接口一致:sort:{ sortField, sortOrder },如 stock.transaction.list) */
|
||||||
function buildSortPayload(): StockReportSearchBody['sort'] | undefined {
|
function buildSortPayload(): StockReportSearchBody['sort'] | undefined {
|
||||||
if (!SORTABLE_FIELDS.has(currentSort.prop)) return undefined
|
if (!SORTABLE_FIELDS.has(currentSort.prop)) return undefined
|
||||||
if (!currentSort.order) return undefined
|
if (!currentSort.order) return undefined
|
||||||
const sortOrder = currentSort.order === 'ascending' ? 'ASC' : 'DESC'
|
const sortOrder = currentSort.order === 'ascending' ? 'ASC' : 'DESC'
|
||||||
return {
|
return { sortField: currentSort.prop as any, sortOrder }
|
||||||
sortField: currentSort.prop as any,
|
|
||||||
sort_field: currentSort.prop as any,
|
|
||||||
sortOrder,
|
|
||||||
sort_order: sortOrder
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 查询与导出共用的业务条件(不含分页,导出走全量) */
|
||||||
function buildReportQueryPayload(): StockReportSearchBody {
|
function buildReportQueryPayload(): StockReportSearchBody {
|
||||||
const where = normalizeScanConditionToReportWhere(currentConditionRaw.value)
|
const where = normalizeScanConditionToReportWhere(currentConditionRaw.value)
|
||||||
const sort = buildSortPayload()
|
const sort = buildSortPayload()
|
||||||
@ -301,16 +278,71 @@ function buildReportQueryPayload(): StockReportSearchBody {
|
|||||||
return body
|
return body
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleExportWaybill() {
|
/** 列表查询请求体:在业务条件基础上附加分页参数 */
|
||||||
|
function buildReportSearchPayload(): StockReportSearchBody {
|
||||||
|
const body = buildReportQueryPayload()
|
||||||
|
body.pagination = { page: pagination.currentPage, pageSize: pagination.pageSize }
|
||||||
|
return body
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 解析响应分页信息(兼容 res.data / res 两层结构) */
|
||||||
|
function parseReportPagination(res: any) {
|
||||||
|
const payload = res?.data && typeof res.data === 'object' ? res.data : res
|
||||||
|
const pg = payload?.pagination && typeof payload.pagination === 'object' ? payload.pagination : {}
|
||||||
|
return {
|
||||||
|
page: Number(pg.page) > 0 ? Number(pg.page) : pagination.currentPage,
|
||||||
|
pageSize: Number(pg.pageSize) > 0 ? Number(pg.pageSize) : pagination.pageSize,
|
||||||
|
total: Number(pg.total) > 0 ? Number(pg.total) : 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 表格勾选的行(用于「导出选中」) */
|
||||||
|
const selectionRows = ref<any[]>([])
|
||||||
|
|
||||||
|
function handleSelectionChange(rows: any[]) {
|
||||||
|
selectionRows.value = rows || []
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 导出选项:全部=当前筛选条件下全部;选中=勾选行(stock_id in 叠加当前筛选)。mode 语义:item=含 LOCK;不传=仅出入库 */
|
||||||
|
const exportDropdownItems: ExportDropdownItem[] = [
|
||||||
|
{ label: '仅出入库(不含锁定记录)', action: 'handleExportOnlyInOut' },
|
||||||
|
{ label: '全部(含锁定记录)', action: 'handleExportWithLock', divided: true },
|
||||||
|
{ label: '导出选中·仅出入库', action: 'handleExportSelectedOnlyInOut', divided: true },
|
||||||
|
{ label: '导出选中·全部(含锁定记录)', action: 'handleExportSelectedWithLock' }
|
||||||
|
]
|
||||||
|
|
||||||
|
/** 勾选行的有效 stock_id(去重去空;后端数组即 in 匹配,参考 inventory 导出选中写法) */
|
||||||
|
function collectSelectedStockIds(): number[] {
|
||||||
|
return Array.from(
|
||||||
|
new Set(
|
||||||
|
selectionRows.value
|
||||||
|
.map((row: any) => Number(row.stock_id))
|
||||||
|
.filter((id: number) => Number.isFinite(id) && id > 0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 导出选中请求体:在 buildReportQueryPayload 的 where 基础上叠加 stock_id in */
|
||||||
|
function buildSelectedExportPayload(): Record<string, unknown> {
|
||||||
|
const stockIds = collectSelectedStockIds()
|
||||||
|
const body = buildReportQueryPayload()
|
||||||
|
const where: Record<string, any> = body.where ? { ...body.where } : {}
|
||||||
|
where.stock_id = stockIds.length === 1 ? stockIds[0] : stockIds
|
||||||
|
return { ...body, where }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 仅出入库:不传 export_mode,后端「变更记录」sheet 排除 LOCK,仅含出入库/移库等变动 */
|
||||||
|
async function handleExportOnlyInOut() {
|
||||||
if (hasPendingExportTask()) {
|
if (hasPendingExportTask()) {
|
||||||
ElMessage.warning('检测到未完成导出任务,请等待当前任务完成后再试')
|
ElMessage.warning('检测到未完成导出任务,请等待当前任务完成后再试')
|
||||||
resumeExportTaskFromStorage()
|
resumeExportTaskFromStorage()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
await submitExportTaskWithMode(buildReportQueryPayload() as Record<string, unknown>, 'waybill')
|
await submitExportTask(buildReportQueryPayload() as Record<string, unknown>)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleExportItem() {
|
/** 全部:传 export_mode='item',后端「变更记录」sheet 含 LOCK(锁定/解锁)记录 */
|
||||||
|
async function handleExportWithLock() {
|
||||||
if (hasPendingExportTask()) {
|
if (hasPendingExportTask()) {
|
||||||
ElMessage.warning('检测到未完成导出任务,请等待当前任务完成后再试')
|
ElMessage.warning('检测到未完成导出任务,请等待当前任务完成后再试')
|
||||||
resumeExportTaskFromStorage()
|
resumeExportTaskFromStorage()
|
||||||
@ -319,12 +351,48 @@ async function handleExportItem() {
|
|||||||
await submitExportTaskWithMode(buildReportQueryPayload() as Record<string, unknown>, 'item')
|
await submitExportTaskWithMode(buildReportQueryPayload() as Record<string, unknown>, 'item')
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleExportAction(action: string) {
|
/** 导出选中·仅出入库(不传 export_mode) */
|
||||||
if (action === 'handleExportItem') {
|
async function handleExportSelectedOnlyInOut() {
|
||||||
void handleExportItem()
|
if (!collectSelectedStockIds().length) {
|
||||||
|
ElMessage.warning('请先在表格勾选要导出的记录')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
void handleExportWaybill()
|
if (hasPendingExportTask()) {
|
||||||
|
ElMessage.warning('检测到未完成导出任务,请等待当前任务完成后再试')
|
||||||
|
resumeExportTaskFromStorage()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
await submitExportTask(buildSelectedExportPayload())
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 导出选中·全部(含锁定记录,export_mode='item') */
|
||||||
|
async function handleExportSelectedWithLock() {
|
||||||
|
if (!collectSelectedStockIds().length) {
|
||||||
|
ElMessage.warning('请先在表格勾选要导出的记录')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (hasPendingExportTask()) {
|
||||||
|
ElMessage.warning('检测到未完成导出任务,请等待当前任务完成后再试')
|
||||||
|
resumeExportTaskFromStorage()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
await submitExportTaskWithMode(buildSelectedExportPayload(), 'item')
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleExportAction(action: string) {
|
||||||
|
if (action === 'handleExportWithLock') {
|
||||||
|
void handleExportWithLock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (action === 'handleExportSelectedOnlyInOut') {
|
||||||
|
void handleExportSelectedOnlyInOut()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (action === 'handleExportSelectedWithLock') {
|
||||||
|
void handleExportSelectedWithLock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
void handleExportOnlyInOut()
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadFilterData() {
|
async function loadFilterData() {
|
||||||
@ -373,30 +441,33 @@ async function loadData() {
|
|||||||
loading.value = true
|
loading.value = true
|
||||||
const started = Date.now()
|
const started = Date.now()
|
||||||
selectedRid.value = null
|
selectedRid.value = null
|
||||||
const body = buildReportQueryPayload()
|
|
||||||
try {
|
try {
|
||||||
const res: any = await searchInventoryReport(
|
const res: any = await searchInventoryReport(buildReportSearchPayload())
|
||||||
Object.keys(body).length > 0 ? body : undefined
|
const payload = res?.data && typeof res.data === 'object' ? res.data : res
|
||||||
)
|
const ok =
|
||||||
if (res && (res.flag === 'success' || res.code === 200)) {
|
res?.flag === 'success' ||
|
||||||
const raw = extractReportList(res)
|
res?.code === 200 ||
|
||||||
fullList.value = withRowIds(raw)
|
res?.code === 1 ||
|
||||||
|
(payload && Array.isArray(payload.list))
|
||||||
|
if (ok) {
|
||||||
|
const raw = Array.isArray(payload?.list) ? payload.list : []
|
||||||
|
list.value = withRowIds(raw)
|
||||||
columns.value = buildReportTableColumns(raw)
|
columns.value = buildReportTableColumns(raw)
|
||||||
pagination.currentPage = 1
|
const pg = parseReportPagination(res)
|
||||||
applyClientPage()
|
pagination.currentPage = pg.page
|
||||||
|
pagination.pageSize = pg.pageSize
|
||||||
|
pagination.total = pg.total
|
||||||
queryTime.value = Date.now() - started
|
queryTime.value = Date.now() - started
|
||||||
if (raw.length === 0) {
|
if (raw.length === 0 && pagination.total === 0) {
|
||||||
ElMessage.info('当前条件下暂无数据')
|
ElMessage.info('当前条件下暂无数据')
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fullList.value = []
|
|
||||||
list.value = []
|
list.value = []
|
||||||
columns.value = buildReportTableColumns([])
|
columns.value = buildReportTableColumns([])
|
||||||
pagination.total = 0
|
pagination.total = 0
|
||||||
ElMessage.error(res?.message || '查询失败')
|
ElMessage.error(payload?.message || res?.message || '查询失败')
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
fullList.value = []
|
|
||||||
list.value = []
|
list.value = []
|
||||||
columns.value = buildReportTableColumns([])
|
columns.value = buildReportTableColumns([])
|
||||||
pagination.total = 0
|
pagination.total = 0
|
||||||
@ -415,13 +486,13 @@ function handleSortChange({ prop, order }: { prop: string; order: '' | 'ascendin
|
|||||||
|
|
||||||
function handlePageChange(page: number) {
|
function handlePageChange(page: number) {
|
||||||
pagination.currentPage = page
|
pagination.currentPage = page
|
||||||
applyClientPage()
|
loadData()
|
||||||
}
|
}
|
||||||
|
|
||||||
function handlePageSizeChange(size: number) {
|
function handlePageSizeChange(size: number) {
|
||||||
pagination.pageSize = size
|
pagination.pageSize = size
|
||||||
pagination.currentPage = 1
|
pagination.currentPage = 1
|
||||||
applyClientPage()
|
loadData()
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleRowClick(row: any) {
|
function handleRowClick(row: any) {
|
||||||
|
|||||||
@ -16,7 +16,13 @@
|
|||||||
<div class="toolbar">
|
<div class="toolbar">
|
||||||
<div class="toolbar-left">
|
<div class="toolbar-left">
|
||||||
<el-button size="small" type="primary" @click="loadData">刷新</el-button>
|
<el-button size="small" type="primary" @click="loadData">刷新</el-button>
|
||||||
<ExportModeDropdown :loading="exportLoading" @action="handleExportAction" />
|
<ExportModeDropdown
|
||||||
|
:loading="exportLoading"
|
||||||
|
label="导出"
|
||||||
|
default-action="handleExportOnlyInOut"
|
||||||
|
:items="exportDropdownItems"
|
||||||
|
@action="handleExportAction"
|
||||||
|
/>
|
||||||
<el-button size="small" @click="openColumnConfigPanel">字段设置</el-button>
|
<el-button size="small" @click="openColumnConfigPanel">字段设置</el-button>
|
||||||
<el-button size="small" @click="toggleDetailVisible">{{ detailVisible ? '隐藏详情' : '显示详情' }}</el-button>
|
<el-button size="small" @click="toggleDetailVisible">{{ detailVisible ? '隐藏详情' : '显示详情' }}</el-button>
|
||||||
<el-divider direction="vertical" />
|
<el-divider direction="vertical" />
|
||||||
@ -24,12 +30,6 @@
|
|||||||
v-model="warehouseFilterId"
|
v-model="warehouseFilterId"
|
||||||
@change="handleWarehouseChange"
|
@change="handleWarehouseChange"
|
||||||
/>
|
/>
|
||||||
<!-- <span class="toolbar-title">库存报表</span>
|
|
||||||
<el-tag size="small" type="info">共 {{ pagination.total }} 条</el-tag> -->
|
|
||||||
<template v-if="pagination.total > 0">
|
|
||||||
<el-tag size="small" effect="plain">入库合计 {{ formatNumber(sumInbound) }}</el-tag>
|
|
||||||
<el-tag size="small" effect="plain">出库合计 {{ formatNumber(sumOutbound) }}</el-tag>
|
|
||||||
</template>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -47,9 +47,11 @@
|
|||||||
:table-size="tableSize"
|
:table-size="tableSize"
|
||||||
:pagination="pagination"
|
:pagination="pagination"
|
||||||
:show-index="true"
|
:show-index="true"
|
||||||
|
show-selection
|
||||||
:loading="loading"
|
:loading="loading"
|
||||||
:query-time="queryTime"
|
:query-time="queryTime"
|
||||||
@current-change="handleRowClick"
|
@current-change="handleRowClick"
|
||||||
|
@selection-change="handleSelectionChange"
|
||||||
@sort-change="handleSortChange"
|
@sort-change="handleSortChange"
|
||||||
@page-change="handlePageChange"
|
@page-change="handlePageChange"
|
||||||
@page-size-change="handlePageSizeChange"
|
@page-size-change="handlePageSizeChange"
|
||||||
@ -114,6 +116,7 @@ import dayjs from 'dayjs'
|
|||||||
import ScanBox from '@/components/ScanBox/index.vue'
|
import ScanBox from '@/components/ScanBox/index.vue'
|
||||||
import UpperTable from '@/components/UpperTable/index.vue'
|
import UpperTable from '@/components/UpperTable/index.vue'
|
||||||
import ExportModeDropdown from '@/components/ExportModeDropdown.vue'
|
import ExportModeDropdown from '@/components/ExportModeDropdown.vue'
|
||||||
|
import type { ExportDropdownItem } from '@/components/ExportModeDropdown.vue'
|
||||||
import WarehouseSelect from '@/components/WarehouseSelect.vue'
|
import WarehouseSelect from '@/components/WarehouseSelect.vue'
|
||||||
import AsyncExportProgressDialog from '@/components/AsyncExportProgressDialog.vue'
|
import AsyncExportProgressDialog from '@/components/AsyncExportProgressDialog.vue'
|
||||||
import { useAsyncExportTask } from '@/composables/useAsyncExportTask'
|
import { useAsyncExportTask } from '@/composables/useAsyncExportTask'
|
||||||
@ -189,6 +192,7 @@ const {
|
|||||||
exportProgressPercent,
|
exportProgressPercent,
|
||||||
exportProgressStatus,
|
exportProgressStatus,
|
||||||
exportStatusLabel,
|
exportStatusLabel,
|
||||||
|
submitExportTask,
|
||||||
submitExportTaskWithMode,
|
submitExportTaskWithMode,
|
||||||
resumeExportTaskFromStorage,
|
resumeExportTaskFromStorage,
|
||||||
hasPendingExportTask
|
hasPendingExportTask
|
||||||
@ -198,7 +202,6 @@ const {
|
|||||||
queryProgress: (params) => getExportTaskProgress(params)
|
queryProgress: (params) => getExportTaskProgress(params)
|
||||||
})
|
})
|
||||||
|
|
||||||
const fullList = ref<any[]>([])
|
|
||||||
const list = ref<any[]>([])
|
const list = ref<any[]>([])
|
||||||
|
|
||||||
/** 货主侧不显示的列 */
|
/** 货主侧不显示的列 */
|
||||||
@ -225,7 +228,7 @@ const currentConditionRaw = ref<any>({})
|
|||||||
/** toolbar 全部仓库筛选值(独立于 scan-box 条件,空值=全部仓库) */
|
/** toolbar 全部仓库筛选值(独立于 scan-box 条件,空值=全部仓库) */
|
||||||
const warehouseFilterId = ref<number | string | null>(null)
|
const warehouseFilterId = ref<number | string | null>(null)
|
||||||
|
|
||||||
const selectedRow = computed(() => fullList.value.find((r) => r.__rid === selectedRid.value) || null)
|
const selectedRow = computed(() => list.value.find((r) => r.__rid === selectedRid.value) || null)
|
||||||
|
|
||||||
const detailKeys = computed(() => {
|
const detailKeys = computed(() => {
|
||||||
if (!selectedRow.value) return []
|
if (!selectedRow.value) return []
|
||||||
@ -233,17 +236,6 @@ const detailKeys = computed(() => {
|
|||||||
return sortReportDetailKeys(keys)
|
return sortReportDetailKeys(keys)
|
||||||
})
|
})
|
||||||
|
|
||||||
const sumInbound = computed(() =>
|
|
||||||
fullList.value.reduce((a, r) => a + Number((r as any).inbound_total ?? 0), 0)
|
|
||||||
)
|
|
||||||
const sumOutbound = computed(() =>
|
|
||||||
fullList.value.reduce((a, r) => a + Number((r as any).outbound_total ?? 0), 0)
|
|
||||||
)
|
|
||||||
|
|
||||||
function formatNumber(n: number) {
|
|
||||||
return Number.isFinite(n) ? n.toLocaleString('zh-CN') : '--'
|
|
||||||
}
|
|
||||||
|
|
||||||
function fieldLabel(key: string) {
|
function fieldLabel(key: string) {
|
||||||
return reportFieldLabels[key] || key
|
return reportFieldLabels[key] || key
|
||||||
}
|
}
|
||||||
@ -270,13 +262,6 @@ function isWideKey(key: string) {
|
|||||||
return detailValue(key).length > 80
|
return detailValue(key).length > 80
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractReportList(res: any): any[] {
|
|
||||||
if (!res) return []
|
|
||||||
if (res.data != null && Array.isArray(res.data.list)) return res.data.list
|
|
||||||
if (Array.isArray(res.list)) return res.list
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
|
|
||||||
function withRowIds(rows: any[]) {
|
function withRowIds(rows: any[]) {
|
||||||
return rows.map((row, idx) => ({
|
return rows.map((row, idx) => ({
|
||||||
...row,
|
...row,
|
||||||
@ -284,25 +269,14 @@ function withRowIds(rows: any[]) {
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyClientPage() {
|
|
||||||
const total = fullList.value.length
|
|
||||||
pagination.total = total
|
|
||||||
const start = (pagination.currentPage - 1) * pagination.pageSize
|
|
||||||
list.value = fullList.value.slice(start, start + pagination.pageSize)
|
|
||||||
}
|
|
||||||
|
|
||||||
const SORTABLE_FIELDS = new Set(['begin_total', 'inbound_total', 'outbound_total', 'end_total'])
|
const SORTABLE_FIELDS = new Set(['begin_total', 'inbound_total', 'outbound_total', 'end_total'])
|
||||||
|
|
||||||
|
/** 排序参数(与其他列表接口一致:sort:{ sortField, sortOrder },如 stock.transaction.list) */
|
||||||
function buildSortPayload(): StockReportSearchBody['sort'] | undefined {
|
function buildSortPayload(): StockReportSearchBody['sort'] | undefined {
|
||||||
if (!SORTABLE_FIELDS.has(currentSort.prop)) return undefined
|
if (!SORTABLE_FIELDS.has(currentSort.prop)) return undefined
|
||||||
if (!currentSort.order) return undefined
|
if (!currentSort.order) return undefined
|
||||||
const sortOrder = currentSort.order === 'ascending' ? 'ASC' : 'DESC'
|
const sortOrder = currentSort.order === 'ascending' ? 'ASC' : 'DESC'
|
||||||
return {
|
return { sortField: currentSort.prop as any, sortOrder }
|
||||||
sortField: currentSort.prop as any,
|
|
||||||
sort_field: currentSort.prop as any,
|
|
||||||
sortOrder,
|
|
||||||
sort_order: sortOrder
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** toolbar 全部仓库过滤:并入报表查询 where(直接值,与报表后端约定一致) */
|
/** toolbar 全部仓库过滤:并入报表查询 where(直接值,与报表后端约定一致) */
|
||||||
@ -332,16 +306,71 @@ function buildReportQueryPayload(): StockReportSearchBody {
|
|||||||
return body
|
return body
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleExportWaybill() {
|
/** 列表查询请求体:在业务条件基础上附加分页参数 */
|
||||||
|
function buildReportSearchPayload(): StockReportSearchBody {
|
||||||
|
const body = buildReportQueryPayload()
|
||||||
|
body.pagination = { page: pagination.currentPage, pageSize: pagination.pageSize }
|
||||||
|
return body
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 解析响应分页信息(兼容 res.data / res 两层结构) */
|
||||||
|
function parseReportPagination(res: any) {
|
||||||
|
const payload = res?.data && typeof res.data === 'object' ? res.data : res
|
||||||
|
const pg = payload?.pagination && typeof payload.pagination === 'object' ? payload.pagination : {}
|
||||||
|
return {
|
||||||
|
page: Number(pg.page) > 0 ? Number(pg.page) : pagination.currentPage,
|
||||||
|
pageSize: Number(pg.pageSize) > 0 ? Number(pg.pageSize) : pagination.pageSize,
|
||||||
|
total: Number(pg.total) > 0 ? Number(pg.total) : 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 表格勾选的行(用于「导出选中」) */
|
||||||
|
const selectionRows = ref<any[]>([])
|
||||||
|
|
||||||
|
function handleSelectionChange(rows: any[]) {
|
||||||
|
selectionRows.value = rows || []
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 导出选项:全部=当前筛选条件下全部;选中=勾选行(stock_id in 叠加当前筛选)。mode 语义:item=含 LOCK;不传=仅出入库 */
|
||||||
|
const exportDropdownItems: ExportDropdownItem[] = [
|
||||||
|
{ label: '仅出入库(不含锁定记录)', action: 'handleExportOnlyInOut' },
|
||||||
|
{ label: '全部(含锁定记录)', action: 'handleExportWithLock', divided: true },
|
||||||
|
{ label: '导出选中·仅出入库', action: 'handleExportSelectedOnlyInOut', divided: true },
|
||||||
|
{ label: '导出选中·全部(含锁定记录)', action: 'handleExportSelectedWithLock' }
|
||||||
|
]
|
||||||
|
|
||||||
|
/** 勾选行的有效 stock_id(去重去空;后端数组即 in 匹配,参考 inventory 导出选中写法) */
|
||||||
|
function collectSelectedStockIds(): number[] {
|
||||||
|
return Array.from(
|
||||||
|
new Set(
|
||||||
|
selectionRows.value
|
||||||
|
.map((row: any) => Number(row.stock_id))
|
||||||
|
.filter((id: number) => Number.isFinite(id) && id > 0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 导出选中请求体:在 buildReportQueryPayload 的 where 基础上叠加 stock_id in */
|
||||||
|
function buildSelectedExportPayload(): Record<string, unknown> {
|
||||||
|
const stockIds = collectSelectedStockIds()
|
||||||
|
const body = buildReportQueryPayload()
|
||||||
|
const where: Record<string, any> = body.where ? { ...body.where } : {}
|
||||||
|
where.stock_id = stockIds.length === 1 ? stockIds[0] : stockIds
|
||||||
|
return { ...body, where }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 仅出入库:不传 export_mode,后端「变更记录」sheet 排除 LOCK,仅含出入库/移库等变动 */
|
||||||
|
async function handleExportOnlyInOut() {
|
||||||
if (hasPendingExportTask()) {
|
if (hasPendingExportTask()) {
|
||||||
ElMessage.warning('检测到未完成导出任务,请等待当前任务完成后再试')
|
ElMessage.warning('检测到未完成导出任务,请等待当前任务完成后再试')
|
||||||
resumeExportTaskFromStorage()
|
resumeExportTaskFromStorage()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
await submitExportTaskWithMode(buildReportQueryPayload() as Record<string, unknown>, 'waybill')
|
await submitExportTask(buildReportQueryPayload() as Record<string, unknown>)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleExportItem() {
|
/** 全部:传 export_mode='item',后端「变更记录」sheet 含 LOCK(锁定/解锁)记录 */
|
||||||
|
async function handleExportWithLock() {
|
||||||
if (hasPendingExportTask()) {
|
if (hasPendingExportTask()) {
|
||||||
ElMessage.warning('检测到未完成导出任务,请等待当前任务完成后再试')
|
ElMessage.warning('检测到未完成导出任务,请等待当前任务完成后再试')
|
||||||
resumeExportTaskFromStorage()
|
resumeExportTaskFromStorage()
|
||||||
@ -350,12 +379,48 @@ async function handleExportItem() {
|
|||||||
await submitExportTaskWithMode(buildReportQueryPayload() as Record<string, unknown>, 'item')
|
await submitExportTaskWithMode(buildReportQueryPayload() as Record<string, unknown>, 'item')
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleExportAction(action: string) {
|
/** 导出选中·仅出入库(不传 export_mode) */
|
||||||
if (action === 'handleExportItem') {
|
async function handleExportSelectedOnlyInOut() {
|
||||||
void handleExportItem()
|
if (!collectSelectedStockIds().length) {
|
||||||
|
ElMessage.warning('请先在表格勾选要导出的记录')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
void handleExportWaybill()
|
if (hasPendingExportTask()) {
|
||||||
|
ElMessage.warning('检测到未完成导出任务,请等待当前任务完成后再试')
|
||||||
|
resumeExportTaskFromStorage()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
await submitExportTask(buildSelectedExportPayload())
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 导出选中·全部(含锁定记录,export_mode='item') */
|
||||||
|
async function handleExportSelectedWithLock() {
|
||||||
|
if (!collectSelectedStockIds().length) {
|
||||||
|
ElMessage.warning('请先在表格勾选要导出的记录')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (hasPendingExportTask()) {
|
||||||
|
ElMessage.warning('检测到未完成导出任务,请等待当前任务完成后再试')
|
||||||
|
resumeExportTaskFromStorage()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
await submitExportTaskWithMode(buildSelectedExportPayload(), 'item')
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleExportAction(action: string) {
|
||||||
|
if (action === 'handleExportWithLock') {
|
||||||
|
void handleExportWithLock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (action === 'handleExportSelectedOnlyInOut') {
|
||||||
|
void handleExportSelectedOnlyInOut()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (action === 'handleExportSelectedWithLock') {
|
||||||
|
void handleExportSelectedWithLock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
void handleExportOnlyInOut()
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadFilterData() {
|
async function loadFilterData() {
|
||||||
@ -397,27 +462,30 @@ async function loadData() {
|
|||||||
loading.value = true
|
loading.value = true
|
||||||
const started = Date.now()
|
const started = Date.now()
|
||||||
selectedRid.value = null
|
selectedRid.value = null
|
||||||
const body = buildReportQueryPayload()
|
|
||||||
try {
|
try {
|
||||||
const res: any = await searchStoreReport(
|
const res: any = await searchStoreReport(buildReportSearchPayload())
|
||||||
Object.keys(body).length > 0 ? body : undefined
|
const payload = res?.data && typeof res.data === 'object' ? res.data : res
|
||||||
)
|
const ok =
|
||||||
if (res && (res.flag === 'success' || res.code === 200)) {
|
res?.flag === 'success' ||
|
||||||
const raw = extractReportList(res)
|
res?.code === 200 ||
|
||||||
fullList.value = withRowIds(raw)
|
res?.code === 1 ||
|
||||||
|
(payload && Array.isArray(payload.list))
|
||||||
|
if (ok) {
|
||||||
|
const raw = Array.isArray(payload?.list) ? payload.list : []
|
||||||
|
list.value = withRowIds(raw)
|
||||||
columns.value = buildStoreReportColumns(raw)
|
columns.value = buildStoreReportColumns(raw)
|
||||||
pagination.currentPage = 1
|
const pg = parseReportPagination(res)
|
||||||
applyClientPage()
|
pagination.currentPage = pg.page
|
||||||
|
pagination.pageSize = pg.pageSize
|
||||||
|
pagination.total = pg.total
|
||||||
queryTime.value = Date.now() - started
|
queryTime.value = Date.now() - started
|
||||||
} else {
|
} else {
|
||||||
fullList.value = []
|
|
||||||
list.value = []
|
list.value = []
|
||||||
columns.value = buildStoreReportColumns([])
|
columns.value = buildStoreReportColumns([])
|
||||||
pagination.total = 0
|
pagination.total = 0
|
||||||
ElMessage.error(res?.message || '查询失败')
|
ElMessage.error(payload?.message || res?.message || '查询失败')
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
fullList.value = []
|
|
||||||
list.value = []
|
list.value = []
|
||||||
columns.value = buildStoreReportColumns([])
|
columns.value = buildStoreReportColumns([])
|
||||||
pagination.total = 0
|
pagination.total = 0
|
||||||
@ -436,13 +504,13 @@ function handleSortChange({ prop, order }: { prop: string; order: '' | 'ascendin
|
|||||||
|
|
||||||
function handlePageChange(page: number) {
|
function handlePageChange(page: number) {
|
||||||
pagination.currentPage = page
|
pagination.currentPage = page
|
||||||
applyClientPage()
|
loadData()
|
||||||
}
|
}
|
||||||
|
|
||||||
function handlePageSizeChange(size: number) {
|
function handlePageSizeChange(size: number) {
|
||||||
pagination.pageSize = size
|
pagination.pageSize = size
|
||||||
pagination.currentPage = 1
|
pagination.currentPage = 1
|
||||||
applyClientPage()
|
loadData()
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleRowClick(row: any) {
|
function handleRowClick(row: any) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user