WMS_PDA/pages/work/order/weighing.vue

465 lines
12 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="weighing-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--highlight">{{ netWeight !== '' ? netWeight : '--' }}</text>
</view>
<view class="info-row">
<text class="info-label">称重重量</text>
<view class="info-value-input">
<u-input
v-model="manualWeight"
type="digit"
placeholder="请输入重量"
border="surround"
:customStyle="{ flex: 1 }"
:focus="weightFocused"
class="weigh-input"
></u-input>
<text class="info-unit">g</text>
</view>
</view>
</view>
<!-- 提交按钮 -->
<view class="submit-section" v-show="showOrderInfo">
<u-button
type="primary"
:customStyle="{ backgroundColor: '#2979ff', borderColor: '#2979ff', width: '100%' }"
:disabled="!manualWeight"
:loading="submitting"
@click="handleSubmitWeight"
>设置重量</u-button>
</view>
</view>
</view>
</template>
<script>
import voice from '@/core/utils/voice';
export default {
data() {
return {
scanInput: '',
scanFocused: false,
showScanInput: false,
orderInfo: {
order_id: 0,
waybill_code: ''
},
waves: [],
orderDetail: null,
orderItems: [],
expresses: [],
netWeight: '',
manualWeight: '',
weightFocused: false,
submitting: false,
showOrderInfo: false
};
},
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.fetchOrderInfo(code);
},
handleCameraScan() {
// 调用相机扫码
uni.scanCode({
success: (res) => {
this.scanInput = res.result;
this.handleScanConfirm(res.result);
}
});
},
speakVoice(text) {
voice.speak(text, { minInterval: 800 });
},
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及所属波次信息
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 }, '', false);
if (detailRes && detailRes.flag !== 'failure') {
const detailData = detailRes.data || {};
this.orderDetail = detailData.detail || null;
this.orderItems = detailData.items || [];
this.expresses = detailData.expresses || [];
// 从订单详情中更新商品净重
if (detailData.detail && detailData.detail.items_weight !== undefined && detailData.detail.items_weight !== null) {
this.netWeight = detailData.detail.items_weight;
}
// 从运单信息中更新称重重量
const firstExpress = (detailData.expresses || [])[0];
if (firstExpress && firstExpress.weighing_weight !== undefined && firstExpress.weighing_weight !== null) {
// 接口返回 kg,页面显示 g,乘以 1000 转换
this.manualWeight = String(Math.round(firstExpress.weighing_weight * 1000));
}
}
} catch (e) {
console.error('获取订单详情失败', e);
}
}
} catch (e) {
console.error('获取波次信息失败', e);
}
this.showOrderInfo = true;
// 自动聚焦称重重量输入框
this.$nextTick(() => {
this.weightFocused = true;
});
} else {
uni.showToast({ title: res.msg || '查询失败', icon: 'none' });
this.speakVoice('无记录');
}
} catch (e) {
uni.showToast({ title: '网络异常', icon: 'none' });
this.speakVoice('无记录');
} finally {
uni.hideLoading();
}
},
handleSubmitWeight() {
if (!this.manualWeight) {
uni.showToast({ title: '请输入称重重量', icon: 'none' });
return;
}
this.submitting = true;
const payload = {
order_id: 0,
waybill_code: this.orderInfo.waybill_code,
weighing_weight: Number((Number(this.manualWeight) / 1000).toFixed(3))
};
this.$http('order.recheckOrder.updateExpressWeighingWeight', payload, '', false)
.then(res => {
if (res && res.flag !== 'failure') {
uni.showToast({ title: '设置成功', icon: 'success' });
this.speakVoice('称重成功');
this.resetForm();
} else {
uni.showToast({ title: res.msg || '提交失败', icon: 'none' });
this.speakVoice('称重失败');
}
})
.catch(() => {
uni.showToast({ title: '网络异常', icon: 'none' });
this.speakVoice('称重失败');
})
.finally(() => {
this.submitting = false;
});
},
handleBack() {
uni.navigateBack();
},
handleReset() {
this.resetForm();
},
resetForm() {
this.scanInput = '';
this.orderInfo = { order_id: 0, waybill_code: '' };
this.waves = [];
this.orderDetail = null;
this.orderItems = [];
this.expresses = [];
this.netWeight = '';
this.manualWeight = '';
this.weightFocused = false;
this.showOrderInfo = false;
this.scanFocused = true;
}
}
};
</script>
<style lang="scss" scoped>
.weighing-page {
.normar_container {
min-height: 100vh;
background-color: #f5f5f5;
}
/* ===== 左侧手动输入按钮 ===== */
::v-deep .nav-title .left {
min-width: auto;
gap: 0;
}
::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;
&:nth-child(-n+2) {
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;
&--highlight {
color: #000;
}
}
.info-value-input {
flex: 1;
flex-direction: row;
align-items: center;
display: flex;
gap: 8rpx;
.info-unit {
font-size: 32rpx;
color: #000;
white-space: nowrap;
}
}
.weigh-input {
::v-deep .u-input__content__field-wrapper__field {
font-size: 40rpx !important;
text-align: center !important;
}
}
}
}
/* ===== 提交按钮 ===== */
.submit-section {
padding: 40rpx 24rpx;
}
}
</style>