This commit is contained in:
yin 2026-09-30 18:14:16 +08:00
parent 13af833645
commit 52810f991f
5 changed files with 874 additions and 0 deletions

224
src/api/stock/report.ts Normal file
View File

@ -0,0 +1,224 @@
/**
* 库存报表(`stock.report.searchStore`)
*
* 与 new3 Web 端 `src/views/storage/report/store.vue`(**货主侧**)同一个接口
* (它引的是 `@/api/stock.report/stock.report` 的 `searchStoreReport`)。
* ⚠️ 同模块还有**仓库侧**的 `stock.report.search` —— 小程序是货主侧(与「收货单」用
* `getStoreReceivingList` 同理),货主侧才会**不收 `store_ids`**、也不提供 `by_space`。
*
* ```
* body = { where?: {...}, sort?: {...}, pagination: { page, pageSize } }
* 返回 data = { list: [...], pagination: { page, pageSize, total } }
* ```
*
* ⚠️ **这是第三套 `where` 形状 —— 扁平值**:
* ```
* where.keyword = 'xxx' // 不是 { operator, value }
* where.warehouse_ids = [3] // 仓库是**数组**写法(不是 warehouse_id)
* where.start_time = '2026-09-01 00:00:00'
* where.end_time = '2026-09-30 23:59:59'
* ```
* 对照:`stock.warehouse.externalList` = 裸值单值;`storage.receiving.*` = `{ operator, value }`。
*
* 小程序端展示的字段取自 new3 `report-config.ts` 的 `fixedReportColumns`,并**去掉货主侧
* 不显示的列**(new3 `store.vue` 的 `STORE_SIDE_HIDDEN_COLS = {store_id, store_name}`):
* 商品名称 / 商品编码 / 条码 / SKU / 期初数量 / 区间内入库 / 区间内出库 / 期末数量 /
* 统计区间 / 仓库。排序、按库位统计、导出等 Web 能力移动端不做。
*/
import request from '@/utils/request'
import type { BizResponse } from '@/utils/request'
import { SYSTEM_URL, gatewayParams } from '@/utils/gateway'
/**
* 每页条数:**固定 50 条,页面不提供修改**
*
* 明细行是纯文本(没有图片),单页可以比「外仓商品」的 20 条多放一些,少翻页;
* 与「收货单」取同一个值,便于记忆
*/
export const REPORT_PAGE_SIZE = 50
/** 报表明细行(只声明小程序用到的字段,其余用索引签名兜住) */
export interface ReportItem {
/** 统计区间开始 / 结束(后端原值,形如 `2026-09-01 00:00:00`) */
start_time?: string | null
end_time?: string | null
/** 商品库存 ID(Web 端列名是 SKU) */
stock_id?: number
store_id?: number
/** 仓库 */
warehouse_id?: number
warehouse_name?: string
/** 期初数量 */
begin_total?: number
/** 区间内入库 */
inbound_total?: number
/** 区间内出库 */
outbound_total?: number
/** 期末数量 */
end_total?: number
/** 货主(货主侧不展示,保留字段便于排查) */
store_name?: string
item_name?: string
item_code?: string
barcode?: string
/** 库位:只有 `by_space=true` 才有,货主侧不提供该条件,正常不会返回 */
space_id?: number | null
space_name?: string | null
[key: string]: any
}
/** 列表响应体 `data` */
export interface ReportPayload {
list?: ReportItem[]
total?: number
pagination?: { page?: number; pageSize?: number; total?: number }
[key: string]: any
}
/** 查询条件(页面传入) */
export interface ReportQuery {
page?: number
pageSize?: number
/** 商品关键字:SKU ID / 商品编码 / 商品名称 / 条码 模糊匹配 */
keyword?: string
/** 仓库 id(接口是**数组**写法 `warehouse_ids`),空字符串表示全部 */
warehouse_id?: number | string
/** 统计区间开始(`YYYY-MM-DD HH:mm:ss`) */
start_time?: string
/** 统计区间结束(`YYYY-MM-DD HH:mm:ss`) */
end_time?: string
}
function isFilled(value: unknown): boolean {
return value !== undefined && value !== null && value !== ''
}
/**
* 组装请求体
*
* `where` 全是**扁平值**;无有效条件时**不传 `where`**(new3 同款写法 ——
* 空对象可能被后端当成「筛了空」)
*/
function buildBody(query: ReportQuery): Record<string, any> {
const { page = 1, pageSize = REPORT_PAGE_SIZE, keyword, warehouse_id, start_time, end_time } = query
const where: Record<string, any> = {}
if (keyword && String(keyword).trim()) where.keyword = String(keyword).trim()
if (isFilled(warehouse_id)) {
const num = Number(warehouse_id)
// 与 new3 `applyWarehouseToWhere()` 一致:能转数字就给数字数组,否则原样包成数组
where.warehouse_ids = Number.isFinite(num) ? [num] : [warehouse_id]
}
if (isFilled(start_time)) where.start_time = start_time
if (isFilled(end_time)) where.end_time = end_time
const body: Record<string, any> = { pagination: { page, pageSize } }
if (Object.keys(where).length) body.where = where
return body
}
/** 库存报表明细(分页) */
export function fetchStoreReportList(
query: ReportQuery = {}
): Promise<BizResponse<ReportPayload>> {
return request<ReportPayload>({
url: SYSTEM_URL,
method: 'POST',
params: gatewayParams('stock.report.searchStore'),
data: buildBody(query),
// 需要登录:未登录时不发请求,直接弹登录抽屉
auth: true
})
}
/** 总数:后端放在 `pagination.total`(也可能在顶层 `total`) */
export function readTotal(payload: ReportPayload | undefined | null): number {
const total = payload?.pagination?.total ?? payload?.total ?? 0
const num = Number(total)
return Number.isFinite(num) && num > 0 ? num : 0
}
// ── 统计区间 ──────────────────────────────────────────────────────────────
/** 预设区间(含「全部」);默认「全部」= 不传时间条件,跟随后端默认口径 */
export const REPORT_PERIOD_OPTIONS: Array<{ value: string; label: string }> = [
{ value: '', label: '全部' },
{ value: 'today', label: '今天' },
{ value: 'd7', label: '近 7 天' },
{ value: 'd30', label: '近 30 天' },
{ value: 'month', label: '本月' }
]
const pad2 = (num: number): string => String(num).padStart(2, '0')
/**
* 日期 → `YYYY-MM-DD HH:mm:ss`
*
* 与 new3 `normalizeReportStartDateParam` / `normalizeReportEndDateParam` 等价
* (开始取当天 00:00:00、结束取当天 23:59:59,不用 `dayjs`:小程序端不引这个依赖)
*/
function toParam(date: Date, endOfDay = false): string {
const day = `${date.getFullYear()}-${pad2(date.getMonth() + 1)}-${pad2(date.getDate())}`
return `${day} ${endOfDay ? '23:59:59' : '00:00:00'}`
}
function addDays(base: Date, days: number): Date {
const next = new Date(base.getTime())
next.setDate(next.getDate() + days)
return next
}
/**
* 预设区间 → `{ start_time, end_time }`
*
* @param key 预设标识;`''`(全部)返回 `null` = 不传时间条件
*
* ⚠️ 天数**含今天**:近 7 天 = 今天往前推 6 天
*/
export function buildPeriodRange(key: string): { start_time: string; end_time: string } | null {
if (!key) return null
const now = new Date()
const end = toParam(now, true)
if (key === 'today') return { start_time: toParam(now), end_time: end }
if (key === 'd7') return { start_time: toParam(addDays(now, -6)), end_time: end }
if (key === 'd30') return { start_time: toParam(addDays(now, -29)), end_time: end }
if (key === 'month') {
return { start_time: toParam(new Date(now.getFullYear(), now.getMonth(), 1)), end_time: end }
}
return null
}
// ── 展示文本 ──────────────────────────────────────────────────────────────
/**
* 数量文案:带千分位(如 `1,234`)
*
* 不用 `toLocaleString('zh-CN')`:小程序 JSCore 对 locale 参数支持不稳,
* 手写分组更可控(与 new3 `formatReportNumber` 的展示效果一致)
*/
export function readNumberText(value: unknown): string {
if (!isFilled(value)) return '—'
const num = Number(value)
if (!Number.isFinite(num)) return '—'
const [intPart, decPart] = String(num).split('.')
const sign = intPart.startsWith('-') ? '-' : ''
const digits = sign ? intPart.slice(1) : intPart
const grouped = digits.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
const decimal = decPart ? `.${decPart.slice(0, 4)}` : ''
return `${sign}${grouped}${decimal}`
}
/** 统计区间文案:只到**日期**(`2026-09-01 ~ 2026-09-30`),移动端一行放得下 */
export function readPeriodText(item: ReportItem | undefined | null): string {
const start = item?.start_time ? String(item.start_time).slice(0, 10) : ''
const end = item?.end_time ? String(item.end_time).slice(0, 10) : ''
if (start && end) return `${start} ~ ${end}`
return start || end || '—'
}

View File

@ -78,6 +78,15 @@
"backgroundTextStyle": "dark",
"onReachBottomDistance": 80
}
},
{
"path": "external-inventory/report",
"style": {
"navigationBarTitleText": "库存报表",
"enablePullDownRefresh": true,
"backgroundTextStyle": "dark",
"onReachBottomDistance": 80
}
}
]
}
@ -136,6 +145,10 @@
{
"name": "收货单",
"path": "pagesA/external-inventory/receiving"
},
{
"name": "库存报表",
"path": "pagesA/external-inventory/report"
}
]
},

View File

@ -0,0 +1,586 @@
<template>
<view class="page">
<!-- required 未登录:页内「请先登录」+ 去登录,**不自动跳转** -->
<auth-gate auth="required">
<template #default>
<!-- 筛选区(吸顶):商品关键字 + 搜索;仓库 / 统计区间用胶囊按钮唤起底部选择器 -->
<view class="filter">
<view class="filter__row">
<view class="filter__input">
<up-input
v-model="form.keyword"
color="#303133"
placeholder-style="color: #c0c4cc"
placeholder="搜索商品名称/编码/条码"
prefix-icon="search"
border="none"
clearable
confirm-type="search"
@confirm="onSearch"
></up-input>
</view>
<up-button
type="primary"
shape="circle"
size="small"
text="搜索"
@click="onSearch"
></up-button>
</view>
<view class="filter__row filter__row--chips">
<view
class="chip"
:class="{ 'chip--active': isFilled(form.warehouse_id) }"
@click="openPicker('warehouse')"
>
<text class="chip__text">{{ labelOf('warehouse') }}</text>
<up-icon
name="arrow-down"
size="12"
:color="isFilled(form.warehouse_id) ? '#2979ff' : '#909399'"
></up-icon>
</view>
<view
class="chip"
:class="{ 'chip--active': !!form.period }"
@click="openPicker('period')"
>
<text class="chip__text">{{ labelOf('period') }}</text>
<up-icon
name="arrow-down"
size="12"
:color="form.period ? '#2979ff' : '#909399'"
></up-icon>
</view>
<view v-if="hasFilter" class="filter__reset" @click="onReset">重置</view>
</view>
</view>
<!-- 首屏加载(翻页时保留旧列表,只把页码控件置为「加载中…」,避免整屏闪动) -->
<view v-if="loading && !list.length" class="loading">
<up-loading-icon mode="circle" size="18" text="加载中"></up-loading-icon>
</view>
<template v-else-if="list.length">
<!-- 报表明细卡片:商品名称 + 仓库 / 编码·条码·SKU / 期初·入库·出库·期末 / 统计区间 -->
<view
v-for="(item, index) in list"
:key="item.stock_id ?? item.item_code ?? index"
class="rpt"
>
<view class="rpt__head">
<text class="rpt__name">{{ item.item_name || '未命名商品' }}</text>
<text class="rpt__wh">{{ item.warehouse_name || '—' }}</text>
</view>
<view class="rpt__meta">
<text class="rpt__meta-item">编码 {{ item.item_code || '—' }}</text>
<text class="rpt__meta-item">条码 {{ item.barcode || '—' }}</text>
<text class="rpt__meta-item">SKU {{ isFilled(item.stock_id) ? item.stock_id : '—' }}</text>
</view>
<view class="rpt__grid">
<view class="rpt__num">
<text class="rpt__num-label">期初数量</text>
<text class="rpt__num-value">{{ numTextOf(item.begin_total) }}</text>
</view>
<view class="rpt__num">
<text class="rpt__num-label">区间内入库</text>
<text class="rpt__num-value rpt__num-value--in">{{ numTextOf(item.inbound_total) }}</text>
</view>
<view class="rpt__num">
<text class="rpt__num-label">区间内出库</text>
<text class="rpt__num-value rpt__num-value--out">{{ numTextOf(item.outbound_total) }}</text>
</view>
<view class="rpt__num">
<text class="rpt__num-label">期末数量</text>
<text class="rpt__num-value rpt__num-value--end">{{ numTextOf(item.end_total) }}</text>
</view>
</view>
<view class="rpt__period">统计区间 {{ periodTextOf(item) }}</view>
</view>
</template>
<!-- 空态:无数据 / 加载失败(有筛选条件时文案不同) -->
<empty-state v-else v-bind="emptyStateProps" @retry="loadPage(1)"></empty-state>
</template>
</auth-gate>
<!-- 分页器(固定底部,公共组件;每页条数由 REPORT_PAGE_SIZE 固定,不可改) -->
<page-pager
v-if="list.length"
:total="total"
:page="pageNo"
:page-size="REPORT_PAGE_SIZE"
:loading="loading"
unit="条明细"
@change="goPage"
></page-pager>
<!-- 选择器(仓库 / 统计区间):底部弹层,选项多时组件自带名称搜索 -->
<option-picker
:show="pickerVisible"
:title="pickerTitle"
:options="pickerOptions"
:value="pickerValue"
:loading="pickerLoading"
@select="chooseOption"
@close="closePicker"
></option-picker>
<!-- 登录抽屉:点「去登录」或碰需要登录的接口时就地弹出(不跳页) -->
<auth-modal></auth-modal>
</view>
</template>
<script setup lang="ts">
/**
* 库存报表(列表)
*
* 接口与 new3 Web 端 `views/storage/report/store.vue`(**货主侧**)**同源**:
* `stock.report.searchStore`,见 `api/stock/report.ts`。
* ⚠️ 同模块另一个 `stock.report.search` 是**仓库侧**(会按 `store_ids` 过滤),别拿错。
*
* 展示字段取自 new3 `report-config.ts` 的 `fixedReportColumns`,并去掉货主侧不显示的
* `store_id` / `store_name`(new3 `store.vue` 的 `STORE_SIDE_HIDDEN_COLS`):
* 商品名称 / 编码 / 条码 / SKU / 期初数量 / 区间内入库 / 区间内出库 / 期末数量 / 统计区间 / 仓库。
*
* 移动端取舍(与「外仓商品」「收货单」一致):
* - 筛选只保留**商品关键字 + 仓库 + 统计区间**(`keyword` / `warehouse_ids` / `start_time`+`end_time`);
* Web 的 SKU 多选、按库位统计、列排序、导出都不做
* - 每页固定 50 条不可改,分页用固定底部的 `components/page-pager`,**整页替换**不做追加
* - 统计区间用**预设**(今天 / 近 7 天 / 近 30 天 / 本月 / 全部)代替 Web 的日期范围选择器 ——
* 移动端拉日历挑区间体验差,预设覆盖了绝大多数看报表的场景;默认「全部」跟随服务端口径
*
* ⚠️ 三条必须保持一致,改任意一处都要同步另两处(`npm run check:pages` 会校验):
* 1. 本文件的物理路径 `pagesA/external-inventory/report`
* 2. `src/pages.json` 里 `subPackages[pagesA]` 的注册
* 3. `src/router/pages.ts` 的 `PAGE_REGISTRY`(key = 后端 `wms_permission.path` = `/external-inventory/report`)
*/
import { computed, reactive, ref, watch } from 'vue'
import { onLoad, onPullDownRefresh } from '@dcloudio/uni-app'
import { usePageAuth } from '@/composables/usePageAuth'
import AuthModal from '@/components/auth-modal/auth-modal.vue'
import OptionPicker from '@/components/option-picker/option-picker.vue'
import PagePager from '@/components/page-pager/page-pager.vue'
import { fetchWarehouseOptions } from '@/api/index/index'
import type { SelectOption } from '@/api/index/index'
import {
REPORT_PAGE_SIZE,
REPORT_PERIOD_OPTIONS,
buildPeriodRange,
fetchStoreReportList,
readNumberText,
readPeriodText,
readTotal
} from '@/api/stock/report'
import type { ReportItem } from '@/api/stock/report'
/** 本页是 required:未登录时只做页内提示,不自动跳登录 */
const { isLogin } = usePageAuth('required')
/**
* 筛选条件
*
* - `keyword` 输入框回车 / 点搜索才生效(避免每输入一个字就请求)
* - `period` 是**预设标识**(界面状态),`start_time` / `end_time` 才是真正发给后端的参数
* —— 两者由 `applyPeriod()` 一起写,避免出现「预设显示近 7 天、实际传的是别的区间」
*/
const form = reactive({
keyword: '',
warehouse_id: '' as string | number,
period: '',
start_time: '',
end_time: ''
})
const list = ref<ReportItem[]>([])
/** 后端总数(分页器靠它算总页数) */
const total = ref(0)
/** 当前页码(1-based) */
const pageNo = ref(1)
const loading = ref(false)
const isFilled = (value: unknown): boolean =>
value !== undefined && value !== null && value !== ''
const hasFilter = computed(
() => !!form.keyword.trim() || isFilled(form.warehouse_id) || !!form.period
)
const numTextOf = (value: unknown): string => readNumberText(value)
const periodTextOf = (item: ReportItem): string => readPeriodText(item)
/** 总页数(按固定每页条数算;总数 0 时也算 1 页,避免出现「第 1/0 页」) */
const pageCount = computed(() => Math.max(1, Math.ceil(total.value / REPORT_PAGE_SIZE)))
/** 翻页后回到顶部(否则新一页会从上一页的滚动位置继续,看着像没动) */
const scrollToTop = (): void => {
uni.pageScrollTo({ scrollTop: 0, duration: 0 })
}
/**
* 拉取指定页(**整页替换**,不做追加 —— 分页由底部页码控件驱动)
* @param target 目标页码(1-based),越界自动夹到 `[1, pageCount]`
*/
const loadPage = async (target = pageNo.value): Promise<void> => {
if (!isLogin.value) return
if (loading.value) return
// 未知总数时(首屏)先不夹上界,拿到 total 后页码自会收敛
const max = total.value > 0 ? pageCount.value : Number.MAX_SAFE_INTEGER
const page = Math.min(Math.max(1, Math.floor(target) || 1), max)
loading.value = true
try {
const res = await fetchStoreReportList({
page,
pageSize: REPORT_PAGE_SIZE,
keyword: form.keyword,
warehouse_id: form.warehouse_id,
start_time: form.start_time,
end_time: form.end_time
})
const payload = res?.data
list.value = payload?.list || []
total.value = readTotal(payload)
pageNo.value = page
} catch {
// 失败提示由 request 层统一 toast;这里保留原页与旧数据(不把用户用到空白页)
} finally {
loading.value = false
uni.stopPullDownRefresh()
}
}
/** 切页(分页器按钮用):夹取范围、已在目标页则不动作 */
const goPage = (target: number): void => {
if (loading.value) return
const next = Math.min(Math.max(1, Math.floor(target) || 1), pageCount.value)
if (next === pageNo.value) return
loadPage(next).then(scrollToTop)
}
/** 筛选变了必须重拉第 1 页(不能因为「还在第 1 页」就跳过) */
const reloadFirstPage = (): void => {
loadPage(1).then(scrollToTop)
}
const onSearch = (): void => {
reloadFirstPage()
}
const onReset = (): void => {
form.keyword = ''
form.warehouse_id = ''
// 清预设时一并清掉真正的时间参数(只清 period 会留下上次的区间)
applyPeriod('')
reloadFirstPage()
}
/** 下拉刷新:重拉当前页;若当前页已越界(总数变少)则回到第 1 页 */
const refresh = async (): Promise<void> => {
await loadPage(pageNo.value)
if (!list.value.length && pageNo.value > 1) await loadPage(1)
}
// ── 仓库 / 统计区间 选择器(同一个底部弹层组件复用)──
type PickerKind = 'warehouse' | 'period'
const pickerVisible = ref(false)
const pickerKind = ref<PickerKind>('warehouse')
const pickerLoading = ref(false)
const warehouseOptions = ref<SelectOption[]>([])
const PICKER_TITLES: Record<PickerKind, string> = {
warehouse: '选择仓库',
period: '选择统计区间'
}
/**
* 胶囊上显示的名称
*
* 未选中时显示**筛选项名**(仓库 / 统计区间),选中后显示具体值(仓库名 / 近 7 天)
*/
const PICKER_NAMES: Record<PickerKind, string> = {
warehouse: '仓库',
period: '统计区间'
}
/**
* 预设区间:写 `period` 的同时把 `start_time` / `end_time` 落到表单
* (`''` = 全部 → 清空时间参数,不传即跟随后端默认口径)
*/
const applyPeriod = (key: string): void => {
form.period = key
const range = buildPeriodRange(key)
form.start_time = range?.start_time || ''
form.end_time = range?.end_time || ''
}
/** 某个维度当前选中的值 */
const valueOf = (kind: PickerKind): string | number =>
kind === 'warehouse' ? form.warehouse_id : form.period
const pickerTitle = computed(() => PICKER_TITLES[pickerKind.value])
const pickerValue = computed(() => valueOf(pickerKind.value))
/** 弹层选项:仓库来自接口(含「全部仓库」),区间是本地常量;「名称搜索」在 option-picker 内部 */
const pickerOptions = computed<SelectOption[]>(() =>
pickerKind.value === 'warehouse'
? [{ value: '', label: '全部仓库' }, ...warehouseOptions.value]
: REPORT_PERIOD_OPTIONS
)
/**
* 胶囊文案:未选中 = 筛选项名,选中 = 选项文案(找不到就原样显示值)
*
* 文案由「当前值 + 选项表」算出来,不再额外维护一份 label 状态,重置时也就不会漏掉某个胶囊
*/
const labelOf = (kind: PickerKind): string => {
const value = valueOf(kind)
if (!isFilled(value)) return PICKER_NAMES[kind]
const options = kind === 'warehouse' ? warehouseOptions.value : REPORT_PERIOD_OPTIONS
return options.find((option) => String(option.value) === String(value))?.label || String(value)
}
/** 仓库选项只有用到时才拉(拉过就缓存,不重复请求) */
const ensureWarehouseOptions = async (): Promise<void> => {
if (warehouseOptions.value.length) return
pickerLoading.value = true
try {
warehouseOptions.value = await fetchWarehouseOptions()
} catch {
// 失败提示由 request 层统一 toast;这里保持空列表(弹层里只剩「全部仓库」)
} finally {
pickerLoading.value = false
}
}
const openPicker = (kind: PickerKind): void => {
pickerKind.value = kind
pickerVisible.value = true
if (kind === 'warehouse') ensureWarehouseOptions()
}
const closePicker = (): void => {
pickerVisible.value = false
}
const chooseOption = (option: SelectOption): void => {
if (pickerKind.value === 'period') {
applyPeriod(String(option.value))
} else {
form.warehouse_id = option.value
}
closePicker()
reloadFirstPage()
}
/** 空态文案:有筛选条件时不能用「服务器出差了」这种口气 */
const emptyStateProps = computed(() =>
hasFilter.value ? { text: '没有符合条件的报表明细,试试换个关键字或筛选条件' } : {}
)
// ── 生命周期 ──
onLoad(() => {
loadPage(1)
})
// 未登录进来是空态(页内有登录引导);登录成功后自动拉一次
watch(isLogin, (value) => {
if (value && !list.value.length) loadPage(1)
})
// 下拉刷新:重拉当前页
onPullDownRefresh(() => {
refresh()
})
</script>
<style lang="scss" scoped>
.page {
min-height: 100vh;
background-color: #f5f6fa;
/* 给固定底部的分页器留位置(分页器只有一行),否则最后一张卡会被盖住 */
padding-bottom: 140rpx;
}
/* 筛选区:吸顶。部分低版本基础库不支持 sticky 就退化为普通块,不影响使用 */
.filter {
position: sticky;
top: 0;
z-index: 10;
padding: 16rpx 24rpx 12rpx;
background-color: #ffffff;
border-bottom: 1rpx solid #ebeef5;
&__row {
display: flex;
align-items: center;
&--chips {
margin-top: 8rpx;
/* 筛选项再多也不会被挤出屏幕 */
flex-wrap: wrap;
}
}
&__input {
flex: 1;
/* flex 子项里的输入框必须允许收缩,否则长占位符会把搜索按钮挤出去 */
min-width: 0;
margin-right: 16rpx;
padding: 0 20rpx;
background-color: #f5f6fa;
border-radius: 999rpx;
}
&__reset {
padding: 8rpx 8rpx 8rpx 16rpx;
font-size: 24rpx;
color: #2979ff;
}
}
.chip {
display: flex;
align-items: center;
max-width: 320rpx;
/* 允许换行,所以上下各留 4rpx 避免换行后贴在一起 */
margin: 4rpx 16rpx 4rpx 0;
padding: 10rpx 20rpx;
background-color: #f5f6fa;
border-radius: 999rpx;
&--active {
background-color: rgba(41, 121, 255, 0.1);
}
&__text {
margin-right: 6rpx;
font-size: 24rpx;
color: #606266;
/* 仓库名可能很长:截断而不是把筛选行撑破 */
max-width: 240rpx;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
}
.loading {
display: flex;
align-items: center;
justify-content: center;
padding: 96rpx 0;
}
/* 报表明细卡片 */
.rpt {
margin: 20rpx 24rpx 0;
padding: 24rpx;
background-color: #ffffff;
border-radius: 16rpx;
&__head {
display: flex;
align-items: center;
justify-content: space-between;
padding-bottom: 16rpx;
border-bottom: 1rpx solid #f2f3f5;
}
&__name {
flex: 1;
min-width: 0;
margin-right: 16rpx;
font-size: 30rpx;
font-weight: 600;
color: #303133;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
&__wh {
flex-shrink: 0;
max-width: 220rpx;
font-size: 24rpx;
color: #909399;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
&__meta {
display: flex;
flex-wrap: wrap;
margin-top: 12rpx;
}
&__meta-item {
margin: 4rpx 24rpx 4rpx 0;
font-size: 24rpx;
color: #909399;
}
/* 四个数量两列排(一行放四个在窄屏上会挤成竖条) */
&__grid {
display: flex;
flex-wrap: wrap;
margin-top: 12rpx;
}
&__num {
display: flex;
align-items: baseline;
width: 50%;
margin-top: 12rpx;
}
&__num-label {
flex-shrink: 0;
font-size: 24rpx;
color: #909399;
}
&__num-value {
margin-left: 10rpx;
font-size: 30rpx;
font-weight: 600;
color: #303133;
/* 百万级数字也不把两列撑变形 */
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
&--in {
color: #19be6b;
}
&--out {
color: #ff9900;
}
&--end {
color: #2979ff;
}
}
&__period {
margin-top: 16rpx;
padding-top: 12rpx;
border-top: 1rpx solid #f2f3f5;
font-size: 22rpx;
color: #c0c4cc;
}
}
/* 分页器样式在 components/page-pager(三个列表页共用,勿在此重复定义) */
</style>

View File

@ -158,6 +158,16 @@ export const PAGE_REGISTRY: PageMeta[] = [
auth: 'required'
// 对应后端 id=633(父节点 632「外仓库存」分类)—— 同样必须与 key 逐字符相等
// 不设 hidden → 登录后由后端菜单下发才出现;不设 common → 走「后端菜单」那一侧
},
{
key: '/external-inventory/report',
path: 'pagesA/external-inventory/report',
title: '库存报表',
// 本地兜底图标;后端 id=637 下发的是 file-text(uview 图标表里存在同名图标)
icon: 'file-text',
auth: 'required'
// 对应后端 id=637(父节点 632「外仓库存」分类,sort=1 排在「收货单」之后)
// 接口 stock.report.searchStore(**货主侧**),见 api/stock/report.ts
}
// ─────────────── 待启用(页面文件就绪后再登记)───────────────

View File

@ -429,6 +429,47 @@ body = { pagination: { page, pageSize }, where: { <字段>: { operator, value }
引用完整性 125 个 / 0 缺失
- ⚠️ 待实测:`is_review` **不在** new3 货主侧列定义里,筛选是否生效需在工具里点一次确认
### 3.6 库存报表页面实现(2026-09-30)
后端新增小程序页面权限:**637** `/external-inventory/report`「库存报表」
(632「外仓库存」的子,sort 1 排在「收货单」之后,`meta_icon='file-text'`)。
> ⚠️ **id 不是顺序分配**:634/635/636 已被 pda「移库记录」/ web「库存盘点」/ api 权限占用 ——
> 新增 `miniprogram_pages` 前先查空闲 id(本次按 634 直接 INSERT 撞过主键)。
#### 接口(`src/api/stock/report.ts`)
```
POST {base}/system?method=stock.report.searchStore&v=1.0&timestamp=...
body = { where?: {...}, sort?: {...}, pagination: { page, pageSize } }
返回 data = { list: [...], pagination: { page, pageSize, total } }
```
- 与 new3 `views/storage/report/store.vue`(**货主侧**)同源;仓库侧是同模块的
`stock.report.search`(按 `store_ids` 过滤)—— 别拿错(「收货单」也是走货主侧 `getStoreReceivingList`)
- ⚠️ **第三套 `where` 形状:扁平值**(前两套分别是「外仓商品」的裸值、「收货单」的 `{operator,value}`):
`where.keyword` / `where.warehouse_ids = [id]`(**数组**,不是 `warehouse_id`)/
`where.start_time` / `where.end_time`;**无有效条件时连 `where` 都不传**(new3 同款写法)
- 货主侧不收 `store_ids`、不提供 `by_space`
#### 页面(`pagesA/external-inventory/report.vue`)
- 筛选:**商品关键字 + 仓库 + 统计区间**(→ `keyword` / `warehouse_ids` / `start_time`+`end_time`)
- **统计区间用预设**(全部 / 今天 / 近 7 天 / 近 30 天 / 本月)代替 Web 的日期范围选择器 ——
移动端拉日历挑区间体验差;默认「全部」= 不传时间条件、跟随后端默认口径;
天数**含今天**(近 7 天 = 往前推 6 天),格式 `YYYY-MM-DD HH:mm:ss`(start 00:00:00 / end 23:59:59)
- 卡片字段(new3 `fixedReportColumns` 去掉货主侧隐藏的 `store_id`/`store_name`):
商品名称 + 仓库 / 编码 · 条码 · SKU / **2×2 四个数量**(期初 / 区间内入库 / 区间内出库 / 期末)/
统计区间(只到日期);数量带千分位(手写分组,不用 `toLocaleString`:小程序 JSCore 的 locale 支持不稳)
- 分页:`REPORT_PAGE_SIZE = 50` 固定,复用公共 `page-pager`(`unit="条明细"`),**整页替换**
- 未做(Web 能力,移动端刻意不做):SKU 多选、按库位统计、列排序、导出
- 校验:`type-check` 通过;`check:pages` → **11 条注册表 / 11 个已注册页面 / 0 告警**;
产物已重建(页面 js/wxml/json/wxss + `api/stock/report.js`,含 `stock.report.searchStore` /
`warehouse_ids`;wxml 含四个数量与统计区间标签),引用完整性 131 个 / 0 缺失
- ✅ **接口存在性已取证**:未带 token 请求 `stock.report.searchStore` → **HTTP 401**
(对照组:伪造方法名 `stock.report.searchStoreXyz` → 500)。
待你在工具里确认的是「带 token 能正常返回数据」以及页面字段是否都下发
---
## 4. 下一步任务清单