440 lines
11 KiB
Vue
440 lines
11 KiB
Vue
<template>
|
||
<view>
|
||
<view class="normar_container">
|
||
<page-nav title="新建收货任务"></page-nav>
|
||
<scroll-view class="container" scroll-y>
|
||
<u-form class="form_box" :model="formData" :rules="rules" ref="formRef" label-width="150rpx">
|
||
<!-- 基础信息 -->
|
||
<view class="section">
|
||
<view class="section-title">基础信息</view>
|
||
|
||
<!-- 店铺信息 -->
|
||
<u-form-item label="货主" @click="showStorePicker = true">
|
||
<u-input v-model="storeName" placeholder="请选择货主" />
|
||
</u-form-item>
|
||
|
||
<!-- 来货方式 -->
|
||
<u-form-item label="来货方式" prop="delivery_method" required>
|
||
<u-radio-group v-model="formData.delivery_method">
|
||
<u-radio v-for="item in deliveryMethods" :key="item.value" :name="item.value"
|
||
:label="item.label"></u-radio>
|
||
</u-radio-group>
|
||
</u-form-item>
|
||
|
||
<!-- 车牌号(货车时显示) -->
|
||
<u-form-item v-if="formData.delivery_method === 'truck'" label="车牌号" prop="license_plate">
|
||
<u-input v-model="formData.license_plate" placeholder="请输入车牌号" maxlength="20" />
|
||
</u-form-item>
|
||
|
||
<!-- 物流单号(非货车时显示) -->
|
||
<u-form-item v-if="formData.delivery_method !== 'truck' && formData.delivery_method !== 'other'"
|
||
label="物流单号" prop="tracking_number">
|
||
<view class="tracking-input-wrap">
|
||
<u-input v-model="formData.tracking_number" placeholder="请输入快递/物流单号" maxlength="100" />
|
||
<view class="scan-camera-btn" @click="handleTrackingScan">
|
||
<u-icon name="camera" size="34rpx" color="#2979ff"></u-icon>
|
||
</view>
|
||
</view>
|
||
</u-form-item>
|
||
</view>
|
||
|
||
<!-- 装卸信息 -->
|
||
<view class="section">
|
||
<view class="section-title">装卸信息</view>
|
||
|
||
<!-- 装卸方式 -->
|
||
<u-form-item label="装卸方式" prop="loading_method" required>
|
||
<u-radio-group v-model="formData.loading_method">
|
||
<u-radio v-for="item in loadingMethods" :key="item.value" :name="item.value"
|
||
:label="item.label"></u-radio>
|
||
</u-radio-group>
|
||
</u-form-item>
|
||
|
||
<!-- 总箱数 -->
|
||
<u-form-item label="总箱数" prop="total_boxes">
|
||
<u-input v-model="formData.total_boxes" type="number" placeholder="请输入总箱数" />
|
||
</u-form-item>
|
||
|
||
<!-- 总托盘数 -->
|
||
<u-form-item label="总托盘数" prop="total_pallets">
|
||
<u-input v-model="formData.total_pallets" type="number" placeholder="请输入总托盘数" />
|
||
</u-form-item>
|
||
|
||
<!-- 录像设备 -->
|
||
<u-form-item label="录像设备">
|
||
<u-input v-model="formData.video_device_id" placeholder="直接扫描收货区录像码" maxlength="50" />
|
||
</u-form-item>
|
||
</view>
|
||
|
||
<!-- 备注信息 -->
|
||
<view class="section">
|
||
<view class="section-title">备注信息</view>
|
||
<u-form-item label="备注">
|
||
<u-input v-model="formData.remark" type="textarea" placeholder="请输入备注信息" height="120" />
|
||
</u-form-item>
|
||
</view>
|
||
</u-form>
|
||
</scroll-view>
|
||
<view class="submit-area">
|
||
<u-button type="primary" @click="handleSubmit" :loading="submitting">
|
||
创建收货任务
|
||
</u-button>
|
||
<u-button @click="handleReset">
|
||
重置
|
||
</u-button>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 货主选择器 -->
|
||
<inputAndSelect title="选择货主" :list="storeList" :show="showStorePicker" :value="formData.store_id"
|
||
@change="handleStoreChange" @close="showStorePicker=false"></inputAndSelect>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
export default {
|
||
data() {
|
||
return {
|
||
storeName: "不设置",
|
||
formData: {
|
||
store_id: null,
|
||
delivery_method: 'truck',
|
||
license_plate: '',
|
||
tracking_number: '',
|
||
loading_method: 'with_pallet',
|
||
video_device_id: '',
|
||
total_boxes: '',
|
||
total_pallets: '',
|
||
remark: '',
|
||
status: 'receiving',
|
||
},
|
||
|
||
showStorePicker: false,
|
||
|
||
deliveryMethods: [{
|
||
value: 'truck',
|
||
label: '货车'
|
||
},
|
||
{
|
||
value: 'express',
|
||
label: '快递'
|
||
},
|
||
{
|
||
value: 'other',
|
||
label: '其他'
|
||
},
|
||
],
|
||
|
||
loadingMethods: [{
|
||
value: 'with_pallet',
|
||
label: '带托盘'
|
||
},
|
||
{
|
||
value: 'without_pallet',
|
||
label: '不带托盘'
|
||
},
|
||
],
|
||
|
||
storeList: [],
|
||
|
||
rules: {
|
||
'delivery_method': [{
|
||
required: true,
|
||
message: '请选择来货方式',
|
||
trigger: 'blur'
|
||
}],
|
||
'loading_method': [{
|
||
required: true,
|
||
message: '请选择装卸方式',
|
||
trigger: 'blur'
|
||
}],
|
||
'license_plate': [{
|
||
validator: (rule, value, callback) => {
|
||
if (this.formData.delivery_method === 'truck' && !value) {
|
||
callback(new Error('车牌号不能为空'));
|
||
} else {
|
||
callback();
|
||
}
|
||
},
|
||
trigger: 'blur'
|
||
}],
|
||
'tracking_number': [{
|
||
validator: (rule, value, callback) => {
|
||
const method = this.formData.delivery_method;
|
||
if (method === 'express' && !value) {
|
||
callback(new Error('物流单号不能为空'));
|
||
} else {
|
||
callback();
|
||
}
|
||
},
|
||
trigger: 'blur'
|
||
}],
|
||
'total_boxes': [{
|
||
type: 'number',
|
||
message: '箱数必须为数字',
|
||
trigger: 'blur'
|
||
}],
|
||
'total_pallets': [{
|
||
type: 'number',
|
||
message: '托盘数必须为数字',
|
||
trigger: 'blur'
|
||
}],
|
||
},
|
||
submitting: false,
|
||
};
|
||
},
|
||
|
||
methods: {
|
||
normalizeUniScanResult(scanResult) {
|
||
if (!scanResult) {
|
||
return '';
|
||
}
|
||
|
||
if (typeof scanResult === 'string') {
|
||
return scanResult.trim();
|
||
}
|
||
|
||
if (typeof scanResult.result === 'string') {
|
||
return scanResult.result.trim();
|
||
}
|
||
|
||
if (Array.isArray(scanResult.result)) {
|
||
const firstResult = scanResult.result.find(item => item);
|
||
if (typeof firstResult === 'string') {
|
||
return firstResult.trim();
|
||
}
|
||
if (firstResult && typeof firstResult.data === 'string') {
|
||
return firstResult.data.trim();
|
||
}
|
||
}
|
||
|
||
if (typeof scanResult.data === 'string') {
|
||
return scanResult.data.trim();
|
||
}
|
||
|
||
return '';
|
||
},
|
||
handleTrackingScan() {
|
||
uni.scanCode({
|
||
onlyFromCamera: false,
|
||
scanType: ['qrCode', 'barCode', 'datamatrix', 'pdf417'],
|
||
success: (res) => {
|
||
const rawCode = this.normalizeUniScanResult(res);
|
||
if (!rawCode) {
|
||
uni.showToast({
|
||
title: '未识别到有效内容',
|
||
icon: 'none'
|
||
});
|
||
return;
|
||
}
|
||
|
||
this.formData.tracking_number = rawCode;
|
||
},
|
||
fail: (error) => {
|
||
const errMsg = String(error?.errMsg || '').toLowerCase();
|
||
if (errMsg.includes('cancel')) {
|
||
return;
|
||
}
|
||
|
||
uni.showToast({
|
||
title: '扫码失败,请重试',
|
||
icon: 'none'
|
||
});
|
||
}
|
||
});
|
||
},
|
||
async loadStore() {
|
||
try {
|
||
const res = await this.$http("common.store", {});
|
||
if (res.stores) {
|
||
this.storeList = res.stores;
|
||
}
|
||
} catch (error) {
|
||
console.error('加载货主失败:', error);
|
||
}
|
||
},
|
||
async scan(data) {
|
||
// 解析广播扫描数据
|
||
// 携带REC标识头数据,自动填充录像设备
|
||
if (data && data.data) {
|
||
const scanText = data.data.trim();
|
||
|
||
// 检查是否包含REC标识头,不是则直接忽略
|
||
if (scanText.startsWith('REC')) {
|
||
// 提取REC后面的设备编号
|
||
// 格式可能为:REC-设备编号 或 REC设备编号
|
||
let deviceCode = '';
|
||
|
||
// 处理不同格式的REC标识
|
||
if (scanText.startsWith('REC-')) {
|
||
// 格式: REC-设备编号
|
||
deviceCode = scanText.substring(4).trim();
|
||
} else if (scanText.startsWith('REC')) {
|
||
// 格式: REC设备编号
|
||
deviceCode = scanText.substring(3).trim();
|
||
}
|
||
|
||
// 如果成功提取到设备编号
|
||
if (deviceCode) {
|
||
// 自动填充到录像设备字段
|
||
this.formData.video_device_id = deviceCode;
|
||
|
||
// 可选:给用户一个提示
|
||
uni.showToast({
|
||
title: `已扫描录像设备: ${deviceCode}`,
|
||
icon: 'success',
|
||
duration: 2000
|
||
});
|
||
}
|
||
// 如果没有提取到设备编号,也直接忽略,不提示用户
|
||
return;
|
||
}
|
||
|
||
if (this.formData.delivery_method === 'express') {
|
||
this.formData.tracking_number = scanText;
|
||
}
|
||
}
|
||
},
|
||
async handleSubmit() {
|
||
try {
|
||
await this.$refs.formRef.validate();
|
||
|
||
this.submitting = true;
|
||
|
||
const submitData = {
|
||
...this.formData
|
||
};
|
||
|
||
const result = await this.$http("storage.receiving.create",submitData);
|
||
if(result.code==200){
|
||
uni.showToast({
|
||
title: '创建成功',
|
||
icon: 'success'
|
||
});
|
||
}else{
|
||
throw new Error("创建失败"+result.message);
|
||
|
||
}
|
||
setTimeout(() => {
|
||
uni.navigateTo({
|
||
url: `./receivingDetail?id=${result.id}`
|
||
});
|
||
}, 1500);
|
||
|
||
} catch (error) {
|
||
uni.showToast({
|
||
title: '创建失败'+error,
|
||
icon: 'error'
|
||
});
|
||
} finally {
|
||
this.submitting = false;
|
||
}
|
||
},
|
||
|
||
handleReset() {
|
||
uni.showModal({
|
||
title: '确认重置',
|
||
content: '确定要重置所有表单数据吗?',
|
||
success: (res) => {
|
||
if (res.confirm) {
|
||
this.$refs.formRef.resetFields();
|
||
this.storeName = "不设置";
|
||
this.formData.store_id = null;
|
||
}
|
||
}
|
||
});
|
||
},
|
||
|
||
handleStoreChange(option) {
|
||
if (!option) {
|
||
this.storeName = "不设置";
|
||
this.formData.store_id = null;
|
||
} else {
|
||
this.storeName = option.label;
|
||
this.formData.store_id = option.value;
|
||
}
|
||
this.showStorePicker = false;
|
||
},
|
||
},
|
||
|
||
onLoad() {
|
||
this.$store.dispatch('broadcast/setCallbacks', {
|
||
onResult: this.scan
|
||
});
|
||
this.$store.dispatch('broadcast/start');
|
||
this.loadStore();
|
||
},
|
||
onShow() {
|
||
this.$store.dispatch('broadcast/resume');
|
||
},
|
||
onHide() {
|
||
this.$store.dispatch('broadcast/pause');
|
||
},
|
||
onUnload() {
|
||
this.$store.dispatch('broadcast/stop');
|
||
}
|
||
};
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.container {
|
||
flex: 1;
|
||
height: 100rpx;
|
||
|
||
.form_box {
|
||
padding: 20rpx;
|
||
}
|
||
}
|
||
|
||
.section {
|
||
background-color: #fff;
|
||
border-radius: 16rpx;
|
||
padding: 30rpx;
|
||
margin-bottom: 30rpx;
|
||
|
||
.section-title {
|
||
font-size: 32rpx;
|
||
font-weight: bold;
|
||
color: #333;
|
||
margin-bottom: 30rpx;
|
||
padding-bottom: 20rpx;
|
||
border-bottom: 2rpx solid #f0f0f0;
|
||
}
|
||
}
|
||
|
||
.tracking-input-wrap {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 16rpx;
|
||
width: 100%;
|
||
|
||
::v-deep .u-input {
|
||
flex: 1;
|
||
}
|
||
|
||
.scan-camera-btn {
|
||
width: 76rpx;
|
||
height: 76rpx;
|
||
border-radius: 38rpx;
|
||
background: #eef4ff;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
flex-shrink: 0;
|
||
box-shadow: 0 4rpx 12rpx rgba(41, 121, 255, 0.12);
|
||
|
||
&:active {
|
||
opacity: 0.85;
|
||
}
|
||
}
|
||
}
|
||
|
||
.submit-area {
|
||
display: flex;
|
||
flex-direction: row;
|
||
padding: 20rpx;
|
||
gap: 20rpx;
|
||
border-top: 1px solid rgba(0, 0, 0, .3);
|
||
background-color: #FFF;
|
||
}
|
||
</style> |