466 lines
13 KiB
Vue
466 lines
13 KiB
Vue
<template>
|
||
<view class="shipping-label-page">
|
||
<view class="normar_container">
|
||
<page-nav :title="title">
|
||
<template #right>
|
||
<view
|
||
class="nav-manual-input"
|
||
:class="{ 'nav-manual-input--inactive': !showScanInput }"
|
||
@click="toggleScanInput"
|
||
>
|
||
<text class="nav-manual-input-text">{{ showScanInput ? '关闭手动输入' : '手动输入' }}</text>
|
||
</view>
|
||
</template>
|
||
</page-nav>
|
||
|
||
<!-- 波次/面单号 手动输入区 -->
|
||
<view class="scan-section" v-show="showScanInput">
|
||
<view class="scan-input-wrap">
|
||
<u-input
|
||
v-model="scanInput"
|
||
placeholder="扫描/输入快递单号"
|
||
border="surround"
|
||
:customStyle="{ flex: 1 }"
|
||
:focus="scanFocused"
|
||
@confirm="handleScanConfirm"
|
||
></u-input>
|
||
<view class="scan-camera-btn" @click="handleCameraScan">
|
||
<u-icon name="camera" size="22" color="#2979ff"></u-icon>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 已打印但未领料的波次数量(固定) -->
|
||
<view class="unclaimed-wave-count">
|
||
<text class="unclaimed-wave-count-label">确认打印未领料波次数量:</text>
|
||
<text class="unclaimed-wave-count-value">{{ unclaimedWaveCount }}</text>
|
||
</view>
|
||
<!-- 领料信息:标题固定,波次号列表滚动 -->
|
||
<view class="claim-info-section">
|
||
<view class="claim-info-header">
|
||
<text class="claim-info-header-text">领料信息:</text>
|
||
</view>
|
||
<scroll-view v-if="claimList.length" class="claim-info-scroll" scroll-y>
|
||
<view class="claim-info-body">
|
||
<view v-for="item in reversedClaimList" :key="item" class="info-row">
|
||
<text class="info-value">{{ item }}</text>
|
||
</view>
|
||
</view>
|
||
</scroll-view>
|
||
<view v-else class="content-placeholder">
|
||
<u-icon name="file-text" size="86" color="#c0c4cc"></u-icon>
|
||
<text class="placeholder-text">暂无数据</text>
|
||
</view>
|
||
</view>
|
||
<view class="safe-area-bottom"></view>
|
||
|
||
<!-- 底部操作栏 -->
|
||
<view class="claim-footer">
|
||
<view class="claim-footer-total">
|
||
<text class="claim-footer-total-label">总数量</text>
|
||
<text class="claim-footer-total-value">{{ totalQuantity }}</text>
|
||
</view>
|
||
<view class="claim-footer-btn" @click="handleFinishClaim">
|
||
<text class="claim-footer-btn-text">返回结束领料</text>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
import voice from '@/core/utils/voice';
|
||
|
||
export default {
|
||
data() {
|
||
return {
|
||
title: '面单波次领料',
|
||
showScanInput: false,
|
||
scanInput: '',
|
||
scanFocused: false,
|
||
totalQuantity: 0,
|
||
submitting: false,
|
||
claimList: [],
|
||
unclaimedWaveCount: 0,
|
||
unclaimedWavePolling: false
|
||
};
|
||
},
|
||
computed: {
|
||
// 波次号倒序(最新扫描的排最上)
|
||
reversedClaimList() {
|
||
return this.claimList.slice().reverse();
|
||
}
|
||
},
|
||
onLoad() {
|
||
// 注册广播扫码回调并启动
|
||
this.$store.dispatch('broadcast/setCallbacks', {
|
||
onResult: this.onScanData
|
||
});
|
||
this.$store.dispatch('broadcast/start');
|
||
},
|
||
onShow() {
|
||
// 返回页面时重新恢复本页扫码回调(避免被其它页面覆盖后扫码失效),再恢复广播
|
||
this.$store.dispatch('broadcast/setCallbacks', {
|
||
onResult: this.onScanData
|
||
});
|
||
this.$store.dispatch('broadcast/resume');
|
||
// 启动「已打印但未领料波次数量」长轮询
|
||
this.startUnclaimedWavePolling();
|
||
},
|
||
onHide() {
|
||
this.$store.dispatch('broadcast/pause');
|
||
this.stopUnclaimedWavePolling();
|
||
},
|
||
onUnload() {
|
||
this.$store.dispatch('broadcast/stop');
|
||
this.stopUnclaimedWavePolling();
|
||
},
|
||
methods: {
|
||
// 广播扫码回调:扫码枪扫描结果
|
||
onScanData(data) {
|
||
const scanText = data && data.data ? String(data.data).trim() : '';
|
||
if (!scanText) return;
|
||
console.log('[面单波次领料] 广播扫描:', scanText);
|
||
this.scanInput = scanText;
|
||
this.submitWaveClaim(scanText);
|
||
},
|
||
toggleScanInput() {
|
||
this.showScanInput = !this.showScanInput;
|
||
},
|
||
handleScanConfirm(value) {
|
||
const code = value || this.scanInput;
|
||
if (!code) return;
|
||
this.submitWaveClaim(code);
|
||
},
|
||
// 扫描面单号领取整波(领料):pick.waveClaimScan
|
||
// - 按面单号定位订单后反查波次,仅支持大团购(pick_mode=5)与非抓取散单(source=0)整波领料
|
||
// - 抓取波次返回 400(data.no_claim_needed=true)无需领料;波次已全部领料返回 already_claimed
|
||
async submitWaveClaim(waybillNo) {
|
||
const code = String(waybillNo || '').trim();
|
||
if (!code) return;
|
||
if (this.submitting) return;
|
||
this.submitting = true;
|
||
uni.showLoading({ title: '领料中...', mask: true });
|
||
try {
|
||
const res = await this.$http('pick.waveClaimScan', {
|
||
waybill_no: code
|
||
}, '', false);
|
||
this.handleWaveClaimResponse(res);
|
||
} catch (error) {
|
||
const msg = String((error && (error.msg || error.message || error.errMsg)) || '领料失败');
|
||
uni.showToast({ title: msg, icon: 'none' });
|
||
if (this.isNotFoundError(error)) {
|
||
this.speakVoice('没有波次');
|
||
} else {
|
||
this.speakVoice('领取失败');
|
||
}
|
||
} finally {
|
||
this.submitting = false;
|
||
uni.hideLoading();
|
||
}
|
||
},
|
||
handleWaveClaimResponse(res) {
|
||
const data = (res && res.data && typeof res.data === 'object' && !Array.isArray(res.data)) ? res.data : {};
|
||
// 业务失败
|
||
if (res && res.flag === 'failure') {
|
||
if (data.no_claim_needed === true) {
|
||
uni.showToast({ title: '该波次为抓取波次,无需领料', icon: 'none' });
|
||
this.speakVoice('无需领料');
|
||
} else if (this.isNotFoundError(res)) {
|
||
// 404:未找到该面单号对应的订单,或波次不存在/不属于当前仓库
|
||
uni.showToast({ title: (res && (res.message || res.msg)) || '未找到该面单号对应的订单或波次', icon: 'none' });
|
||
this.speakVoice('没有波次');
|
||
} else {
|
||
uni.showToast({ title: (res && (res.message || res.msg)) || '领料失败', icon: 'none' });
|
||
this.speakVoice('领取失败');
|
||
}
|
||
return;
|
||
}
|
||
// 成功:合并顶层与 data(兼容不同返回结构)
|
||
const payload = { ...(res || {}), ...data };
|
||
if (payload.status === 'already_claimed') {
|
||
uni.showToast({ title: payload.tip || '该波次已领料', icon: 'none' });
|
||
this.speakVoice('失败,波次已领料');
|
||
} else {
|
||
// claimed:整波领料完成,追加波次号(去重)并累计总数量
|
||
const waveNo = String(payload.wave_no || '').trim();
|
||
if (waveNo && !this.claimList.includes(waveNo)) {
|
||
this.claimList.push(waveNo);
|
||
this.totalQuantity += 1;
|
||
}
|
||
uni.showToast({ title: payload.tip || '整波领料完成', icon: 'success' });
|
||
this.speakVoice('领取成功');
|
||
}
|
||
// 清空已提交的面单号输入
|
||
if (this.scanInput === String(payload.waybill_no || '')) {
|
||
this.scanInput = '';
|
||
}
|
||
},
|
||
// 识别 404:未找到面单号对应订单,或波次不存在/不属于当前仓库
|
||
isNotFoundError(res) {
|
||
if (!res || typeof res !== 'object') return false;
|
||
const code = res.code || res.statusCode || res.status || res.httpCode;
|
||
if (Number(code) === 404) return true;
|
||
const text = String((res && (res.message || res.msg)) || '').toLowerCase();
|
||
return text.indexOf('未找到') > -1 || text.indexOf('不存在') > -1 || text.indexOf('404') > -1;
|
||
},
|
||
speakVoice(text) {
|
||
if (voice && typeof voice.speak === 'function') {
|
||
voice.speak(text, { minInterval: 800 });
|
||
}
|
||
},
|
||
// 「已打印但未领料的波次数量」长轮询(order.wave.confirmPrintUnclaimedWaveCount)
|
||
// 后端长轮询:不传 last_count 立即返回当前值;传 last_count 后最长等待 60s,变化立即返回
|
||
startUnclaimedWavePolling() {
|
||
if (this.unclaimedWavePolling) return;
|
||
this.unclaimedWavePolling = true;
|
||
this.pollUnclaimedWaveCount(null);
|
||
},
|
||
stopUnclaimedWavePolling() {
|
||
this.unclaimedWavePolling = false;
|
||
},
|
||
async pollUnclaimedWaveCount(lastCount) {
|
||
if (!this.unclaimedWavePolling) return;
|
||
let nextCount = lastCount;
|
||
try {
|
||
const params = (lastCount === null || lastCount === undefined)
|
||
? {}
|
||
: { last_count: lastCount };
|
||
// 最后一个参数 timeout=70000:后端长轮询最长等待 60s,客户端超时需大于 60s
|
||
const res = await this.$http(
|
||
'order.wave.confirmPrintUnclaimedWaveCount',
|
||
params,
|
||
'',
|
||
false,
|
||
'text',
|
||
70000
|
||
);
|
||
const data = (res && res.data && typeof res.data === 'object' && !Array.isArray(res.data))
|
||
? res.data
|
||
: {};
|
||
const payload = { ...(res || {}), ...data };
|
||
const count = Number(payload.count);
|
||
this.unclaimedWaveCount = Number.isFinite(count) ? count : 0;
|
||
nextCount = this.unclaimedWaveCount;
|
||
} catch (error) {
|
||
console.warn('[面单波次领料] 未领料波次数量轮询失败:', error);
|
||
// 失败后延迟 2s 重试(沿用原 last_count 基线)
|
||
await this.sleep(2000);
|
||
}
|
||
if (this.unclaimedWavePolling) {
|
||
this.pollUnclaimedWaveCount(nextCount);
|
||
}
|
||
},
|
||
sleep(ms) {
|
||
return new Promise(resolve => setTimeout(resolve, ms));
|
||
},
|
||
handleCameraScan() {
|
||
uni.scanCode({
|
||
success: (res) => {
|
||
this.scanInput = res.result;
|
||
this.handleScanConfirm(res.result);
|
||
}
|
||
});
|
||
},
|
||
handleFinishClaim() {
|
||
// TODO: 结束领料(可在此调用结束领料接口后再返回)
|
||
uni.navigateBack({
|
||
delta: 1,
|
||
fail: () => {}
|
||
});
|
||
}
|
||
}
|
||
};
|
||
</script>
|
||
<style lang="scss" scoped>
|
||
.shipping-label-page {
|
||
height: 100vh;
|
||
background: #f8f9fa;
|
||
}
|
||
|
||
.normar_container {
|
||
height: 100%;
|
||
display: flex;
|
||
flex-direction: column;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.content-placeholder {
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
justify-content: center;
|
||
flex: 1;
|
||
height: 0;
|
||
}
|
||
|
||
.placeholder-text {
|
||
margin-top: 24rpx;
|
||
font-size: 28rpx;
|
||
color: #909399;
|
||
}
|
||
|
||
/* ===== 已打印未领料波次数 ===== */
|
||
.unclaimed-wave-count {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: flex-start;
|
||
margin: 20rpx 24rpx 0;
|
||
padding: 24rpx;
|
||
background: #FFE7BA;
|
||
border-radius: 12rpx;
|
||
|
||
.unclaimed-wave-count-label {
|
||
font-size: 32rpx;
|
||
font-weight: bold;
|
||
color: #D46B08;
|
||
}
|
||
|
||
.unclaimed-wave-count-value {
|
||
margin-left: 12rpx;
|
||
font-size: 48rpx;
|
||
line-height: 32rpx;
|
||
font-weight: bold;
|
||
color: #D46B08;
|
||
}
|
||
}
|
||
|
||
/* ===== 领料信息 ===== */
|
||
.claim-info-section {
|
||
flex: 1;
|
||
height: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
background: #fff;
|
||
margin: 20rpx 24rpx 0;
|
||
border-radius: 12rpx;
|
||
overflow: hidden;
|
||
|
||
.claim-info-header {
|
||
padding: 24rpx;
|
||
background-color: #D9F7BE;
|
||
|
||
.claim-info-header-text {
|
||
font-size: 32rpx;
|
||
font-weight: bold;
|
||
color: #389E0D;
|
||
}
|
||
}
|
||
|
||
.claim-info-scroll {
|
||
flex: 1;
|
||
height: 0;
|
||
}
|
||
|
||
.claim-info-body {
|
||
.info-row {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
padding: 24rpx;
|
||
border-bottom: 1rpx solid #f0f0f0;
|
||
|
||
&:last-child {
|
||
border-bottom: none;
|
||
}
|
||
|
||
.info-value {
|
||
font-size: 38rpx;
|
||
color: #000;
|
||
text-align: center;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
::v-deep .nav-title .right {
|
||
width: auto;
|
||
min-width: 80rpx;
|
||
display: flex;
|
||
justify-content: flex-end;
|
||
}
|
||
|
||
.nav-manual-input {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
height: 52rpx;
|
||
padding: 0 20rpx;
|
||
background: #fa8c16;
|
||
border-radius: 8rpx;
|
||
|
||
&--inactive {
|
||
background: #2979ff;
|
||
}
|
||
|
||
.nav-manual-input-text {
|
||
font-size: 28rpx;
|
||
color: #ffffff;
|
||
white-space: nowrap;
|
||
}
|
||
}
|
||
|
||
/* ===== 手动输入搜索框 ===== */
|
||
.scan-section {
|
||
padding: 20rpx 24rpx;
|
||
background: #fff;
|
||
margin-bottom: 16rpx;
|
||
|
||
.scan-input-wrap {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 16rpx;
|
||
|
||
.scan-camera-btn {
|
||
width: 72rpx;
|
||
height: 72rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
background: #f0f7ff;
|
||
border-radius: 8rpx;
|
||
flex-shrink: 0;
|
||
}
|
||
}
|
||
}
|
||
|
||
/* ===== 底部操作栏 ===== */
|
||
.claim-footer {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
padding: 16rpx 24rpx calc(16rpx + env(safe-area-inset-bottom));
|
||
background: #fff;
|
||
border-top: 1rpx solid #f0f0f0;
|
||
|
||
.claim-footer-total {
|
||
display: flex;
|
||
align-items: baseline;
|
||
|
||
.claim-footer-total-label {
|
||
font-size: 28rpx;
|
||
color: #606266;
|
||
margin-right: 8rpx;
|
||
}
|
||
|
||
.claim-footer-total-value {
|
||
font-size: 48rpx;
|
||
font-weight: bold;
|
||
color: #389E0D;
|
||
}
|
||
}
|
||
|
||
.claim-footer-btn {
|
||
padding: 16rpx 40rpx;
|
||
background: #2979ff;
|
||
border-radius: 8rpx;
|
||
|
||
.claim-footer-btn-text {
|
||
font-size: 30rpx;
|
||
color: #ffffff;
|
||
white-space: nowrap;
|
||
}
|
||
}
|
||
}
|
||
</style>
|