1
This commit is contained in:
parent
48dbe020ff
commit
4dc90ac539
@ -64,6 +64,8 @@ export type StockCheckAuditAction = 'approve' | 'reject'
|
||||
/** 盘点主表行(create 响应 / list rows / detail.check 同构) */
|
||||
export type StockCheckTask = {
|
||||
id: number
|
||||
/** 所属仓库ID(服务端按登录上下文注入) */
|
||||
warehouse_id?: number
|
||||
/** 盘点单号(PD+YYYYMMDD+6 位序号,按仓库隔离) */
|
||||
check_no: string
|
||||
/** 盘点名称/主题 */
|
||||
@ -72,9 +74,18 @@ export type StockCheckTask = {
|
||||
mode: StockCheckMode
|
||||
/** 货主ID(type=store 按货主盘点时有值) */
|
||||
store_id?: number | null
|
||||
/** 货主名称(list 回包附加字段,type=store 等场景有值,用于列表「货主名称」列) */
|
||||
store_name?: string | null
|
||||
/** 盘点范围快照(后端可选字段,常为 null) */
|
||||
scope_snapshot?: unknown
|
||||
status: StockCheckStatus
|
||||
detail_status: StockCheckDetailStatus
|
||||
/** 盘点日期 */
|
||||
/**
|
||||
* 盘点日期
|
||||
*
|
||||
* ⚠️ stock.check.list 最新回包**已不含该字段**(创建也不再传日期),
|
||||
* 保留仅作兼容(detail 等回包或历史数据可能仍有值),前端列表/详情不再展示。
|
||||
*/
|
||||
check_date?: string | null
|
||||
/** 实际开始时间(开始盘点作业后回填) */
|
||||
start_time?: string | null
|
||||
@ -225,7 +236,12 @@ export type StockCheckResultRow = StockCheckDetailRow & {
|
||||
|
||||
// ============ stock.check.create ============
|
||||
|
||||
/** stock.check.create 请求参数(warehouse_id 服务端注入,禁止前端传;check_date 必填) */
|
||||
/**
|
||||
* stock.check.create 请求参数(warehouse_id 服务端注入,禁止前端传)
|
||||
*
|
||||
* 注意:前端**统一不传** check_date,由服务端缺省为当天(接口文档标注其为必填,
|
||||
* 若后续后端收紧校验,需在此恢复必填并在表单中补回日期选择)。
|
||||
*/
|
||||
export type StockCheckCreateParams = {
|
||||
/** 盘点名称/主题 */
|
||||
title?: string
|
||||
@ -235,8 +251,8 @@ export type StockCheckCreateParams = {
|
||||
mode?: StockCheckMode
|
||||
/** 货主ID(type=store 时必填) */
|
||||
store_id?: number
|
||||
/** 盘点日期(必填,须可被 Date 解析) */
|
||||
check_date: string
|
||||
/** 盘点日期(前端不传,服务端缺省当天;传入时须可被 Date 解析) */
|
||||
check_date?: string
|
||||
remark?: string
|
||||
}
|
||||
|
||||
@ -257,16 +273,176 @@ export function stockCheckCreate(
|
||||
} as any)
|
||||
}
|
||||
|
||||
// ============ stock.check.patternList ============
|
||||
|
||||
/**
|
||||
* 盘点定式(快速创建盘点任务时可选的内置模板)
|
||||
*
|
||||
* 定式由后端代码注册(app/service/systems/stock_check_patterns.js),**不建表**,共 5 个:
|
||||
* empty_location=空库位盘点 / mis_shipment=错发盘点 / expiring=临期盘点 /
|
||||
* static=静态盘点 / warning=预警盘点
|
||||
*/
|
||||
export type StockCheckPattern = {
|
||||
/** 定式ID(创建时作为 pattern_id 传入) */
|
||||
id: string
|
||||
/** 定式名称 */
|
||||
name: string
|
||||
/** 定式说明 */
|
||||
description?: string
|
||||
/**
|
||||
* 定式收集盘点对象后的明细形态:
|
||||
* goods → 命中商品库存ID(stock_ids)→ 商品行明细
|
||||
* location → 命中库位列表 → 库位行明细
|
||||
*/
|
||||
type?: 'goods' | 'location' | string
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
/** stock.check.patternList 响应(无入参) */
|
||||
export type StockCheckPatternListResponse = {
|
||||
/** 内置定式清单 */
|
||||
patterns?: StockCheckPattern[]
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
/**
|
||||
* stock.check.patternList:拉取盘点定式清单(供前端选择定式快速创建盘点任务)
|
||||
*
|
||||
* 返回代码注册的 5 个内置定式,每条含 id/name/description/type;无入参。
|
||||
*/
|
||||
export function stockCheckPatternList(): Promise<
|
||||
StockCheckPatternListResponse & {
|
||||
code?: number
|
||||
message?: string
|
||||
data?: Partial<StockCheckPatternListResponse> | StockCheckPattern[]
|
||||
}
|
||||
> {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'stock.check.patternList',
|
||||
v,
|
||||
timestamp: new Date().getTime()
|
||||
},
|
||||
data: {},
|
||||
isSystemApi: true
|
||||
} as any)
|
||||
}
|
||||
|
||||
// ============ stock.check.patternCreate ============
|
||||
|
||||
/**
|
||||
* stock.check.patternCreate 请求参数
|
||||
*
|
||||
* warehouse_id 与创建人均由服务端从登录上下文注入(ctx.user.store_id / id / employees_name),
|
||||
* 前端**禁止传入**;check_date 可不传(缺省今天),故前端无需选择盘点日期。
|
||||
*/
|
||||
export type StockCheckPatternCreateParams = {
|
||||
/** 定式ID:empty_location / mis_shipment / expiring / static / warning(patternId 为驼峰兼容别名) */
|
||||
pattern_id: string
|
||||
/** 定式ID(驼峰别名,兼容写法;两者都传时 pattern_id 优先) */
|
||||
patternId?: string
|
||||
/** 盘点名称/主题,缺省取定式 name */
|
||||
title?: string
|
||||
/** 盘点方式,缺省 open:open=明盘 / blind=盲盘 */
|
||||
mode?: StockCheckMode
|
||||
/** 盘点日期(可省略,缺省今天) */
|
||||
check_date?: string
|
||||
/** 备注 */
|
||||
remark?: string
|
||||
}
|
||||
|
||||
/** stock.check.patternCreate 响应 */
|
||||
export type StockCheckPatternCreateResponse = {
|
||||
/** 创建出的盘点任务(部分回包形态下与响应同级) */
|
||||
check?: StockCheckTask
|
||||
/** 按定式收集到的盘点对象数量 */
|
||||
total_items?: number
|
||||
/** static 定式:批量写入 wms_stock_static_check_task 的命中条数(写入失败不影响主流程) */
|
||||
static_written?: number
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
/**
|
||||
* stock.check.patternCreate:**按定式快速创建盘点任务**
|
||||
*
|
||||
* - 入参 `pattern_id`(兼容 `patternId` 驼峰写法,两者都传时 `pattern_id` 优先)
|
||||
* - warehouse_id / 创建人由服务端注入;按定式收集盘点对象(goods 型 → stock_ids,location 型 → 库位列表)
|
||||
* - 无符合条件对象时后端报 400;创建后主表 status 直接为 `submitted`(待审核)、detail_status=none_checked
|
||||
* - static 定式创建成功后会把命中的 stock_id 批量写入 wms_stock_static_check_task(失败不影响主流程)
|
||||
* - 写操作,记录操作日志
|
||||
*/
|
||||
export function stockCheckPatternCreate(
|
||||
data: StockCheckPatternCreateParams
|
||||
): Promise<
|
||||
StockCheckPatternCreateResponse & {
|
||||
code?: number
|
||||
message?: string
|
||||
data?: Partial<StockCheckPatternCreateResponse>
|
||||
}
|
||||
> {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'stock.check.patternCreate',
|
||||
v,
|
||||
timestamp: new Date().getTime()
|
||||
},
|
||||
data,
|
||||
isSystemApi: true
|
||||
} as any)
|
||||
}
|
||||
|
||||
// ============ stock.check.list ============
|
||||
|
||||
/** stock.check.list 的 where 条件 */
|
||||
/**
|
||||
* where 条件项(后端查询协议):`{ operator, value, type? }`
|
||||
*
|
||||
* 规范见仓库根目录 stock-stockWarehouse-query-rules.md(与其他 storage 列表一致),
|
||||
* 前端**不能**直接传裸标量/数组,必须包成该结构。
|
||||
*/
|
||||
export type StockCheckWhereCondition = {
|
||||
/** 操作符:eq / ne / like / notlike / in / notin / between / notbetween / isnull / isnotnull ... */
|
||||
operator: string
|
||||
/** 查询值(between 时为 [start, end]) */
|
||||
value: unknown
|
||||
/** 值类型:text / number / boolean / date / daterange / datetimerange */
|
||||
type?: 'text' | 'number' | 'boolean' | 'date' | 'daterange' | 'datetimerange'
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间范围条件(`operator=between` + `type=datetimerange`,值带时分秒)
|
||||
*
|
||||
* 实测(2026-10-01):时间范围必须精确到时分秒——只传 `YYYY-MM-DD`(type=daterange)
|
||||
* 会把当天带时分秒的记录全部排除,导致「今天无结果」。
|
||||
*/
|
||||
export type StockCheckRangeCondition = StockCheckWhereCondition & {
|
||||
operator: 'between' | 'notbetween'
|
||||
/** [开始, 结束],'YYYY-MM-DD HH:mm:ss'(仅日期时会补 00:00:00 / 23:59:59) */
|
||||
value: [string, string]
|
||||
type: 'daterange' | 'datetimerange'
|
||||
}
|
||||
|
||||
/** stock.check.list 的 where 条件(每项均为 `{ operator, value, type? }` 结构) */
|
||||
export type StockCheckListWhere = {
|
||||
/** 状态筛选(单值或数组):created/submitted/rejected/approved/checking/completed/cancelled */
|
||||
status?: StockCheckStatus | StockCheckStatus[]
|
||||
/** 货主筛选 */
|
||||
store_id?: number
|
||||
/** 关键字:对盘点单号/标题模糊匹配 */
|
||||
keyword?: string
|
||||
/** 关键字(盘点单号/标题模糊匹配):`{ operator: 'like', value: 'PD2026', type: 'text' }` */
|
||||
keyword?: StockCheckWhereCondition
|
||||
/** 状态筛选:created/submitted/rejected/approved/checking/completed/cancelled */
|
||||
status?: StockCheckWhereCondition
|
||||
/** 货主筛选:`{ operator: 'eq', value: 100000, type: 'number' }` */
|
||||
store_id?: StockCheckWhereCondition
|
||||
/** 盘点范围筛选(all/location/store/goods):`{ operator: 'eq', value: 'goods', type: 'text' }` */
|
||||
type?: StockCheckWhereCondition
|
||||
/** 盘点方式筛选(open/blind):`{ operator: 'eq', value: 'blind', type: 'text' }` */
|
||||
mode?: StockCheckWhereCondition
|
||||
/** 创建时间范围(含时分秒):`{ operator: 'between', value: ['2026-10-01 00:00:00', '2026-10-01 23:59:59'], type: 'datetimerange' }` */
|
||||
created_at?: StockCheckRangeCondition
|
||||
/** 盘点开始时间范围(对应列表「开始时间」列) */
|
||||
start_time?: StockCheckRangeCondition
|
||||
/** 盘点结束时间范围(对应列表「结束时间」列) */
|
||||
end_time?: StockCheckRangeCondition
|
||||
}
|
||||
|
||||
/** stock.check.list 请求参数 */
|
||||
|
||||
@ -36,7 +36,7 @@ const props = defineProps<{
|
||||
value: any
|
||||
}>()
|
||||
|
||||
/** 显示文本:translateField 翻译 > format 格式化 > 原始值 */
|
||||
/** 显示文本:translateField 翻译 > format 格式化 > 原始值(空值统一显示 —) */
|
||||
const displayValue = computed(() => {
|
||||
const v = props.value
|
||||
if (props.config?.translateField) {
|
||||
@ -48,7 +48,7 @@ const displayValue = computed(() => {
|
||||
if (props.config?.format === 'date') {
|
||||
return formatDate(v)
|
||||
}
|
||||
return v ?? '—'
|
||||
return v === undefined || v === null || v === '' ? '—' : v
|
||||
})
|
||||
|
||||
const resolvedTagType = computed(() => {
|
||||
|
||||
@ -7,10 +7,11 @@
|
||||
(范围行 + 已盘/差异/状态/作业记录聚合)
|
||||
- 尚未开始作业的阶段(created/rejected/submitted,必然无作业记录)→ **stock.check.detail**
|
||||
(纯范围行,不含聚合;此时作业类列不渲染,无需多发一次聚合查询)
|
||||
行形态由任务 type 决定:
|
||||
明细行形态由任务 type 决定,表格统一「平铺」展示(不用展开行):
|
||||
- 商品行(scope_type=goods,type=store/goods):一行一个库存商品(商品快照 + 已盘聚合)
|
||||
- 库位行(scope_type=location,type=all/location):一行一个库位,行内按商品聚合 stocks[],
|
||||
上报需带 stock_id → 展开行内按商品逐条上报
|
||||
- 库位行(scope_type=location,type=all/location):一行一个库位 + 行内商品各一行
|
||||
(result 的 stocks[] 平铺;无商品时保留库位行本身、商品列为 —)
|
||||
上报需带 stock_id → 商品行直接上报;同明细的「明细类型 / 库位」单元格合并显示
|
||||
2. 盘点作业:行内或批量上报(stock.check.report,**覆盖式**:
|
||||
商品行=同明细+同库位;库位行=同明细+同商品+同库位,均重复上报为更新)
|
||||
3. 完成盘点(stock.check.finish,允许部分未盘完成:
|
||||
@ -33,7 +34,7 @@
|
||||
{{ isLocationTask ? '添加库位' : '添加商品' }}
|
||||
</el-button>
|
||||
<el-button
|
||||
v-if="canReport"
|
||||
v-if="canReport && !isLocationTask"
|
||||
size="small"
|
||||
type="primary"
|
||||
plain
|
||||
@ -67,134 +68,61 @@
|
||||
<el-table
|
||||
ref="tableRef"
|
||||
v-loading="loading"
|
||||
:data="pagedItems"
|
||||
row-key="id"
|
||||
:data="pagedRows"
|
||||
row-key="flat_key"
|
||||
border
|
||||
stripe
|
||||
size="small"
|
||||
:height="tableHeight"
|
||||
:span-method="spanMethod"
|
||||
>
|
||||
<el-table-column type="index" label="#" width="56" align="center" :index="indexMethod" />
|
||||
<!-- 库位行:展开后按商品逐行上报(report 需要 stock_id) -->
|
||||
<el-table-column v-if="isLocationTask" type="expand" width="46">
|
||||
<template #default="{ row }">
|
||||
<div class="stock-expand">
|
||||
<el-table :data="rowStocks(row)" border size="small">
|
||||
<el-table-column type="index" label="#" width="46" align="center" />
|
||||
<el-table-column prop="item_code" label="商品编码" min-width="130" show-overflow-tooltip />
|
||||
<el-table-column prop="item_name" label="商品名称" min-width="160" show-overflow-tooltip />
|
||||
<el-table-column label="账面数量" width="100" align="center">
|
||||
<template #default="scope">{{ maskQuantity(scope.row.system_quantity) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="已盘" width="90" align="center">
|
||||
<template #default="scope">{{ scope.row.checked_quantity ?? '—' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="差异" width="90" align="center">
|
||||
<template #default="scope">
|
||||
<span v-if="isQuantityMasked" class="hint-text">—</span>
|
||||
<span v-else :class="diffClass(scope.row.diff_quantity)">
|
||||
{{ formatDiff(scope.row.diff_quantity) }}
|
||||
</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="本库位数量" width="140" align="center">
|
||||
<template #default="scope">
|
||||
<el-input-number
|
||||
v-if="canReport"
|
||||
v-model="stockQuantityMap[stockKey(row.id, scope.row.stock_id)]"
|
||||
size="small"
|
||||
:min="0"
|
||||
:step="1"
|
||||
step-strictly
|
||||
controls-position="right"
|
||||
class="quantity-input"
|
||||
/>
|
||||
<span v-else class="hint-text">—</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="80" align="center">
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
v-if="canReport"
|
||||
link
|
||||
type="primary"
|
||||
size="small"
|
||||
:loading="reportingId === Number(row.id)"
|
||||
@click="reportStock(row, scope.row)"
|
||||
>
|
||||
上报
|
||||
</el-button>
|
||||
<span v-else class="hint-text">—</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<template #empty>
|
||||
<div class="empty-tip">该库位暂无可盘商品</div>
|
||||
</template>
|
||||
</el-table>
|
||||
</div>
|
||||
</template>
|
||||
<!-- 明细类型:商品行 / 库位行(同一单内由任务 type 决定,显式标注便于核对) -->
|
||||
<el-table-column label="明细类型" width="90" align="center">
|
||||
<template #default="{ row }">{{ itemScopeLabel(row) }}</template>
|
||||
</el-table-column>
|
||||
<!-- 商品行:商品快照列 -->
|
||||
<el-table-column
|
||||
v-if="!isLocationTask"
|
||||
prop="item_code"
|
||||
label="商品编码"
|
||||
min-width="130"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<el-table-column
|
||||
v-if="!isLocationTask"
|
||||
prop="item_name"
|
||||
label="商品名称"
|
||||
min-width="160"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<el-table-column
|
||||
v-if="!isLocationTask"
|
||||
prop="spec"
|
||||
label="规格"
|
||||
min-width="110"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<el-table-column
|
||||
v-if="!isLocationTask"
|
||||
prop="batch_no"
|
||||
label="批次号"
|
||||
min-width="110"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<!-- 库位行:商品数(明细下面按商品聚合) -->
|
||||
<el-table-column v-if="isLocationTask" label="商品数" width="80" align="center">
|
||||
<template #default="{ row }">{{ rowStocks(row).length }}</template>
|
||||
<!-- 商品列:仅商品类任务显示(库位类任务不展示商品快照,商品明细看「作业明细」) -->
|
||||
<el-table-column v-if="!isLocationTask" label="商品编码" min-width="130" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ row.item_code || '—' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column v-if="!isLocationTask" label="商品名称" min-width="160" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ row.item_name || '—' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column v-if="!isLocationTask" label="规格" min-width="110" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ row.spec || '—' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column v-if="!isLocationTask" label="批次号" min-width="110" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ row.batch_no || '—' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="库位" min-width="130" show-overflow-tooltip>
|
||||
<template #default="{ row }">
|
||||
<!-- 库位行:库位以明细自身库位为准,只读 -->
|
||||
<!-- 库位行:库位以明细自身库位为准,只读(同明细的行合并单元格);商品行可填库位 -->
|
||||
<span v-if="isLocationTask">{{ formatLocationCodes(row) }}</span>
|
||||
<el-input
|
||||
v-else-if="canReport"
|
||||
v-model="locationMap[row.id]"
|
||||
v-model="locationMap[row.item.id]"
|
||||
size="small"
|
||||
placeholder="库位编码(可留空=无库位)"
|
||||
/>
|
||||
<span v-else>{{ formatLocationCodes(row) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<!-- 账面/实盘输入列:仅商品类任务(库位类任务不在此面板上报) -->
|
||||
<el-table-column v-if="!isLocationTask" label="账面数量" width="100" align="center">
|
||||
<template #default="{ row }">{{ maskQuantity(row.system_quantity) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column v-if="!isLocationTask" label="本库位数量" width="130" align="center">
|
||||
<el-table-column v-if="!isLocationTask" label="本库位数量" width="140" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-input-number
|
||||
v-if="canReport"
|
||||
v-model="quantityMap[row.id]"
|
||||
v-if="isReportableRow(row)"
|
||||
:model-value="rowQuantity(row)"
|
||||
size="small"
|
||||
:min="0"
|
||||
:step="1"
|
||||
step-strictly
|
||||
controls-position="right"
|
||||
class="quantity-input"
|
||||
@update:model-value="onRowQuantityChange(row, $event)"
|
||||
/>
|
||||
<span v-else class="hint-text">—</span>
|
||||
</template>
|
||||
@ -221,25 +149,16 @@
|
||||
<el-table-column v-if="useResultSource" label="最近上报" width="160">
|
||||
<template #default="{ row }">{{ formatTime(row.last_checked_at) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="110" align="center" fixed="right">
|
||||
<!-- 操作列:仅商品类任务(库位类任务的上报在「作业明细」侧处理) -->
|
||||
<el-table-column v-if="!isLocationTask" label="操作" width="100" align="center" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<!-- 库位行:在展开行里按商品上报 -->
|
||||
<el-button
|
||||
v-if="canReport && isLocationTask"
|
||||
v-if="isReportableRow(row)"
|
||||
link
|
||||
type="primary"
|
||||
size="small"
|
||||
@click="toggleExpand(row)"
|
||||
>
|
||||
{{ isRowExpanded(row) ? '收起' : '展开上报' }}
|
||||
</el-button>
|
||||
<el-button
|
||||
v-else-if="canReport"
|
||||
link
|
||||
type="primary"
|
||||
size="small"
|
||||
:loading="reportingId === Number(row.id)"
|
||||
@click="reportRow(row)"
|
||||
:loading="reportingId === Number(row.item.id)"
|
||||
@click="reportFlatRow(row)"
|
||||
>
|
||||
上报
|
||||
</el-button>
|
||||
@ -253,12 +172,12 @@
|
||||
</el-table>
|
||||
</div>
|
||||
|
||||
<div v-if="items.length > pageSize" class="pagination-container">
|
||||
<div v-if="flatRows.length > pageSize" class="pagination-container">
|
||||
<el-pagination
|
||||
v-model:current-page="page"
|
||||
v-model:page-size="pageSize"
|
||||
:page-sizes="[10, 20, 50, 100]"
|
||||
:total="items.length"
|
||||
:total="flatRows.length"
|
||||
layout="total, sizes, prev, pager, next"
|
||||
background
|
||||
size="small"
|
||||
@ -339,6 +258,13 @@ const stockQuantityMap = reactive<Record<string, number | undefined>>({})
|
||||
/** 商品行库位输入(明细ID → 库位编码) */
|
||||
const locationMap = reactive<Record<string, string>>({})
|
||||
|
||||
/** 明细类型文案(scope_type:goods=商品 / location=库位;接口未返回时按任务类型兜底) */
|
||||
function itemScopeLabel(item: Record<string, any>): string {
|
||||
const scope = item?.scope_type
|
||||
if (scope !== undefined && scope !== null && scope !== '') return translate('scope_type', scope)
|
||||
return isLocationTask.value ? '库位' : '商品'
|
||||
}
|
||||
|
||||
/** 库位行内商品的数量输入 key */
|
||||
function stockKey(detailId: unknown, stockId: unknown): string {
|
||||
return `${detailId}:${stockId}`
|
||||
@ -349,6 +275,48 @@ function rowStocks(item: Record<string, any>): Record<string, any>[] {
|
||||
return Array.isArray(item?.stocks) ? item.stocks : []
|
||||
}
|
||||
|
||||
/**
|
||||
* 平铺行(表格数据源)
|
||||
*
|
||||
* - 商品行(scope_type=goods):一行一个明细,商品快照取自明细自身
|
||||
* - 库位行(scope_type=location):将行内商品(result 的 stocks[])平铺为多行,
|
||||
* 一行一个商品,商品快照/账面数量/已盘/差异取商品(stock)的值;
|
||||
* 无商品时保留库位行本身(商品列显示 —,不可上报)
|
||||
* 每行带 `flat_key`(行 key)与 `item`(明细行,上报/库位等仍以明细为准)
|
||||
*/
|
||||
const flatRows = computed<Record<string, any>[]>(() => {
|
||||
const list: Record<string, any>[] = []
|
||||
for (const item of items.value) {
|
||||
const detailId = Number(item.id) || 0
|
||||
if (!isLocationTask.value) {
|
||||
list.push({ ...item, flat_key: `d${detailId}`, detail_id: detailId, item })
|
||||
continue
|
||||
}
|
||||
const stocks = rowStocks(item)
|
||||
if (!stocks.length) {
|
||||
list.push({ ...item, flat_key: `d${detailId}`, detail_id: detailId, item })
|
||||
continue
|
||||
}
|
||||
for (const stock of stocks) {
|
||||
list.push({
|
||||
...item,
|
||||
flat_key: `d${detailId}:s${stock.stock_id}`,
|
||||
detail_id: detailId,
|
||||
item,
|
||||
stock,
|
||||
item_code: stock.item_code ?? null,
|
||||
item_name: stock.item_name ?? null,
|
||||
spec: stock.spec ?? null,
|
||||
batch_no: stock.batch_no ?? null,
|
||||
system_quantity: stock.system_quantity ?? null,
|
||||
checked_quantity: stock.checked_quantity ?? null,
|
||||
diff_quantity: stock.diff_quantity ?? null
|
||||
})
|
||||
}
|
||||
}
|
||||
return list
|
||||
})
|
||||
|
||||
function hasQuantity(value: unknown): boolean {
|
||||
if (value === undefined || value === null || (value as any) === '') return false
|
||||
return Number.isFinite(Number(value))
|
||||
@ -363,18 +331,16 @@ const emptyText = computed(() =>
|
||||
: '暂无盘点明细'
|
||||
)
|
||||
|
||||
/** 已填写实盘数量的行(商品行按明细 / 库位行按明细+商品) */
|
||||
/** 已填写实盘数量的行(库位行按明细+商品 / 商品行按明细) */
|
||||
const dirtyRows = computed<ReportTarget[]>(() => {
|
||||
const list: ReportTarget[] = []
|
||||
for (const item of items.value) {
|
||||
if (isLocationTask.value) {
|
||||
for (const stock of rowStocks(item)) {
|
||||
if (hasQuantity(stockQuantityMap[stockKey(item.id, stock.stock_id)])) {
|
||||
list.push({ item, stock })
|
||||
}
|
||||
for (const row of flatRows.value) {
|
||||
if (row.stock) {
|
||||
if (hasQuantity(stockQuantityMap[stockKey(row.item.id, row.stock.stock_id)])) {
|
||||
list.push({ item: row.item, stock: row.stock })
|
||||
}
|
||||
} else if (hasQuantity(quantityMap[String(item.id)])) {
|
||||
list.push({ item })
|
||||
} else if (!isLocationTask.value && hasQuantity(quantityMap[String(row.item.id)])) {
|
||||
list.push({ item: row.item })
|
||||
}
|
||||
}
|
||||
return list
|
||||
@ -394,26 +360,60 @@ useResizeObserver(tableHostRef, (entries) => {
|
||||
if (h >= 120) tableHeight.value = Math.floor(h)
|
||||
})
|
||||
|
||||
const pagedItems = computed(() => {
|
||||
const pagedRows = computed(() => {
|
||||
const start = (page.value - 1) * pageSize.value
|
||||
return items.value.slice(start, start + pageSize.value)
|
||||
return flatRows.value.slice(start, start + pageSize.value)
|
||||
})
|
||||
|
||||
function indexMethod(index: number) {
|
||||
return (page.value - 1) * pageSize.value + index + 1
|
||||
}
|
||||
|
||||
/**
|
||||
* 平铺后按明细合并「明细类型 / 库位」单元格(仅库位类任务、仅当前页内)
|
||||
* 首个同明细行返回 [跨行数, 1],其余返回 [0, 0](不渲染)
|
||||
*/
|
||||
function spanMethod({ rowIndex, column }: any): number[] | undefined {
|
||||
if (!isLocationTask.value) return undefined
|
||||
const label = String(column?.label ?? '')
|
||||
if (label !== '明细类型' && label !== '库位') return undefined
|
||||
const rows = pagedRows.value
|
||||
const row = rows[rowIndex]
|
||||
if (!row) return undefined
|
||||
const prev = rows[rowIndex - 1]
|
||||
if (prev && prev.detail_id === row.detail_id) return [0, 0]
|
||||
let count = 1
|
||||
for (let i = rowIndex + 1; i < rows.length; i += 1) {
|
||||
if (rows[i]?.detail_id === row.detail_id) count += 1
|
||||
else break
|
||||
}
|
||||
return [count, 1]
|
||||
}
|
||||
|
||||
function handlePageChange() {
|
||||
nextTick(() => tableRef.value?.setScrollTop?.(0))
|
||||
}
|
||||
|
||||
/** 展开/收起库位行(展开行内才有按商品上报的入口) */
|
||||
function toggleExpand(row: Record<string, any>) {
|
||||
tableRef.value?.toggleRowExpansion?.(row)
|
||||
/** 该行是否可填实盘数量并上报(库位行需有对应商品库存;商品行直接可填) */
|
||||
function isReportableRow(row: Record<string, any>): boolean {
|
||||
if (!canReport.value) return false
|
||||
return isLocationTask.value ? Boolean(row?.stock) : true
|
||||
}
|
||||
|
||||
function isRowExpanded(row: Record<string, any>): boolean {
|
||||
return Boolean(tableRef.value?.store?.states?.expandRows?.[String(row?.id)])
|
||||
/** 该行当前的实盘输入值(库位行按明细+商品,商品行按明细) */
|
||||
function rowQuantity(row: Record<string, any>): number | undefined {
|
||||
return row?.stock
|
||||
? stockQuantityMap[stockKey(row.item.id, row.stock.stock_id)]
|
||||
: quantityMap[String(row.item.id)]
|
||||
}
|
||||
|
||||
function setRowQuantity(row: Record<string, any>, value: number | undefined) {
|
||||
if (row?.stock) stockQuantityMap[stockKey(row.item.id, row.stock.stock_id)] = value
|
||||
else quantityMap[String(row.item.id)] = value
|
||||
}
|
||||
|
||||
function onRowQuantityChange(row: Record<string, any>, value: number | undefined | null) {
|
||||
setRowQuantity(row, value === null ? undefined : value)
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
@ -450,18 +450,34 @@ async function loadItems() {
|
||||
}
|
||||
}
|
||||
|
||||
/** 明细已盘库位编码(location_codes 优先,其次 locations 兜底;剔除「无库位」分组的空串/null) */
|
||||
/** 明细自身的库位编码(库位行 rows[].location_code;商品行与「无库位」分组为空) */
|
||||
function ownLocationCode(item: Record<string, any>): string {
|
||||
const code = item?.location_code
|
||||
return code === null || code === undefined || String(code).trim() === '' ? '' : String(code)
|
||||
}
|
||||
|
||||
/**
|
||||
* 明细库位编码集合
|
||||
*
|
||||
* - 结果行(stock.check.result):取 location_codes,其次 locations 兜底
|
||||
* - 范围行(stock.check.detail,未开始作业阶段):无聚合字段,**库位行**(scope_type=location)
|
||||
* 取自身 location_code(否则库位列显示「—」,detail 的库位行只带 location_code)
|
||||
* 「无库位」分组的空串/null 一律剔除;商品行不掺入自身预设库位
|
||||
*/
|
||||
function resolveLocationCodes(item: Record<string, any>): string[] {
|
||||
const raw = Array.isArray(item?.location_codes) && item.location_codes.length
|
||||
? item.location_codes
|
||||
: Array.isArray(item?.locations)
|
||||
? item.locations.map((loc: any) => loc?.location_code)
|
||||
: []
|
||||
return [...new Set(
|
||||
raw
|
||||
.filter((code: unknown) => code !== null && code !== undefined && String(code).trim() !== '')
|
||||
.map((code: any) => String(code))
|
||||
)]
|
||||
const codes = raw
|
||||
.filter((code: unknown) => code !== null && code !== undefined && String(code).trim() !== '')
|
||||
.map((code: any) => String(code))
|
||||
|
||||
const own = item?.scope_type === 'location' ? ownLocationCode(item) : ''
|
||||
if (own && !codes.includes(own)) codes.push(own)
|
||||
|
||||
return [...new Set(codes)]
|
||||
}
|
||||
|
||||
/** 是否存在「无库位」分组的记录(该分组库中存空串,接口返回归一为 null) */
|
||||
@ -579,7 +595,7 @@ async function reportRow(item: Record<string, any>) {
|
||||
emit('changed')
|
||||
}
|
||||
|
||||
/** 展开行内上报(库位行的某个商品) */
|
||||
/** 行内上报(库位行的某个商品;report 需要 stock_id) */
|
||||
async function reportStock(item: Record<string, any>, stock: Record<string, any>) {
|
||||
const ok = await doReport({ item, stock })
|
||||
if (!ok) return
|
||||
@ -587,6 +603,12 @@ async function reportStock(item: Record<string, any>, stock: Record<string, any>
|
||||
emit('changed')
|
||||
}
|
||||
|
||||
/** 平铺行上报:有商品按商品上报,商品行直接按明细上报 */
|
||||
async function reportFlatRow(row: Record<string, any>) {
|
||||
if (row?.stock) await reportStock(row.item, row.stock)
|
||||
else await reportRow(row.item)
|
||||
}
|
||||
|
||||
/** 批量上报:逐行串行提交,避免并发写同一盘点单 */
|
||||
async function reportDirty() {
|
||||
const targets = [...dirtyRows.value]
|
||||
@ -750,14 +772,7 @@ watch(
|
||||
}
|
||||
}
|
||||
|
||||
/* 库位行展开区:内层商品表 */
|
||||
.stock-expand {
|
||||
padding: 4px 12px;
|
||||
|
||||
.quantity-input {
|
||||
width: 110px;
|
||||
}
|
||||
}
|
||||
/* 库位行内的商品已平铺到主表,无需展开区样式 */
|
||||
|
||||
.diff-text {
|
||||
color: #606266;
|
||||
|
||||
@ -89,7 +89,7 @@ function getRowData(): Record<string, any> | null {
|
||||
|
||||
/** 解析显示值:format 格式化 > translateField 翻译 > 原始值 */
|
||||
function resolveDisplayValue(field: DetailFieldConfig, value: any): string {
|
||||
// 后端时间字段多为时间戳,需按配置格式化(created_at/start_time/end_time=datetime,check_date=date);
|
||||
// 后端时间字段多为时间戳/ISO 串,需按配置格式化(created_at/start_time/end_time=datetime);
|
||||
// 字段配置里没带 format 时回退读 FIELD_DICT,避免旧配置/自定义 detailConfig 导致时间戳直出
|
||||
const format = field.format ?? FIELD_DICT[field.key]?.slot?.format
|
||||
if (format === 'datetime') {
|
||||
@ -101,7 +101,8 @@ function resolveDisplayValue(field: DetailFieldConfig, value: any): string {
|
||||
if (field.translateField) {
|
||||
return translate(field.translateField, value)
|
||||
}
|
||||
return value ?? '—'
|
||||
// 空值统一显示 —(与列表一致)
|
||||
return value === undefined || value === null || value === '' ? '—' : value
|
||||
}
|
||||
|
||||
/** 格式化 pre 渲染值:数组/对象转 JSON 字符串 */
|
||||
|
||||
@ -8,6 +8,8 @@
|
||||
* 列表 stock.check.list → 本文件 tabPages[].api.list
|
||||
* 详情 stock.check.detail → CheckItemsPanel(明细面板自行拉取)
|
||||
* 新建 stock.check.create → pages/CheckFormDialog.vue
|
||||
* 定式清单 stock.check.patternList → pages/CheckPatternDialog.vue(快速创建)
|
||||
* 快速创建 stock.check.patternCreate → pages/CheckPatternDialog.vue(按定式创建,免填日期)
|
||||
* 加明细 stock.check.addDetail → pages/CheckStockPickerDialog.vue
|
||||
* 上报 stock.check.report → CheckItemsPanel(行内 / 批量上报,覆盖式)
|
||||
* 记录列表 stock.check.recordList → CheckRecordsPanel(作业记录页签)
|
||||
@ -144,10 +146,19 @@ export interface FieldDefinition {
|
||||
key: string
|
||||
label: string
|
||||
scanBox: {
|
||||
type: 'text' | 'select' | 'daterange' | 'number'
|
||||
type: 'text' | 'select' | 'daterange' | 'datetimerange' | 'number'
|
||||
group?: string
|
||||
/** 支持数组或 ref(ref 由 resolveTabConfig 解包,保证选项异步加载后仍响应式) */
|
||||
options?: { label: string; value: any }[] | any
|
||||
/** 日期/日期时间范围占位提示(daterange 类型专用) */
|
||||
startPlaceholder?: string
|
||||
endPlaceholder?: string
|
||||
/** 可用操作符(ScanBox 用;只配一项时不出操作符下拉) */
|
||||
operators?: string[]
|
||||
/** 默认操作符(不配时取 ScanBox 内置默认:文本 eq / 区间 between) */
|
||||
defaultOperator?: string
|
||||
/** 隐藏操作符下拉(配合单一项 operators) */
|
||||
hideOperator?: boolean
|
||||
} | null
|
||||
table: {
|
||||
minWidth?: number
|
||||
@ -207,6 +218,11 @@ export const VALUE_MAPS: Record<string, Record<string, string>> = {
|
||||
open: '明盘',
|
||||
blind: '盲盘'
|
||||
},
|
||||
/** 明细行形态 scope_type(明细行的类型:商品行 / 库位行) */
|
||||
scope_type: {
|
||||
goods: '商品',
|
||||
location: '库位'
|
||||
},
|
||||
/** 明细行状态(stock.check.detail 的 rows[].status:checked=有作业记录 / unchecked=未盘) */
|
||||
check_item_status: {
|
||||
unchecked: '未盘',
|
||||
@ -354,11 +370,17 @@ export const TAG_RESOLVERS: Record<string, (val: any) => string> = {
|
||||
// 二、FIELD_DICT 实例 — 在此定义页面所需的所有字段
|
||||
// ============================================================
|
||||
export const FIELD_DICT: Record<string, FieldDefinition> = {
|
||||
/** 关键字(对盘点单号 / 盘点名称模糊匹配,对应 where.keyword) */
|
||||
/** 关键字(对盘点单号 / 盘点名称模糊匹配,对应 where.keyword = { operator: 'like', value, type: 'text' }) */
|
||||
keyword: {
|
||||
key: 'keyword',
|
||||
label: '盘点单号/名称',
|
||||
scanBox: { type: 'text', group: SCANBOX_GROUPS.basic },
|
||||
scanBox: {
|
||||
type: 'text',
|
||||
group: SCANBOX_GROUPS.basic,
|
||||
operators: ['like'],
|
||||
defaultOperator: 'like',
|
||||
hideOperator: true
|
||||
},
|
||||
table: null,
|
||||
slot: null
|
||||
},
|
||||
@ -388,14 +410,16 @@ export const FIELD_DICT: Record<string, FieldDefinition> = {
|
||||
type: {
|
||||
key: 'type',
|
||||
label: '盘点范围',
|
||||
scanBox: null,
|
||||
// 范围筛选(value 为英文枚举,直接作为 where.type 回传)
|
||||
scanBox: { type: 'select', group: SCANBOX_GROUPS.basic, options: getOptions('type') },
|
||||
table: { minWidth: 100, align: 'center' },
|
||||
slot: { type: 'tag', tagType: 'info', translateField: 'type' }
|
||||
},
|
||||
mode: {
|
||||
key: 'mode',
|
||||
label: '盘点方式',
|
||||
scanBox: null,
|
||||
// 方式筛选(value 为英文枚举,直接作为 where.mode 回传)
|
||||
scanBox: { type: 'select', group: SCANBOX_GROUPS.basic, options: getOptions('mode') },
|
||||
table: { minWidth: 100, align: 'center' },
|
||||
slot: { type: 'tag', tagType: 'info', translateField: 'mode' }
|
||||
},
|
||||
@ -435,14 +459,6 @@ export const FIELD_DICT: Record<string, FieldDefinition> = {
|
||||
table: { minWidth: 90, align: 'center' },
|
||||
slot: null
|
||||
},
|
||||
check_date: {
|
||||
key: 'check_date',
|
||||
label: '盘点日期',
|
||||
scanBox: null,
|
||||
table: { minWidth: 110, align: 'center' },
|
||||
// 后端返回时间戳,需按「日期」展示(YYYY-MM-DD)
|
||||
slot: { type: 'text', format: 'date' }
|
||||
},
|
||||
creator_name: {
|
||||
key: 'creator_name',
|
||||
label: '创建人',
|
||||
@ -450,27 +466,53 @@ export const FIELD_DICT: Record<string, FieldDefinition> = {
|
||||
table: { minWidth: 100 },
|
||||
slot: null
|
||||
},
|
||||
/** 货主名称(列表行回包字段 store_name,仅 type=store 等场景有值) */
|
||||
store_name: {
|
||||
key: 'store_name',
|
||||
label: '货主名称',
|
||||
scanBox: null,
|
||||
table: { minWidth: 110, showOverflowTooltip: true },
|
||||
slot: null,
|
||||
detailLabel: '货主名称'
|
||||
},
|
||||
created_at: {
|
||||
key: 'created_at',
|
||||
label: '创建时间',
|
||||
scanBox: null,
|
||||
// 精确到时分秒的范围筛选(ScanBox 默认取 00:00:00 ~ 23:59:59)
|
||||
// → where.created_at = { operator: 'between', value: ['2026-10-01 00:00:00', '2026-10-01 23:59:59'], type: 'datetimerange' }
|
||||
scanBox: {
|
||||
type: 'datetimerange',
|
||||
group: SCANBOX_GROUPS.time,
|
||||
startPlaceholder: '开始时间',
|
||||
endPlaceholder: '结束时间'
|
||||
},
|
||||
table: { minWidth: 165 },
|
||||
slot: { type: 'text', format: 'datetime' }
|
||||
},
|
||||
start_time: {
|
||||
key: 'start_time',
|
||||
label: '开始时间',
|
||||
scanBox: null,
|
||||
table: null,
|
||||
// 仅详情面板展示,后端返回时间戳
|
||||
scanBox: {
|
||||
type: 'datetimerange',
|
||||
group: SCANBOX_GROUPS.time,
|
||||
startPlaceholder: '开始时间',
|
||||
endPlaceholder: '结束时间'
|
||||
},
|
||||
table: { minWidth: 165 },
|
||||
// 后端返回时间戳/ISO 串,按 YYYY-MM-DD HH:mm:ss 展示;未开始盘点时为 —
|
||||
slot: { type: 'text', format: 'datetime' }
|
||||
},
|
||||
end_time: {
|
||||
key: 'end_time',
|
||||
label: '结束时间',
|
||||
scanBox: null,
|
||||
table: null,
|
||||
// 仅详情面板展示,后端返回时间戳
|
||||
scanBox: {
|
||||
type: 'datetimerange',
|
||||
group: SCANBOX_GROUPS.time,
|
||||
startPlaceholder: '开始时间',
|
||||
endPlaceholder: '结束时间'
|
||||
},
|
||||
table: { minWidth: 165 },
|
||||
// 后端返回时间戳/ISO 串,按 YYYY-MM-DD HH:mm:ss 展示;未完成时为 —
|
||||
slot: { type: 'text', format: 'datetime' }
|
||||
},
|
||||
remark: {
|
||||
@ -657,6 +699,13 @@ export function resolveTabConfig(raw: TabPageRawConfig): TabPageConfig {
|
||||
? (isRef(def.scanBox.options) ? def.scanBox.options.value : [...def.scanBox.options])
|
||||
: undefined,
|
||||
group: def.scanBox.group,
|
||||
// 日期范围占位提示(daterange 专用,ScanBox 未传时自带上限默认文案)
|
||||
startPlaceholder: def.scanBox.startPlaceholder,
|
||||
endPlaceholder: def.scanBox.endPlaceholder,
|
||||
// 操作符配置(不配时用 ScanBox 内置默认)
|
||||
operators: def.scanBox.operators,
|
||||
defaultOperator: def.scanBox.defaultOperator,
|
||||
hideOperator: def.scanBox.hideOperator,
|
||||
required: (def.scanBox as any).required
|
||||
})
|
||||
}
|
||||
@ -674,11 +723,19 @@ export function resolveTabConfig(raw: TabPageRawConfig): TabPageConfig {
|
||||
}
|
||||
|
||||
// 展开列插槽
|
||||
// 注:未显式配置 slot 的普通列也注册为「纯文本」插槽,统一交给 ColumnCellRenderer 渲染,
|
||||
// 否则 UpperTable 会直接输出原值,null/空串会显示为空白(需求:没有的显示 —)。
|
||||
// 带 copyAction 的列(如盘点单号)保持默认渲染,避免丢失点击复制。
|
||||
const columnSlots: Record<string, ColumnSlotConfig> = {}
|
||||
for (const key of raw.tableColumnKeys) {
|
||||
const def = FIELD_DICT[key]
|
||||
if (!def || !def.slot) continue
|
||||
columnSlots[def.key] = { ...def.slot }
|
||||
if (!def || !def.table) continue
|
||||
if (def.slot) {
|
||||
columnSlots[def.key] = { ...def.slot }
|
||||
continue
|
||||
}
|
||||
if (def.table.copyAction) continue
|
||||
columnSlots[def.key] = { type: 'text' }
|
||||
}
|
||||
|
||||
// 展开明细面板配置
|
||||
@ -736,27 +793,130 @@ export function resolveTabConfig(raw: TabPageRawConfig): TabPageConfig {
|
||||
// ============================================================
|
||||
// 九、buildWhereConditions — 将 ScanBox 条件转为 API where 参数
|
||||
// ============================================================
|
||||
// 后端 where 条件协议(见 stock-stockWarehouse-query-rules.md,与其他 storage 列表一致):
|
||||
// where: { <字段>: { operator, value, type? } }
|
||||
// 例:{ keyword: { operator: 'like', value: 'PD2026', type: 'text' },
|
||||
// status: { operator: 'eq', value: 'created', type: 'text' },
|
||||
// start_time: { operator: 'between', value: ['2026-10-01 00:00:00', '2026-10-01 23:59:59'], type: 'datetimerange' } }
|
||||
|
||||
/** 后端 where 条件支持的值类型(其他类型会被忽略,统一按字段类型推导) */
|
||||
const WHERE_VALUE_TYPES = new Set(['text', 'number', 'boolean', 'date', 'daterange', 'datetimerange'])
|
||||
|
||||
/** 无需填值的操作符 */
|
||||
const NULLISH_OPERATORS = new Set(['isnull', 'isnotnull'])
|
||||
|
||||
function isEmptyConditionValue(value: any): boolean {
|
||||
if (value === undefined || value === null || value === '') return true
|
||||
if (Array.isArray(value) && value.length === 0) return true
|
||||
return false
|
||||
}
|
||||
|
||||
/** 是否为 ScanBox 归一后的条件对象({ value, operator, type, ... }) */
|
||||
function isConditionObject(cond: any): boolean {
|
||||
return (
|
||||
Boolean(cond) &&
|
||||
typeof cond === 'object' &&
|
||||
!Array.isArray(cond) &&
|
||||
('operator' in cond || 'value' in cond || 'type' in cond)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 推导 where 条件的 type:
|
||||
* 优先用条件自带的类型(ScanBox 会带 'select'/'text'/'daterange' 等伪类型,非协议值则重新推导)
|
||||
*/
|
||||
function resolveWhereType(
|
||||
declaredType: any,
|
||||
fieldType: string | undefined,
|
||||
value: any,
|
||||
operator: string
|
||||
): string {
|
||||
const declared = declaredType === undefined || declaredType === null ? '' : String(declaredType)
|
||||
if (WHERE_VALUE_TYPES.has(declared)) return declared
|
||||
if (fieldType === 'daterange' || fieldType === 'datetimerange') return 'daterange'
|
||||
if (operator === 'between' || operator === 'notbetween') return 'daterange'
|
||||
if (fieldType === 'number' || typeof value === 'number') return 'number'
|
||||
if (fieldType === 'boolean' || typeof value === 'boolean') return 'boolean'
|
||||
return 'text'
|
||||
}
|
||||
|
||||
/** 值映射(FIELD_DICT.filterParamMap:界面值 → 接口值) */
|
||||
function applyFilterParamMap(def: FieldDefinition | undefined, value: any): any {
|
||||
const map = def?.filterParamMap
|
||||
if (!map || Array.isArray(value) || value === undefined || value === null) return value
|
||||
const mapped = map[String(value)]
|
||||
return mapped !== undefined ? mapped : value
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间范围端点补全时分秒:
|
||||
* - 已带时分秒('2026-10-01 09:30:00' / ISO)→ 原样返回
|
||||
* - 仅日期('2026-10-01')→ 开始补 00:00:00、结束补 23:59:59
|
||||
*/
|
||||
function completeRangeTime(value: string, bound: 'start' | 'end'): string {
|
||||
const text = value.trim()
|
||||
if (!text) return ''
|
||||
if (text.includes(':')) return text
|
||||
return `${text.slice(0, 10)} ${bound === 'start' ? '00:00:00' : '23:59:59'}`
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个条件归一化为 `{ operator, value, type }`,空条件返回 null。
|
||||
*
|
||||
* 兼容两种输入:
|
||||
* - ScanBox 自定义筛选:`{ value, operator, type, field, isMultiple }`
|
||||
* - 预设/缓存/代码构造:数组或标量(按字段类型补默认操作符:区间→between,多值→in,其余→eq)
|
||||
*/
|
||||
function normalizeWhereCondition(key: string, cond: any): Record<string, any> | null {
|
||||
const def = FIELD_DICT[key]
|
||||
const fieldType = def?.scanBox?.type
|
||||
const isRangeField = fieldType === 'daterange' || fieldType === 'datetimerange'
|
||||
|
||||
const isObj = isConditionObject(cond)
|
||||
const rawValue: any = isObj ? cond.value : cond
|
||||
const rawOperator = isObj ? String(cond.operator || '') : ''
|
||||
|
||||
// 为空 / 不为空:无需填值
|
||||
if (NULLISH_OPERATORS.has(rawOperator)) {
|
||||
return { operator: rawOperator, value: null, type: resolveWhereType(cond?.type, fieldType, null, rawOperator) }
|
||||
}
|
||||
if (isEmptyConditionValue(rawValue)) return null
|
||||
|
||||
const operator =
|
||||
rawOperator || (Array.isArray(rawValue) ? 'in' : isRangeField ? 'between' : 'eq')
|
||||
|
||||
// 时间范围:值统一归一为 [start, end],只给日期时补全时分秒(开始 00:00:00 / 结束 23:59:59,
|
||||
// 否则 datetime 字段按 'YYYY-MM-DD' 比对会把当天带时分秒的记录全部排除)
|
||||
if (isRangeField || operator === 'between' || operator === 'notbetween') {
|
||||
const range = Array.isArray(rawValue) ? rawValue : [rawValue, rawValue]
|
||||
const start = range[0] === undefined || range[0] === null ? '' : String(range[0]).trim()
|
||||
if (!start) return null
|
||||
const endRaw = range[1] === undefined || range[1] === null || range[1] === '' ? start : String(range[1]).trim()
|
||||
const rangeType =
|
||||
resolveWhereType(cond?.type, fieldType, rawValue, 'between') === 'datetimerange'
|
||||
? 'datetimerange'
|
||||
: 'daterange'
|
||||
const withTime = rangeType === 'datetimerange'
|
||||
return {
|
||||
operator: operator === 'notbetween' ? 'notbetween' : 'between',
|
||||
value: [
|
||||
withTime ? completeRangeTime(start, 'start') : start,
|
||||
withTime ? completeRangeTime(endRaw, 'end') : endRaw
|
||||
],
|
||||
type: rangeType
|
||||
}
|
||||
}
|
||||
|
||||
const value = applyFilterParamMap(def, rawValue)
|
||||
return { operator, value, type: resolveWhereType(cond?.type, fieldType, value, operator) }
|
||||
}
|
||||
|
||||
/** 将 ScanBox 条件对象转为后端 where 参数(`{ <字段>: { operator, value, type } }`) */
|
||||
export function buildWhereConditions(rawConditions: Record<string, any>): Record<string, any> {
|
||||
const where: Record<string, any> = {}
|
||||
for (const [key, cond] of Object.entries(rawConditions || {})) {
|
||||
let value: any = undefined
|
||||
if (cond && typeof cond === 'object' && 'operator' in cond) {
|
||||
value = (cond as any).value
|
||||
} else if (cond !== undefined && cond !== null && cond !== '') {
|
||||
value = Array.isArray(cond) ? cond[0] ?? '' : cond
|
||||
}
|
||||
if (value === undefined || value === null || value === '' || (Array.isArray(value) && value.length === 0)) {
|
||||
continue
|
||||
}
|
||||
const def = FIELD_DICT[key]
|
||||
if (def?.filterParamMap) {
|
||||
const mapped = def.filterParamMap[String(value)]
|
||||
if (mapped !== undefined) {
|
||||
where[key] = mapped
|
||||
continue
|
||||
}
|
||||
}
|
||||
where[key] = value
|
||||
const normalized = normalizeWhereCondition(key, cond)
|
||||
if (normalized) where[key] = normalized
|
||||
}
|
||||
return where
|
||||
}
|
||||
@ -807,6 +967,20 @@ export const TOOLBAR_BUTTONS: Record<string, ToolbarButtonConfig> = {
|
||||
size: 'small',
|
||||
action: 'openCreateCheck'
|
||||
},
|
||||
/**
|
||||
* 快速创建(stock.check.patternList + stock.check.patternCreate):
|
||||
* 选择内置盘点定式一键生成盘点任务(后端按定式收集盘点对象),免填盘点日期,
|
||||
* 创建后主表直接进入「待审核」。
|
||||
*/
|
||||
patternCreate: {
|
||||
key: 'patternCreate',
|
||||
label: '快速创建',
|
||||
category: 'function',
|
||||
type: 'primary',
|
||||
plain: true,
|
||||
size: 'small',
|
||||
action: 'openPatternCreate'
|
||||
},
|
||||
/**
|
||||
* 导出选中(stock.check.export):导出表格中勾选的盘点单(单次上限 50)。
|
||||
* 无勾选时不置灰,点击后提示先勾选。
|
||||
@ -895,14 +1069,16 @@ const TABLE_COLUMN_KEYS = [
|
||||
'title',
|
||||
'type',
|
||||
'mode',
|
||||
'store_name',
|
||||
'status',
|
||||
'detail_status',
|
||||
'total_items',
|
||||
'checked_items',
|
||||
'diff_items',
|
||||
'check_date',
|
||||
'creator_name',
|
||||
'created_at',
|
||||
'start_time',
|
||||
'end_time',
|
||||
'operation'
|
||||
]
|
||||
|
||||
@ -911,12 +1087,13 @@ const DETAIL_SECTIONS = [
|
||||
{
|
||||
title: '基本信息',
|
||||
columnCount: 3,
|
||||
fieldKeys: ['check_no', 'title', 'type', 'mode', 'status', 'detail_status', 'store_id']
|
||||
fieldKeys: ['check_no', 'title', 'type', 'mode', 'status', 'detail_status', 'store_id', 'store_name']
|
||||
},
|
||||
{
|
||||
title: '进度信息',
|
||||
columnCount: 3,
|
||||
fieldKeys: ['total_items', 'checked_items', 'diff_items', 'creator_name', 'check_date']
|
||||
// 注:check_date 已随接口更新移除(list 不再返回「盘点日期」)
|
||||
fieldKeys: ['total_items', 'checked_items', 'diff_items', 'creator_name']
|
||||
},
|
||||
{
|
||||
title: '时间信息',
|
||||
@ -1013,8 +1190,10 @@ function buildCheckTab(
|
||||
name,
|
||||
label,
|
||||
scanBoxCacheKey: `stock-check-${name}`,
|
||||
// 筛选:盘点单号/名称(where.keyword)、盘点状态(where.status)、货主(where.store_id)
|
||||
scanBoxFieldKeys: ['keyword', 'status', 'store_id'],
|
||||
// 筛选:盘点单号/名称(where.keyword)、盘点状态(where.status)、货主(where.store_id)、
|
||||
// 盘点范围(where.type)、盘点方式(where.mode)、
|
||||
// 创建/开始/结束时间范围(where.<field> = { operator: 'between', value: ['YYYY-MM-DD HH:mm:ss', ...], type: 'datetimerange' })
|
||||
scanBoxFieldKeys: ['keyword', 'status', 'store_id', 'type', 'mode', 'created_at', 'start_time', 'end_time'],
|
||||
tableColumnKeys: TABLE_COLUMN_KEYS,
|
||||
upperTableDefaults: {
|
||||
title: '盘点单列表',
|
||||
|
||||
@ -2,11 +2,17 @@
|
||||
库存盘点(storage/stockcheck)— 配置驱动页面(views/mode 模板 v2)
|
||||
|
||||
接口:库存盘点模块 stock.check(详见 src/api/stock.check/stock.check.ts)
|
||||
- 列表/详情/新建/加明细/上报/提交/审核/完成/取消/批量删除/导出选中+导出进度
|
||||
- 列表/详情/新建/快速创建(按盘点定式)/加明细/上报/提交/审核/完成/取消/批量删除/导出选中+导出进度
|
||||
|
||||
快速创建(工具栏「快速创建」→ pages/CheckPatternDialog.vue):
|
||||
- stock.check.patternList 拉取 5 个内置定式(空库位/错发/临期/静态/预警),
|
||||
选定式 + 输入盘点名称即可创建(无需填盘点日期,也无需手选盘点范围);
|
||||
后端按定式自动收集盘点对象(goods 型→商品行 / location 型→库位行),
|
||||
创建后主表直接为 submitted(待审核),故不再引导手动添加明细。
|
||||
|
||||
页面结构:
|
||||
┌──────────┬──────────────────────────────────────────────┐
|
||||
│ ScanBox │ OrderToolbarButtonGroup(刷新/新建盘点/导出选中…) │
|
||||
│ ScanBox │ OrderToolbarButtonGroup(刷新/新建盘点/快速创建/导出选中…) │
|
||||
│(单号/状态│ ┌──────────────────────────────────────────┐│
|
||||
│ /货主) │ │ UpperTable(盘点单列表 + 操作列) ││
|
||||
│ │ ├──────────────────────────────────────────┤│
|
||||
@ -222,6 +228,8 @@
|
||||
|
||||
<!-- ===== 功能弹窗(pages/ 目录下的组件) ===== -->
|
||||
<CheckFormDialog v-model:visible="createVisible" @success="handleCreateSuccess" />
|
||||
<!-- 快速创建(stock.check.patternList + stock.check.patternCreate,免填盘点日期) -->
|
||||
<CheckPatternDialog v-model:visible="patternVisible" @success="handlePatternCreateSuccess" />
|
||||
<CheckStockPickerDialog
|
||||
v-model:visible="pickerVisible"
|
||||
:task-id="pickerTaskId"
|
||||
@ -273,11 +281,13 @@ import {
|
||||
isCheckApiSuccess,
|
||||
isLocationScopeType,
|
||||
loadStoreOptions,
|
||||
buildWhereConditions,
|
||||
type TabPageConfig,
|
||||
type DetailTabConfig,
|
||||
type ToolbarButtonConfig,
|
||||
} from './config/template-config'
|
||||
import CheckFormDialog from './pages/CheckFormDialog.vue'
|
||||
import CheckPatternDialog from './pages/CheckPatternDialog.vue'
|
||||
import CheckStockPickerDialog from './pages/CheckStockPickerDialog.vue'
|
||||
import {
|
||||
stockCheckAudit,
|
||||
@ -443,6 +453,7 @@ const toolbarActionMap: Record<string, () => void> = {
|
||||
openColumnConfigPanel: () => { upperTableRef.value?.openColumnConfig?.() },
|
||||
toggleDetailVisible: () => { detailVisible.value = !detailVisible.value },
|
||||
openCreateCheck: () => { createVisible.value = true },
|
||||
openPatternCreate: () => { patternVisible.value = true },
|
||||
handleExport: () => { void doExport() },
|
||||
handleBatchDelete: () => { void doBatchDelete() }
|
||||
}
|
||||
@ -678,7 +689,8 @@ const loadData = async () => {
|
||||
})
|
||||
: {
|
||||
pagination: { page: pagination.currentPage, pageSize: pagination.pageSize },
|
||||
where: conditions
|
||||
// 兜底:同样需套用后端 where 协议 `{ operator, value, type }`
|
||||
where: buildWhereConditions(conditions)
|
||||
}
|
||||
|
||||
const res = await cfg.api.list(params)
|
||||
@ -841,6 +853,8 @@ const upperPaneFullStyle = computed(() => ({
|
||||
// 弹窗:新建盘点 / 添加盘点商品
|
||||
// ============================================================
|
||||
const createVisible = ref(false)
|
||||
/** 快速创建(按盘点定式)弹窗 */
|
||||
const patternVisible = ref(false)
|
||||
const pickerVisible = ref(false)
|
||||
const pickerTask = ref<Record<string, any> | null>(null)
|
||||
const pickerTaskId = computed(() => Number(pickerTask.value?.id) || 0)
|
||||
@ -886,6 +900,14 @@ async function handleCreateSuccess(task: { id: number; check_no: string; title:
|
||||
openStockPicker({ id: task.id, check_no: task.check_no, title: task.title, type: task.type })
|
||||
}
|
||||
|
||||
/**
|
||||
* 快速创建成功:按定式创建的盘点单已自动收集盘点对象并直接进入「待审核」,
|
||||
* 无需再引导添加明细,仅刷新列表与详情。
|
||||
*/
|
||||
async function handlePatternCreateSuccess() {
|
||||
await reloadAndResyncDetail()
|
||||
}
|
||||
|
||||
/** 添加明细成功:刷新列表(total_items 已变化) */
|
||||
async function handleItemsAdded() {
|
||||
await reloadAndResyncDetail()
|
||||
|
||||
@ -6,10 +6,11 @@
|
||||
- type 盘点范围:all 按库位(缺省,未传库位时后端自动拉取全仓启用库位)
|
||||
/ location 按库位(指定库位)/ store 按货主按商品 / goods 按商品
|
||||
—— all/location 生成「库位明细行」,store/goods 生成「商品明细行」
|
||||
- mode 盘点方式:open 明盘(缺省,可见账面数量)/ blind 盲盘
|
||||
- mode 盘点方式:open 明盘 / blind 盲盘
|
||||
—— 库位类(all / location)固定为 blind 盲盘且不可更改;商品类(store / goods)默认明盘
|
||||
- store_id 货主ID(type=store 时必填)
|
||||
- check_date 盘点日期(必填,须可被 Date 解析)
|
||||
- remark 备注
|
||||
盘点日期(check_date)前端**统一不传**,由服务端缺省为当天。
|
||||
warehouse_id 由服务端注入,前端不传。
|
||||
-->
|
||||
<template>
|
||||
@ -66,21 +67,14 @@
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="盘点方式" prop="mode">
|
||||
<el-radio-group v-model="form.mode">
|
||||
<el-radio-group v-model="form.mode" :disabled="isLocationType">
|
||||
<el-radio value="open">明盘</el-radio>
|
||||
<el-radio value="blind">盲盘</el-radio>
|
||||
</el-radio-group>
|
||||
<span v-if="form.mode === 'blind'" class="form-tip">盲盘:盘点作业时前端不显示账面数量</span>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="盘点日期" prop="check_date">
|
||||
<el-date-picker
|
||||
v-model="form.check_date"
|
||||
type="date"
|
||||
value-format="YYYY-MM-DD"
|
||||
placeholder="请选择盘点日期"
|
||||
style="width: 100%"
|
||||
/>
|
||||
<span v-if="isLocationType" class="form-tip form-tip--lock">
|
||||
库位盘点固定为盲盘(不可更改):盘点作业时前端不显示账面数量
|
||||
</span>
|
||||
<span v-else-if="form.mode === 'blind'" class="form-tip">盲盘:盘点作业时前端不显示账面数量</span>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="备注" prop="remark">
|
||||
@ -133,30 +127,21 @@ const emit = defineEmits<{
|
||||
const formRef = ref<FormInstance>()
|
||||
const submitting = ref(false)
|
||||
|
||||
function todayString() {
|
||||
const d = new Date()
|
||||
const pad = (n: number) => String(n).padStart(2, '0')
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`
|
||||
}
|
||||
|
||||
const form = reactive<{
|
||||
title: string
|
||||
type: StockCheckType
|
||||
store_id: number | undefined
|
||||
mode: StockCheckMode
|
||||
check_date: string
|
||||
remark: string
|
||||
}>({
|
||||
title: '',
|
||||
type: 'all',
|
||||
store_id: undefined,
|
||||
mode: 'open',
|
||||
check_date: todayString(),
|
||||
mode: 'blind',
|
||||
remark: ''
|
||||
})
|
||||
|
||||
const rules: FormRules = {
|
||||
check_date: [{ required: true, message: '请选择盘点日期', trigger: 'change' }],
|
||||
store_id: [
|
||||
{
|
||||
validator: (_rule, value, callback) => {
|
||||
@ -170,6 +155,14 @@ const rules: FormRules = {
|
||||
|
||||
const isLocationType = computed(() => isLocationScopeType(form.type))
|
||||
|
||||
/** 库位类盘点(all/location)固定盲盘、不可更改;切回商品类恢复默认明盘 */
|
||||
watch(
|
||||
() => form.type,
|
||||
(type) => {
|
||||
form.mode = isLocationScopeType(type) ? 'blind' : 'open'
|
||||
}
|
||||
)
|
||||
|
||||
/** 库位类任务创建后要添加的是「库位」而不是「商品」 */
|
||||
const createAlertText = computed(() => {
|
||||
if (!isLocationType.value) {
|
||||
@ -193,8 +186,7 @@ function resetForm() {
|
||||
form.title = ''
|
||||
form.type = 'all'
|
||||
form.store_id = undefined
|
||||
form.mode = 'open'
|
||||
form.check_date = todayString()
|
||||
form.mode = 'blind'
|
||||
form.remark = ''
|
||||
}
|
||||
|
||||
@ -224,7 +216,6 @@ async function handleSubmit() {
|
||||
type: form.type,
|
||||
mode: form.mode,
|
||||
store_id: form.type === 'store' ? form.store_id : undefined,
|
||||
check_date: form.check_date,
|
||||
remark: form.remark.trim() || undefined
|
||||
})
|
||||
if (!isCheckApiSuccess(res)) {
|
||||
@ -257,6 +248,13 @@ async function handleSubmit() {
|
||||
color: #e6a23c;
|
||||
}
|
||||
|
||||
.form-tip--lock {
|
||||
margin-left: 0;
|
||||
width: 100%;
|
||||
line-height: 1.5;
|
||||
color: #909399;
|
||||
}
|
||||
|
||||
.type-tip {
|
||||
width: 100%;
|
||||
margin-top: 2px;
|
||||
|
||||
275
src/views/storage/stockcheck/pages/CheckPatternDialog.vue
Normal file
275
src/views/storage/stockcheck/pages/CheckPatternDialog.vue
Normal file
@ -0,0 +1,275 @@
|
||||
<!--
|
||||
CheckPatternDialog — 快速创建盘点任务(stock.check.patternList + stock.check.patternCreate)
|
||||
|
||||
与 CheckFormDialog(stock.check.create)的区别:
|
||||
- 无需手选盘点范围:直接选「盘点定式」(后端代码注册的 5 个内置定式),
|
||||
由后端按定式收集盘点对象(goods 型 → 商品行明细 / location 型 → 库位行明细)
|
||||
- 无需传入盘点日期(check_date 缺省今天,接口可不传)
|
||||
- 创建后主表状态直接为 submitted(待审核),明细进度 none_checked,不需要再手动加明细
|
||||
|
||||
入参:pattern_id(必填,兼容 patternId 驼峰)+ title/remark(均可选,title 缺省取定式 name)
|
||||
不传 check_date(缺省今天,弹窗不提供日期选择),也不传 mode(由后端按定式决定)。
|
||||
warehouse_id 与创建人由服务端从登录上下文注入,前端不传。
|
||||
-->
|
||||
<template>
|
||||
<el-dialog
|
||||
:model-value="visible"
|
||||
title="快速创建盘点单"
|
||||
width="min(560px, 94vw)"
|
||||
align-center
|
||||
destroy-on-close
|
||||
:close-on-click-modal="false"
|
||||
@update:model-value="handleVisibleChange"
|
||||
@closed="handleClosed"
|
||||
>
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="form"
|
||||
:rules="rules"
|
||||
label-width="90px"
|
||||
size="small"
|
||||
@submit.prevent
|
||||
>
|
||||
<el-form-item label="盘点定式" prop="pattern_id">
|
||||
<el-select
|
||||
v-model="form.pattern_id"
|
||||
:loading="patternLoading"
|
||||
filterable
|
||||
clearable
|
||||
placeholder="输入定式名称筛选,如:临期盘点"
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option
|
||||
v-for="opt in patternOptions"
|
||||
:key="opt.value"
|
||||
:label="opt.label"
|
||||
:value="opt.value"
|
||||
/>
|
||||
</el-select>
|
||||
<div class="type-tip">
|
||||
{{ selectedPattern
|
||||
? (selectedPattern.description || '按该定式自动收集盘点对象,创建后进入待审核。')
|
||||
: '选择定式后由后端自动收集盘点对象(无需手动添加明细)。' }}
|
||||
</div>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="盘点名称" prop="title">
|
||||
<el-input
|
||||
v-model="form.title"
|
||||
maxlength="50"
|
||||
show-word-limit
|
||||
:placeholder="titlePlaceholder"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input v-model="form.remark" type="textarea" :rows="3" maxlength="200" show-word-limit placeholder="可留空" />
|
||||
</el-form-item>
|
||||
|
||||
<el-alert
|
||||
type="info"
|
||||
:closable="false"
|
||||
show-icon
|
||||
:title="createAlertText"
|
||||
/>
|
||||
</el-form>
|
||||
|
||||
<template #footer>
|
||||
<el-button size="small" @click="handleVisibleChange(false)">取消</el-button>
|
||||
<el-button
|
||||
size="small"
|
||||
type="primary"
|
||||
:loading="submitting"
|
||||
:disabled="!form.pattern_id"
|
||||
@click="handleSubmit"
|
||||
>
|
||||
确认创建
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, reactive, ref, watch } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import { isCheckApiSuccess } from '../config/template-config'
|
||||
import {
|
||||
stockCheckPatternCreate,
|
||||
stockCheckPatternList,
|
||||
type StockCheckPattern
|
||||
} from '@/api/stock.check/stock.check'
|
||||
|
||||
defineOptions({ name: 'CheckPatternDialog' })
|
||||
|
||||
const props = defineProps<{ visible: boolean }>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:visible', value: boolean): void
|
||||
/** 创建成功(携创建出的盘点单关键信息;type 用于决定后续添加「商品」还是「库位」) */
|
||||
(e: 'success', task: { id: number; check_no: string; title: string; type: string }): void
|
||||
}>()
|
||||
|
||||
const formRef = ref<FormInstance>()
|
||||
const submitting = ref(false)
|
||||
|
||||
// ===== 定式清单(只拉一次,弹窗间复用) =====
|
||||
const patterns = ref<StockCheckPattern[]>([])
|
||||
const patternLoading = ref(false)
|
||||
let patternLoaded = false
|
||||
|
||||
const patternOptions = computed(() =>
|
||||
patterns.value.map((p) => ({
|
||||
value: String(p.id ?? ''),
|
||||
label: String(p.name ?? p.id ?? ''),
|
||||
description: String(p.description ?? '')
|
||||
}))
|
||||
)
|
||||
|
||||
const selectedPattern = computed<StockCheckPattern | undefined>(() =>
|
||||
patterns.value.find((p) => String(p.id ?? '') === form.pattern_id)
|
||||
)
|
||||
|
||||
const titlePlaceholder = computed(() =>
|
||||
selectedPattern.value?.name ? `留空默认取定式名称:${selectedPattern.value.name}` : '留空默认取定式名称'
|
||||
)
|
||||
|
||||
/** 创建后由后端自动收集盘点对象并进入待审核(与 create 的「空盘点单」不同) */
|
||||
const isLocationPattern = computed(() => String(selectedPattern.value?.type ?? '') === 'location')
|
||||
|
||||
const createAlertText = computed(() =>
|
||||
isLocationPattern.value
|
||||
? '创建后按定式自动收集「库位」盘点对象,盘点单直接进入待审核;无符合条件对象时后端会提示失败。'
|
||||
: '创建后按定式自动收集「商品」盘点对象,盘点单直接进入待审核;无符合条件对象时后端会提示失败。'
|
||||
)
|
||||
|
||||
const form = reactive<{
|
||||
pattern_id: string
|
||||
title: string
|
||||
remark: string
|
||||
}>({
|
||||
pattern_id: '',
|
||||
title: '',
|
||||
remark: ''
|
||||
})
|
||||
|
||||
const rules: FormRules = {
|
||||
pattern_id: [{ required: true, message: '请选择盘点定式', trigger: 'change' }]
|
||||
}
|
||||
|
||||
function handleVisibleChange(value: boolean) {
|
||||
emit('update:visible', value)
|
||||
}
|
||||
|
||||
function handleClosed() {
|
||||
formRef.value?.clearValidate()
|
||||
submitting.value = false
|
||||
}
|
||||
|
||||
function resetForm() {
|
||||
form.pattern_id = ''
|
||||
form.title = ''
|
||||
form.remark = ''
|
||||
}
|
||||
|
||||
/** 拉取定式清单,兼容 {patterns}/{list}/{data:[...]} 等回包形态 */
|
||||
async function loadPatterns() {
|
||||
if (patternLoaded || patternLoading.value) return
|
||||
patternLoading.value = true
|
||||
try {
|
||||
const res: any = await stockCheckPatternList()
|
||||
if (!isCheckApiSuccess(res)) return
|
||||
const raw: any =
|
||||
res?.patterns ??
|
||||
res?.list ??
|
||||
res?.data?.patterns ??
|
||||
res?.data?.list ??
|
||||
(Array.isArray(res?.data) ? res.data : [])
|
||||
patterns.value = Array.isArray(raw)
|
||||
? raw
|
||||
.map((p: any) => ({
|
||||
...p,
|
||||
id: String(p?.id ?? p?.pattern_id ?? ''),
|
||||
name: String(p?.name ?? p?.title ?? p?.id ?? ''),
|
||||
description: String(p?.description ?? p?.desc ?? '')
|
||||
}))
|
||||
.filter((p: StockCheckPattern) => Boolean(p.id))
|
||||
: []
|
||||
} catch (e) {
|
||||
console.error('[stockcheck] 加载盘点定式失败', e)
|
||||
} finally {
|
||||
patternLoading.value = false
|
||||
patternLoaded = true
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.visible,
|
||||
(visible) => {
|
||||
if (!visible) return
|
||||
resetForm()
|
||||
formRef.value?.clearValidate()
|
||||
void loadPatterns()
|
||||
}
|
||||
)
|
||||
|
||||
/** 定式 type → 盘点范围 type(goods=商品行 / location=库位行) */
|
||||
function resolveTaskType(payload: any): string {
|
||||
const fromResponse = String(payload?.type ?? '')
|
||||
if (fromResponse) return fromResponse
|
||||
return isLocationPattern.value ? 'location' : 'goods'
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
if (!formRef.value) return
|
||||
try {
|
||||
await formRef.value.validate()
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
|
||||
submitting.value = true
|
||||
try {
|
||||
const res: any = await stockCheckPatternCreate({
|
||||
pattern_id: form.pattern_id,
|
||||
title: form.title.trim() || undefined,
|
||||
remark: form.remark.trim() || undefined
|
||||
})
|
||||
if (!isCheckApiSuccess(res)) {
|
||||
throw new Error(res?.message || '快速创建盘点单失败')
|
||||
}
|
||||
const data: any = res?.data && (res.data.id || res.data.check_no || res.data.check) ? res.data : res
|
||||
const payload: any = data?.check ?? data
|
||||
const task = {
|
||||
id: Number(payload?.id) || 0,
|
||||
check_no: String(payload?.check_no ?? ''),
|
||||
title: String(payload?.title ?? form.title ?? selectedPattern.value?.name ?? ''),
|
||||
type: resolveTaskType(payload)
|
||||
}
|
||||
ElMessage.success(task.check_no ? `盘点单 ${task.check_no} 创建成功` : '盘点单创建成功')
|
||||
emit('update:visible', false)
|
||||
emit('success', task)
|
||||
} catch (e: any) {
|
||||
console.error('[stockcheck] 快速创建盘点单失败', e)
|
||||
ElMessage.error(e?.message || '快速创建盘点单失败')
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.form-tip {
|
||||
margin-left: 10px;
|
||||
font-size: 12px;
|
||||
color: #e6a23c;
|
||||
}
|
||||
|
||||
.type-tip {
|
||||
width: 100%;
|
||||
margin-top: 2px;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
color: #909399;
|
||||
}
|
||||
</style>
|
||||
131
temp_stockcheck_tail.txt
Normal file
131
temp_stockcheck_tail.txt
Normal file
@ -0,0 +1,131 @@
|
||||
storageQuantityMap,
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* å°†å<E280A0>•æ<E280A2>¡ç›˜ç‚¹æ˜Žç»†æ ¼å¼<C3A5>化为è<C2BA>šå<C5A1>ˆè¾“出行ã€?
|
||||
* 商å“<C3A5>行:è<C5A1>šå<C5A1>ˆä½œä¸šè®°å½•输出已盘数é‡<C3A9>/差异/库ä½<C3A4>列表ç‰ï¼›
|
||||
* 库ä½<C3A4>行:按商å“<C3A5>è<EFBFBD>šå<C5A1>ˆä½œä¸šè®°å½•输å‡?stocks 列表(å<CB86>« wms_storage è´¦é<C2A6>¢ä¸Žå·®å¼‚)ã€?
|
||||
*
|
||||
* @param {Object} params æ ¼å¼<C3A5>化å<E28093>‚æ•°ã€?
|
||||
* @param {Object} params.detailRow 明细原始行�
|
||||
* @param {Map<number, Array<Object>>} params.recordsByDetail 按明细ID分组的作业记录�
|
||||
* @param {Map<number, Object>} params.stockMap 商å“<C3A5>å¿«ç…§æ˜ å°„ã€?
|
||||
* @param {Map<string, number>} params.storageQuantityMap 库ä½<C3A4>商å“<C3A5>è´¦é<C2A6>¢æ•°é‡<C3A9>æ˜ å°„ï¼ˆé”® `${space_id}_${stock_id}`)ã€?
|
||||
* @return {Object} æ ¼å¼<C3A5>化å<E28093>Žçš„æ˜Žç»†è¡Œã€?
|
||||
*/
|
||||
_formatDetailAggregationRow(params = {}) {
|
||||
const { detailRow, recordsByDetail, stockMap, storageQuantityMap } = params;
|
||||
const detailRowId = Number(detailRow.id);
|
||||
const scopeType = (detailRow.scope_type || 'goods') === 'location' ? 'location' : 'goods';
|
||||
const detailRecords = recordsByDetail.get(detailRowId) || [];
|
||||
|
||||
const locationCodes = [ ...new Set(detailRecords
|
||||
.map(record => String(record.location_code || '').trim())
|
||||
.filter(Boolean)) ];
|
||||
const checkers = [ ...new Set(detailRecords
|
||||
.map(record => String(record.checker_name || '').trim())
|
||||
.filter(Boolean)) ];
|
||||
const lastCheckedAt = detailRecords.length > 0
|
||||
? detailRecords[detailRecords.length - 1].checked_at
|
||||
: null;
|
||||
|
||||
// 按库ä½<C3A4>è<EFBFBD>šå<C5A1>ˆä½œä¸šè®°å½•(库ä½<C3A4>为空归入"æ— åº“ä½?分组,location_code ä¸?null),按首æ<E28093>¡è®°å½?id å<>‡åº<C3A5>
|
||||
const locationGroups = new Map();
|
||||
for (const record of detailRecords) {
|
||||
const recordLocationCode = record.location_code !== null && record.location_code !== undefined
|
||||
? String(record.location_code).trim()
|
||||
: '';
|
||||
if (!locationGroups.has(recordLocationCode)) {
|
||||
locationGroups.set(recordLocationCode, {
|
||||
location_id: recordLocationCode ? (Number(record.location_id) || null) : null,
|
||||
location_code: recordLocationCode || null,
|
||||
quantity: 0,
|
||||
first_record_id: Number(record.id) || 0,
|
||||
});
|
||||
}
|
||||
const locationGroup = locationGroups.get(recordLocationCode);
|
||||
locationGroup.quantity += Number(record.quantity) || 0;
|
||||
}
|
||||
const locations = [ ...locationGroups.values() ]
|
||||
.sort((left, right) => left.first_record_id - right.first_record_id)
|
||||
.map(locationGroup => ({
|
||||
location_id: locationGroup.location_id,
|
||||
location_code: locationGroup.location_code,
|
||||
quantity: locationGroup.quantity,
|
||||
}));
|
||||
|
||||
const base = {
|
||||
...detailRow,
|
||||
scope_type: scopeType,
|
||||
location_codes: locationCodes,
|
||||
checkers,
|
||||
last_checked_at: lastCheckedAt,
|
||||
records: detailRecords,
|
||||
locations,
|
||||
};
|
||||
|
||||
if (scopeType === 'goods') {
|
||||
const checkedQuantity = detailRecords.reduce((sum, record) => sum + (Number(record.quantity) || 0), 0);
|
||||
const diffQuantity = checkedQuantity - Number(detailRow.system_quantity || 0);
|
||||
return {
|
||||
...base,
|
||||
checked_quantity: detailRecords.length > 0 ? checkedQuantity : null,
|
||||
diff_quantity: detailRecords.length > 0 ? diffQuantity : null,
|
||||
is_diff: detailRecords.length > 0 && diffQuantity !== 0 ? 1 : 0,
|
||||
status: detailRecords.length > 0 ? 'checked' : 'unchecked',
|
||||
};
|
||||
}
|
||||
|
||||
// 库ä½<C3A4>行:按商å“<C3A5>è<EFBFBD>šå<C5A1>ˆè®°å½•,账é<C2A6>¢ä»?wms_storage å<>–(location_id 为空时账é<C2A6>¢æŒ‰ 0ï¼?
|
||||
const quantityByStock = new Map();
|
||||
for (const record of detailRecords) {
|
||||
const stockId = Number(record.stock_id);
|
||||
if (!Number.isInteger(stockId) || stockId <= 0) {
|
||||
continue;
|
||||
}
|
||||
const agg = quantityByStock.get(stockId) || { checked: 0 };
|
||||
agg.checked += Number(record.quantity) || 0;
|
||||
quantityByStock.set(stockId, agg);
|
||||
}
|
||||
const locationId = detailRow.location_id !== null && detailRow.location_id !== undefined
|
||||
? Number(detailRow.location_id)
|
||||
: 0;
|
||||
let checkedQuantity = 0;
|
||||
let diffQuantitySum = 0;
|
||||
let hasDiff = false;
|
||||
const stocks = [ ...quantityByStock.keys() ]
|
||||
.sort((left, right) => left - right)
|
||||
.map(stockId => {
|
||||
const agg = quantityByStock.get(stockId);
|
||||
const stock = stockMap.get(stockId) || {};
|
||||
const systemQuantity = locationId > 0
|
||||
? (storageQuantityMap.get(`${locationId}_${stockId}`) || 0)
|
||||
: 0;
|
||||
const diffQuantity = agg.checked - systemQuantity;
|
||||
checkedQuantity += agg.checked;
|
||||
diffQuantitySum += diffQuantity;
|
||||
if (diffQuantity !== 0) {
|
||||
hasDiff = true;
|
||||
}
|
||||
return {
|
||||
stock_id: stockId,
|
||||
item_code: stock.item_code || null,
|
||||
item_name: stock.item_name || null,
|
||||
system_quantity: systemQuantity,
|
||||
checked_quantity: agg.checked,
|
||||
diff_quantity: diffQuantity,
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
...base,
|
||||
stocks,
|
||||
checked_quantity: detailRecords.length > 0 ? checkedQuantity : null,
|
||||
diff_quantity: detailRecords.length > 0 ? diffQuantitySum : null,
|
||||
is_diff: hasDiff ? 1 : 0,
|
||||
status: detailRecords.length > 0 ? 'checked' : 'unchecked',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
Loading…
x
Reference in New Issue
Block a user