WMS_PDA/pages/work/order/bindPkgMat.vue
2026-07-15 17:58:15 +08:00

435 lines
11 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="package-binding-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 info-row--header">
<text class="info-label">快递号</text>
<text class="info-value">{{ orderInfo.waybill_code || '--' }}</text>
</view>
<view class="info-row">
<text class="info-label">包材</text>
<view class="info-value-input">
<u-input
v-model="packageInputCode"
placeholder="扫描/输入包材条码"
type="textarea"
:autoHeight="true"
border="surround"
:customStyle="{ flex: 1, minHeight: '72rpx', padding: '8rpx 0' }"
:focus="packageFocused"
@confirm="handlePackageCodeSearch"
></u-input>
<view class="scan-camera-btn-sm" @click="handlePackageCameraScan">
<u-icon name="camera" size="22" color="#2979ff"></u-icon>
</view>
</view>
</view>
</view>
<!-- 提交按钮 -->
<view class="submit-section" v-show="showOrderInfo">
<u-button
type="primary"
:customStyle="{ backgroundColor: '#2979ff', borderColor: '#2979ff', width: '100%' }"
:disabled="!scannedPackageMaterial"
:loading="submitting"
@click="handleSubmitBinding"
>确认绑定</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: ''
},
suggestedPkg: null,
packageInputCode: '',
packageFocused: false,
scannedPackageMaterial: null,
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) return;
// 如果已显示订单信息,则扫描结果作为包材条码处理
if (this.showOrderInfo) {
this.packageInputCode = scanText;
this.handlePackageCodeSearch(scanText);
} else {
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);
}
});
},
handlePackageCameraScan() {
uni.scanCode({
success: (res) => {
this.packageInputCode = res.result;
this.handlePackageCodeSearch(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 || {};
this.orderInfo = {
order_id: data.order_id || 0,
waybill_code: code
};
// 获取推荐包材
if (data.suggested_package_material) {
this.suggestedPkg = data.suggested_package_material;
} else if (Array.isArray(data.list) && data.list.length > 0) {
const firstItem = data.list[0];
if (firstItem.suggested_package_material) {
this.suggestedPkg = firstItem.suggested_package_material;
}
}
this.showOrderInfo = true;
this.$nextTick(() => {
this.packageFocused = true;
});
uni.showToast({ title: '查询成功', icon: 'success' });
} else {
uni.showToast({ title: (res && res.msg) || '查询失败', icon: 'none' });
this.speakVoice('无记录');
}
} catch (e) {
uni.showToast({ title: '网络异常', icon: 'none' });
this.speakVoice('无记录');
} finally {
uni.hideLoading();
}
},
async handlePackageCodeSearch(value) {
const code = value || this.packageInputCode;
if (!code) {
uni.showToast({ title: '请输入包材条码', icon: 'none' });
return;
}
const trimmed = String(code).trim();
uni.showLoading({ title: '查询包材...', mask: true });
try {
const res = await this.$http('setting.packageMaterial.search', { keyword: trimmed }, '', false);
const list = Array.isArray(res?.data) ? res.data : [];
const matched = list.find(item => String(item.material_code || '') === trimmed);
if (matched) {
this.scannedPackageMaterial = matched;
this.packageInputCode = matched.material_name || matched.material_code || trimmed;
uni.hideLoading();
uni.showToast({ title: '数据一致', icon: 'success' });
this.speakVoice('数据一致');
} else {
this.scannedPackageMaterial = null;
uni.hideLoading();
uni.showToast({ title: '无记录', icon: 'none' });
this.speakVoice('无记录');
}
} catch (error) {
uni.hideLoading();
const msg = String(error?.message || error?.msg || '查询包材失败');
uni.showToast({ title: msg, icon: 'none' });
}
},
async handleSubmitBinding() {
if (!this.scannedPackageMaterial) {
uni.showToast({ title: '请先扫描包材', icon: 'none' });
return;
}
const waybillNo = String(this.orderInfo.waybill_code || '').trim();
if (!waybillNo) {
uni.showToast({ title: '缺少运单号', icon: 'none' });
return;
}
this.submitting = true;
const packageMaterialId = String(this.scannedPackageMaterial.id || '');
if (!packageMaterialId) {
uni.showToast({ title: '包材数据异常,缺少ID', icon: 'none' });
this.submitting = false;
return;
}
try {
const res = await this.$http('order.bindExpressPackageMaterialByWaybill', {
waybill_code: waybillNo,
package_material_id: packageMaterialId
}, '', false);
if (res && res.flag !== 'failure') {
uni.showToast({ title: '包材绑定成功', icon: 'success' });
this.speakVoice('绑定成功');
this.resetForm();
} else {
uni.showToast({ title: (res && res.msg) || '绑定失败', icon: 'none' });
this.speakVoice('绑定失败');
}
} catch (error) {
const msg = String(error?.message || error?.msg || '绑定失败');
uni.showToast({ title: msg, icon: 'none' });
this.speakVoice('绑定失败');
} finally {
this.submitting = false;
}
},
handleReset() {
this.resetForm();
},
resetForm() {
this.scanInput = '';
this.orderInfo = { order_id: 0, waybill_code: '' };
this.suggestedPkg = null;
this.packageInputCode = '';
this.packageFocused = false;
this.scannedPackageMaterial = null;
this.showOrderInfo = false;
this.scanFocused = true;
}
}
};
</script>
<style lang="scss" scoped>
.package-binding-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;
&--header {
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: #2979ff;
font-weight: 500;
}
}
.info-value-input {
flex: 1;
flex-direction: row;
align-items: flex-start;
display: flex;
gap: 8rpx;
::v-deep .u-input__content__field-wrapper__field {
text-align: center !important;
font-size: 40rpx !important;
}
::v-deep .u-textarea {
text-align: center;
}
.scan-camera-btn-sm {
width: 60rpx;
height: 60rpx;
display: flex;
align-items: center;
justify-content: center;
background: #f0f7ff;
border-radius: 8rpx;
flex-shrink: 0;
}
}
}
}
/* ===== 提交按钮 ===== */
.submit-section {
padding: 40rpx 24rpx;
}
}
</style>