From 06d49f83b968d64a8bd44320e457457a34d968b3 Mon Sep 17 00:00:00 2001 From: liufumingren Date: Sat, 4 Jul 2026 00:50:25 +0800 Subject: [PATCH] 1 --- src/api/stock/stock.ts | 18 +++++++- src/views/stock/stock/index.vue | 17 ++++++- src/views/storage/inventory/index.vue | 43 ++++++++++++------ .../storage/inventory/inventory-config.ts | 44 ------------------- 4 files changed, 61 insertions(+), 61 deletions(-) diff --git a/src/api/stock/stock.ts b/src/api/stock/stock.ts index 40541efb..320b74c0 100644 --- a/src/api/stock/stock.ts +++ b/src/api/stock/stock.ts @@ -2,7 +2,21 @@ import request from '@/utils/request' const v = "1.0"; -export function stockWarehouse(pagination: any, data: any) { +export type StockWarehouseListSort = { + sortField?: string + sortOrder?: 'asc' | 'desc' | 'ASC' | 'DESC' +} + +export type StockWarehouseListParams = { + pagination?: { + page?: number + pageSize?: number + } + where?: Record + sort?: StockWarehouseListSort +} + +export function stockWarehouse(pagination: any, data: any, sort?: StockWarehouseListSort) { return request({ url: '/system', method: 'post', @@ -11,7 +25,7 @@ export function stockWarehouse(pagination: any, data: any) { v, timestamp: new Date().getTime() }, - data: { pagination, where: data }, + data: { pagination, where: data, sort }, isSystemApi: true } as any) } diff --git a/src/views/stock/stock/index.vue b/src/views/stock/stock/index.vue index 0c5e9da8..aa2c983e 100644 --- a/src/views/stock/stock/index.vue +++ b/src/views/stock/stock/index.vue @@ -82,6 +82,7 @@ @current-change="handleRowClick" @page-change="handlePageChange" @page-size-change="handlePageSizeChange" + @sort-change="handleSortChange" @refresh="handleRefresh" @selection-change="selectionChange" > @@ -326,6 +327,8 @@ const pagination = reactive({ page: 1 }) +const currentSort = reactive({ prop: '', order: '' }) + const batchConfig = reactive(JSON.parse(JSON.stringify(stockBatchConfig))) const importDialogVisible = ref(false) @@ -514,7 +517,11 @@ const loadData = async () => { // 调试用:前端打印查看转换结果,确认 operator/value/type 是否符合预期 // console.log('Query Params:', JSON.stringify(params, null, 2)) - const res = await stockApi.stockWarehouse(pagination, params) + const sort = currentSort.prop + ? { sortField: currentSort.prop, sortOrder: currentSort.order === 'ascending' ? 'ASC' : 'DESC' } + : undefined + + const res = await stockApi.stockWarehouse(pagination, params, sort) if (res && res.data) { list.value = res.data.list if (res.data.pagination) { @@ -545,6 +552,14 @@ const handlePageSizeChange = (size: number) => { loadData() } +const handleSortChange = ({ prop, order }: any) => { + currentSort.prop = prop + currentSort.order = order + pagination.currentPage = 1 + pagination.page = 1 + loadData() +} + const handleRowClick = (row: any) => { if (row) { currentStockId.value = row.id diff --git a/src/views/storage/inventory/index.vue b/src/views/storage/inventory/index.vue index 47e6fdf8..16a60080 100644 --- a/src/views/storage/inventory/index.vue +++ b/src/views/storage/inventory/index.vue @@ -26,6 +26,14 @@ {{ detailVisible ? '隐藏详情' : '显示详情' }} + +
+ + + + + +
@@ -194,8 +202,6 @@ import { formatInventoryTypeLabel, inventoryExportColumns, isInventoryFlagEnabled, - normalizeScanConditionToInventoryWhere, - parseInventoryGroupByBatch, productstockColums, } from './inventory-config' import { exportUpperTableRows } from '@/views/order/orderManagement/utils/export' @@ -255,8 +261,7 @@ const queryTime = ref(0) const pagination = reactive({ currentPage: 1, pageSize: 20, total: 0 }) const tableSize = ref('small') -const currentConditionRaw = ref(null) -const groupByBatch = computed(() => parseInventoryGroupByBatch(currentConditionRaw.value)) +const groupByBatch = ref(false) const columns = computed(() => { const cols: any[] = JSON.parse(JSON.stringify(productstockColums)) if (groupByBatch.value) { @@ -340,9 +345,7 @@ async function loadData() { try { const params: any = { pagination: { page: pagination.currentPage, pageSize: pagination.pageSize }, - where: normalizeScanConditionToInventoryWhere( - currentConditionRaw.value ?? scanBox.value?.getConditions?.() ?? {} - ), + where: scanBox.value?.getConditions?.() || {}, group_by_batch: groupByBatch.value } @@ -433,23 +436,17 @@ async function loadFilterData() { } function handleConditionChange(condition: any) { - currentConditionRaw.value = condition pagination.currentPage = 1 - selectedEntryId.value = null loadData() } const handleConditionClear = () => { - currentConditionRaw.value = {} pagination.currentPage = 1 - selectedEntryId.value = null loadData() } function handleConditionReset() { - currentConditionRaw.value = {} pagination.currentPage = 1 - selectedEntryId.value = null if (scanBox.value?.reset) { scanBox.value.reset() } @@ -534,6 +531,12 @@ function handlePageSizeChange(size: number) { loadData() } +function handleGroupByBatchChange() { + pagination.currentPage = 1 + selectedEntryId.value = null + loadData() +} + function handleCreateEntry() { ElMessage.info('新建入库单') } @@ -578,7 +581,7 @@ async function handleExport(mode: 'waybill' | 'item' = 'waybill') { const params: any = { pagination: { page: 1, pageSize: 10000 }, - where: normalizeScanConditionToInventoryWhere(currentConditionRaw.value ?? scanBox.value?.getConditions?.() ?? {}), + where: scanBox.value?.getConditions?.() || {}, group_by_batch: true } const res: any = await inventoryApi.getInventoryList(params) @@ -697,6 +700,18 @@ function orderStatusTagType(val: string): any { @use "../../order/orderManagement/styles/order-sub.scss"; .order-sub-container .main-content { + .toolbar-right { + display: flex; + flex-direction: row; + gap: 8px; + align-items: center; + + .toolbar-label { + font-size: 12px; + color: #606266; + } + } + .expiry-date-expired { color: #f56c6c; font-weight: 600; diff --git a/src/views/storage/inventory/inventory-config.ts b/src/views/storage/inventory/inventory-config.ts index 53b4341b..840e585c 100644 --- a/src/views/storage/inventory/inventory-config.ts +++ b/src/views/storage/inventory/inventory-config.ts @@ -18,43 +18,6 @@ export function inventoryScanField( return { ...field, group: INVENTORY_SCAN_FIELD_GROUPS[group] } as InventoryScanFieldConfig } -function extractInventoryScanConds(condition: any): Record | null { - if (!condition || typeof condition !== 'object') return null - if (condition.conditions && typeof condition.conditions === 'object') { - return condition.conditions - } - return condition -} - -/** 从 ScanBox 条件解析 group_by_batch(默认 false = 合并模式) */ -export function parseInventoryGroupByBatch(condition: any): boolean { - const conds = extractInventoryScanConds(condition) - if (!conds || !Object.prototype.hasOwnProperty.call(conds, 'group_by_batch')) { - return false - } - const raw = conds.group_by_batch?.value ?? conds.group_by_batch - if (raw === true || raw === 'true' || raw === 1 || raw === '1') return true - return false -} - -/** 将 ScanBox 条件转为 list 接口 where(排除查询设置项 group_by_batch) */ -export function normalizeScanConditionToInventoryWhere(condition: any): Record { - const conds = extractInventoryScanConds(condition) - if (!conds) return {} - - const where: Record = {} - Object.keys(conds).forEach((key) => { - if (key === 'group_by_batch') return - const c = conds[key] - if (c && typeof c === 'object' && !Array.isArray(c) && 'value' in c) { - where[key] = c - } else { - where[key] = c - } - }) - return where -} - /** 为库存 ScanBox 基础信息字段附加分组标签 */ export type InventoryScanFieldConfig = Record & { group: string @@ -103,13 +66,6 @@ export const availableFields: InventoryScanFieldConfig[] = [ { label: '分配', value: 'FP' } ] }) as InventoryScanFieldConfig, - inventoryScanField('options', { - value: 'group_by_batch', - label: '按批次查询', - type: 'boolean', - defaultValue: false, - placeholder: '开启后按库存明细逐条返回;关闭则按库位+商品合并' - }) ] /** 库位展示名:优先 custom_name,其次 space_code */ export function formatInventorySpaceLabel(space?: Record | null, fallback = ''): string {