feat(shop-product): 店铺商品支持店铺/平台类型/商家编码多值筛选

- 列表接口支持 shop_ids / platform_types / outer_codes(逗号分隔或数组,去重、上限 200),店铺与平台类型为 IN 条件,商家编码为多值精确匹配;保留单值 shop_id 与关键词模糊查询

- 前端:店铺改为多选虚拟下拉、新增平台类型多选、新增商家编码多值控件(收起英文逗号拼接、展开一行一个)

- 导出同步支持多值筛选(多选控件按 CSV 提交)并补上「平台类型」列

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
liufumingren 2026-11-06 22:22:41 +08:00
parent 262d9d4203
commit fe97be2893
6 changed files with 297 additions and 15 deletions

View File

@ -10,6 +10,26 @@ const EDITABLE_ORDER_STATUSES = [ ORDER_STATUS.PENDING, ORDER_STATUS.EXCEPTION ]
/** 批量绑定的单次上限(避免一次请求里重建过多订单明细) */
const BATCH_BIND_LIMIT = 500;
/** 多值筛选参数的单次上限(防止超长 IN 拖垮查询) */
const MAX_FILTER_VALUES = 200;
/**
* 解析多值筛选参数:支持数组(a=1&a=2)与逗号分隔字符串(a=1,2),去空去重
* @param {*} value 原始参数
* @param {number} [max] 最多保留的值个数
* @return {Array<string>} 值列表
*/
function parseListParam(value, max = MAX_FILTER_VALUES) {
const raw = Array.isArray(value) ? value : String(value == null ? '' : value).split(',');
const list = [];
for (const item of raw) {
const text = String(item == null ? '' : item).trim();
if (text && !list.includes(text)) list.push(text);
if (list.length >= max) break;
}
return list;
}
/**
* @controller ShopProductController 店铺商品管理
* 采集自各平台店铺的商品,可单向绑定系统商品(products)或组合商品(combo_products)
@ -17,14 +37,18 @@ const BATCH_BIND_LIMIT = 500;
class ShopProductController extends Controller {
/**
* @summary 店铺商品列表
* @description 分页查询店铺商品,支持按店铺、绑定状态、关键词(标题/商家编码/平台商品ID)过滤;
* @description 分页查询店铺商品,支持按店铺(多选)、平台类型(多选)、商家编码(多个精确匹配)、
* 绑定状态、关键词(标题/商家编码/平台商品ID)过滤;
* has_unbound_order=1 时只返回「有订单但未绑定系统商品」的店铺商品
* @router get /api/shop-products
* @apikey
* @request query integer page 页码,默认 1
* @request query integer pageSize 每页条数,默认 20
* @request query integer principal_id 所属主体ID(必填,需当前账号已绑定该主体)
* @request query integer shop_id 店铺ID,不传则不过滤
* @request query string shop_ids 店铺ID,多个用英文逗号分隔(如 12,18)
* @request query integer shop_id 店铺ID(单值,兼容旧调用)
* @request query string platform_types 平台类型编码(PDD/DYXD/SPH…),多个用英文逗号分隔
* @request query string outer_codes 商家编码,多个用英文逗号分隔(精确匹配)
* @request query integer bind_type 绑定类型:0未绑定 1系统商品 2组合商品
* @request query integer status 状态:1在售 0下架
* @request query string keyword 关键词,匹配标题、商家编码或平台商品ID
@ -35,12 +59,31 @@ class ShopProductController extends Controller {
const { ctx } = this;
const Op = this.app.Sequelize.Op;
const { page, pageSize, offset, limit } = parsePagination(ctx.query);
const { shop_id: shopId, bind_type: bindType, status, keyword, has_unbound_order: hasUnboundOrder } = ctx.query;
const {
shop_id: shopId,
shop_ids: shopIds,
platform_types: platformTypes,
outer_codes: outerCodes,
bind_type: bindType,
status,
keyword,
has_unbound_order: hasUnboundOrder,
} = ctx.query;
const principalId = Number(ctx.state.principalId);
const where = {};
where.principal_id = principalId;
if (shopId) where.shop_id = Number(shopId);
const shopIdList = parseListParam(shopIds)
.map(Number)
.filter(id => Number.isInteger(id) && id > 0);
if (shopIdList.length) where.shop_id = { [Op.in]: shopIdList };
else if (shopId) where.shop_id = Number(shopId);
// 平台类型按系统预设编码筛选(PDD / DYXD / SPH…)
const platformTypeList = parseListParam(platformTypes);
if (platformTypeList.length) where.platform_type = { [Op.in]: platformTypeList };
// 商家编码支持多个精确匹配(与关键词的模糊匹配区分开)
const outerCodeList = parseListParam(outerCodes).map(code => code.slice(0, 100));
if (outerCodeList.length) where.outer_code = { [Op.in]: outerCodeList };
if (bindType !== undefined && bindType !== '') where.bind_type = Number(bindType);
if (status !== undefined && status !== '') where.status = Number(status);

View File

@ -20,6 +20,7 @@ const {
const { BILL_STATUS_LABELS, BILL_STATUS_ORDER } = require('../lib/billStatus');
const { INBOUND_ORDER_TYPES, OUTBOUND_ORDER_TYPES } = require('../lib/wms/orderTypes');
const { BIZ_TYPES } = require('./stockRecord');
const { PLATFORM_PRESETS, platformNameOf } = require('../lib/platformCode');
/* ==================== 选项常量(标签一律取自各业务模块的单一来源) ==================== */
@ -70,6 +71,35 @@ const SUCCESS_OPTIONS = [
/** 业务动作选项(出库推送锁定 / 出库解锁 / 订单审核锁定 …) */
const BIZ_TYPE_OPTIONS = Object.keys(BIZ_TYPES).map(value => ({ label: BIZ_TYPES[value].label, value }));
/**
* 多值筛选值 → 去重后的字符串列表(兼容数组与英文/中文逗号分隔)
* @param {*} value 原始筛选值
* @param {number} [max] 最多保留个数(防止超长 IN)
* @return {Array<string>} 值列表
*/
function csvValues(value, max = 200) {
const raw = Array.isArray(value) ? value : String(value == null ? '' : value).split(',');
const list = [];
for (const item of raw) {
const text = String(item == null ? '' : item).trim();
if (text && !list.includes(text)) list.push(text);
if (list.length >= max) break;
}
return list;
}
/**
* 追加多值 IN 条件(空列表跳过)
* @param {Object} wh makeWhere() 结果
* @param {string} column 列名
* @param {Array} values 值列表
* @return {void} 直接追加到 wh
*/
function whereIn(wh, column, values) {
if (!values.length) return;
wh.raw(`${column} IN (${values.map(() => '?').join(',')})`, ...values);
}
/** 入库单 / 出库单类型选项 */
const INBOUND_TYPE_OPTIONS = Object.keys(INBOUND_ORDER_TYPES).map(value => ({ label: `${INBOUND_ORDER_TYPES[value]}(${value})`, value }));
const OUTBOUND_TYPE_OPTIONS = Object.keys(OUTBOUND_ORDER_TYPES).map(value => ({ label: `${OUTBOUND_ORDER_TYPES[value]}(${value})`, value }));
@ -82,6 +112,8 @@ const PLATFORM_OPTIONS = [
{ label: '京东', value: 'jd' },
{ label: '其他', value: 'other' },
];
/** 店铺商品平台类型选项:系统预设平台编码(与 app/lib/platformCode.js 同源) */
const PLATFORM_TYPE_OPTIONS = PLATFORM_PRESETS.map(item => ({ label: item.name, value: item.code }));
const PRINCIPAL_TYPE_OPTIONS = [
{ label: '自营', value: 1 },
{ label: '加盟', value: 2 },
@ -480,6 +512,11 @@ const SHOP_PRODUCT_COLUMNS = [
expr: '(SELECT s.name FROM principal_subsidiaries s WHERE s.id = t.subsidiary_id)',
},
{ key: 'bind_type', header: '绑定类型', format: labels(BIND_TYPE_MAP) },
{
key: 'platform_type',
header: '平台类型',
format: value => (value ? platformNameOf(value) : ''),
},
{ key: 'product_id', header: '系统商品ID' },
{ key: 'product_name', header: '系统商品名称', expr: '(SELECT p.item_name FROM products p WHERE p.id = t.product_id)' },
{ key: 'combo_product_id', header: '组合商品ID' },
@ -954,7 +991,9 @@ const EXPORT_TYPES = {
shop_product: {
label: '店铺商品',
filters: [
{ key: 'shop_id', label: '店铺', type: 'shop' },
{ key: 'shop_ids', label: '店铺', type: 'shop', multiple: true },
{ key: 'platform_types', label: '平台类型', type: 'select', options: PLATFORM_TYPE_OPTIONS, multiple: true },
{ key: 'outer_codes', label: '商家编码', type: 'text', placeholder: '多个用英文逗号分隔' },
{ key: 'bind_type', label: '绑定类型', type: 'select', options: BIND_TYPE_OPTIONS },
{ key: 'status', label: '状态', type: 'select', options: ENABLE_OPTIONS },
{ key: 'has_unbound_order', label: '只看有订单未绑定', type: 'select', options: [{ value: '1', label: '是' }] },
@ -967,6 +1006,10 @@ const EXPORT_TYPES = {
.eq('t.bind_type', f.bind_type)
.eq('t.status', f.status)
.kw([ 't.title', 't.outer_item_id', 't.outer_sku_id', 't.outer_code' ], f.keyword);
// 多值筛选:店铺 / 平台类型 / 商家编码(与列表接口同口径)
whereIn(wh, 't.shop_id', csvValues(f.shop_ids).map(Number).filter(id => Number.isInteger(id) && id > 0));
whereIn(wh, 't.platform_type', csvValues(f.platform_types));
whereIn(wh, 't.outer_code', csvValues(f.outer_codes));
// 有订单未绑定:与列表接口同口径(未绑定 + 被未解析的订单明细引用)
if (String(f.has_unbound_order) === '1') {
wh.raw('t.bind_type = 0');

View File

@ -31,6 +31,8 @@ export interface ExportFilterDef {
type: ExportFilterType
options?: ExportFilterOption[]
placeholder?: string
/** 是否多选:多选值提交时按英文逗号拼接(如店铺/平台类型) */
multiple?: boolean
}
/** 导出任务状态:0待处理 1处理中 2已完成 3失败 */

View File

@ -64,6 +64,25 @@ const productId = computed({
set: (v: number | null) => emit('update:modelValue', v),
})
/**
* 多选筛选值(数组 ↔ 英文逗号分隔字符串)
* 导出任务里筛选值统一按字符串保存,多选在提交前拼成 CSV,与后端 CSV 解析口径一致
*/
const multiValue = computed({
get: () => {
const raw = props.modelValue
if (Array.isArray(raw)) return raw.map(v => String(v))
return String(raw ?? '')
.split(',')
.map(item => item.trim())
.filter(Boolean)
},
set: (v: unknown) => {
const list = Array.isArray(v) ? v.map(item => String(item)) : []
emit('update:modelValue', list.join(','))
},
})
function onProductSelect(product: ProductSearchItem) {
emit('update:modelValue', product.id)
emit('update:productLabel', product.item_code ? `${product.item_code} ${product.item_name}` : product.item_name || '')
@ -77,7 +96,21 @@ function clearProduct() {
<template>
<el-select
v-if="field.type === 'select'"
v-if="field.type === 'select' && field.multiple"
v-model="multiValue"
placeholder="全部"
clearable
filterable
multiple
collapse-tags
collapse-tags-tooltip
style="width: 100%"
>
<el-option v-for="o in field.options || []" :key="String(o.value)" :label="o.label" :value="o.value" />
</el-select>
<el-select
v-else-if="field.type === 'select'"
v-model="value"
placeholder="全部"
clearable
@ -116,6 +149,19 @@ function clearProduct() {
<el-button v-if="productId != null" link type="primary" @click="clearProduct">清除</el-button>
</div>
<VirtualSelect
v-else-if="field.type === 'shop' && field.multiple"
v-model="multiValue"
:options="shopOptions"
placeholder="全部"
clearable
filterable
multiple
collapse-tags
collapse-tags-tooltip
style="width: 100%"
/>
<VirtualSelect
v-else-if="field.type === 'shop'"
v-model="value"

View File

@ -0,0 +1,110 @@
<script setup lang="ts">
import { computed, ref, watch } from 'vue'
import { ArrowDown } from '@element-plus/icons-vue'
/**
* 多值文本筛选控件(如商家编码批量查询)
*
* 收起时把多个值用英文逗号拼成一行显示(如 A,B,C);点击展开为多行文本,
* 一行一个值,确认后回填并收起。输入既支持换行分隔,也兼容英文/中文逗号与分号。
*/
const props = withDefaults(
defineProps<{
/** 已选值列表 */
modelValue?: string[]
/** 收起状态下的占位提示 */
placeholder?: string
/** 收起时的分隔符 */
separator?: string
/** 控件宽度 */
width?: string
}>(),
{
modelValue: () => [],
placeholder: '',
separator: ',',
width: '220px',
},
)
const emit = defineEmits<{
'update:modelValue': [value: string[]]
}>()
/** 弹层是否展开 */
const open = ref(false)
/** 展开状态下编辑中的文本(一行一个) */
const draft = ref('')
const display = computed(() => (props.modelValue || []).join(props.separator))
// 每次展开都用当前值重置编辑内容,避免上次取消的输入残留
watch(open, (value) => {
if (value) draft.value = (props.modelValue || []).join('\n')
})
/**
* 解析多行/逗号分隔文本为去重后的值列表
* @param text 编辑中的文本
* @return 值列表
*/
function parseValues(text: string): string[] {
const list = String(text || '')
.split(/[\n\r,,;;]+/)
.map(item => item.trim())
.filter(Boolean)
return Array.from(new Set(list))
}
function confirm() {
emit('update:modelValue', parseValues(draft.value))
open.value = false
}
function clear() {
draft.value = ''
emit('update:modelValue', [])
open.value = false
}
</script>
<template>
<el-popover v-model:visible="open" placement="bottom-start" :width="280" trigger="click">
<template #reference>
<el-input
:model-value="display"
:placeholder="placeholder"
readonly
:style="{ width }"
class="multi-value-input"
>
<template #suffix>
<el-icon><ArrowDown /></el-icon>
</template>
</el-input>
</template>
<el-input
v-model="draft"
type="textarea"
:rows="6"
resize="none"
placeholder="一行一个,也可用英文逗号分隔"
/>
<div class="multi-value-actions">
<el-button link size="small" @click="clear">清空</el-button>
<el-button type="primary" size="small" @click="confirm">确定</el-button>
</div>
</el-popover>
</template>
<style scoped>
.multi-value-input :deep(.el-input__inner) {
cursor: pointer;
}
.multi-value-actions {
display: flex;
justify-content: flex-end;
gap: 8px;
margin-top: 8px;
}
</style>

View File

@ -16,10 +16,11 @@ import { getComboProducts, type ComboProductItem } from '@/api/comboProduct'
import DataTable from '@/components/DataTable.vue'
import ExportButton from '@/components/ExportButton.vue'
import ListPager from '@/components/ListPager.vue'
import MultiValueFilter from '@/components/MultiValueFilter.vue'
import OperationLogPanel from '@/components/OperationLogPanel.vue'
import { DEFAULT_PAGE_SIZE, useListPage } from '@/composables/useListPage'
import VirtualSelect from '@/components/VirtualSelect.vue'
import { platformNameOf } from '@/constants/platform'
import { PLATFORM_PRESETS, platformNameOf } from '@/constants/platform'
import { mediaUrl } from '@/utils/media'
const BIND_TAGS: Record<number, string> = { 0: 'info', 1: 'success', 2: 'warning' }
@ -29,7 +30,12 @@ const shops = ref<ShopItem[]>([])
const query = reactive({
page: 1,
pageSize: DEFAULT_PAGE_SIZE,
shop_id: '' as string | number,
/** 店铺多选 */
shop_ids: [] as number[],
/** 平台类型多选(系统预设编码) */
platform_types: [] as string[],
/** 商家编码多值(精确匹配) */
outer_codes: [] as string[],
bind_type: '' as string | number,
status: '' as string | number,
keyword: '',
@ -43,13 +49,15 @@ const { loading, list, total, elapsed, fetchList, search, handlePageChange, hand
const params: Record<string, unknown> = {
page: query.page,
pageSize: query.pageSize,
shop_id: query.shop_id,
bind_type: query.bind_type,
status: query.status,
keyword: query.keyword,
}
// 多值筛选统一按英文逗号拼接,后端逐项解析为 IN 条件
if (query.shop_ids.length) params.shop_ids = query.shop_ids.join(',')
if (query.platform_types.length) params.platform_types = query.platform_types.join(',')
if (query.outer_codes.length) params.outer_codes = query.outer_codes.join(',')
if (!params.keyword) delete params.keyword
if (params.shop_id === '') delete params.shop_id
if (params.bind_type === '') delete params.bind_type
if (params.status === '') delete params.status
// 只看有订单未绑定时,绑定状态必然是「未绑定」,避免两个条件互相打架
@ -71,7 +79,9 @@ async function fetchShops() {
}
function reset() {
query.shop_id = ''
query.shop_ids = []
query.platform_types = []
query.outer_codes = []
query.bind_type = ''
query.status = ''
query.keyword = ''
@ -87,7 +97,9 @@ function toggleUnboundOrderFilter() {
/** 导出筛选条件(与列表筛选同源) */
const exportFilters = computed(() => ({
shop_id: query.shop_id,
shop_ids: query.shop_ids.join(','),
platform_types: query.platform_types.join(','),
outer_codes: query.outer_codes.join(','),
bind_type: query.has_unbound_order ? 0 : query.bind_type,
status: query.status,
keyword: query.keyword.trim(),
@ -444,7 +456,8 @@ const pullForm = reactive({
const externalShops = computed(() => shops.value.filter((shop) => Number(shop.type) === 2))
function openPull() {
pullForm.shop_id = query.shop_id !== '' ? query.shop_id : (externalShops.value[0]?.id ?? '')
// 列表已选单个店铺时带过来,否则默认第一个外部打单平台店铺
pullForm.shop_id = query.shop_ids.length === 1 ? query.shop_ids[0] : (externalShops.value[0]?.id ?? '')
pullForm.outer_item_id = ''
pullForm.outer_sku_id = ''
pullVisible.value = true
@ -516,13 +529,38 @@ onBeforeUnmount(() => {
<el-form :inline="true" class="search-bar">
<el-form-item label="店铺">
<VirtualSelect
v-model="query.shop_id"
v-model="query.shop_ids"
:options="shops"
label-key="name"
value-key="id"
placeholder="全部"
multiple
collapse-tags
collapse-tags-tooltip
filterable
clearable
style="width: 160px"
style="width: 220px"
/>
</el-form-item>
<el-form-item label="平台类型">
<el-select
v-model="query.platform_types"
placeholder="全部"
multiple
collapse-tags
collapse-tags-tooltip
filterable
clearable
style="width: 180px"
>
<el-option v-for="p in PLATFORM_PRESETS" :key="p.code" :label="p.name" :value="p.code" />
</el-select>
</el-form-item>
<el-form-item label="商家编码">
<MultiValueFilter
v-model="query.outer_codes"
placeholder="多个编码"
width="200px"
/>
</el-form-item>
<el-form-item label="关键词">