992 lines
23 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view class="review-detail">
<!-- 空状态 -->
<view v-if="goodsList.length === 0" class="empty-state">
<u-icon name="list" size="86" color="#c0c4cc"></u-icon>
<text class="empty-text">暂无拣货商品</text>
</view>
<!-- 商品详情 -->
<view v-else class="content-layout">
<!-- 订单信息行 -->
<view class="order-info-row">
<view class="order-info-left">
<text class="order-info-text" v-if="detailInfo.waybillNo && detailInfo.waybillNo !== '--'">运单:{{ detailInfo.waybillNo }}</text>
<text class="order-info-text" v-else>波次:{{ detailInfo.waveNo }}</text>
<text class="order-info-divider"></text>
<text class="order-info-text">拣货人:{{ detailInfo.pickerName }}</text>
</view>
<view class="order-info-right">
<view class="reprint-btn" @click="$emit('reprint')">面单补打</view>
</view>
</view>
<view v-if="detailInfo.listType === 'group'" class="wave-info-row">
<text class="wave-info-text">波次订单:{{ detailInfo.totalOrders || '--' }}单</text>
<text class="wave-info-divider"></text>
<text class="wave-info-text">篮号:{{ detailInfo.waveIndex || detailInfo.boxNo || '--' }}</text>
</view>
<view class="top-module">
<view class="top-card">
<view class="top-main top-main--horizontal">
<!-- 左侧图片 -->
<view class="goods-thumb" @click.stop="previewCurrentGoodsImage">
<u-image
class="goods-image"
:src="currentGoods.imageUrl || ''"
mode="aspectFill"
width="140rpx"
height="140rpx"
>
<template #error>
<view class="image-placeholder image-placeholder--large">
<u-icon name="photo" size="28" color="#c0c4cc"></u-icon>
</view>
</template>
</u-image>
<view v-if="getCurrentGoodsImageList().length > 1" class="image-badge">
<text class="image-badge-text">1/{{ getCurrentGoodsImageList().length }}</text>
</view>
</view>
<!-- 右侧信息 -->
<view class="top-info top-info--compact">
<view class="info-row name-barcode-row">
<text class="goods-name goods-name--compact">{{ currentGoods.skuName || '--' }}</text>
<text class="barcode-tag" :class="{ 'barcode-tag--matched': isCurrentBarcodeMatched }" @click="handleBarcodeClick">{{ currentGoods.barcode || '--' }}</text>
</view>
<view class="info-row">
<text class="info-label">数量</text>
<text class="info-value" :class="{ 'info-value--warn': isScannedComplete }">{{ currentGoods.scannedQty || 0 }} / {{ currentGoods.planQty || 0 }}</text>
</view>
<view v-if="detailInfo.listType !== 'group'" class="info-row">
<text class="info-label">蓝号</text>
<text class="info-value">{{ detailInfo.waveIndex || (detailInfo.boxNo ? '' : '--') }}<text v-if="detailInfo.boxNo" class="box-no-suffix">{{ detailInfo.boxNo }}号篮</text></text>
</view>
<view class="info-row">
<text class="info-label">规格</text>
<text class="info-value">{{ currentGoods.location || '--' }}</text>
</view>
</view>
</view>
</view>
</view>
<view class="bottom-module">
<view class="bottom-module-title">商品列表</view>
<view class="pick-list-scroll">
<!-- 宫格模式 -->
<view v-if="viewMode === 'grid'" class="pick-list pick-list--grid">
<view
v-for="(item, index) in goodsList"
:key="item.id"
class="pick-item-wrap"
@click="selectGoods(index)"
>
<view
class="metric-card-btn"
:class="{
'metric-card-btn--active': index === currentGoodsIndex,
'metric-card-btn--matched': isGoodsMatched(item)
}"
>
<view class="order-corner"></view>
<view class="metric-diagonal"></view>
<text class="metric-order">{{ item.lineNo || 0 }}</text>
<text class="metric-product">{{ item.planQty || 0 }}</text>
<text class="metric-scanned">{{ item.scannedQty || 0 }}</text>
</view>
</view>
</view>
<!-- 列表模式 -->
<view v-else class="pick-list pick-list--table">
<view class="list-table-header">
<text class="list-table-col list-table-col--no">序号</text>
<text class="list-table-col list-table-col--name">商品名称</text>
<text class="list-table-col list-table-col--qty">计划</text>
<text class="list-table-col list-table-col--qty">已扫</text>
<text class="list-table-col list-table-col--status">状态</text>
</view>
<view
v-for="(item, index) in goodsList"
:key="item.id"
class="list-table-row"
:class="{
'list-table-row--active': index === currentGoodsIndex,
'list-table-row--matched': isGoodsMatched(item)
}"
@click="selectGoods(index)"
>
<text class="list-table-col list-table-col--no">{{ item.lineNo || index + 1 }}</text>
<text class="list-table-col list-table-col--name">{{ item.skuName || '--' }}</text>
<text class="list-table-col list-table-col--qty">{{ item.planQty || 0 }}</text>
<text class="list-table-col list-table-col--qty" :class="{ 'list-table-col--done': (item.scannedQty || 0) >= (item.planQty || 0) }">{{ item.scannedQty || 0 }}</text>
<text class="list-table-col list-table-col--status" :class="isGoodsMatched(item) ? 'list-table-col--matched-text' : ''">{{ isGoodsMatched(item) ? '已匹配' : '待匹配' }}</text>
</view>
</view>
</view>
<!-- 推荐包材提示 -->
<view v-if="detailInfo.suggestedPkg" class="package-info-hint">
<text class="package-info-label">推荐包材:</text>
<text class="package-info-value">{{ detailInfo.suggestedPkg.name }}({{ detailInfo.suggestedPkg.code }})</text>
<text class="package-info-spec">{{ detailInfo.suggestedPkg.spec }}</text>
</view>
<view class="safe-area-bottom"></view>
</view>
</view>
<!-- 底部合计 -->
<view class="bottom-summary">
<text class="bottom-summary-text">合计:<text class="bottom-summary-value">{{ totalPlanQty }}</text></text>
<text class="bottom-summary-scan">已扫:<text class="bottom-summary-value">{{ totalScannedQty }}</text><text class="bottom-summary-split">/</text><text class="bottom-summary-total">{{ totalPlanQty }}</text>件</text>
<view v-if="canConfirmRecheck && !autoShip" class="confirm-btn" @click="$emit('confirmRecheck')">确认复核</view>
<view class="view-mode-toggle" @click="toggleViewMode">
<u-icon :name="viewMode === 'grid' ? 'list' : 'grid'" size="32" color="#2979ff"></u-icon>
<text class="view-mode-text">{{ viewMode === 'grid' ? '列表' : '宫格' }}</text>
</view>
</view>
</view>
</template>
<script>
import voice from '@/core/utils/voice';
export default {
name: 'ReviewDetail',
created() {
console.log('[ReviewDetail] created');
},
mounted() {
console.log('[ReviewDetail] mounted, goodsList length:', this.goodsList?.length);
},
props: {
goodsList: {
type: Array,
default: () => []
},
scanQty: {
type: Number,
default: 1
},
autoShip: {
type: Boolean,
default: false
},
detailInfo: {
type: Object,
default: () => ({
recordId: '',
orderId: 0,
waveId: '',
waveNo: '--',
waybillNo: '',
matchType: '',
recheckStatus: '',
pickerName: '--',
cartNo: '--',
status: 'pending',
unreviewedCount: 0,
storeRemark: '',
waveIndex: '',
orderIds: [],
interceptStatus: '',
printStationId: '',
printStationName: '',
boxNo: ''
})
},
scannedPackageMaterial: {
type: Object,
default: null
}
},
data() {
// 读取本地存储的视图模式,默认列表模式
let savedMode = 'list';
try {
const stored = uni.getStorageSync('review_view_mode');
if (stored === 'grid' || stored === 'list') {
savedMode = stored;
}
} catch (e) {
// 忽略读取失败
}
return {
currentGoodsIndex: 0,
matchedGoodsId: '',
matchedGoodsState: {},
viewMode: savedMode
};
},
computed: {
currentGoods() {
return this.goodsList[this.currentGoodsIndex] || {};
},
isCurrentBarcodeMatched() {
const currentId = String(this.currentGoods?.id || '');
if (!currentId) return false;
return !!this.matchedGoodsState[currentId];
},
totalPlanQty() {
return this.goodsList.reduce((sum, item) => sum + (item.planQty || 0), 0);
},
totalScannedQty() {
return this.goodsList.reduce((sum, item) => sum + (item.scannedQty || 0), 0);
},
isReadOnly() {
return String(this.detailInfo?.recheckStatus || '').toLowerCase() === 'fin';
},
isScannedComplete() {
const plan = Number(this.currentGoods?.planQty || 0);
const scanned = Number(this.currentGoods?.scannedQty || 0);
return plan > 0 && scanned >= plan;
},
isAllMatched() {
return this.goodsList.every(item => {
const id = String(item?.id || '');
if (!id) return false;
return !!this.matchedGoodsState[id];
});
},
isAllScanned() {
return this.goodsList.every(item => (item.scannedQty || 0) >= (item.planQty || 0));
},
canConfirmRecheck() {
return this.isAllMatched && this.isAllScanned;
}
},
watch: {
goodsList: {
handler(newList, oldList) {
// 切换订单时重置匹配状态,防止残留
if (oldList && oldList.length > 0 && newList !== oldList) {
this.resetMatchState();
}
const total = this.totalPlanQty;
const scanned = this.totalScannedQty;
if (total > 0 && scanned >= total) {
this.$emit('allScanned');
}
},
deep: true
},
currentGoodsIndex(val) {
this.$emit('currentGoodsChange', val);
}
},
methods: {
isGoodsMatched(item) {
const id = String(item?.id || '');
if (!id) return false;
return !!this.matchedGoodsState[id];
},
normalizeBarcode(value) {
return String(value || '').replace(/\s+/g, '').toUpperCase();
},
extractBarcodeCandidates(item) {
const sourceList = [item?.barcode, item?.skuCode];
const result = [];
sourceList.forEach(source => {
const text = String(source || '').trim();
if (!text) return;
text
.split(/[;,,|\s]+/)
.map(part => this.normalizeBarcode(part))
.filter(part => !!part)
.forEach(part => result.push(part));
});
return Array.from(new Set(result));
},
/**
* 外部调用:处理扫描到的条码
* @param {string} scanCode - 扫描结果
* @returns {boolean} 是否匹配成功
*/
handleScanCode(scanCode) {
// 已复核订单只读,不做商品匹配
if (this.isReadOnly) return false;
const code = this.normalizeBarcode(scanCode);
if (!code) return false;
const matchIndex = this.goodsList.findIndex(item => {
const candidates = this.extractBarcodeCandidates(item);
return candidates.includes(code);
});
if (matchIndex < 0) {
voice.speak('无记录');
return false;
}
this.currentGoodsIndex = matchIndex;
const matchedItem = this.goodsList[matchIndex];
const maxQty = matchedItem?.planQty || 0;
const currentScanned = matchedItem?.scannedQty || 0;
// 已复核完成的商品,不再增加数量
if (currentScanned >= maxQty) {
uni.showToast({ title: '该商品已复核完成', icon: 'none' });
return true;
}
const addQty = Math.min(this.scanQty || 1, maxQty - currentScanned);
const newScanned = Math.min(currentScanned + addQty, maxQty);
// 更新已扫数量
this.$emit('updateScannedQty', matchIndex, newScanned);
// 所有商品都已完成扫描时才播报"数据一致"
const allDone = this.goodsList.every((item, idx) => {
const qty = idx === matchIndex ? newScanned : (item.scannedQty || 0);
return qty >= (item.planQty || 0);
});
if (allDone) {
voice.speak('数据一致');
}
// 已扫数量达到计划数量时,才标记为已匹配
if (newScanned >= maxQty) {
const matchedId = String(matchedItem?.id || '');
if (matchedId) {
this.matchedGoodsId = matchedId;
if (typeof this.$set === 'function') {
this.$set(this.matchedGoodsState, matchedId, true);
} else {
this.matchedGoodsState[matchedId] = true;
}
}
}
// 设置的数量>1时,使用后回归1(一次性)
if ((this.scanQty || 1) > 1) {
this.$emit('resetScanQty');
}
return true;
},
/**
* 无条码复核(点击条码区域触发)
*/
handleBarcodeClick() {
const item = this.currentGoods;
if (!item) return;
const skuName = item.skuName || '商品';
const planQty = item.planQty || 0;
const scannedQty = item.scannedQty || 0;
if (scannedQty >= planQty) {
uni.showToast({ title: '该商品已复核完成', icon: 'none' });
return;
}
uni.showModal({
title: '无条码复核',
content: `将商品「${skuName}」标记为已复核(${scannedQty}/${planQty} → ${planQty}/${planQty})?`,
success: (res) => {
if (!res.confirm) return;
this.$emit('updateScannedQty', this.currentGoodsIndex, planQty);
const matchId = String(item.id || '');
if (matchId) {
this.matchedGoodsId = matchId;
if (typeof this.$set === 'function') {
this.$set(this.matchedGoodsState, matchId, true);
} else {
this.matchedGoodsState[matchId] = true;
}
}
// 标记当前商品条码匹配
this.$emit('barcodeMatched', matchId);
uni.showToast({ title: `已标记为已复核(${planQty}/${planQty})`, icon: 'success' });
voice.speak('数据一致');
}
});
},
previewCurrentGoodsImage() {
const images = this.getCurrentGoodsImageList();
if (!images.length) return;
uni.previewImage({
current: images[0],
urls: images
});
},
getCurrentGoodsImageList() {
const list = Array.isArray(this.currentGoods?.images) ? this.currentGoods.images : [];
const normalizedList = list
.map(url => String(url || '').trim())
.filter(url => !!url);
const currentUrl = String(this.currentGoods?.imageUrl || '').trim();
if (!normalizedList.length && currentUrl) {
return [currentUrl];
}
return normalizedList;
},
selectGoods(index) {
this.currentGoodsIndex = index;
},
toggleViewMode() {
this.viewMode = this.viewMode === 'grid' ? 'list' : 'grid';
try {
uni.setStorageSync('review_view_mode', this.viewMode);
} catch (e) {
console.warn('[ReviewDetail] 保存视图模式失败:', e);
}
this.$emit('viewModeChange', this.viewMode);
},
/**
* 标记条码匹配成功
*/
markBarcodeMatched(itemId) {
const id = String(itemId || '');
if (!id) return;
if (typeof this.$set === 'function') {
this.$set(this.matchedGoodsState, id, true);
} else {
this.matchedGoodsState[id] = true;
}
},
/**
* 重置匹配状态(切换订单时调用)
*/
resetMatchState() {
this.matchedGoodsState = {};
this.matchedGoodsId = '';
this.currentGoodsIndex = 0;
}
}
};
</script>
<style lang="scss" scoped>
.review-detail {
display: flex;
flex-direction: column;
height: 100%;
overflow: hidden;
}
.content-layout {
flex: 1;
display: flex;
flex-direction: column;
min-height: 0;
}
.top-module {
flex-shrink: 0;
}
.top-card {
background: #ffffff;
border-radius: 12rpx;
margin: 12rpx 16rpx 0;
padding: 16rpx;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
}
.goods-thumb {
position: relative;
width: 140rpx;
height: 140rpx;
border-radius: 10rpx;
overflow: hidden;
flex-shrink: 0;
background: #f5f5f5;
}
.goods-image {
width: 140rpx;
height: 140rpx;
}
.image-placeholder--large {
width: 140rpx;
height: 140rpx;
display: flex;
align-items: center;
justify-content: center;
background: #f2f3f5;
border-radius: 10rpx;
}
.image-badge {
position: absolute;
right: 6rpx;
bottom: 6rpx;
background: rgba(0, 0, 0, 0.5);
border-radius: 10rpx;
padding: 2rpx 8rpx;
}
.image-badge-text {
font-size: 18rpx;
color: #ffffff;
line-height: 1.3;
}
.top-main--horizontal {
display: flex;
flex-direction: row;
align-items: flex-start;
gap: 16rpx;
}
.top-info--compact {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
gap: 6rpx;
}
.goods-name--compact {
font-size: 32rpx;
font-weight: 600;
color: #303133;
line-height: 38rpx;
word-break: break-all;
margin-bottom: 2rpx;
}
.info-row {
display: flex;
align-items: center;
font-size: 28rpx;
line-height: 32rpx;
}
.info-label {
color: #909399;
flex-shrink: 0;
width: 60rpx;
}
.info-value {
color: #303133;
flex: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.info-row--barcode-highlight .info-value {
color: #2979ff;
font-weight: 500;
}
.info-value--warn {
color: #07c160;
font-weight: 500;
}
.box-no-suffix {
color: #e6a23c;
margin-left: 6rpx;
font-size: 26rpx;
}
.order-info-row {
display: flex;
align-items: center;
justify-content: space-between;
margin: 8rpx 16rpx 0;
padding: 12rpx 16rpx;
background: #ffffff;
border-radius: 10rpx;
border: 1rpx solid #ebeef5;
}
.order-info-left {
display: flex;
align-items: center;
gap: 12rpx;
flex: 1;
min-width: 0;
}
.order-info-text {
font-size: 28rpx;
color: #909399;
white-space: nowrap;
}
.order-info-divider {
width: 1rpx;
height: 20rpx;
background: #dcdfe6;
flex-shrink: 0;
}
.wave-info-row {
display: flex;
align-items: center;
gap: 12rpx;
margin: 0 16rpx;
padding: 8rpx 16rpx;
background: #f5f7fa;
border-radius: 6rpx;
font-size: 26rpx;
}
.wave-info-text {
color: #606266;
font-size: 26rpx;
}
.wave-info-divider {
width: 1rpx;
height: 18rpx;
background: #dcdfe6;
flex-shrink: 0;
}
.order-info-right {
flex-shrink: 0;
}
.reprint-btn {
padding: 4rpx 16rpx;
border: 1rpx solid #2979ff;
border-radius: 6rpx;
font-size: 26rpx;
color: #2979ff;
line-height: 1.6;
}
.reprint-btn:active {
opacity: 0.7;
}
.name-barcode-row {
gap: 12rpx;
margin-bottom: 2rpx;
}
.name-barcode-row .goods-name--compact {
flex: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.barcode-tag {
flex-shrink: 0;
font-size: 22rpx;
color: #2979ff;
background: #f0f7ff;
border: 1rpx solid #b3d8ff;
border-radius: 6rpx;
padding: 2rpx 10rpx;
line-height: 1.6;
max-width: 240rpx;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.barcode-tag--matched {
color: #07c160;
background: #f0fff5;
border-color: #b3ebc1;
}
.bottom-module {
flex: 1;
min-height: 0;
padding: 8rpx 16rpx 0;
box-sizing: border-box;
overflow-y: auto;
-webkit-overflow-scrolling: touch;
}
.bottom-module-title {
font-size: 30rpx;
font-weight: 600;
color: #303133;
margin-bottom: 8rpx;
}
.pick-list-scroll {
min-height: 0;
}
.pick-list {
display: flex;
flex-wrap: wrap;
gap: 12rpx;
}
.pick-item-wrap {
flex: 0 0 auto;
}
.metric-card-btn {
position: relative;
width: 96rpx;
height: 96rpx;
border: 2rpx solid #dcdfe6;
border-radius: 10rpx;
background: #fafafa;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 2rpx;
overflow: hidden;
}
.metric-card-btn--active {
border-color: #2979ff;
background: #f0f7ff;
}
.metric-card-btn--matched {
border-color: #07c160;
background: #07c160;
}
.metric-card-btn--matched .metric-order,
.metric-card-btn--matched .metric-product,
.metric-card-btn--matched .metric-scanned {
color: #ffffff;
}
.order-corner {
display: none;
}
.metric-diagonal {
display: none;
}
.metric-order {
font-size: 32rpx;
font-weight: 600;
color: #2979ff;
line-height: 1.2;
}
.metric-card-btn--matched .metric-order {
color: #ffffff;
}
.metric-product {
font-size: 20rpx;
color: #909399;
line-height: 1.2;
}
.metric-scanned {
font-size: 20rpx;
color: #e6a23c;
line-height: 1.2;
}
.metric-card-btn--matched .metric-scanned {
color: #ffffff;
}
.bottom-summary {
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: space-between;
padding: 16rpx 24rpx;
padding-bottom: calc(16rpx + env(safe-area-inset-bottom));
background: #ffffff;
border-top: 1rpx solid #ebeef5;
}
.bottom-summary-text {
font-size: 34rpx;
color: #909399;
flex-shrink: 0;
}
.bottom-summary-value {
color: #303133;
font-weight: 500;
margin-left: 4rpx;
}
.bottom-summary-scan {
font-size: 32rpx;
color: #909399;
flex-shrink: 0;
}
.bottom-summary-split {
color: #c0c4cc;
margin: 0 4rpx;
}
.bottom-summary-total {
color: #303133;
font-weight: 500;
}
.confirm-btn {
flex-shrink: 0;
padding: 8rpx 24rpx;
background: #2979ff;
border-radius: 8rpx;
font-size: 32rpx;
color: #ffffff;
font-weight: 500;
line-height: 1.4;
}
.confirm-btn:active {
opacity: 0.7;
}
.view-mode-toggle {
display: flex;
align-items: center;
gap: 6rpx;
padding: 6rpx 12rpx;
border: 1rpx solid #2979ff;
border-radius: 8rpx;
flex-shrink: 0;
}
.view-mode-toggle:active {
opacity: 0.7;
}
.view-mode-text {
font-size: 26rpx;
color: #2979ff;
}
/* 列表模式表格样式 */
.pick-list--table {
display: flex;
flex-direction: column;
gap: 0;
}
.list-table-header {
display: flex;
align-items: center;
padding: 16rpx 12rpx;
background: #f5f7fa;
border-radius: 8rpx 8rpx 0 0;
border-bottom: 2rpx solid #ebeef5;
}
.list-table-row {
display: flex;
align-items: center;
padding: 16rpx 12rpx;
border-bottom: 1rpx solid #f2f3f5;
}
.list-table-row:active {
background: #f5f6fa;
}
.list-table-row--active {
background: #f0f7ff;
}
.list-table-row--matched {
background: #07c160;
}
.list-table-row--matched .list-table-col {
color: #ffffff;
}
.list-table-col {
font-size: 30rpx;
color: #303133;
}
.list-table-header .list-table-col {
color: #909399;
font-weight: 500;
font-size: 28rpx;
}
.list-table-col--no {
width: 80rpx;
text-align: center;
flex-shrink: 0;
}
.list-table-col--name {
flex: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
padding: 0 12rpx;
}
.list-table-col--qty {
width: 90rpx;
text-align: center;
flex-shrink: 0;
}
.list-table-col--status {
width: 100rpx;
text-align: center;
flex-shrink: 0;
}
.list-table-col--done {
color: #07c160;
font-weight: 500;
}
.list-table-col--matched-text {
color: #ffffff;
}
.empty-state {
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.empty-text {
margin-top: 18rpx;
font-size: 36rpx;
color: #909399;
}
.safe-area-bottom {
height: calc(30rpx + env(safe-area-inset-bottom));
}
.package-info-hint {
flex-shrink: 0;
padding: 10rpx 24rpx;
background: #fffbe6;
border-top: 1rpx solid #f0e6b8;
border-bottom: 1rpx solid #f0e6b8;
display: flex;
align-items: center;
gap: 6rpx;
line-height: 1.4;
}
.package-info-label {
font-size: 30rpx;
color: #909399;
flex-shrink: 0;
}
.package-info-value {
font-size: 30rpx;
color: #2979ff;
font-weight: 500;
}
.package-info-spec {
font-size: 30rpx;
color: #c0c4cc;
}
</style>