- 库存盘点:font-weight 600 统一改为 bold,修复真机无加粗效果 - 库存盘点:移除右上角「...」操作菜单,改为「完成盘点」「空库位」直接按钮 - 库存盘点:顶部标题栏字号统一 36rpx,搜索输入框字号 34rpx,提示字号 28→30rpx - 拦截登记:顶部导航重构为自定义 header(返回/标题/输入框开关/重置) - 拦截登记:搜索框改为 u-search 圆角样式并新增「搜索」按钮 - 拦截登记:信息面板标签 32→36rpx、值 32→40rpx,与搜索框间隔调整为 60rpx - 拦截登记:拦截失败提示优化,区分「非拦截订单」等文案 - 库位查询:标题/搜索/计数半格样式调整,浅色背景深色文字、下划线强调 - 其他:page-nav 右侧宽度改 min-width;首页/个人中心弹窗圆角 24→20rpx;多处标题字号 32→36rpx
932 lines
30 KiB
Vue
932 lines
30 KiB
Vue
<template>
|
||
<view class="inv-goods-page">
|
||
<view class="normar_container">
|
||
<page-nav :title="navTitle" />
|
||
|
||
<!-- 顶部:扫描/输入库位码 → 打开「选库位 + 录数量」底部抽屉 -->
|
||
<count-search-panel
|
||
v-if="editable"
|
||
v-model="scanKeyword"
|
||
placeholder="扫描/输入库位码登记数量"
|
||
action-text="登记"
|
||
@search="handleEntryOpen"
|
||
@clear="handleKeywordClear"
|
||
@scan="handleCameraScan"
|
||
/>
|
||
|
||
<scroll-view
|
||
class="inv-goods-scroll"
|
||
scroll-y
|
||
refresher-enabled
|
||
:refresher-triggered="refreshing"
|
||
refresher-background="#f8f9fa"
|
||
@refresherrefresh="handleRefresh"
|
||
@refresherrestore="handleRefresherRestore"
|
||
>
|
||
<view v-if="!editable" class="inv-goods-tip">当前盘点任务状态不可作业,仅可查看</view>
|
||
|
||
<view v-if="editable && pickingPending" class="inv-goods-tip">静态盘点:该商品尚未完成拣货,拣货完成前不能上报</view>
|
||
|
||
<view v-if="loading && !detailRow" class="inv-goods-tip">加载中...</view>
|
||
|
||
<!-- 商品概况(紧凑卡片,有图就显示:商品主图优先,否则用作业照片兜底) -->
|
||
<view class="inv-goods-card">
|
||
<view v-if="cardImage" class="inv-goods-card__thumb" @click="previewGoodsImage">
|
||
<u-image
|
||
:src="cardImage"
|
||
mode="aspectFill"
|
||
width="120rpx"
|
||
height="120rpx"
|
||
radius="10rpx"
|
||
>
|
||
<template #error>
|
||
<view class="inv-goods-card__thumb-empty">
|
||
<text class="inv-goods-card__thumb-text">无图</text>
|
||
</view>
|
||
</template>
|
||
</u-image>
|
||
</view>
|
||
<view class="inv-goods-card__info">
|
||
<view class="inv-goods-card__head">
|
||
<text class="inv-goods-card__title">{{ goodsInfo.itemName || '--' }}</text>
|
||
<text
|
||
class="inv-goods-card__flag"
|
||
:class="hasChecked ? 'inv-goods-card__flag--done' : 'inv-goods-card__flag--todo'"
|
||
>{{ hasChecked ? '已盘' : '未盘' }}</text>
|
||
<text v-if="pickingPending" class="inv-goods-card__flag inv-goods-card__flag--picking">待拣货</text>
|
||
</view>
|
||
<text class="inv-goods-card__line">{{ goodsMetaText }}</text>
|
||
<view class="inv-goods-card__metrics">
|
||
<text v-if="systemQuantityValue !== null" class="inv-goods-card__metric">{{ systemLabel }} {{ systemQuantityValue }}</text>
|
||
<text class="inv-goods-card__metric">已盘 {{ checkedTotalText }}</text>
|
||
<text v-if="diffText" class="inv-goods-card__diff" :class="diffValueClass">{{ diffText }}</text>
|
||
<text v-if="bookHintText" class="inv-goods-card__hint">{{ bookHintText }}</text>
|
||
<text v-if="pickingPending" class="inv-goods-card__hint">{{ pickingHintText }}</text>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 该商品的全部盘点记录(可左滑删除,含作业照片) -->
|
||
<count-location-detail
|
||
:row="detailRow"
|
||
:editable="editable"
|
||
section-title="盘点记录"
|
||
empty-text="该商品暂无盘点记录"
|
||
@delete="handleRecordDelete"
|
||
/>
|
||
|
||
<view v-if="!detailRow && !loading" class="inv-goods-tip">{{ loadError || '未获取到该商品的盘点记录,请返回列表重试' }}</view>
|
||
|
||
<view class="safe-area-bottom"></view>
|
||
</scroll-view>
|
||
</view>
|
||
|
||
<!-- 选库位 + 录数量(底部抽屉,参考库位页的添加商品抽屉) -->
|
||
<count-space-entry-popup
|
||
ref="spaceEntryPopup"
|
||
:show="showEntryPopup"
|
||
:prefill-keyword="pendingLocation"
|
||
:item-name="goodsInfo.itemName"
|
||
:submitting="submitting"
|
||
@close="closeEntryPopup"
|
||
@confirm="handleEntryConfirm"
|
||
/>
|
||
|
||
<!-- 删除盘点记录确认弹窗(自定义样式) -->
|
||
<u-popup
|
||
:show="showDeleteRecordConfirm"
|
||
mode="center"
|
||
:closeable="true"
|
||
:closeOnClickOverlay="false"
|
||
round="20"
|
||
@close="cancelDeleteRecord"
|
||
>
|
||
<view class="delete-confirm-popup">
|
||
<view class="delete-confirm-popup__title">删除盘点记录</view>
|
||
<view class="delete-confirm-popup__body">
|
||
<text class="delete-confirm-popup__text">{{ deleteRecordTarget ? deleteRecordTarget.text : '' }}</text>
|
||
</view>
|
||
<view class="delete-confirm-popup__actions">
|
||
<view class="delete-confirm-popup__btn delete-confirm-popup__btn--cancel" @click="cancelDeleteRecord">取消</view>
|
||
<view
|
||
class="delete-confirm-popup__btn delete-confirm-popup__btn--confirm"
|
||
:class="{ 'delete-confirm-popup__btn--disabled': submitting }"
|
||
@click="confirmDeleteRecord"
|
||
>
|
||
<text>{{ submitting ? '处理中...' : '删除' }}</text>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</u-popup>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
import CountSearchPanel from './inventoryCount-comps/CountSearchPanel.vue';
|
||
import CountLocationDetail from './inventoryCount-comps/CountLocationDetail.vue';
|
||
import CountSpaceEntryPopup from './inventoryCount-comps/CountSpaceEntryPopup.vue';
|
||
import {
|
||
normalizeScanResult,
|
||
extractObjectPayload,
|
||
normalizeGoodsDetailInfo,
|
||
isStaticCheck,
|
||
buildReportParams
|
||
} from './inventoryCount-comps/countModel.js';
|
||
|
||
/** 空商品概况(接口失败/未匹配到明细时的占位) */
|
||
function EMPTY_GOODS_INFO() {
|
||
return {
|
||
itemName: '',
|
||
barcode: '',
|
||
spec: '',
|
||
storeName: '',
|
||
image: '',
|
||
stockId: '',
|
||
systemQuantity: null,
|
||
checkedQuantity: null,
|
||
amount: null,
|
||
// 账面口径(0.3.318):静态盘点取快照、普通盘点取当前库存
|
||
isStatic: false,
|
||
bookSource: '',
|
||
storageQuantity: null,
|
||
snapshotQuantity: null,
|
||
locations: [],
|
||
// 全部库位(含未盘)的明细ID映射:按库位上报时定位 detail_id
|
||
allLocations: [],
|
||
recordCount: 0,
|
||
locationCodes: [],
|
||
lastCheckedAtText: ''
|
||
};
|
||
}
|
||
|
||
/**
|
||
* 账面数量:接口 system_quantity
|
||
* 放在模块级而不是 computed 互调,避免任何“半更新”状态下 this.xxx is not a function 直接白屏
|
||
*/
|
||
function resolveSystemQuantity(goodsInfo) {
|
||
const sys = (goodsInfo || {}).systemQuantity;
|
||
return sys === null || sys === undefined ? null : Number(sys);
|
||
}
|
||
|
||
/** 账面口径标签:静态盘点=账面(快照)、普通盘点=账面(当前库存) */
|
||
function resolveSystemLabel(goodsInfo) {
|
||
const amount = (goodsInfo || {}).amount;
|
||
if (amount && amount.systemLabel) return amount.systemLabel;
|
||
return (goodsInfo || {}).isStatic ? '账面(快照)' : '账面(当前库存)';
|
||
}
|
||
|
||
/** 另一种口径提示(静态看当前库存 / 普通看基准快照,不一致时才提示) */
|
||
function resolveBookHint(goodsInfo) {
|
||
const amount = (goodsInfo || {}).amount;
|
||
return amount && amount.bookHint ? amount.bookHint : '';
|
||
}
|
||
|
||
/** 是否已盘(有作业记录或已盘库位;未盘占位行不算) */
|
||
function resolveHasChecked(goodsInfo) {
|
||
const info = goodsInfo || {};
|
||
if (Number(info.recordCount) > 0) return true;
|
||
const locations = Array.isArray(info.locations) ? info.locations : [];
|
||
return locations.some(item => item && item.checked);
|
||
}
|
||
|
||
/** 已盘合计:优先接口 checked_quantity,缺失时用库位明细合计 */
|
||
function resolveCheckedQuantity(goodsInfo) {
|
||
const info = goodsInfo || {};
|
||
if (info.checkedQuantity !== null && info.checkedQuantity !== undefined) return Number(info.checkedQuantity);
|
||
const locations = Array.isArray(info.locations) ? info.locations : [];
|
||
return locations.reduce((sum, item) => sum + (Number(item.quantity) || 0), 0);
|
||
}
|
||
|
||
/** 盈亏文案:未盘不动账;已盘 = 已盘合计 - 账面 */
|
||
function resolveDiffText(goodsInfo) {
|
||
const info = goodsInfo || {};
|
||
if (!resolveHasChecked(info)) return '';
|
||
const system = resolveSystemQuantity(info);
|
||
if (system === null) {
|
||
return info.amount && info.amount.diffText ? info.amount.diffText : '';
|
||
}
|
||
const diff = resolveCheckedQuantity(info) - system;
|
||
if (diff > 0) return `盘盈 +${diff}`;
|
||
if (diff < 0) return `盘亏 ${-diff}`;
|
||
return '账实相符';
|
||
}
|
||
|
||
/**
|
||
* 商品作业页(goods 视图;从盘点作业商品列表点击/扫码进入)
|
||
* 入参:**只传 id** —— task_id(盘点任务ID)+ detail_id(盘点明细ID)或 stock_id(商品库存ID)
|
||
* 数据:
|
||
* - stock.check.workDataDetail(id + stock_id / detail_id)→ 商品钻取数据:summary(商品级账面/已盘/差异)+ rows(按库位分行)
|
||
* - stock.check.detail(仅主表 check)→ 任务状态 / 盘点模式 / 是否静态盘点
|
||
* 能力:扫码/输入库位 → 底部抽屉选库位 + 录数量(check.report);库位记录可左滑删除(recordDelete)
|
||
*/
|
||
export default {
|
||
components: {
|
||
CountSearchPanel,
|
||
CountLocationDetail,
|
||
CountSpaceEntryPopup
|
||
},
|
||
data() {
|
||
return {
|
||
taskId: '',
|
||
detailId: '',
|
||
// 商品库存ID(0.3.309 起 goods 行不再返回 detail_id,改用 stock_id 进入)
|
||
stockId: '',
|
||
taskInfo: { status: '', mode: '', type: '', isStatic: false, hasStaticFlag: false },
|
||
goodsInfo: EMPTY_GOODS_INFO(),
|
||
loading: false,
|
||
refreshing: false,
|
||
loadError: '',
|
||
submitting: false,
|
||
scanKeyword: '',
|
||
showEntryPopup: false,
|
||
showDeleteRecordConfirm: false,
|
||
deleteRecordTarget: null,
|
||
pendingLocation: ''
|
||
};
|
||
},
|
||
computed: {
|
||
navTitle() {
|
||
return this.goodsInfo.itemName || '商品作业';
|
||
},
|
||
// 仅 approved/checking 可作业(未取到状态时先按可作业处理,由接口 400 兜底)
|
||
editable() {
|
||
const status = String(this.taskInfo.status || '').trim().toLowerCase();
|
||
if (!status) return true;
|
||
return status === 'approved' || status === 'checking';
|
||
},
|
||
// 是否已盘(有库位明细/作业记录)——用于右上角标记与盈亏门控
|
||
hasChecked() {
|
||
return resolveHasChecked(this.goodsInfo);
|
||
},
|
||
// 静态盘点拣货未完成(0.3.320):后端 report 会拒绝,前端先置灰上报入口
|
||
pickingPending() {
|
||
return !!this.goodsInfo.pickingPending;
|
||
},
|
||
pickingHintText() {
|
||
const locked = this.goodsInfo.lockedQuantity;
|
||
return locked === null || locked === undefined ? '拣货未完成,暂不能上报' : `拣货未完成(锁定 ${locked}),暂不能上报`;
|
||
},
|
||
// 账面数量(接口 system_quantity)
|
||
systemQuantityValue() {
|
||
return resolveSystemQuantity(this.goodsInfo);
|
||
},
|
||
// 账面口径标签(快照 / 当前库存)与另一种口径提示
|
||
systemLabel() {
|
||
return resolveSystemLabel(this.goodsInfo);
|
||
},
|
||
bookHintText() {
|
||
return resolveBookHint(this.goodsInfo);
|
||
},
|
||
// 已盘合计(接口 checked_quantity,缺失时用库位明细合计;未盘显示 --)
|
||
checkedTotalText() {
|
||
if (!this.hasChecked) return '--';
|
||
return String(resolveCheckedQuantity(this.goodsInfo));
|
||
},
|
||
// 盈亏:未盘不显示;已盘 = 已盘合计 - 账面
|
||
diffText() {
|
||
return resolveDiffText(this.goodsInfo);
|
||
},
|
||
diffValueClass() {
|
||
if (!this.diffText) return '';
|
||
if (this.diffText.indexOf('盘盈') === 0) return 'inv-goods-card__diff--gain';
|
||
if (this.diffText.indexOf('盘亏') === 0) return 'inv-goods-card__diff--loss';
|
||
return '';
|
||
},
|
||
// 概况卡图片:商品主图优先,没有就用第一个有照片的库位记录兑底
|
||
cardImage() {
|
||
if (this.goodsInfo.image) return this.goodsInfo.image;
|
||
return this.cardImages[0] || '';
|
||
},
|
||
cardImages() {
|
||
if (this.goodsInfo.image) return [this.goodsInfo.image];
|
||
const locations = this.goodsInfo.locations || [];
|
||
return locations.reduce((acc, item) => acc.concat(item.images || []), []);
|
||
},
|
||
// 条码 · 规格 · 货主(与盘点作业商品卡片副标题顺序一致)
|
||
goodsMetaText() {
|
||
return [this.goodsInfo.barcode, this.goodsInfo.spec, this.goodsInfo.storeName].filter(Boolean).join(' · ') || '--';
|
||
},
|
||
// CountLocationDetail 只需要 row 结构(概况在卡片,children = 库位明细:账面/实盘/盈亏)
|
||
detailRow() {
|
||
if (!this.detailId && !this.stockId && !this.goodsInfo.stockId) return null;
|
||
const locations = this.goodsInfo.locations || [];
|
||
const meta = [];
|
||
const codes = this.goodsInfo.locationCodes || [];
|
||
if (codes.length) meta.push({ label: '库位', value: codes.length === 1 ? codes[0] : `${codes.length} 个` });
|
||
if (this.goodsInfo.lastCheckedAtText) meta.push({ label: '最近上报', value: this.goodsInfo.lastCheckedAtText });
|
||
return {
|
||
key: `goods-${this.detailId || this.stockId || this.goodsInfo.stockId}`,
|
||
detailId: this.detailId,
|
||
title: '',
|
||
subtitle: '',
|
||
statusText: '',
|
||
statusClass: '',
|
||
meta,
|
||
// 「共 N 条」按实际已盘库位数统计(未盘占位行不计入)
|
||
goodsCount: locations.filter(item => item && item.checked).length,
|
||
unknownCount: 0,
|
||
children: locations
|
||
};
|
||
}
|
||
},
|
||
onLoad(options = {}) {
|
||
// 页面需 task_id +(detail_id 或 stock_id):商品明细由接口反查
|
||
this.taskId = String(options.task_id || options.taskId || options.id || '').trim();
|
||
this.detailId = String(options.detail_id || options.detailId || '').trim();
|
||
this.stockId = String(options.stock_id || options.stockId || '').trim();
|
||
|
||
this.loadAll();
|
||
this.syncBroadcastWithMode();
|
||
},
|
||
onShow() {
|
||
this.syncBroadcastWithMode();
|
||
},
|
||
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(`[inventoryCountGoods] broadcast/${action} 调用失败:`, error));
|
||
}
|
||
} catch (error) {
|
||
console.warn(`[inventoryCountGoods] broadcast/${action} 调用异常:`, error);
|
||
}
|
||
},
|
||
syncBroadcastWithMode() {
|
||
if (this.editable) {
|
||
this.safeDispatchBroadcast('setCallbacks', { onResult: this.handleBroadcastResult });
|
||
this.safeDispatchBroadcast('start');
|
||
} else {
|
||
this.safeDispatchBroadcast('stop');
|
||
}
|
||
},
|
||
handleBroadcastResult(result) {
|
||
if (!this.editable) return;
|
||
const code = normalizeScanResult(result);
|
||
if (!code) return;
|
||
this.handleScanKeyword(code);
|
||
},
|
||
handleCameraScan() {
|
||
if (!this.editable) return;
|
||
uni.scanCode({
|
||
onlyFromCamera: true,
|
||
scanType: ['qrCode', 'barCode', 'datamatrix', 'pdf417'],
|
||
success: (res) => {
|
||
const code = normalizeScanResult(res);
|
||
if (code) this.handleScanKeyword(code);
|
||
},
|
||
fail: () => {}
|
||
});
|
||
},
|
||
/**
|
||
* 扫码得到库位码:
|
||
* - 抽屉已打开 → 直接带码重新查询(可连续扫码)
|
||
* - 抽屉未打开 → 打开抽屉并带码查询(唯一命中会自动选中,接着输数量)
|
||
*/
|
||
handleScanKeyword(code) {
|
||
const keyword = String(code || '').trim();
|
||
if (!keyword || !this.editable) return;
|
||
this.scanKeyword = keyword;
|
||
if (this.showEntryPopup) {
|
||
const popup = this.$refs.spaceEntryPopup;
|
||
if (popup && typeof popup.applyKeyword === 'function') {
|
||
popup.applyKeyword(keyword);
|
||
}
|
||
return;
|
||
}
|
||
this.openEntryPopup(keyword);
|
||
},
|
||
handleKeywordClear() {
|
||
this.scanKeyword = '';
|
||
},
|
||
/** 语音播报(复用全局 $tools.speakText,受 voice.enabled 开关控制) */
|
||
speakMessage(message, options = {}) {
|
||
const text = String(message || '').trim();
|
||
if (!text) return;
|
||
const tools = this.$tools;
|
||
if (!tools || typeof tools.speakText !== 'function') return;
|
||
try {
|
||
const task = tools.speakText(text, options);
|
||
if (task && typeof task.catch === 'function') {
|
||
task.catch(error => console.warn('[inventoryCountGoods] 语音播报失败:', error));
|
||
}
|
||
} catch (error) {
|
||
console.warn('[inventoryCountGoods] 语音播报异常:', error);
|
||
}
|
||
},
|
||
// ===== 底部抽屉:选库位 + 录数量 =====
|
||
handleEntryOpen() {
|
||
if (!this.editable) return;
|
||
this.openEntryPopup(this.scanKeyword);
|
||
},
|
||
openEntryPopup(keyword) {
|
||
if (!this.editable) return;
|
||
// 静态盘点拣货未完成时后端拒绝上报,这里先拦住,避免录完数量才失败
|
||
if (this.pickingPending) {
|
||
uni.showToast({ title: '商品尚未完成拣货,请等待拣货完成', icon: 'none' });
|
||
this.speakMessage('拣货未完成,暂不能上报', { force: true, minInterval: 0 });
|
||
return;
|
||
}
|
||
this.pendingLocation = String(keyword || '').trim();
|
||
this.showEntryPopup = true;
|
||
},
|
||
closeEntryPopup() {
|
||
this.showEntryPopup = false;
|
||
this.pendingLocation = '';
|
||
},
|
||
/** 抽屉确认:库位 + 数量 → check.report(多库位商品按所选库位取对应明细ID) */
|
||
async handleEntryConfirm(payload) {
|
||
if (!payload || !payload.location) return;
|
||
const ok = await this.submitReport({
|
||
detailId: this.resolveLocationDetailId(payload),
|
||
location: payload.location,
|
||
spaceId: payload.locationId,
|
||
quantity: payload.quantity,
|
||
stockId: this.goodsInfo.stockId
|
||
});
|
||
// 成功才收起抽屉并清空顶部关键字,失败保留输入便于重试
|
||
if (ok) {
|
||
this.handleKeywordClear();
|
||
this.closeEntryPopup();
|
||
}
|
||
},
|
||
/** 按库位定位盘点明细ID(同一商品多库位时每个库位一条明细) */
|
||
resolveLocationDetailId(payload) {
|
||
const target = payload || {};
|
||
const spaceId = target.locationId !== undefined && target.locationId !== null ? String(target.locationId).trim() : '';
|
||
const code = String(target.location || '').trim();
|
||
const candidates = []
|
||
.concat(Array.isArray(this.goodsInfo.allLocations) ? this.goodsInfo.allLocations : [])
|
||
.concat(Array.isArray(this.goodsInfo.locations) ? this.goodsInfo.locations : []);
|
||
const matched = candidates.find(loc => {
|
||
const locSpaceId = String(loc.spaceId || loc.locationId || '').trim();
|
||
if (spaceId && locSpaceId && locSpaceId === spaceId) return true;
|
||
return !!code && String(loc.locationCode || '').trim() === code;
|
||
});
|
||
return (matched && matched.detailId) || this.detailId;
|
||
},
|
||
/** 上报(check.report:detail_id=该库位明细,location=库位) */
|
||
async submitReport(payload) {
|
||
if (!this.editable || this.submitting) return false;
|
||
// 静态盘点拣货未完成:后端会拦,前端先给明确提示
|
||
if (this.pickingPending) {
|
||
uni.showToast({ title: '商品尚未完成拣货,请等待拣货完成', icon: 'none' });
|
||
this.speakMessage('拣货未完成,暂不能上报', { force: true, minInterval: 0 });
|
||
return false;
|
||
}
|
||
if (!payload || (!payload.detailId && !payload.stockId)) {
|
||
uni.showToast({ title: '缺少盘点明细ID', icon: 'none' });
|
||
return false;
|
||
}
|
||
const location = String(payload.location || '').trim();
|
||
if (!location) {
|
||
uni.showToast({ title: '请选择库位', icon: 'none' });
|
||
return false;
|
||
}
|
||
const spaceId = String(payload.spaceId || payload.locationId || '').trim();
|
||
if (!spaceId) {
|
||
uni.showToast({ title: '缺少库位ID(space_id)', icon: 'none' });
|
||
return false;
|
||
}
|
||
const quantity = Number(payload.quantity);
|
||
if (!Number.isInteger(quantity) || quantity < 0 || quantity > 2147483647) {
|
||
uni.showToast({ title: '请输入不小于0且不超过2147483647的整数数量', icon: 'none' });
|
||
return false;
|
||
}
|
||
this.submitting = true;
|
||
try {
|
||
const response = await this.$http('check.report', buildReportParams(this.taskId, {
|
||
detailId: payload.detailId,
|
||
location,
|
||
spaceId,
|
||
quantity,
|
||
stockId: payload.stockId,
|
||
barcode: this.goodsInfo.barcode,
|
||
itemName: this.goodsInfo.itemName
|
||
}));
|
||
if (response?.flag === 'failure') {
|
||
uni.showToast({ title: '接口失败', icon: 'none' });
|
||
this.speakMessage('登记失败', { force: true, minInterval: 0 });
|
||
return false;
|
||
}
|
||
uni.showToast({ title: '已登记', icon: 'success', duration: 800 });
|
||
this.speakMessage('已登记', { force: true, minInterval: 0 });
|
||
await this.loadInfo();
|
||
return true;
|
||
} catch (error) {
|
||
console.error('[inventoryCountGoods] 盘点上报失败:', error);
|
||
uni.showToast({ title: '异常', icon: 'none' });
|
||
this.speakMessage('登记失败', { force: true, minInterval: 0 });
|
||
return false;
|
||
} finally {
|
||
this.submitting = false;
|
||
}
|
||
},
|
||
/** 概况卡图片预览 */
|
||
previewGoodsImage() {
|
||
const urls = this.cardImages;
|
||
if (!urls.length) return;
|
||
uni.previewImage({ current: urls[0], urls });
|
||
},
|
||
/** 删除该库位的作业记录(stock.check.recordDelete,按 record_ids 批量) */
|
||
handleRecordDelete(child) {
|
||
if (!this.editable) return;
|
||
const recordIds = child && Array.isArray(child.recordIds)
|
||
? child.recordIds.filter(Boolean)
|
||
: (child && child.recordId ? [child.recordId] : []);
|
||
if (!recordIds.length) {
|
||
uni.showToast({ title: '该记录不支持删除', icon: 'none' });
|
||
return;
|
||
}
|
||
if (!this.taskId) {
|
||
uni.showToast({ title: '缺少盘点任务ID', icon: 'none' });
|
||
return;
|
||
}
|
||
const scope = child.title || '该库位';
|
||
const suffix = recordIds.length > 1 ? `的 ${recordIds.length} 条记录` : '这条记录';
|
||
this.deleteRecordTarget = {
|
||
recordIds,
|
||
text: `确认删除「${scope}」${suffix}?`
|
||
};
|
||
this.showDeleteRecordConfirm = true;
|
||
},
|
||
cancelDeleteRecord() {
|
||
this.showDeleteRecordConfirm = false;
|
||
this.deleteRecordTarget = null;
|
||
},
|
||
async confirmDeleteRecord() {
|
||
this.showDeleteRecordConfirm = false;
|
||
const target = this.deleteRecordTarget;
|
||
this.deleteRecordTarget = null;
|
||
if (!target || !target.recordIds || !target.recordIds.length) return;
|
||
await this.removeRecords(target.recordIds);
|
||
},
|
||
async removeRecords(recordIds) {
|
||
if (!this.editable || !this.taskId) return false;
|
||
const ids = (Array.isArray(recordIds) ? recordIds : [recordIds])
|
||
.map(id => Number(id))
|
||
.filter(id => Number.isFinite(id) && id > 0);
|
||
if (!ids.length) return false;
|
||
if (this.submitting) return false;
|
||
this.submitting = true;
|
||
try {
|
||
const response = await this.$http('check.recordDelete', {
|
||
id: Number(this.taskId),
|
||
record_ids: ids
|
||
});
|
||
if (response?.flag === 'failure') {
|
||
uni.showToast({ title: response.message || '删除失败', icon: 'none' });
|
||
this.speakMessage('删除失败', { force: true, minInterval: 0 });
|
||
return false;
|
||
}
|
||
const payload = extractObjectPayload(response);
|
||
const deleted = Number(payload.deleted_count);
|
||
const skipped = Array.isArray(payload.skipped_ids) ? payload.skipped_ids.length : 0;
|
||
let title = '已删除';
|
||
if (Number.isFinite(deleted)) title = `已删除 ${deleted} 条`;
|
||
if (skipped) title += `,跳过 ${skipped} 条`;
|
||
uni.showToast({ title, icon: 'none', duration: 1600 });
|
||
this.speakMessage('已删除', { force: true, minInterval: 0 });
|
||
await this.loadInfo();
|
||
return true;
|
||
} catch (error) {
|
||
console.error('[inventoryCountGoods] 删除作业记录失败:', error);
|
||
uni.showToast({ title: '删除失败', icon: 'none' });
|
||
this.speakMessage('删除失败', { force: true, minInterval: 0 });
|
||
return false;
|
||
} finally {
|
||
this.submitting = false;
|
||
}
|
||
},
|
||
// ===== 下拉刷新 =====
|
||
async handleRefresh() {
|
||
// 防重入:同一手势可能被重复触发
|
||
if (this.refreshing) return;
|
||
this.refreshing = true;
|
||
// App 端原生 refresher 需先收到 true、再收到 false 才会收回(同列表页修复)
|
||
await this.$nextTick();
|
||
try {
|
||
await this.loadAll();
|
||
} finally {
|
||
setTimeout(() => {
|
||
this.refreshing = false;
|
||
}, 300);
|
||
}
|
||
},
|
||
handleRefresherRestore() {
|
||
this.refreshing = false;
|
||
},
|
||
// ===== 数据加载 =====
|
||
/** 任务信息 → 明细(先拿到 mode,避免数量口径缺失) */
|
||
async loadAll() {
|
||
await this.loadTaskInfo();
|
||
await this.loadInfo();
|
||
},
|
||
/** 任务概况(stock.check.detail:只返回主表 check)——入参仅任务ID */
|
||
async loadTaskInfo() {
|
||
const taskId = Number(this.taskId);
|
||
if (!Number.isFinite(taskId) || taskId <= 0) return null;
|
||
try {
|
||
const response = await this.$http('check.detail', { id: taskId });
|
||
if (response?.flag === 'failure') return null;
|
||
const check = extractObjectPayload(response).check || {};
|
||
this.taskInfo = {
|
||
status: String(check.status || '').trim().toLowerCase(),
|
||
mode: String(check.mode || '').trim().toLowerCase(),
|
||
type: check.type || '',
|
||
// 静态盘点:账面取明细快照;普通盘点取当前库存(0.3.318)
|
||
isStatic: isStaticCheck(check.is_static !== undefined ? check.is_static : check.isStatic),
|
||
hasStaticFlag: (check.is_static !== undefined ? check.is_static : check.isStatic) !== undefined
|
||
};
|
||
return this.taskInfo;
|
||
} catch (error) {
|
||
console.error('[inventoryCountGoods] 盘点任务信息加载失败:', error);
|
||
return null;
|
||
}
|
||
},
|
||
/** 商品明细(stock.check.workDataDetail:id + stock_id / detail_id,兼容 summary+rows 钻取结构)——含商品信息/主图/账面/已盘/差异 + 各库位明细 */
|
||
async loadInfo() {
|
||
const taskId = Number(this.taskId);
|
||
if (!Number.isFinite(taskId) || taskId <= 0) {
|
||
this.loadError = '缺少盘点任务ID';
|
||
uni.showToast({ title: this.loadError, icon: 'none' });
|
||
return null;
|
||
}
|
||
const detailId = Number(this.detailId);
|
||
const routeStockId = Number(this.stockId);
|
||
const knownStockId = Number(this.goodsInfo.stockId);
|
||
const stockId = Number.isFinite(knownStockId) && knownStockId > 0
|
||
? knownStockId
|
||
: (Number.isFinite(routeStockId) && routeStockId > 0 ? routeStockId : 0);
|
||
const params = { id: taskId };
|
||
if (Number.isFinite(detailId) && detailId > 0) params.detail_id = detailId;
|
||
if (stockId > 0) params.stock_id = stockId;
|
||
if (!params.detail_id && !params.stock_id) {
|
||
this.loadError = '缺少盘点明细ID/商品库存ID';
|
||
uni.showToast({ title: this.loadError, icon: 'none' });
|
||
return null;
|
||
}
|
||
this.loading = true;
|
||
try {
|
||
const response = await this.$http('check.workDataDetail', params);
|
||
if (response?.flag === 'failure') {
|
||
this.goodsInfo = EMPTY_GOODS_INFO();
|
||
this.loadError = response.message || '盘点明细加载失败';
|
||
uni.showToast({ title: this.loadError, icon: 'none' });
|
||
return null;
|
||
}
|
||
const info = normalizeGoodsDetailInfo(extractObjectPayload(response), this.taskInfo.mode, {
|
||
isStatic: this.taskInfo.hasStaticFlag ? this.taskInfo.isStatic : undefined
|
||
});
|
||
if (info) this.goodsInfo = Object.assign({}, this.goodsInfo, info);
|
||
this.loadError = '';
|
||
return this.goodsInfo;
|
||
} catch (error) {
|
||
console.error('[inventoryCountGoods] 盘点明细加载失败:', error);
|
||
this.goodsInfo = EMPTY_GOODS_INFO();
|
||
this.loadError = '盘点明细加载失败';
|
||
uni.showToast({ title: this.loadError, icon: 'none' });
|
||
return null;
|
||
} finally {
|
||
this.loading = false;
|
||
}
|
||
}
|
||
}
|
||
};
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.inv-goods-page {
|
||
height: 100vh;
|
||
background: #f8f9fa;
|
||
}
|
||
|
||
.normar_container {
|
||
height: 100%;
|
||
display: flex;
|
||
flex-direction: column;
|
||
overflow: hidden;
|
||
}
|
||
|
||
/* 顶部标题栏字号 */
|
||
::v-deep .nav-title .title {
|
||
font-size: 36rpx;
|
||
}
|
||
|
||
/* 数量录入条(紧接 CountSearchPanel,同一白底 + 分隔线视觉) */
|
||
.inv-goods-scroll {
|
||
flex: 1;
|
||
min-height: 0;
|
||
height: auto;
|
||
padding: 20rpx 0 0;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
/* 商品概况(紧凑卡片:图片 + 名称/规格/数量,密度比逐行 label/value 高) */
|
||
.inv-goods-card {
|
||
display: flex;
|
||
align-items: flex-start;
|
||
margin: 0 12rpx 16rpx;
|
||
padding: 20rpx 24rpx;
|
||
background: #ffffff;
|
||
border: 2rpx solid #ebedf2;
|
||
border-radius: 20rpx;
|
||
box-shadow: 0 6rpx 20rpx rgba(31, 45, 61, 0.06);
|
||
}
|
||
|
||
.inv-goods-card__thumb {
|
||
flex-shrink: 0;
|
||
margin-right: 20rpx;
|
||
}
|
||
|
||
.inv-goods-card__thumb-empty {
|
||
width: 120rpx;
|
||
height: 120rpx;
|
||
border-radius: 10rpx;
|
||
background: #f5f7fa;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
}
|
||
|
||
.inv-goods-card__thumb-text {
|
||
font-size: 22rpx;
|
||
color: #c0c4cc;
|
||
}
|
||
|
||
.inv-goods-card__info {
|
||
flex: 1;
|
||
min-width: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
|
||
.inv-goods-card__head {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
}
|
||
|
||
.inv-goods-card__title {
|
||
flex: 1;
|
||
min-width: 0;
|
||
font-size: 38rpx;
|
||
font-weight: bold;
|
||
color: #303133;
|
||
line-height: 1.3;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
.inv-goods-card__flag {
|
||
flex-shrink: 0;
|
||
margin-left: 16rpx;
|
||
font-size: 36rpx;
|
||
line-height: 1.2;
|
||
}
|
||
|
||
.inv-goods-card__flag--done {
|
||
color: #18a058;
|
||
}
|
||
|
||
.inv-goods-card__flag--todo {
|
||
color: #ff9800;
|
||
}
|
||
|
||
/* 静态盘点拣货未完成(后端会拒绝上报,需置灰上报入口) */
|
||
.inv-goods-card__flag--picking {
|
||
color: #e64340;
|
||
}
|
||
|
||
.inv-goods-card__line {
|
||
margin-top: 6rpx;
|
||
font-size: 34rpx;
|
||
color: #606266;
|
||
line-height: 1.4;
|
||
word-break: break-all;
|
||
}
|
||
|
||
.inv-goods-card__metrics {
|
||
margin-top: 10rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
flex-wrap: wrap;
|
||
}
|
||
|
||
.inv-goods-card__metric {
|
||
margin-right: 20rpx;
|
||
font-size: 34rpx;
|
||
color: #303133;
|
||
}
|
||
|
||
.inv-goods-card__diff {
|
||
margin-right: 20rpx;
|
||
font-size: 34rpx;
|
||
font-weight: bold;
|
||
}
|
||
|
||
.inv-goods-card__diff--gain {
|
||
color: #18a058;
|
||
}
|
||
|
||
.inv-goods-card__diff--loss {
|
||
color: #e64340;
|
||
}
|
||
|
||
/* 另一种账面口径提示(静态看当前库存 / 普通看基准快照) */
|
||
.inv-goods-card__hint {
|
||
margin-right: 20rpx;
|
||
font-size: 30rpx;
|
||
color: #b8811a;
|
||
}
|
||
|
||
.inv-goods-tip {
|
||
margin: 0 12rpx 16rpx;
|
||
padding: 24rpx;
|
||
background: #fff8e6;
|
||
border: 2rpx solid #ffe1a8;
|
||
border-radius: 16rpx;
|
||
font-size: 30rpx;
|
||
color: #b8811a;
|
||
text-align: center;
|
||
}
|
||
|
||
.safe-area-bottom {
|
||
height: 20rpx;
|
||
}
|
||
|
||
/* 删除盘点记录确认弹窗(自定义样式) */
|
||
.delete-confirm-popup {
|
||
width: 640rpx;
|
||
padding: 40rpx 32rpx 32rpx;
|
||
background: #ffffff;
|
||
border-radius: 20rpx;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.delete-confirm-popup__title {
|
||
font-size: 42rpx;
|
||
font-weight: bold;
|
||
color: #303133;
|
||
text-align: center;
|
||
margin-bottom: 32rpx;
|
||
}
|
||
|
||
.delete-confirm-popup__body {
|
||
margin-bottom: 36rpx;
|
||
padding: 24rpx;
|
||
background: #fef0f0;
|
||
border-radius: 12rpx;
|
||
}
|
||
|
||
.delete-confirm-popup__text {
|
||
font-size: 36rpx;
|
||
color: #303133;
|
||
line-height: 1.6;
|
||
}
|
||
|
||
.delete-confirm-popup__actions {
|
||
display: flex;
|
||
align-items: center;
|
||
}
|
||
|
||
.delete-confirm-popup__btn {
|
||
flex: 1;
|
||
height: 88rpx;
|
||
border-radius: 12rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-size: 36rpx;
|
||
font-weight: 500;
|
||
}
|
||
|
||
.delete-confirm-popup__btn + .delete-confirm-popup__btn {
|
||
margin-left: 20rpx;
|
||
}
|
||
|
||
.delete-confirm-popup__btn--cancel {
|
||
background: #f5f7fa;
|
||
color: #606266;
|
||
border: 1rpx solid #dcdfe6;
|
||
}
|
||
|
||
.delete-confirm-popup__btn--confirm {
|
||
background: #f56c6c;
|
||
color: #ffffff;
|
||
}
|
||
|
||
.delete-confirm-popup__btn--disabled {
|
||
opacity: 0.6;
|
||
pointer-events: none;
|
||
}
|
||
</style>
|