diff --git a/src/views/express/waybill/config/template-config.ts b/src/views/express/waybill/config/template-config.ts index 70fcc492..47e955f4 100644 --- a/src/views/express/waybill/config/template-config.ts +++ b/src/views/express/waybill/config/template-config.ts @@ -66,6 +66,9 @@ export interface FieldDefinition { options?: { label: string; value: any }[] multiple?: boolean filterable?: boolean + operators?: string[] + defaultOperator?: string + hideOperator?: boolean } | null table: { minWidth?: number @@ -192,8 +195,8 @@ export const FIELD_DICT: Record = { waybill_code: { key: 'waybill_code', label: '运单号', - // 传参口径(对齐 waybill.warehouse.list 文档):单值字符串 = 模糊 LIKE;多值(ScanBox 的「包含/IN」切数组)= **精确 Op.in** - scanBox: { type: 'text', group: SCANBOX_GROUPS.basic }, + // 接口按单值 LIKE、多值 IN 处理,不支持其它 ScanBox 文本操作符。 + scanBox: { type: 'text', group: SCANBOX_GROUPS.basic, operators: ['like', 'in'], defaultOperator: 'like' }, table: { minWidth: 170, fixed: 'left', copyAction: 'copy', showOverflowTooltip: true }, slot: null, detailLabel: '运单号' @@ -203,7 +206,7 @@ export const FIELD_DICT: Record = { label: '主单号', // 传参口径(2026-10-07 文档):单值/多值均为**精确匹配**,先定位 order_id 再返回该订单下全部(主+子)运单; // 与运单号同时传入时**按 AND 叠加**(旧「主单号优先」口径已废弃) - scanBox: { type: 'text', group: SCANBOX_GROUPS.basic }, + scanBox: { type: 'text', group: SCANBOX_GROUPS.basic, operators: ['eq', 'in'], defaultOperator: 'eq' }, table: { minWidth: 170, copyAction: 'copy', showOverflowTooltip: true }, slot: null, detailLabel: '主单号' @@ -211,16 +214,17 @@ export const FIELD_DICT: Record = { waybill_type: { key: 'waybill_type', label: '运单类型', - scanBox: { type: 'select', group: SCANBOX_GROUPS.basic, options: getOptions('waybillType') }, + scanBox: { type: 'select', group: SCANBOX_GROUPS.basic, options: getOptions('waybillType'), hideOperator: true }, table: { minWidth: 90, align: 'center' }, slot: { type: 'tag', tagResolver: 'resolveWaybillTypeTag', translateField: 'waybillType' }, - detailLabel: '运单类型' + detailLabel: '运单类型', + filterParamMap: { 主单号: '1', 子单号: '2' } }, order_no: { key: 'order_no', label: '发货单号', - // ⚠️ waybill.warehouse.list 文档:orderNo 模糊搜索「暂不可用,待快照字段就绪」→ 当前传了也不会生效,保留筛选项等后端就绪 - scanBox: { type: 'text', group: SCANBOX_GROUPS.basic }, + // waybill.warehouse.list 的 orderNo 暂不可用,故不提供无效筛选项。 + scanBox: null, table: { minWidth: 160, copyAction: 'copy', showOverflowTooltip: true }, slot: null, detailLabel: '订单号' @@ -228,7 +232,7 @@ export const FIELD_DICT: Record = { order_id: { key: 'order_id', label: '订单ID', - scanBox: { type: 'text', group: SCANBOX_GROUPS.basic }, + scanBox: { type: 'number', group: SCANBOX_GROUPS.basic, operators: ['eq'], defaultOperator: 'eq' }, table: { minWidth: 90, align: 'center', copyAction: 'copy' }, slot: null, detailLabel: '订单ID' @@ -236,7 +240,7 @@ export const FIELD_DICT: Record = { source_order_codes: { key: 'source_order_codes', label: '平台交易单号', - scanBox: { type: 'text', group: SCANBOX_GROUPS.basic }, + scanBox: null, table: { minWidth: 160, copyAction: 'copy', showOverflowTooltip: true }, slot: null, detailLabel: '平台交易单号' @@ -244,7 +248,8 @@ export const FIELD_DICT: Record = { keyword: { key: 'keyword', label: '关键词', - scanBox: { type: 'text', group: SCANBOX_GROUPS.basic }, + // 服务端目前仅按运单号搜索,且会覆盖 waybillCode;避免提供误导性筛选。 + scanBox: null, table: null, slot: null }, @@ -267,7 +272,7 @@ export const FIELD_DICT: Record = { store_name: { key: 'store_name', label: '货主', - scanBox: { type: 'select', group: SCANBOX_GROUPS.basic, options: [], multiple: true, filterable: true }, + scanBox: { type: 'select', group: SCANBOX_GROUPS.basic, options: [], filterable: true, hideOperator: true }, table: { minWidth: 120, showOverflowTooltip: true }, slot: null, detailLabel: '货主名称' @@ -321,14 +326,14 @@ export const FIELD_DICT: Record = { detailLabel: '打包人' }, // —— 物流信息 —— - // logistics_code: { - // key: 'logistics_code', - // label: '物流编码', - // scanBox: { type: 'select', group: SCANBOX_GROUPS.logistics, options: [] }, - // table: { minWidth: 100, align: 'center' }, - // slot: null, - // detailLabel: '物流公司编码' - // }, + logistics_code: { + key: 'logistics_code', + label: '物流公司', + scanBox: { type: 'select', group: SCANBOX_GROUPS.logistics, options: [], hideOperator: true }, + table: { minWidth: 100, align: 'center' }, + slot: null, + detailLabel: '物流公司编码' + }, logistics_name: { key: 'logistics_name', label: '物流公司', @@ -340,7 +345,7 @@ export const FIELD_DICT: Record = { logistics_interface_id: { key: 'logistics_interface_id', label: '物流接口ID', - scanBox: { type: 'text', group: SCANBOX_GROUPS.logistics }, + scanBox: { type: 'number', group: SCANBOX_GROUPS.logistics, operators: ['eq'], defaultOperator: 'eq' }, table: { minWidth: 110, align: 'center' }, slot: null, detailLabel: '物流接口ID' @@ -353,19 +358,19 @@ export const FIELD_DICT: Record = { slot: null, detailLabel: '物流接口' }, - // platform_code: { - // key: 'platform_code', - // label: '平台', - // scanBox: { type: 'select', group: SCANBOX_GROUPS.logistics, options: [] }, - // table: { minWidth: 90, align: 'center' }, - // slot: null, - // detailLabel: '平台编码' - // }, + platform_code: { + key: 'platform_code', + label: '平台', + scanBox: { type: 'select', group: SCANBOX_GROUPS.logistics, options: [], hideOperator: true }, + table: { minWidth: 90, align: 'center' }, + slot: null, + detailLabel: '平台编码' + }, // —— 包裹信息 —— package_material_id: { key: 'package_material_id', label: '包材ID', - scanBox: { type: 'text', group: SCANBOX_GROUPS.basic }, + scanBox: { type: 'number', group: SCANBOX_GROUPS.basic, operators: ['eq'], defaultOperator: 'eq' }, table: { minWidth: 90, align: 'center' }, slot: null, detailLabel: '包材ID' @@ -390,7 +395,7 @@ export const FIELD_DICT: Record = { status: { key: 'status', label: '运单状态', - scanBox: { type: 'select', group: SCANBOX_GROUPS.status, options: getOptions('waybillStatus') }, + scanBox: { type: 'select', group: SCANBOX_GROUPS.status, options: getOptions('waybillStatus'), hideOperator: true }, table: { minWidth: 100, align: 'center' }, slot: { type: 'tag', tagResolver: 'resolveWaybillStatusTag', translateField: 'waybillStatus' }, detailLabel: '运单状态', @@ -407,26 +412,29 @@ export const FIELD_DICT: Record = { is_back: { key: 'is_back', label: '是否退回', - scanBox: { type: 'select', group: SCANBOX_GROUPS.status, options: getOptions('yesNo') }, + scanBox: { type: 'select', group: SCANBOX_GROUPS.status, options: getOptions('yesNo'), hideOperator: true }, table: { minWidth: 100, align: 'center' }, slot: { type: 'tag', tagResolver: 'resolveYesNoTag', translateField: 'yesNo' }, - detailLabel: '是否退回' + detailLabel: '是否退回', + filterParamMap: { 是: 'Y', 否: 'N' } }, is_intercept: { key: 'is_intercept', label: '是否拦截', - scanBox: { type: 'select', group: SCANBOX_GROUPS.status, options: getOptions('yesNo') }, + scanBox: { type: 'select', group: SCANBOX_GROUPS.status, options: getOptions('yesNo'), hideOperator: true }, table: { minWidth: 100, align: 'center' }, slot: { type: 'tag', tagResolver: 'resolveYesNoTag', translateField: 'yesNo' }, - detailLabel: '是否拦截' + detailLabel: '是否拦截', + filterParamMap: { 是: 'Y', 否: 'N' } }, is_galaxy_receive: { key: 'is_galaxy_receive', - label: '揽收', - scanBox: { type: 'select', group: SCANBOX_GROUPS.status, options: getOptions('yesNo') }, + label: '是否星河签收', + scanBox: { type: 'select', group: SCANBOX_GROUPS.status, options: getOptions('yesNo'), hideOperator: true }, table: { minWidth: 100, align: 'center' }, slot: { type: 'tag', tagResolver: 'resolveYesNoTag', translateField: 'yesNo' }, - detailLabel: '是否揽收' + detailLabel: '是否星河签收', + filterParamMap: { 是: 'Y', 否: 'N' } }, // —— 重量与打印 —— weighing_weight: { @@ -448,9 +456,10 @@ export const FIELD_DICT: Record = { hasWeighingWeight: { key: 'hasWeighingWeight', label: '是否已称重', - scanBox: { type: 'select', group: SCANBOX_GROUPS.status, options: getOptions('bool') }, + scanBox: { type: 'select', group: SCANBOX_GROUPS.status, options: getOptions('bool'), hideOperator: true }, table: null, - slot: null + slot: null, + filterParamMap: { 是: 'true', 否: 'false' } }, print_count: { key: 'print_count', @@ -630,6 +639,9 @@ export function resolveTabConfig(raw: TabPageRawConfig): TabPageConfig { group: def.scanBox.group, multiple: def.scanBox.multiple, filterable: def.scanBox.filterable, + operators: def.scanBox.operators, + defaultOperator: def.scanBox.defaultOperator, + hideOperator: def.scanBox.hideOperator, required: (def.scanBox as any).required }) } @@ -777,19 +789,18 @@ export function buildWhereConditions(rawConditions: Record): Record // 字段名映射(snake_case → camelCase) const apiKey = WHERE_FIELD_MAP[key] || key - // 类型转换(对齐 API 参数类型:number / boolean) - value = coerceValue(value, apiKey) - // filterParamMap 值映射(仅单值) const def = FIELD_DICT[key] if (def?.filterParamMap && !Array.isArray(value)) { const mapped = def.filterParamMap[String(value)] if (mapped !== undefined) { - where[apiKey] = mapped - continue + value = mapped } } + // 类型转换(映射后再转换,避免中文标签被转成 NaN) + value = coerceValue(value, apiKey) + // 扁平传值(string / number / boolean / array) where[apiKey] = value } @@ -886,9 +897,7 @@ export const tabPages: TabPageRawConfig[] = [ scanBoxFieldKeys: [ 'waybill_code', 'main_waybill_code', - 'keyword', 'waybill_type', - 'order_no', 'order_id', 'store_name', 'logistics_code', diff --git a/src/views/express/waybill/index.vue b/src/views/express/waybill/index.vue index 90bf0c78..e352cd25 100644 --- a/src/views/express/waybill/index.vue +++ b/src/views/express/waybill/index.vue @@ -273,6 +273,11 @@ import AsyncExportProgressDialog from '@/components/AsyncExportProgressDialog.vu import OrderToolbarButtonGroup from '@/components/ToolbarButtonGroup/index.vue' import { waybillWarehouseDetail } from '@/api/waybill.warehouse' import { useAsyncExportTask } from '@/composables/useAsyncExportTask' +import { + extractStoreListFromResponse, + mapExpressListToCompanySelectOptions, + mapStoreListToSelectOptions +} from '@/utils/storeScanOptions' import type { ToolbarButtonConfig as OrderToolbarButtonConfig } from '@/components/ToolbarButtonGroup/types' import { PAGE_CONFIG, @@ -327,7 +332,7 @@ function syncScanBoxFields() { } /** 注入 ScanBox 下拉选项 */ -function injectScanBoxOptions(fieldValue: string, options: { label: string; value: string }[]) { +function injectScanBoxOptions(fieldValue: string, options: { label: string; value: string | number }[]) { const field = dynamicScanBoxFields.value.find((f: any) => f.value === fieldValue) if (field) { field.options = options @@ -342,30 +347,31 @@ async function loadScanBoxOptions() { getPlatformList({ systemOnly: true }), loadStores() ]) - const expressRaw: any[] = expressRes?.data?.list ?? expressRes?.data ?? [] - const platformRaw: any[] = platformRes?.data?.list ?? platformRes?.data ?? [] - const storesRaw: any[] = (storesRes as any)?.data?.stores ?? (storesRes as any)?.stores ?? [] + const expressPayload = expressRes?.data ?? expressRes + const expressRaw: any[] = Array.isArray(expressPayload) + ? expressPayload + : expressPayload?.list ?? expressPayload?.items ?? expressPayload?.records ?? [] + const platformPayload = platformRes?.data ?? platformRes + const platformRaw: any[] = Array.isArray(platformPayload) + ? platformPayload + : platformPayload?.list ?? platformPayload?.items ?? platformPayload?.records ?? [] + const storesRaw = extractStoreListFromResponse(storesRes) - const expressOptions = expressRaw.map((item: any) => ({ - label: `${item.code ?? item.logistics_code ?? ''} — ${item.name ?? item.logistics_name ?? ''}`, - value: String(item.code ?? item.logistics_code ?? '') - })).filter((opt: any) => opt.value) + const expressOptions = mapExpressListToCompanySelectOptions(expressRaw) const platformOptions = platformRaw.map((item: any) => ({ label: `${item.code ?? item.platform_code ?? ''} — ${item.name ?? item.platform_name ?? ''}`, value: String(item.code ?? item.platform_code ?? '') })).filter((opt: any) => opt.value) - const storeOptions = storesRaw.map((item: any) => ({ - label: item.label ?? item.name ?? item.store_name ?? '', - value: item.value ?? item.id ?? item.store_id - })).filter((opt: any) => opt.value != null && opt.value !== '') + const storeOptions = mapStoreListToSelectOptions(storesRaw) injectScanBoxOptions('logistics_code', expressOptions) injectScanBoxOptions('platform_code', platformOptions) injectScanBoxOptions('store_name', storeOptions) - } catch { - // 选项加载失败时使用空数组 + } catch (error) { + console.error('[WaybillWarehouse] 加载筛选选项失败:', error) + ElMessage.error('加载筛选选项失败,请刷新页面重试') } }