fix(商品): 统一列表查询 where 为 operator/value/type 结构
外仓商品页(stock/external_stock):
- 筛选条件改用 buildStockQuery;原来把 ScanBox 的 {value,operator,type} 拍平成裸值,后端解析失败(搜索条件格式错误)
- 筛选字段对齐系统商品页:修复「货物编码」被标成条码、重复两个「条码」;库存数量改 number;Y/N 开关改 boolean;分组/操作符统一
- 筛选不再重置工具栏选择的仓库
其余页面统一:
- 收回/组合商品选择弹窗、商品回收站:where 统一改用 buildStockQuery
- 合计 5 处调用 stock.warehouse.list 的页面全部为嵌套规范
This commit is contained in:
parent
0b00014427
commit
2cdedda6f2
@ -72,6 +72,7 @@
|
||||
import { nextTick, onMounted, onUnmounted, ref, watch } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { warehouseSearch, stockWarehouse } from '@/api/stock/stock'
|
||||
import { buildStockQuery } from '@/utils/stockQueryBuilder'
|
||||
import {
|
||||
isStockApiSuccess,
|
||||
parseStockWarehouseSearch,
|
||||
@ -193,8 +194,8 @@ function formatRowLabel(item: StockPickerItem): string {
|
||||
async function loadInitialList() {
|
||||
loading.value = true
|
||||
try {
|
||||
const where: Record<string, unknown> = {}
|
||||
if (props.storeId) where.store_id = props.storeId
|
||||
// where 统一按 stock.warehouse.list 规范:{ 字段: { operator, value, type } }
|
||||
const where = buildStockQuery(props.storeId ? { store_id: props.storeId } : {})
|
||||
const res: any = await stockWarehouse({ page: 1, pageSize: PICKER_LIST_PAGE_SIZE }, where)
|
||||
if (!isStockApiSuccess(res)) {
|
||||
list.value = []
|
||||
|
||||
@ -60,6 +60,7 @@
|
||||
import { ref, watch } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { stockWarehouse, warehouseSearch } from '@/api/stock/stock'
|
||||
import { buildStockQuery } from '@/utils/stockQueryBuilder'
|
||||
import { isComboGoodsApiSuccess, parseStockWarehouseListResponse } from '../combo-stock-config'
|
||||
import {
|
||||
getStockItemCode,
|
||||
@ -135,10 +136,8 @@ function mapRows(rawList: unknown[]): ComboStockPickerItem[] {
|
||||
async function loadInitialList() {
|
||||
loading.value = true
|
||||
try {
|
||||
const where: Record<string, unknown> = {}
|
||||
if (props.storeId) {
|
||||
where.store_id = props.storeId
|
||||
}
|
||||
// where 统一按 stock.warehouse.list 规范:{ 字段: { operator, value, type } }
|
||||
const where = buildStockQuery(props.storeId ? { store_id: props.storeId } : {})
|
||||
const res: any = await stockWarehouse({ page: 1, pageSize: PICKER_LIST_PAGE_SIZE }, where)
|
||||
if (!isComboGoodsApiSuccess(res)) {
|
||||
list.value = []
|
||||
|
||||
@ -297,6 +297,8 @@ import type { ToolbarButtonConfig } from '@/views/order/orderManagement/config/o
|
||||
import { getStatusTextClass } from '@/views/order/orderManagement/config/order-common-config'
|
||||
import { useAsyncExportTask } from '@/composables/useAsyncExportTask'
|
||||
import { useVerticalSplitPane } from '@/composables/useVerticalSplitPane'
|
||||
import { buildStockQuery } from '@/utils/stockQueryBuilder'
|
||||
import { stockScanField } from '@/views/stock/stock/stock-config'
|
||||
|
||||
// ─── 列表列配置 ─────────────────────────────────────────────────────────────
|
||||
const columns = [
|
||||
@ -325,119 +327,113 @@ const columns = [
|
||||
{ prop: 'update_at_display', label: '更新时间', width: 160, sortable: true }
|
||||
]
|
||||
|
||||
// ─── 筛选字段配置 ─────────────────────────────────────────────────────────
|
||||
// ─── 筛选字段配置(字段结构与系统商品页 stock/stock 保持一致)────────────────
|
||||
const availableFields: any[] = [
|
||||
{
|
||||
label: '关键词',
|
||||
value: 'keyword',
|
||||
type: 'text',
|
||||
operators: ['like'],
|
||||
placeholder: '商品编码/名称/条码',
|
||||
group: '基础信息'
|
||||
},
|
||||
{
|
||||
label: '商品名称',
|
||||
value: 'item_name',
|
||||
type: 'text',
|
||||
group: '基础信息'
|
||||
},
|
||||
{
|
||||
label: '品牌',
|
||||
value: 'brand_name',
|
||||
type: 'text',
|
||||
group: '基础信息'
|
||||
},
|
||||
{
|
||||
label: '条码',
|
||||
value: 'goods_code',
|
||||
type: 'text',
|
||||
group: '基础信息'
|
||||
},
|
||||
{
|
||||
label: 'SKU',
|
||||
// ===== 商品标识 =====
|
||||
stockScanField('product', {
|
||||
value: 'id',
|
||||
label: 'SKU',
|
||||
type: 'text',
|
||||
group: '基础信息'
|
||||
},
|
||||
{
|
||||
label: '条码',
|
||||
placeholder: '请输入SKU',
|
||||
operators: ['eq', 'contains'],
|
||||
defaultOperator: 'eq'
|
||||
}),
|
||||
stockScanField('product', {
|
||||
value: 'item_code',
|
||||
label: '商品编码',
|
||||
type: 'text',
|
||||
placeholder: '请输入商品编码',
|
||||
operators: ['eq', 'ne', 'contains', 'startswith', 'endswith'],
|
||||
defaultOperator: 'eq'
|
||||
}),
|
||||
stockScanField('product', {
|
||||
value: 'goods_code',
|
||||
label: '货物编码',
|
||||
type: 'text',
|
||||
placeholder: '请输入货物编码',
|
||||
operators: ['eq', 'ne', 'contains'],
|
||||
defaultOperator: 'eq'
|
||||
}),
|
||||
|
||||
// ===== 商品信息 =====
|
||||
stockScanField('info', {
|
||||
value: 'item_name',
|
||||
label: '商品名称',
|
||||
type: 'text',
|
||||
placeholder: '请输入商品名称',
|
||||
operators: ['eq', 'ne', 'contains'],
|
||||
defaultOperator: 'eq'
|
||||
}),
|
||||
stockScanField('info', {
|
||||
value: 'barcode',
|
||||
label: '条码',
|
||||
type: 'text',
|
||||
group: '基础信息'
|
||||
},
|
||||
{
|
||||
label: '库存数量',
|
||||
value: 'quantity',
|
||||
placeholder: '请输入商品条码',
|
||||
operators: ['eq', 'contains'],
|
||||
defaultOperator: 'eq'
|
||||
}),
|
||||
stockScanField('info', {
|
||||
value: 'brand_name',
|
||||
label: '品牌',
|
||||
type: 'text',
|
||||
group: '基础信息'
|
||||
},
|
||||
{
|
||||
label: '外部商品绑定',
|
||||
value: 'has_bound_item',
|
||||
type: 'select',
|
||||
group: '流程状态',
|
||||
options: [
|
||||
{ label: '全部', value: undefined },
|
||||
{ label: '是', value: 'Y' },
|
||||
{ label: '否', value: 'N' }
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'ABC分类',
|
||||
value: 'level',
|
||||
type: 'select',
|
||||
group: '流程状态',
|
||||
options: [
|
||||
{ label: '全部', value: undefined },
|
||||
{ label: 'A', value: 'A' },
|
||||
{ label: 'B', value: 'B' },
|
||||
{ label: 'C', value: 'C' }
|
||||
]
|
||||
},
|
||||
{
|
||||
label: '是否图片',
|
||||
placeholder: '请输入品牌',
|
||||
operators: ['eq', 'ne', 'contains', 'startswith', 'endswith'],
|
||||
defaultOperator: 'eq'
|
||||
}),
|
||||
|
||||
// ===== 商品属性 =====
|
||||
stockScanField('attribute', {
|
||||
value: 'is_images',
|
||||
label: '是否有图片',
|
||||
type: 'boolean'
|
||||
}),
|
||||
stockScanField('attribute', {
|
||||
value: 'has_bound_item',
|
||||
label: '外部商品绑定',
|
||||
type: 'boolean',
|
||||
placeholder: '请选择是否已绑定外部商品'
|
||||
}),
|
||||
stockScanField('attribute', {
|
||||
value: 'level',
|
||||
label: 'ABC分类',
|
||||
type: 'select',
|
||||
group: '流程状态',
|
||||
placeholder: '请选择分类',
|
||||
options: [
|
||||
{ label: '全部', value: undefined },
|
||||
{ label: '是', value: 'Y' },
|
||||
{ label: '否', value: 'N' }
|
||||
{ value: 'A', label: 'A类' },
|
||||
{ value: 'B', label: 'B类' },
|
||||
{ value: 'C', label: 'C类' }
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'SN管理',
|
||||
}),
|
||||
|
||||
// ===== 库存信息 =====
|
||||
stockScanField('inventory', {
|
||||
value: 'quantity',
|
||||
label: '库存数量',
|
||||
type: 'number',
|
||||
placeholder: '请输入库存数量',
|
||||
operators: ['eq', 'ne', 'gt', 'lt', 'ge', 'le', 'between'],
|
||||
defaultOperator: 'ge'
|
||||
}),
|
||||
|
||||
// ===== 管理标识 =====
|
||||
stockScanField('management', {
|
||||
value: 'is_sn_mgmt',
|
||||
type: 'select',
|
||||
group: '流程状态',
|
||||
options: [
|
||||
{ label: '全部', value: undefined },
|
||||
{ label: '是', value: 'Y' },
|
||||
{ label: '否', value: 'N' }
|
||||
]
|
||||
},
|
||||
{
|
||||
label: '保质期管理',
|
||||
label: '序列号管理',
|
||||
type: 'boolean',
|
||||
placeholder: '请选择是否序列号管理'
|
||||
}),
|
||||
stockScanField('management', {
|
||||
value: 'is_shelf_life_mgmt',
|
||||
type: 'select',
|
||||
group: '流程状态',
|
||||
options: [
|
||||
{ label: '全部', value: undefined },
|
||||
{ label: '是', value: 'Y' },
|
||||
{ label: '否', value: 'N' }
|
||||
]
|
||||
},
|
||||
{
|
||||
label: '批次管理',
|
||||
label: '保质期管理',
|
||||
type: 'boolean',
|
||||
placeholder: '请选择是否保质期管理'
|
||||
}),
|
||||
stockScanField('management', {
|
||||
value: 'is_batch_mgmt',
|
||||
type: 'select',
|
||||
group: '流程状态',
|
||||
options: [
|
||||
{ label: '全部', value: undefined },
|
||||
{ label: '是', value: 'Y' },
|
||||
{ label: '否', value: 'N' }
|
||||
]
|
||||
}
|
||||
label: '批次管理',
|
||||
type: 'boolean',
|
||||
placeholder: '请选择是否批次管理'
|
||||
})
|
||||
]
|
||||
|
||||
const presetTree: any[] = []
|
||||
@ -451,7 +447,7 @@ const scanBox = ref<any>(null)
|
||||
const activeTab = ref('info')
|
||||
|
||||
const pagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
|
||||
const queryForm = reactive({ keyword: '', warehouse_id: undefined as number | string | undefined })
|
||||
const queryForm = reactive({ warehouse_id: undefined as number | string | undefined })
|
||||
const currentCondition = ref<any>({})
|
||||
const currentSort = reactive({ prop: '', order: '' })
|
||||
const summary = ref<any>(null)
|
||||
@ -480,10 +476,7 @@ const {
|
||||
|
||||
function buildExportPayload() {
|
||||
const payload: any = {
|
||||
where: { ...currentCondition.value }
|
||||
}
|
||||
if (queryForm.keyword) {
|
||||
payload.where.keyword = queryForm.keyword
|
||||
where: buildStockQuery(currentCondition.value)
|
||||
}
|
||||
if (queryForm.warehouse_id !== undefined && queryForm.warehouse_id !== null && queryForm.warehouse_id !== '') {
|
||||
payload.warehouse_id = queryForm.warehouse_id
|
||||
@ -624,9 +617,6 @@ function handleToolbarButtonClick(action: ToolbarButtonConfig['action']) {
|
||||
handler()
|
||||
}
|
||||
|
||||
// ─── 特殊字段键(不作为 where 条件,需要单独提取)──────────────────────
|
||||
const SPECIAL_KEYS = ['keyword', 'warehouse_id']
|
||||
|
||||
// ─── 加载列表 ──────────────────────────────────────────────────────────────
|
||||
async function loadList() {
|
||||
loading.value = true
|
||||
@ -636,10 +626,7 @@ async function loadList() {
|
||||
page: pagination.currentPage,
|
||||
pageSize: pagination.pageSize
|
||||
},
|
||||
where: { ...currentCondition.value }
|
||||
}
|
||||
if (queryForm.keyword) {
|
||||
params.where.keyword = queryForm.keyword
|
||||
where: buildStockQuery(currentCondition.value)
|
||||
}
|
||||
|
||||
const sort: StockWarehouseListSort | undefined = currentSort.prop
|
||||
@ -672,41 +659,14 @@ async function loadList() {
|
||||
|
||||
// ─── 事件处理 ──────────────────────────────────────────────────────────────
|
||||
function handleConditionChange(condition: any) {
|
||||
const where: any = {}
|
||||
// 重置特殊字段
|
||||
queryForm.keyword = ''
|
||||
queryForm.warehouse_id = undefined
|
||||
|
||||
if (condition) {
|
||||
Object.keys(condition).forEach(k => {
|
||||
if (SPECIAL_KEYS.includes(k)) {
|
||||
// 关键词、仓库 从 condition 提取到 queryForm
|
||||
const c = condition[k]
|
||||
const val = (c && typeof c === 'object' && c.value !== undefined) ? c.value : c
|
||||
if (k === 'keyword' && val) {
|
||||
queryForm.keyword = val
|
||||
} else if (k === 'warehouse_id' && val !== undefined && val !== null && val !== '') {
|
||||
queryForm.warehouse_id = val
|
||||
}
|
||||
return
|
||||
}
|
||||
const c = condition[k]
|
||||
if (c && typeof c === 'object' && c.value !== undefined) {
|
||||
if (c.value !== '' && c.value !== null) {
|
||||
where[k] = c.value
|
||||
}
|
||||
} else if (c !== '' && c !== null && c !== undefined) {
|
||||
where[k] = c
|
||||
}
|
||||
})
|
||||
}
|
||||
currentCondition.value = where
|
||||
// ScanBox 直接下发 { field: { value, operator, type } } 结构,
|
||||
// 原样保留,交由 buildStockQuery 转为后端 where 规范,避免丢失操作符/类型
|
||||
currentCondition.value = condition && typeof condition === 'object' ? condition : {}
|
||||
pagination.currentPage = 1
|
||||
loadList()
|
||||
}
|
||||
|
||||
function handleReset() {
|
||||
queryForm.keyword = ''
|
||||
currentCondition.value = {}
|
||||
if (scanBox.value?.reset) {
|
||||
scanBox.value.reset()
|
||||
|
||||
@ -111,6 +111,7 @@ import { ref, reactive, onMounted, watch } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { Search, Delete, RefreshLeft, Refresh } from '@element-plus/icons-vue'
|
||||
import * as stockApi from '@/api/stock/stock'
|
||||
import { buildStockQuery } from '@/utils/stockQueryBuilder'
|
||||
import { parseTime } from '@/utils/index'
|
||||
import { formatBarcodeText } from '@/utils/barcode'
|
||||
|
||||
@ -217,11 +218,12 @@ const loadData = async () => {
|
||||
if (loading.value) return
|
||||
loading.value = true
|
||||
try {
|
||||
const params: any = {
|
||||
// where 统一按 stock.warehouse.list 规范:{ 字段: { operator, value, type } }
|
||||
const params: any = buildStockQuery({
|
||||
is_deleted: 1, // Assuming backend supports this flag for recycle bin
|
||||
keyword: searchKeyword.value,
|
||||
type: filterType.value
|
||||
}
|
||||
})
|
||||
const response = await stockApi.stockWarehouse(pagination, params)
|
||||
if (response && (response as any).code === 200) {
|
||||
list.value = (response as any).data.list || []
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user