feat(收货商品): 查询系统商品改用 stock.warehouse.search 关键字检索+本地分页
This commit is contained in:
parent
5b0f1f9c00
commit
9b6be17119
@ -335,7 +335,7 @@
|
||||
]"
|
||||
@selection-change="handleSystemProductSelectionChange"
|
||||
@row-click="handleSystemProductRowClick"
|
||||
@page-change="querySystemProducts"
|
||||
@page-change="onSystemProductPageChange"
|
||||
@page-size-change="onSystemProductPageSizeChange"
|
||||
/>
|
||||
</div>
|
||||
@ -533,6 +533,12 @@ import * as receivingApi from '@/api/storage_receiving/receiving'
|
||||
import * as stockApi from '@/api/stock/stock'
|
||||
import * as indexApi from '@/api/index/index'
|
||||
import { getStatusTextClass } from '@/views/order/orderManagement/config/order-common-config'
|
||||
import {
|
||||
isStockApiSuccess,
|
||||
parseStockWarehouseSearch,
|
||||
mapStockPickerItem,
|
||||
getStockBarcodes
|
||||
} from '@/views/order/orderManagement/utils/stock-picker-helpers'
|
||||
import * as warehouseApi from '@/api/warehouse/warehouse'
|
||||
import { buildStockQuery } from '@/utils/stockQueryBuilder'
|
||||
import * as XLSX from 'xlsx'
|
||||
@ -956,6 +962,7 @@ const systemProductPickerVisible = ref(false)
|
||||
const systemProductLoading = ref(false)
|
||||
const systemProductKeyword = ref('')
|
||||
const systemProductResults = ref<any[]>([])
|
||||
const systemProductAllResults = ref<any[]>([])
|
||||
const systemProductSelection = ref<any[]>([])
|
||||
const systemProductPagination = reactive({ page: 1, pageSize: 10, total: 0 })
|
||||
|
||||
@ -1533,27 +1540,6 @@ const normalizeQuantityByTotalAndSpec = (itemPayload: any) => {
|
||||
itemPayload.box_remainder = safeTotal % safeSpec
|
||||
}
|
||||
|
||||
const buildSystemProductSearchParams = (keyword: string, storeId?: number) => {
|
||||
const params: Record<string, any> = {}
|
||||
|
||||
if (Number.isFinite(storeId) && (storeId as number) > 0) {
|
||||
params.store_id = { operator: 'eq', value: storeId }
|
||||
}
|
||||
|
||||
const text = String(keyword || '').trim()
|
||||
if (!text) return params
|
||||
|
||||
if (/^\d{6,}$/.test(text)) {
|
||||
params.barcode = { operator: 'contains', value: text, type: 'text' }
|
||||
} else if (/^\d+$/.test(text)) {
|
||||
params.id = { operator: 'eq', value: Number(text), type: 'number' }
|
||||
} else {
|
||||
params.item_name = { operator: 'contains', value: text, type: 'text' }
|
||||
}
|
||||
|
||||
return params
|
||||
}
|
||||
|
||||
const querySystemProductById = async (skuId: number) => {
|
||||
if (!Number.isFinite(skuId) || skuId <= 0) return null
|
||||
try {
|
||||
@ -2041,37 +2027,111 @@ const handleSystemProductRowClick = (row: any) => {
|
||||
systemProductSelection.value = [row]
|
||||
}
|
||||
|
||||
const onSystemProductPageSizeChange = (size: number) => {
|
||||
systemProductPagination.pageSize = size
|
||||
querySystemProducts(1)
|
||||
/** stock.warehouse.search 响应行归一化:暴露当前弹窗所需字段并保留原始行数据 */
|
||||
const normalizeSystemProductRow = (raw: any): any => {
|
||||
const mapped = mapStockPickerItem(raw)
|
||||
const itemId = Number(mapped?.item_id)
|
||||
if (!Number.isInteger(itemId) || itemId <= 0) return null
|
||||
|
||||
const storeNameCandidates = [
|
||||
raw?.store_stock?.store_remask,
|
||||
raw?.store_stock?.store_name,
|
||||
raw?.store_name,
|
||||
raw?.store_remask,
|
||||
mapped?.store_name,
|
||||
mapped?.store_remask,
|
||||
raw?.stock?.store_remask,
|
||||
raw?.goods?.store_remask
|
||||
]
|
||||
let storeName = ''
|
||||
for (const candidate of storeNameCandidates) {
|
||||
const text = String(candidate ?? '').trim()
|
||||
if (text && text.toLowerCase() !== 'null') {
|
||||
storeName = text
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
const weightRaw = raw?.weight ?? raw?.gross_weight
|
||||
const weight = weightRaw === '' || weightRaw === null || weightRaw === undefined
|
||||
? ''
|
||||
: Number(weightRaw)
|
||||
|
||||
return {
|
||||
...raw,
|
||||
...mapped,
|
||||
id: itemId,
|
||||
item_name: String(mapped?.item_name ?? '').trim() || String(raw?.product_name ?? '').trim(),
|
||||
barcodes: getStockBarcodes(raw),
|
||||
store_name: storeName,
|
||||
weight
|
||||
}
|
||||
}
|
||||
|
||||
/** 应用本地分页切片:warehouseSearch 一次返回全部匹配,由前端分页展示 */
|
||||
const applySystemProductPageSlice = () => {
|
||||
const { page, pageSize } = systemProductPagination
|
||||
const start = (page - 1) * pageSize
|
||||
const end = start + pageSize
|
||||
systemProductResults.value = systemProductAllResults.value.slice(start, end)
|
||||
}
|
||||
|
||||
const onSystemProductPageChange = (page: number) => {
|
||||
const maxPage = Math.max(1, Math.ceil(systemProductPagination.total / systemProductPagination.pageSize))
|
||||
systemProductPagination.page = Math.min(Math.max(1, page), maxPage)
|
||||
applySystemProductPageSlice()
|
||||
}
|
||||
|
||||
const onSystemProductPageSizeChange = (size: number) => {
|
||||
systemProductPagination.pageSize = size
|
||||
systemProductPagination.page = 1
|
||||
applySystemProductPageSlice()
|
||||
}
|
||||
|
||||
/** 查询系统商品:使用 stock.warehouse.search 关键字检索(store_id + keyword),一次取回全部匹配后本地分页 */
|
||||
const querySystemProducts = async (page = 1) => {
|
||||
systemProductLoading.value = true
|
||||
try {
|
||||
const paginationParam = { page, pageSize: systemProductPagination.pageSize }
|
||||
const where = buildStockQuery(
|
||||
buildSystemProductSearchParams(systemProductKeyword.value, boundStoreId.value)
|
||||
)
|
||||
const res: any = await stockApi.stockWarehouse(paginationParam, where)
|
||||
const keyword = String(systemProductKeyword.value ?? '').trim()
|
||||
const storeId = boundStoreId.value
|
||||
|
||||
if (res && (res.code === 200 || res.flag === 'success') && res.data) {
|
||||
systemProductResults.value = res.data.list || []
|
||||
systemProductPagination.total = res.data.pagination?.total || res.data.total || systemProductResults.value.length
|
||||
systemProductPagination.page = page
|
||||
} else {
|
||||
const requestData: { keyword?: string; store_id?: number } = {}
|
||||
if (keyword) {
|
||||
requestData.keyword = keyword
|
||||
}
|
||||
if (storeId != null && Number.isFinite(Number(storeId)) && Number(storeId) > 0) {
|
||||
requestData.store_id = Number(storeId)
|
||||
}
|
||||
|
||||
const res: any = await stockApi.warehouseSearch(requestData)
|
||||
if (!isStockApiSuccess(res)) {
|
||||
systemProductAllResults.value = []
|
||||
systemProductResults.value = []
|
||||
systemProductPagination.total = 0
|
||||
systemProductPagination.page = page
|
||||
systemProductPagination.page = 1
|
||||
if (res?.message) {
|
||||
ElMessage.error(res.message)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const { list } = parseStockWarehouseSearch(res)
|
||||
systemProductAllResults.value = (list || [])
|
||||
.map((row: any) => normalizeSystemProductRow(row))
|
||||
.filter((row: any): row is any => row != null)
|
||||
|
||||
systemProductPagination.total = systemProductAllResults.value.length
|
||||
const maxPage = Math.max(1, Math.ceil(systemProductPagination.total / systemProductPagination.pageSize))
|
||||
const safePage = Math.min(Math.max(1, page), maxPage)
|
||||
systemProductPagination.page = safePage
|
||||
applySystemProductPageSlice()
|
||||
} catch (error) {
|
||||
console.error('查询系统商品失败', error)
|
||||
ElMessage.error('查询系统商品失败')
|
||||
systemProductAllResults.value = []
|
||||
systemProductResults.value = []
|
||||
systemProductPagination.total = 0
|
||||
systemProductPagination.page = 1
|
||||
} finally {
|
||||
systemProductLoading.value = false
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user