308 lines
7.3 KiB
Vue
308 lines
7.3 KiB
Vue
<template>
|
||
<view class="block-registration-page">
|
||
<view class="normar_container">
|
||
<page-nav title="拦截登记">
|
||
<template #left>
|
||
<view
|
||
class="nav-manual-input"
|
||
:class="{ 'nav-manual-input--inactive': !showScanInput }"
|
||
@click="toggleScanInput"
|
||
>
|
||
<text class="nav-manual-input-text">{{ showScanInput ? '关闭手动输入' : '手动输入' }}</text>
|
||
</view>
|
||
</template>
|
||
<template #right>
|
||
<view class="nav-reset" @click="handleReset">
|
||
<text class="nav-reset-text">重置</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="info-list" :class="{ 'info-list--no-scan': !showScanInput }" v-show="showOrderInfo">
|
||
<view class="info-row">
|
||
<text class="info-label">快递号</text>
|
||
<text class="info-value">{{ orderInfo.waybill_code || '--' }}</text>
|
||
</view>
|
||
<view class="info-row">
|
||
<text class="info-label">状态</text>
|
||
<text class="info-value info-value--status">{{ interceptStatusText }}</text>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
import voice from '@/core/utils/voice';
|
||
|
||
export default {
|
||
data() {
|
||
return {
|
||
scanInput: '',
|
||
scanFocused: false,
|
||
showScanInput: false,
|
||
orderInfo: {
|
||
waybill_code: ''
|
||
},
|
||
interceptStatus: '',
|
||
showOrderInfo: false
|
||
};
|
||
},
|
||
computed: {
|
||
interceptStatusText() {
|
||
const map = {
|
||
'': '未拦截',
|
||
'none': '未拦截',
|
||
'requested': '拦截中',
|
||
'pending': '拦截中',
|
||
'intercepting': '拦截中',
|
||
'intercepted': '仓库已拦截',
|
||
'intercepted_at_warehouse': '仓库已拦截',
|
||
'intercept_success': '拦截成功',
|
||
'intercept_failed': '拦截失败',
|
||
'cancelled': '已取消'
|
||
};
|
||
const key = String(this.interceptStatus || '').trim();
|
||
return map[key] || key || '未拦截';
|
||
}
|
||
},
|
||
onLoad() {
|
||
this.$store.dispatch('broadcast/setCallbacks', {
|
||
onResult: this.onScanData
|
||
});
|
||
this.$store.dispatch('broadcast/start');
|
||
},
|
||
onShow() {
|
||
this.$store.dispatch('broadcast/resume');
|
||
},
|
||
onHide() {
|
||
this.$store.dispatch('broadcast/pause');
|
||
},
|
||
onUnload() {
|
||
this.$store.dispatch('broadcast/stop');
|
||
},
|
||
methods: {
|
||
onScanData(data) {
|
||
const scanText = data && data.data ? data.data.trim() : '';
|
||
console.log('[拦截登记] 广播扫描到快递单号:', scanText);
|
||
if (scanText) {
|
||
this.scanInput = scanText;
|
||
this.handleScanConfirm(scanText);
|
||
}
|
||
},
|
||
toggleScanInput() {
|
||
this.showScanInput = !this.showScanInput;
|
||
},
|
||
handleScanConfirm(value) {
|
||
const code = value || this.scanInput;
|
||
if (!code) return;
|
||
this.fetchInterceptScan(code);
|
||
},
|
||
handleCameraScan() {
|
||
// 调用相机扫码
|
||
uni.scanCode({
|
||
success: (res) => {
|
||
this.scanInput = res.result;
|
||
this.handleScanConfirm(res.result);
|
||
}
|
||
});
|
||
},
|
||
speakVoice(text) {
|
||
voice.speak(text, { minInterval: 800 });
|
||
},
|
||
// 拦截扫描:通过运单号查找运单记录。
|
||
// 非拦截订单会被拒绝并提示「非拦截订单」:运单记录不存在,或运单 is_intercept≠'Y' 且关联订单
|
||
// intercept_status 不在 requested/intercepting。
|
||
// 校验通过后标记退回与拦截(is_back='Y', is_intercept='Y'),处理关联的未完结售后工单
|
||
// (写入「库内拦截成功」步骤并置为 completed)。
|
||
// 若运单关联到订单,则将订单拦截状态更新为 intercepted_at_warehouse(step=4、outbound_status=fin)
|
||
// 并释放储位分配与订单锁(仅订单级状态更新,不标记订单下其他面单)。工单处理失败不阻断主流程。
|
||
async fetchInterceptScan(code) {
|
||
uni.showLoading({ title: '拦截登记中...' });
|
||
try {
|
||
const res = await this.$http('order.recheckOrder.interceptScan', { waybill_code: code }, '', false);
|
||
if (res && res.flag !== 'failure') {
|
||
const data = res.data || {};
|
||
const order = data.order && typeof data.order === 'object' ? data.order : {};
|
||
this.orderInfo = {
|
||
waybill_code: data.waybill_code || code
|
||
};
|
||
this.interceptStatus = String(order.intercept_status || 'intercepted_at_warehouse').trim();
|
||
this.showOrderInfo = true;
|
||
uni.showToast({ title: '拦截登记成功', icon: 'success' });
|
||
this.speakVoice('拦截成功');
|
||
} else {
|
||
uni.showToast({ title: res.msg || '拦截登记失败', icon: 'none' });
|
||
this.speakVoice('非拦截订单');
|
||
}
|
||
} catch (e) {
|
||
uni.showToast({ title: '网络异常', icon: 'none' });
|
||
this.speakVoice('网络异常');
|
||
} finally {
|
||
uni.hideLoading();
|
||
}
|
||
},
|
||
handleBack() {
|
||
uni.navigateBack();
|
||
},
|
||
handleReset() {
|
||
this.resetForm();
|
||
},
|
||
resetForm() {
|
||
this.scanInput = '';
|
||
this.orderInfo = { waybill_code: '' };
|
||
this.interceptStatus = '';
|
||
this.showOrderInfo = false;
|
||
this.scanFocused = true;
|
||
}
|
||
}
|
||
};
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.block-registration-page {
|
||
.normar_container {
|
||
min-height: 100vh;
|
||
background-color: #f5f5f5;
|
||
}
|
||
|
||
/* ===== 左侧手动输入按钮 ===== */
|
||
::v-deep .nav-title .left {
|
||
min-width: auto;
|
||
gap: 0;
|
||
}
|
||
|
||
::v-deep .nav-title .title {
|
||
padding-left: 40rpx;
|
||
}
|
||
|
||
::v-deep .nav-title .right {
|
||
width: auto;
|
||
min-width: 80rpx;
|
||
}
|
||
|
||
.nav-manual-input {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
width: 210rpx;
|
||
height: 52rpx;
|
||
background: #fa8c16;
|
||
border-radius: 8rpx;
|
||
|
||
&--inactive {
|
||
background: #2979ff;
|
||
}
|
||
|
||
.nav-manual-input-text {
|
||
font-size: 32rpx;
|
||
color: #ffffff;
|
||
white-space: nowrap;
|
||
}
|
||
}
|
||
|
||
/* ===== 重置按钮 ===== */
|
||
.nav-reset {
|
||
padding: 8rpx 0;
|
||
|
||
.nav-reset-text {
|
||
font-size: 32rpx;
|
||
color: #fff;
|
||
background-color: #2979ff;
|
||
padding: 8rpx 24rpx;
|
||
border-radius: 8rpx;
|
||
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;
|
||
}
|
||
}
|
||
}
|
||
|
||
/* ===== 信息展示列表 ===== */
|
||
.info-list {
|
||
background: #fff;
|
||
margin: 0 24rpx 16rpx;
|
||
|
||
&--no-scan {
|
||
margin-top: 20rpx;
|
||
}
|
||
border-radius: 12rpx;
|
||
overflow: hidden;
|
||
|
||
.info-row {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
padding: 24rpx 24rpx;
|
||
border-bottom: 1rpx solid #f0f0f0;
|
||
|
||
&:first-child {
|
||
background-color: #ffedd5;
|
||
}
|
||
|
||
&:last-child {
|
||
border-bottom: none;
|
||
}
|
||
|
||
.info-label {
|
||
font-size: 32rpx;
|
||
color: #000;
|
||
width: 160rpx;
|
||
flex-shrink: 0;
|
||
text-align: center;
|
||
}
|
||
|
||
.info-value {
|
||
font-size: 32rpx;
|
||
color: #000;
|
||
flex: 1;
|
||
text-align: center;
|
||
|
||
&--status {
|
||
color: #f5222d;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
</style>
|