This commit is contained in:
liufumingren 2026-07-04 00:50:25 +08:00
parent 806f53d1d6
commit 06d49f83b9
4 changed files with 61 additions and 61 deletions

View File

@ -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<string, any>
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)
}

View File

@ -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

View File

@ -26,6 +26,14 @@
<el-button size="small" @click="toggleDetailVisible">{{ detailVisible ? '隐藏详情' : '显示详情' }}</el-button>
<!-- <el-button>是否按批次显示</el-button> -->
</div>
<div class="toolbar-right">
<span class="toolbar-label"></span>
<el-select v-model="groupByBatch" size="small" style="width:120px" @change="handleGroupByBatchChange">
<el-option label="汇总查询" :value="false" />
<el-option label="批次查询" :value="true" />
</el-select>
</div>
</div>
<div class="split-stack" ref="splitStackRef">
@ -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<any>(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;

View File

@ -18,43 +18,6 @@ export function inventoryScanField<G extends InventoryScanFieldGroupKey>(
return { ...field, group: INVENTORY_SCAN_FIELD_GROUPS[group] } as InventoryScanFieldConfig
}
function extractInventoryScanConds(condition: any): Record<string, any> | 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<string, any> {
const conds = extractInventoryScanConds(condition)
if (!conds) return {}
const where: Record<string, any> = {}
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<string, any> & {
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<string, any> | null, fallback = ''): string {