WMS_PDA/pages/work/order/weighing.vue
zm2000 428f06ebd3 feat: 新增移库记录页面
- 新增 pages/warehouse/inventoryTransfer.vue:支持按商品条码/名称/操作人搜索、
  扫码查询、移入/移出类型筛选、分页列表(展示商品、数量、移出/移入库位、操作人等)
- pages.json 注册 pages/warehouse/inventoryTransfer 路由
- core/request/apis.js 新增 warehouse.getSpaceInfo、storage.transaction.list 接口
- pages/index/index.vue、pages/home/edit-quick-actions.vue:工作台「移库记录」
  菜单点击跳转到移库记录页

  refactor: 重构称重页查询与校验逻辑

- 改用 common.toOrder + order.detail 查询,替代原 scanOrder 分支逻辑
- 按波次号前缀区分散单/团单(B 开头视为团单),新增 isGroupOrder 状态
- 增加称重前置校验:未拣货、未复核禁止称重;散单未打包禁止称重
- 商品净重统一取订单详情 items_weight,运单匹配成功才回填称重重量
- 提取 clearOrderData 复用清空逻辑
2026-09-27 18:02:08 +08:00

459 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,
isGroupOrder: 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 {
// 1. 按运单号获取订单ID及所属波次信息
const toOrderRes = await this.$http('common.toOrder', { waybill_code: code }, '', false);
if (!toOrderRes || toOrderRes.flag === 'failure') {
uni.showToast({ title: (toOrderRes && (toOrderRes.msg || toOrderRes.message)) || '查询失败', icon: 'none' });
this.speakVoice('无记录');
return;
}
const rawOrderId = Number(toOrderRes.order_id);
if (!(rawOrderId > 0)) {
uni.showToast({ title: '未找到对应订单', icon: 'none' });
this.speakVoice('无记录');
return;
}
this.waves = Array.isArray(toOrderRes.waves) ? toOrderRes.waves : [];
// 2. 获取订单详情(区分散单/团单、校验复核状态、取商品净重与运单称重重量)
const detailRes = await this.$http('order.detail', { order_id: rawOrderId, tableType: 'dispatch' }, '', false);
if (!detailRes || detailRes.flag === 'failure') {
uni.showToast({ title: (detailRes && (detailRes.msg || detailRes.message)) || '查询失败', icon: 'none' });
this.speakVoice('无记录');
return;
}
const detailData = detailRes.data || {};
const detail = detailData.detail || {};
this.orderDetail = detail;
this.orderItems = detailData.items || [];
this.expresses = detailData.expresses || [];
// 3. 区分散单/团单:团单波次号前缀为 B,其余波次前缀为散单
const waveNo = String(detail.wave_no || '').trim();
this.isGroupOrder = waveNo.startsWith('B');
console.log('[称重] 波次号:', waveNo, this.isGroupOrder ? '团单' : '散单');
// 4. 校验:未拣货不允许称重(散单/团单均校验)
const pick = String(detail.pick_status ?? '').trim().toLowerCase();
const pickDone = pick === 'fin' || pick === 'finished' || pick === '1';
if (!pickDone) {
uni.showToast({ title: '订单未拣货,禁止称重', icon: 'none' });
this.speakVoice('订单未拣货,禁止称重');
this.clearOrderData();
return;
}
// 5. 校验:未复核不允许称重(散单/团单均校验)
const recheck = String(detail.recheck_status ?? '').trim().toLowerCase();
const recheckDone = recheck === 'fin' || recheck === 'finished' || recheck === '1';
if (!recheckDone) {
uni.showToast({ title: '订单未复核,禁止称重', icon: 'none' });
this.speakVoice('订单未复核,禁止称重');
this.clearOrderData();
return;
}
// 6. 校验:散单未打包不允许称重(仅散单校验,pack_status 为 fin 视为已打包)
if (!this.isGroupOrder) {
const packStatus = String(detail.pack_status ?? '').trim().toLowerCase();
const packDone = packStatus === 'fin' || packStatus === 'finished' || packStatus === '1';
if (!packDone) {
uni.showToast({ title: '订单未打包,禁止称重', icon: 'none' });
this.speakVoice('订单未打包,禁止称重');
this.clearOrderData();
return;
}
}
this.orderInfo = {
order_id: rawOrderId,
waybill_code: code
};
// 商品净重:散单/团单均取订单详情 items_weight
this.netWeight = detail.items_weight ?? '';
// 称重重量:仅当扫描的运单号能精确匹配到对应运单时才回填,否则留空由用户手动输入
const matchedExpress = (detailData.expresses || []).find(exp => exp.waybill_code === code);
if (matchedExpress && matchedExpress.weighing_weight !== undefined && matchedExpress.weighing_weight !== null) {
this.manualWeight = String(Math.round(matchedExpress.weighing_weight));
} else {
this.manualWeight = '';
}
this.showOrderInfo = true;
// 自动聚焦称重重量输入框
this.$nextTick(() => {
this.weightFocused = true;
});
} catch (e) {
uni.showToast({ title: '网络异常', icon: 'none' });
this.speakVoice('无记录');
} finally {
uni.hideLoading();
}
},
clearOrderData() {
this.showOrderInfo = false;
this.orderInfo = { order_id: 0, waybill_code: '' };
this.waves = [];
this.orderDetail = null;
this.orderItems = [];
this.expresses = [];
this.netWeight = '';
this.manualWeight = '';
this.isGroupOrder = false;
},
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).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.isGroupOrder = 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>