feat: 新增移库记录页面

- 新增 pages/warehouse/inventoryTransfer.vue:支持按商品条码/名称/操作人搜索、
  扫码查询、移入/移出类型筛选、分页列表(展示商品、数量、移出/移入库位、操作人等)
- pages.json 注册 pages/warehouse/inventoryTransfer 路由
- core/request/apis.js 新增 warehouse.getSpaceInfo、storage.transaction.list 接口
- pages/index/index.vue、pages/home/edit-quick-actions.vue:工作台「移库记录」
  菜单点击跳转到移库记录页

  refactor: 重构称重页查询与校验逻辑

- 改用 common.toOrder + order.detail 查询,替代原 scanOrder 分支逻辑
- 按波次号前缀区分散单/团单(B 开头视为团单),新增 isGroupOrder 状态
- 增加称重前置校验:未拣货、未复核禁止称重;散单未打包禁止称重
- 商品净重统一取订单详情 items_weight,运单匹配成功才回填称重重量
- 提取 clearOrderData 复用清空逻辑
This commit is contained in:
zm2000 2026-09-27 18:02:08 +08:00
parent 2eb9cbfc1b
commit 428f06ebd3
6 changed files with 787 additions and 120 deletions

View File

@ -109,6 +109,15 @@ export default {
isSystemApi: true
}
},
/** 仓库 ↓ **/
warehouse: {
getSpaceInfo: {
path: "warehouse.getSpaceInfo",
auth: true,
method: "POST",
isSystemApi: true
}
},
/** 工作台 ↓ **/
workbench: {
list: {
@ -307,6 +316,14 @@ export default {
isSystemApi: true
}
},
transaction: {
list: {
path: "storage.transaction.list",
auth: true,
method: "POST",
isSystemApi: true
}
},
directInbound: {
inbound: {
path: "storage.directInbound.inbound",

View File

@ -117,6 +117,13 @@
"titleNView": false
}
},
{
"path" : "pages/warehouse/inventoryTransfer",
"style" :
{
"titleNView": false
}
},
{
"path" : "pages/403",
"style" :

View File

@ -321,6 +321,7 @@
const isLabelReprint = menuName === '面单补打' || (menuName.includes('面单') && menuName.includes('补打'));
const isBlockRegistration = menuName === '拦截登记';
const isPickingRecord = menuName === '拣货记录' || (menuName.includes('拣货') && menuName.includes('记录'));
const isTransferRecord = menuName === '移库记录' || (menuName.includes('移库') && menuName.includes('记录'));
const rawPath = item?.component || item?.path || '';
const normalizedPath = rawPath ? (rawPath.startsWith('/') ? rawPath : `/${rawPath}`) : '';
const isRandomStorage = menuName === '随机入库' || (menuName.includes('随机') && menuName.includes('入库'));
@ -337,6 +338,10 @@
this.$tools.routerTo('/pages/work/storage/random-storage');
return;
}
if (isTransferRecord) {
this.$tools.routerTo('/pages/warehouse/inventoryTransfer');
return;
}
const targetPath = isGoodsQuery
? '/pages/work/product/query'
: (isOrderPicking

View File

@ -1192,6 +1192,7 @@
const isLabelReprint = menuName === '面单补打' || (menuName.includes('面单') && menuName.includes('补打'));
const isBlockRegistration = menuName === '拦截登记';
const isPickingRecord = menuName === '拣货记录' || (menuName.includes('拣货') && menuName.includes('记录'));
const isTransferRecord = menuName === '移库记录' || (menuName.includes('移库') && menuName.includes('记录'));
const rawPath = item?.component || item?.path || '';
const normalizedPath = rawPath ? (rawPath.startsWith('/') ? rawPath : `/${rawPath}`) : '';
const isRandomStorage = menuName === '随机入库' || (menuName.includes('随机') && menuName.includes('入库'));
@ -1212,6 +1213,10 @@
this.$tools.routerTo('/pages/warehouse/locationInquiry');
return;
}
if (isTransferRecord) {
this.$tools.routerTo('/pages/warehouse/inventoryTransfer');
return;
}
const targetPath = isGoodsQuery
? '/pages/work/product/query'
: (isOrderPicking

View File

@ -0,0 +1,655 @@
<template>
<view class="transfer-record-page">
<view class="normar_container">
<page-nav title="移库记录"></page-nav>
<!-- 搜索区 -->
<view class="search-panel">
<view class="search-input-wrap">
<u-search
v-model="keyword"
placeholder="请输入/扫描商品条码、名称或操作人"
:bg-color="'#f5f5f5'"
shape="round"
:show-action="false"
@search="handleSearch"
@clear="handleClear"
></u-search>
<view class="search-actions">
<view class="scan-btn" @click="handleCameraScan">
<u-icon name="scan" size="38rpx" color="#2979ff"></u-icon>
</view>
<view class="search-divider"></view>
<view class="search-btn" @click="handleSearch">
<text class="search-btn__text">搜索</text>
</view>
</view>
</view>
</view>
<!-- 移库类型筛选 -->
<view class="type-filter">
<view
v-for="opt in transferTypeOptions"
:key="opt.value"
class="type-filter__item"
:class="{ 'type-filter__item--active': transferType === opt.value }"
@click="handleTypeChange(opt.value)"
>
<text class="type-filter__item-text">{{ opt.label }}</text>
</view>
</view>
<!-- 列表区 -->
<scroll-view class="detail-scroll" scroll-y>
<view v-if="recordList.length === 0" class="empty-state">
<u-icon name="list" size="86" color="#c0c4cc"></u-icon>
<text class="empty-text">{{ loading ? '加载中...' : '暂无移库记录' }}</text>
<text class="empty-hint">{{ keyword ? '请检查关键字后重试' : '请在上方输入关键字查询' }}</text>
</view>
<view v-else class="record-list">
<view v-for="(item, index) in recordList" :key="item.id || index" class="record-card">
<view class="record-card__row">
<text class="record-card__label">商品编码</text>
<text class="record-card__value">{{ item.barcode || '--' }}</text>
</view>
<view class="record-card__row">
<text class="record-card__label">商品名称</text>
<text class="record-card__value">{{ item.name || '--' }}</text>
</view>
<view class="record-card__row">
<text class="record-card__label">操作时间</text>
<text class="record-card__value">{{ item.timeText || '--' }}</text>
</view>
<view class="record-card__row">
<text class="record-card__label">操作人</text>
<text class="record-card__value">{{ item.operator || '--' }}</text>
</view>
<view class="record-card__row">
<text class="record-card__label">数量</text>
<text class="record-card__value record-card__value--strong">{{ item.quantityText }}</text>
</view>
<view class="record-card__row">
<text class="record-card__label">移出库位</text>
<text class="record-card__value">{{ item.fromSpace || '--' }}</text>
</view>
<view class="record-card__row record-card__row--last">
<text class="record-card__label">移入库位</text>
<text class="record-card__value">{{ item.toSpace || '--' }}</text>
</view>
</view>
</view>
<view class="safe-area-bottom"></view>
</scroll-view>
<!-- 分页 -->
<view class="pagination-wrap">
<pagination
:pageNum.sync="currentPage"
:pageSize="pageSize"
:total="paginationTotal"
:showTotal="true"
:prevText="'上一页'"
:nextText="'下一页'"
:showFirstLast="true"
:firstText="'首页'"
:lastText="'末页'"
@change="handlePageChange"
/>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
keyword: '',
transferType: 'TRANSFER_IN',
transferTypeOptions: [
{ label: '移入', value: 'TRANSFER_IN' },
{ label: '移出', value: 'TRANSFER_OUT' }
],
pageSize: 20,
currentPage: 1,
paginationTotal: 0,
recordList: [],
loading: false
}
},
onLoad(options = {}) {
// 支持通过 ?keyword=xxx 预填关键字并自动查询
const preset = String(options.keyword || '').trim();
if (preset) {
this.keyword = preset;
this.$nextTick(() => this.loadRecordList(1));
} else {
this.loadRecordList(1);
}
this.safeDispatchBroadcast('setCallbacks', { onResult: this.handleBroadcastResult });
this.safeDispatchBroadcast('start');
},
onShow() {
this.safeDispatchBroadcast('setCallbacks', { onResult: this.handleBroadcastResult });
this.safeDispatchBroadcast('resume');
},
onHide() {
this.safeDispatchBroadcast('pause');
},
onUnload() {
this.safeDispatchBroadcast('stop');
},
methods: {
// ===== 广播/扫码基础设施 =====
safeDispatchBroadcast(action, payload) {
try {
const task = this.$store.dispatch(`broadcast/${action}`, payload);
if (task && typeof task.catch === 'function') {
task.catch(error => console.warn(`[inventoryTransfer] broadcast/${action} 调用失败:`, error));
}
} catch (error) {
console.warn(`[inventoryTransfer] broadcast/${action} 调用异常:`, error);
}
},
normalizeScanResult(scanResult) {
if (!scanResult) return '';
if (typeof scanResult === 'string') return scanResult.trim();
if (typeof scanResult.result === 'string') return scanResult.result.trim();
if (Array.isArray(scanResult.result)) {
const first = scanResult.result.find(item => item);
if (typeof first === 'string') return first.trim();
if (first && typeof first.data === 'string') return first.data.trim();
}
if (typeof scanResult.data === 'string') return scanResult.data.trim();
return '';
},
handleBroadcastResult(result) {
const code = this.normalizeScanResult(result);
if (!code) return;
this.keyword = code;
this.loadRecordList(1);
},
handleCameraScan() {
uni.scanCode({
onlyFromCamera: true,
scanType: ['qrCode', 'barCode', 'datamatrix', 'pdf417'],
success: (res) => {
const code = this.normalizeScanResult(res);
if (!code) return;
this.keyword = code;
this.loadRecordList(1);
},
fail: () => {}
});
},
// ===== 查询 =====
handleSearch() {
this.loadRecordList(1);
},
handleClear() {
this.keyword = '';
this.loadRecordList(1);
},
handleTypeChange(value) {
if (this.transferType === value) return;
this.transferType = value;
this.loadRecordList(1);
},
handlePageChange(page) {
const targetPage = Math.max(1, Number(page || 1));
if (targetPage === this.currentPage) return;
this.currentPage = targetPage;
this.loadRecordList(targetPage);
},
buildRecordParams(page = this.currentPage) {
const params = {
pagination: {
page: Math.max(1, Number(page || 1)),
pageSize: Math.max(1, Number(this.pageSize || 20))
}
};
const keyword = String(this.keyword || '').trim();
if (keyword) {
params.keyword = keyword;
}
if (this.transferType) {
params.where = {
transaction_type: {
operator: 'eq',
value: this.transferType,
type: 'select'
}
};
}
return params;
},
extractRecordPayload(response) {
const candidates = [
response?.data?.data,
response?.data,
response?.result,
response
];
for (let i = 0; i < candidates.length; i += 1) {
const current = candidates[i];
if (current && typeof current === 'object' && !Array.isArray(current)) {
return current;
}
}
return {};
},
extractRecordList(payload, response) {
const candidates = [
payload?.list,
payload?.rows,
payload?.items,
payload?.records,
payload?.data?.list,
response?.data?.list,
response?.data?.data?.list,
response?.list
];
for (let i = 0; i < candidates.length; i += 1) {
if (Array.isArray(candidates[i])) return candidates[i];
}
return [];
},
resolveRecordTotal(payload, response, list) {
const pagination = (payload && typeof payload === 'object') ? (payload.pagination || {}) : {};
const candidates = [
pagination?.total,
pagination?.count,
payload?.pagination?.total,
payload?.total,
payload?.count,
payload?.totalCount,
response?.data?.pagination?.total,
response?.data?.total,
response?.total,
Array.isArray(list) ? list.length : 0
];
for (let i = 0; i < candidates.length; i += 1) {
const value = Number(candidates[i]);
if (Number.isFinite(value) && value >= 0) return value;
}
return 0;
},
firstValue(source, keys) {
for (let i = 0; i < keys.length; i += 1) {
const value = source[keys[i]];
if (value !== null && value !== undefined && String(value).trim() !== '') {
return String(value).trim();
}
}
return '';
},
formatDateTime(value) {
if (value === null || value === undefined || value === '') return '';
const date = new Date(String(value).trim());
if (Number.isNaN(date.getTime())) return String(value).trim();
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
const hour = String(date.getHours()).padStart(2, '0');
const minute = String(date.getMinutes()).padStart(2, '0');
const second = String(date.getSeconds()).padStart(2, '0');
return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
},
normalizeRecordList(list) {
if (!Array.isArray(list)) return [];
return list
.map((item, index) => {
const source = item && typeof item === 'object' ? item : {};
// 商品信息嵌套在 stockItem 内(可能为 null),合并进查找源
const stockItem = source.stockItem && typeof source.stockItem === 'object' ? source.stockItem : {};
const merged = { ...source, ...stockItem };
const barcode = this.firstValue(merged, [
'barcode', 'item_code', 'item_barcode', 'bar_code', 'goods_code', 'product_barcode'
]);
const name = this.firstValue(merged, [
'item_name', 'product_name', 'goods_name', 'name', 'itemName'
]);
const operator = this.firstValue(source, [
'operator_name', 'operatorName', 'operator', 'operate_user', 'operateUser',
'create_user', 'createUser', 'user_name', 'userName', 'scanner_name'
]);
const transactionType = String(source.transaction_type || source.transactionType || '').trim();
// 单库位流水:库位可能是 space_code/space_name 或仅 space_id
const spaceId = this.firstValue(source, ['space_id', 'spaceId']);
const spaceText = this.firstValue(merged, [
'space_code', 'spaceCode', 'space_name', 'spaceName', 'space_no', 'spaceNo'
]) || spaceId;
let fromSpace = this.firstValue(merged, [
'from_space_code', 'fromSpaceCode', 'source_space_code', 'sourceSpaceCode',
'out_space_code', 'outSpaceCode', 'from_location', 'fromLocation', 'from_space', 'from_space_id'
]);
let toSpace = this.firstValue(merged, [
'to_space_code', 'toSpaceCode', 'target_space_code', 'targetSpaceCode',
'in_space_code', 'inSpaceCode', 'to_location', 'toLocation', 'to_space', 'to_space_id'
]);
// 无明确 from/to 时:移出记录的空间为「移出库位」,移入记录的空间为「移入库位」
if (!fromSpace && !toSpace && spaceText) {
if (transactionType === 'TRANSFER_OUT') {
fromSpace = spaceText;
} else {
toSpace = spaceText;
}
}
const timeValue = this.firstValue(source, [
'created_at', 'createdAt', 'create_time', 'createTime',
'operate_time', 'operateTime', 'operation_time', 'operationTime',
'transfer_time', 'transferTime'
]);
const quantityValue = this.firstValue(source, [
'quantity', 'qty', 'num', 'transfer_quantity', 'transferQuantity', 'count'
]);
const quantity = Number(quantityValue);
const id = this.firstValue(source, ['id', 'transfer_id', 'transferId', 'record_id'])
|| `${this.currentPage}-${index + 1}`;
return {
id,
barcode,
name,
operator,
fromSpace,
toSpace,
spaceId,
transactionType,
timeText: this.formatDateTime(timeValue),
quantityText: quantityValue === '' ? '--' : (Number.isFinite(quantity) ? String(quantity) : quantityValue)
};
})
.filter(item => !!(item.barcode || item.name || item.fromSpace || item.toSpace || item.operator));
},
// 按 space_id 批量拉取库位信息,用 custom_name 回填库位显示
async fetchSpaceNames(records) {
if (!Array.isArray(records) || !records.length) return;
const idSet = new Set();
records.forEach(item => {
const raw = item?.spaceId;
if (raw !== '' && raw !== undefined && raw !== null) {
idSet.add(String(raw));
}
});
const ids = Array.from(idSet);
if (!ids.length) return;
const nameMap = {};
const limit = 4;
let cursor = 0;
while (cursor < ids.length) {
const batch = ids.slice(cursor, cursor + limit);
cursor += limit;
await Promise.all(batch.map(async (idStr) => {
try {
const numId = Number(idStr);
const res = await this.$http('warehouse.getSpaceInfo', { id: Number.isFinite(numId) ? numId : idStr }, '', false);
if (res?.flag === 'failure' || Number(res?.code) !== 200) return;
const data = (res?.data && typeof res.data === 'object') ? res.data : {};
const name = String(data.custom_name ?? data.customName ?? data.space_code ?? data.spaceCode ?? '').trim();
if (name) nameMap[idStr] = name;
} catch (error) {
console.warn('[inventoryTransfer] 获取库位信息失败:', idStr, error);
}
}));
}
records.forEach(item => {
const resolved = nameMap[String(item.spaceId)];
if (!resolved) return;
if (item.transactionType === 'TRANSFER_OUT') {
if (!item.fromSpace || item.fromSpace === String(item.spaceId)) {
item.fromSpace = resolved;
}
} else {
if (!item.toSpace || item.toSpace === String(item.spaceId)) {
item.toSpace = resolved;
}
}
});
},
async loadRecordList(page = this.currentPage) {
const targetPage = Math.max(1, Number(page || 1));
this.loading = true;
try {
const response = await this.$http('storage.transaction.list', this.buildRecordParams(targetPage));
const payload = this.extractRecordPayload(response);
const list = this.extractRecordList(payload, response);
this.recordList = this.normalizeRecordList(list);
this.paginationTotal = this.resolveRecordTotal(payload, response, list);
const spaceTask = this.fetchSpaceNames(this.recordList);
if (spaceTask && typeof spaceTask.catch === 'function') {
spaceTask.catch(error => console.warn('[inventoryTransfer] 拉取库位名称失败:', error));
}
const pageInfo = (payload && typeof payload === 'object') ? (payload.pagination || {}) : {};
const pageNo = Number(pageInfo?.page ?? payload?.page ?? targetPage);
this.currentPage = Number.isFinite(pageNo) && pageNo > 0 ? pageNo : targetPage;
const pageSize = Number(pageInfo?.pageSize ?? pageInfo?.page_size ?? this.pageSize);
this.pageSize = Number.isFinite(pageSize) && pageSize > 0 ? pageSize : this.pageSize;
} catch (error) {
console.error('[inventoryTransfer] 移库记录加载失败:', error);
this.recordList = [];
this.paginationTotal = 0;
uni.showToast({ title: '移库记录加载失败', icon: 'none' });
} finally {
this.loading = false;
}
}
}
}
</script>
<style lang="scss" scoped>
.transfer-record-page {
height: 100vh;
background: #f8f9fa;
}
.normar_container {
height: 100%;
display: flex;
flex-direction: column;
overflow: hidden;
}
/* 搜索区 */
.search-panel {
background: #ffffff;
border-bottom: 1rpx solid #f2f2f2;
padding: 16rpx;
box-sizing: border-box;
flex-shrink: 0;
}
.search-input-wrap {
position: relative;
::v-deep .u-search {
width: 100%;
}
::v-deep .u-search__content {
padding-right: 200rpx;
}
::v-deep .u-search__content__close {
margin-right: 12rpx;
}
}
.search-actions {
position: absolute;
right: 24rpx;
top: 50%;
transform: translateY(-50%);
height: 68rpx;
display: flex;
align-items: center;
}
.scan-btn {
height: 68rpx;
padding: 0 8rpx 0 4rpx;
display: flex;
align-items: center;
justify-content: center;
&:active {
opacity: 0.88;
}
}
.search-divider {
width: 1rpx;
height: 28rpx;
background: #dcdfe6;
margin: 0 16rpx 0 10rpx;
}
.search-btn {
height: 68rpx;
padding: 0 8rpx;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
&__text {
font-size: 30rpx;
font-weight: 500;
color: #2979ff;
line-height: 1;
}
&:active {
opacity: 0.88;
}
}
/* 移库类型筛选 */
.type-filter {
background: #ffffff;
border-bottom: 1rpx solid #f2f2f2;
padding: 8rpx 16rpx 20rpx;
box-sizing: border-box;
display: flex;
flex-wrap: wrap;
gap: 16rpx;
flex-shrink: 0;
}
.type-filter__item {
height: 60rpx;
padding: 0 32rpx;
display: flex;
align-items: center;
justify-content: center;
background: #f5f7fa;
border: 1rpx solid #ebeef5;
border-radius: 30rpx;
}
.type-filter__item--active {
background: #ecf3ff;
border-color: #2979ff;
}
.type-filter__item-text {
font-size: 28rpx;
color: #303133;
}
.type-filter__item--active .type-filter__item-text {
color: #2979ff;
}
/* 列表区 */
.detail-scroll {
flex: 1;
min-height: 0;
height: auto;
padding: 20rpx 0 0;
box-sizing: border-box;
}
.empty-state {
padding: 160rpx 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.empty-text {
margin-top: 24rpx;
font-size: 32rpx;
color: #909399;
}
.empty-hint {
margin-top: 12rpx;
font-size: 26rpx;
color: #c0c4cc;
}
.record-list {
display: flex;
flex-direction: column;
padding: 0 12rpx;
box-sizing: border-box;
}
.record-card {
background: #ffffff;
border: 2rpx solid #ebeef5;
border-radius: 16rpx;
padding: 8rpx 24rpx;
margin-bottom: 16rpx;
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
}
.record-card__row {
display: flex;
align-items: flex-start;
padding: 18rpx 0;
border-bottom: 1rpx solid #f5f5f5;
}
.record-card__row--last {
border-bottom: none;
}
.record-card__label {
flex-shrink: 0;
width: 160rpx;
font-size: 28rpx;
color: #909399;
line-height: 1.5;
}
.record-card__value {
flex: 1;
min-width: 0;
font-size: 30rpx;
color: #303133;
line-height: 1.5;
word-break: break-all;
overflow-wrap: break-word;
}
.record-card__value--strong {
font-weight: 600;
color: #2979ff;
}
.safe-area-bottom {
height: calc(20rpx + env(safe-area-inset-bottom));
}
/* 分页 */
.pagination-wrap {
background: #ffffff;
border-top: 1rpx solid #f0f0f0;
padding: 0 24rpx env(safe-area-inset-bottom);
flex-shrink: 0;
}
</style>

View File

@ -97,7 +97,8 @@ import voice from '@/core/utils/voice';
manualWeight: '',
weightFocused: false,
submitting: false,
showOrderInfo: false
showOrderInfo: false,
isGroupOrder: false
};
},
onLoad() {
@ -144,130 +145,95 @@ import voice from '@/core/utils/voice';
speakVoice(text) {
voice.speak(text, { minInterval: 800 });
},
async fetchOrderDetail(code) {
try {
const toOrderRes = await this.$http('common.toOrder', { waybill_code: code }, '', false);
if (toOrderRes && toOrderRes.flag !== 'failure') {
const rawOrderId = Number(toOrderRes.order_id);
if (rawOrderId > 0) {
this.orderInfo.order_id = rawOrderId;
}
this.waves = Array.isArray(toOrderRes.waves) ? toOrderRes.waves : [];
// 调用 order.detail 获取订单详情
try {
const detailRes = await this.$http('order.detail', { order_id: this.orderInfo.order_id, tableType: 'dispatch' }, '', false);
if (detailRes && detailRes.flag !== 'failure') {
const detailData = detailRes.data || {};
this.orderDetail = detailData.detail || null;
this.orderItems = detailData.items || [];
this.expresses = detailData.expresses || [];
// 从订单详情中更新商品净重(仅在扫码接口未提供子单净重时,用主单净重兜底)
if (!this.netWeight && detailData.detail && detailData.detail.items_weight !== undefined && detailData.detail.items_weight !== null) {
this.netWeight = detailData.detail.items_weight;
}
// 从运单信息中更新称重重量:仅当扫描的子单号能精确匹配到对应运单时才填充,
// 匹配不到时称重重量留空,避免误用主单/其它运单的重量,由用户手动输入
const matchedExpress = (detailData.expresses || []).find(exp => exp.waybill_code === code);
if (matchedExpress && matchedExpress.weighing_weight !== undefined && matchedExpress.weighing_weight !== null) {
this.manualWeight = String(Math.round(matchedExpress.weighing_weight));
} else {
this.manualWeight = '';
}
}
} catch (e) {
console.error('获取订单详情失败', e);
}
}
} catch (e) {
console.error('获取波次信息失败', e);
}
},
async fetchOrderInfo(code) {
uni.showLoading({ title: '查询中...' });
try {
const res = await this.$http('order.recheckOrder.scanOrder', { waybill_code: code }, '', false);
if (res && res.flag !== 'failure') {
const data = res.data || {};
if (data.list_type === 'single') {
// 散单模式
const orderItem = (data.list || []).find(
item => item.waybill_no === code
);
if (!orderItem) {
uni.showToast({ title: '未找到匹配订单', icon: 'none' });
this.speakVoice('无记录');
return;
}
if (!orderItem.is_reviewed) {
uni.showToast({ title: '订单未复核', icon: 'none' });
this.speakVoice('订单未复核');
this.showOrderInfo = false;
this.orderInfo = { order_id: 0, waybill_code: '' };
this.waves = [];
this.orderDetail = null;
this.orderItems = [];
this.expresses = [];
this.netWeight = '';
this.manualWeight = '';
return;
}
this.orderInfo = {
order_id: orderItem.order_id || 0,
waybill_code: orderItem.waybill_no || code
};
this.netWeight = orderItem.items_weight ?? '';
this.manualWeight = orderItem.items_weight ? String(orderItem.items_weight) : '';
} else {
// 团购模式 — 由后端按运单号处理
const waveItem = (data.list || [])[0];
const hasUnreviewed = waveItem && waveItem.unreviewed_count > 0;
if (hasUnreviewed) {
uni.showToast({ title: '订单未复核', icon: 'none' });
this.speakVoice('订单未复核');
this.showOrderInfo = false;
this.orderInfo = { order_id: 0, waybill_code: '' };
this.waves = [];
this.orderDetail = null;
this.orderItems = [];
this.expresses = [];
this.netWeight = '';
this.manualWeight = '';
return;
}
this.orderInfo = {
order_id: 0,
waybill_code: code
};
this.netWeight = waveItem?.items_weight ?? '';
this.manualWeight = waveItem?.items_weight ? String(waveItem.items_weight) : '';
}
// 调用 index.toOrder 获取订单ID及所属波次信息(已提取到 fetchOrderDetail 方法)
await this.fetchOrderDetail(code);
this.showOrderInfo = true;
// 自动聚焦称重重量输入框
this.$nextTick(() => {
this.weightFocused = true;
});
} else if (res && res.message === '接口错误: 未找到对应订单') {
// 未找到对应订单时跳过未复核检测,继续查询
this.orderInfo = {
order_id: 0,
waybill_code: code
};
this.showOrderInfo = true;
await this.fetchOrderDetail(code);
this.$nextTick(() => {
this.weightFocused = true;
});
} else {
uni.showToast({ title: res.msg || '查询失败', icon: 'none' });
// 1. 按运单号获取订单ID及所属波次信息
const toOrderRes = await this.$http('common.toOrder', { waybill_code: code }, '', false);
if (!toOrderRes || toOrderRes.flag === 'failure') {
uni.showToast({ title: (toOrderRes && (toOrderRes.msg || toOrderRes.message)) || '查询失败', icon: 'none' });
this.speakVoice('无记录');
return;
}
const rawOrderId = Number(toOrderRes.order_id);
if (!(rawOrderId > 0)) {
uni.showToast({ title: '未找到对应订单', icon: 'none' });
this.speakVoice('无记录');
return;
}
this.waves = Array.isArray(toOrderRes.waves) ? toOrderRes.waves : [];
// 2. 获取订单详情(区分散单/团单、校验复核状态、取商品净重与运单称重重量)
const detailRes = await this.$http('order.detail', { order_id: rawOrderId, tableType: 'dispatch' }, '', false);
if (!detailRes || detailRes.flag === 'failure') {
uni.showToast({ title: (detailRes && (detailRes.msg || detailRes.message)) || '查询失败', icon: 'none' });
this.speakVoice('无记录');
return;
}
const detailData = detailRes.data || {};
const detail = detailData.detail || {};
this.orderDetail = detail;
this.orderItems = detailData.items || [];
this.expresses = detailData.expresses || [];
// 3. 区分散单/团单:团单波次号前缀为 B,其余波次前缀为散单
const waveNo = String(detail.wave_no || '').trim();
this.isGroupOrder = waveNo.startsWith('B');
console.log('[称重] 波次号:', waveNo, this.isGroupOrder ? '团单' : '散单');
// 4. 校验:未拣货不允许称重(散单/团单均校验)
const pick = String(detail.pick_status ?? '').trim().toLowerCase();
const pickDone = pick === 'fin' || pick === 'finished' || pick === '1';
if (!pickDone) {
uni.showToast({ title: '订单未拣货,禁止称重', icon: 'none' });
this.speakVoice('订单未拣货,禁止称重');
this.clearOrderData();
return;
}
// 5. 校验:未复核不允许称重(散单/团单均校验)
const recheck = String(detail.recheck_status ?? '').trim().toLowerCase();
const recheckDone = recheck === 'fin' || recheck === 'finished' || recheck === '1';
if (!recheckDone) {
uni.showToast({ title: '订单未复核,禁止称重', icon: 'none' });
this.speakVoice('订单未复核,禁止称重');
this.clearOrderData();
return;
}
// 6. 校验:散单未打包不允许称重(仅散单校验,pack_status 为 fin 视为已打包)
if (!this.isGroupOrder) {
const packStatus = String(detail.pack_status ?? '').trim().toLowerCase();
const packDone = packStatus === 'fin' || packStatus === 'finished' || packStatus === '1';
if (!packDone) {
uni.showToast({ title: '订单未打包,禁止称重', icon: 'none' });
this.speakVoice('订单未打包,禁止称重');
this.clearOrderData();
return;
}
}
this.orderInfo = {
order_id: rawOrderId,
waybill_code: code
};
// 商品净重:散单/团单均取订单详情 items_weight
this.netWeight = detail.items_weight ?? '';
// 称重重量:仅当扫描的运单号能精确匹配到对应运单时才回填,否则留空由用户手动输入
const matchedExpress = (detailData.expresses || []).find(exp => exp.waybill_code === code);
if (matchedExpress && matchedExpress.weighing_weight !== undefined && matchedExpress.weighing_weight !== null) {
this.manualWeight = String(Math.round(matchedExpress.weighing_weight));
} else {
this.manualWeight = '';
}
this.showOrderInfo = true;
// 自动聚焦称重重量输入框
this.$nextTick(() => {
this.weightFocused = true;
});
} catch (e) {
uni.showToast({ title: '网络异常', icon: 'none' });
this.speakVoice('无记录');
@ -275,6 +241,17 @@ import voice from '@/core/utils/voice';
uni.hideLoading();
}
},
clearOrderData() {
this.showOrderInfo = false;
this.orderInfo = { order_id: 0, waybill_code: '' };
this.waves = [];
this.orderDetail = null;
this.orderItems = [];
this.expresses = [];
this.netWeight = '';
this.manualWeight = '';
this.isGroupOrder = false;
},
handleSubmitWeight() {
if (!this.manualWeight) {
uni.showToast({ title: '请输入称重重量', icon: 'none' });
@ -322,6 +299,7 @@ import voice from '@/core/utils/voice';
this.manualWeight = '';
this.weightFocused = false;
this.showOrderInfo = false;
this.isGroupOrder = false;
this.scanFocused = true;
}
}