From c77276160aea10ff4f81be03d90e98b0f1e9aaa3 Mon Sep 17 00:00:00 2001 From: yangmf_0726 <13243152557@163.com> Date: Mon, 17 Nov 2025 15:43:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E6=A0=87=E8=AF=86=E5=8F=B7=E5=92=8C=E8=B4=A7=E9=81=93=E5=8F=B7?= =?UTF-8?q?=E7=9A=84=E6=8E=92=E5=BA=8F=E9=80=BB=E8=BE=91=EF=BC=8C=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=95=86=E5=93=81=E5=88=97=E8=A1=A8=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mall/product/containergoods/index.vue | 54 ++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/src/views/mall/product/containergoods/index.vue b/src/views/mall/product/containergoods/index.vue index b9e06a28..8e05df53 100644 --- a/src/views/mall/product/containergoods/index.vue +++ b/src/views/mall/product/containergoods/index.vue @@ -327,14 +327,66 @@ const queryParams = ref({ }) // 查询参数 const queryFormRef = ref() // 搜索的表单Ref +const normalizeNumericString = (value?: number | string | null) => { + if (value === undefined || value === null) { + return '' + } + return String(value) +} + +const getDeviceIdValue = (spu: ProductSpuApi.Spu) => { + if (spu.deviceId !== undefined && spu.deviceId !== null) { + return normalizeNumericString(spu.deviceId) + } + const skuDevice = spu.skus?.find((sku) => sku.deviceId !== undefined && sku.deviceId !== null) + return normalizeNumericString(skuDevice?.deviceId ?? '') +} + +const getCabinetChannelValue = (spu: ProductSpuApi.Spu) => { + const channels = + spu.skus + ?.map((sku) => sku.cabinetChannel) + .filter((channel): channel is string => !!channel) ?? [] + if (channels.length === 0) { + return '' + } + const sortedChannels = channels + .map((channel) => normalizeNumericString(channel)) + .sort((a, b) => a.localeCompare(b, undefined, { numeric: true, sensitivity: 'base' })) + return sortedChannels[0] +} + +const compareByDeviceAndCabinet = (a: ProductSpuApi.Spu, b: ProductSpuApi.Spu) => { + const deviceA = getDeviceIdValue(a) + const deviceB = getDeviceIdValue(b) + const deviceCompare = deviceA.localeCompare(deviceB, undefined, { numeric: true, sensitivity: 'base' }) + if (deviceCompare !== 0) { + return deviceCompare + } + const cabinetA = getCabinetChannelValue(a) + const cabinetB = getCabinetChannelValue(b) + const cabinetCompare = cabinetA.localeCompare(cabinetB, undefined, { numeric: true, sensitivity: 'base' }) + if (cabinetCompare !== 0) { + return cabinetCompare + } + return ((a.id ?? 0) as number) - ((b.id ?? 0) as number) +} + /** 查询列表 */ const getList = async () => { loading.value = true try { const data = await ProductSpuApi.getSpuPage(queryParams.value) - list.value = data.list + const sortedList = [...data.list].sort(compareByDeviceAndCabinet) + list.value = sortedList total.value = data.total console.log('查询列表',data) + const cabinetChannels = sortedList + .flatMap((item) => item.skus ?? []) + .map((sku) => sku.cabinetChannel) + .filter((channel): channel is string => !!channel) + .map((channel) => normalizeNumericString(channel)) + console.log('货道号数据:', cabinetChannels) // 清空选中状态(因为列表数据已更新) selectedRows.value = [] } finally {