501 lines
13 KiB
Vue
501 lines
13 KiB
Vue
<template>
|
||
<scroll-view class="scroll-container" scroll-y v-if="receivingInfo">
|
||
<u-form :model="receivingInfo" :rules="rules" ref="infoFormRef" label-width="180rpx">
|
||
<view class="section">
|
||
<view class="section-title">基础信息</view>
|
||
|
||
<u-form-item label="收货单号">
|
||
<u-input v-model="receivingInfo.receiving_number" disabled />
|
||
<u-button style="width: 150rpx;" type="primary" @click="print">打印</u-button>
|
||
</u-form-item>
|
||
|
||
<u-form-item label="货主" prop="store_id">
|
||
<view
|
||
v-if="canBindStore"
|
||
class="store-bind-trigger"
|
||
@click="openStorePicker"
|
||
>
|
||
<text class="store-bind-text">{{ pendingStoreName || '请选择货主绑定' }}</text>
|
||
<view class="store-bind-action">
|
||
<text class="store-bind-action-text">选择绑定</text>
|
||
<u-icon name="arrow-right" size="24rpx" color="#2979ff"></u-icon>
|
||
</view>
|
||
</view>
|
||
<view v-else>{{ receivingInfo.store ? receivingInfo.store.store_remask : '未设置' }}</view>
|
||
</u-form-item>
|
||
|
||
<u-form-item label="来货方式" prop="delivery_method">
|
||
<u-radio-group v-model="receivingInfo.delivery_method" disabled>
|
||
<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="receivingInfo.delivery_method === 'truck'" label="车牌号" prop="license_plate">
|
||
<u-input v-model="receivingInfo.license_plate" disabled placeholder="请输入车牌号" />
|
||
</u-form-item>
|
||
|
||
<u-form-item v-else-if="receivingInfo.delivery_method !== 'other'" label="物流单号" prop="tracking_number">
|
||
<view class="tracking-input-wrap">
|
||
<u-input v-model="receivingInfo.tracking_number" placeholder="请输入物流单号" />
|
||
<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" v-if="receivingInfo.id">
|
||
<view class="section-title">来货照片</view>
|
||
<uploadImgCos business_type="receiving" :value="receivingInfo.images" :business_id="receivingInfo.id" @change="$emit('change')"></uploadImgCos>
|
||
</view>
|
||
|
||
<view class="section">
|
||
<view class="section-title">装卸信息</view>
|
||
|
||
<u-form-item label="装卸方式" prop="loading_method">
|
||
<u-radio-group v-model="receivingInfo.loading_method" disabled>
|
||
<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="receivingInfo.total_boxes" disabled type="number" placeholder="请输入总箱数" />
|
||
</u-form-item>
|
||
|
||
<u-form-item label="总托盘数" prop="total_pallets">
|
||
<u-input v-model="receivingInfo.total_pallets" disabled type="number" placeholder="请输入总托盘数" />
|
||
</u-form-item>
|
||
|
||
<u-form-item label="录像设备">
|
||
<u-input v-model="receivingInfo.video_device_id" disabled placeholder="录像设备ID" />
|
||
</u-form-item>
|
||
</view>
|
||
|
||
<view class="section">
|
||
<view class="section-title">收货状态</view>
|
||
|
||
<u-form-item label="收货状态">
|
||
<u-tag :text="receivingInfo.status | statusFilter" :type="getStatusType(receivingInfo.status)" />
|
||
</u-form-item>
|
||
|
||
<u-form-item label="创建人">
|
||
<u-input v-model="receivingInfo.creator_name" disabled />
|
||
</u-form-item>
|
||
|
||
<u-form-item label="创建时间">
|
||
<u-input :value="formatDate(receivingInfo.created_at)" disabled />
|
||
</u-form-item>
|
||
</view>
|
||
|
||
<view class="section">
|
||
<view class="section-title">备注信息</view>
|
||
<u-form-item label="备注">
|
||
<u-input v-model="receivingInfo.remark" type="textarea" placeholder="请输入备注" height="120" />
|
||
</u-form-item>
|
||
</view>
|
||
<view class="section">
|
||
<view class="section-title">收货码</view>
|
||
<view style="width: 100%;display: flex;flex-direction: column;align-items: center;">
|
||
<canvas id="qrcode" canvas-id="qrcode" style="width: 200px;height: 200px;"></canvas>
|
||
</view>
|
||
</view>
|
||
</u-form>
|
||
<inputAndSelect
|
||
title="选择货主"
|
||
:list="storeList"
|
||
:show="showStorePicker"
|
||
:value="pendingStoreId"
|
||
searchBorder="none"
|
||
@change="handleStoreChange"
|
||
@close="showStorePicker = false"
|
||
></inputAndSelect>
|
||
</scroll-view>
|
||
</template>
|
||
|
||
<script>
|
||
import UQRCode from 'uqrcodejs'
|
||
export default {
|
||
name: 'InfoContainer',
|
||
props: {
|
||
receivingInfo: {
|
||
type: Object,
|
||
required: true
|
||
},
|
||
qrcodeUrl: {
|
||
type: String,
|
||
default: ''
|
||
},
|
||
saving: {
|
||
type: Boolean,
|
||
default: false
|
||
}
|
||
},
|
||
data() {
|
||
return {
|
||
deliveryMethods: [{
|
||
value: 'truck',
|
||
label: '货车'
|
||
},
|
||
{
|
||
value: 'express',
|
||
label: '快递'
|
||
},
|
||
{
|
||
value: 'other',
|
||
label: '其他'
|
||
}
|
||
],
|
||
loadingMethods: [{
|
||
value: 'with_pallet',
|
||
label: '带托盘'
|
||
},
|
||
{
|
||
value: 'without_pallet',
|
||
label: '不带托盘'
|
||
}
|
||
],
|
||
rules: {},
|
||
showStorePicker: false,
|
||
storeList: [],
|
||
pendingStoreId: null,
|
||
pendingStoreName: '',
|
||
bindingStore: false
|
||
};
|
||
},
|
||
computed: {
|
||
canBindStore() {
|
||
return !!this.receivingInfo && !!this.receivingInfo.id && !this.receivingInfo.store_id;
|
||
}
|
||
},
|
||
mounted() {
|
||
console.log("onShow");
|
||
this.qrcode(this.receivingInfo.receiving_number);
|
||
this.loadStoreList();
|
||
},
|
||
filters: {
|
||
statusFilter(status) {
|
||
const map = {
|
||
'receiving': '收货中',
|
||
'completed': '已完成',
|
||
'cancelled': '已取消'
|
||
};
|
||
return map[status] || status;
|
||
}
|
||
},
|
||
watch:{
|
||
'receivingInfo.receiving_number':{
|
||
handler(newval){
|
||
console.log(newval);
|
||
this.qrcode(newval)
|
||
}
|
||
},
|
||
'receivingInfo.store_id': {
|
||
immediate: true,
|
||
handler(newValue) {
|
||
if (newValue) {
|
||
this.pendingStoreId = newValue;
|
||
this.pendingStoreName = this.receivingInfo.store && this.receivingInfo.store.store_remask ? this.receivingInfo.store.store_remask : '';
|
||
} else {
|
||
this.pendingStoreId = null;
|
||
this.pendingStoreName = '';
|
||
}
|
||
}
|
||
}
|
||
},
|
||
methods: {
|
||
speakMessage(message, options = {}) {
|
||
const text = String(message || '').trim();
|
||
if (!text) {
|
||
return;
|
||
}
|
||
|
||
const tools = this.$tools;
|
||
if (!tools || typeof tools.speakText !== 'function') {
|
||
return;
|
||
}
|
||
|
||
try {
|
||
const task = tools.speakText(text, options);
|
||
if (task && typeof task.catch === 'function') {
|
||
task.catch(error => {
|
||
console.warn('[ReceivingDetail-InfoContainer] 语音播报失败:', error);
|
||
});
|
||
}
|
||
} catch (error) {
|
||
console.warn('[ReceivingDetail-InfoContainer] 语音播报异常:', error);
|
||
}
|
||
},
|
||
openStorePicker() {
|
||
this.showStorePicker = true;
|
||
},
|
||
async loadStoreList() {
|
||
try {
|
||
const res = await this.$http('common.store', {});
|
||
this.storeList = Array.isArray(res && res.stores) ? res.stores : [];
|
||
} catch (error) {
|
||
console.error('加载货主列表失败:', error);
|
||
}
|
||
},
|
||
handleStoreChange(option) {
|
||
this.showStorePicker = false;
|
||
|
||
if (!option || !option.value) {
|
||
this.pendingStoreId = null;
|
||
this.pendingStoreName = '';
|
||
return;
|
||
}
|
||
|
||
this.speakMessage('请确认货主绑定');
|
||
|
||
uni.showModal({
|
||
title: '货主绑定',
|
||
content: `是否将当前收货单绑定到货主【${option.label}】?绑定后不可更改。`,
|
||
success: async ({ confirm }) => {
|
||
if (!confirm) {
|
||
return;
|
||
}
|
||
|
||
await this.bindStore(option);
|
||
}
|
||
});
|
||
},
|
||
async bindStore(option) {
|
||
if (!this.receivingInfo || !this.receivingInfo.id || !option || !option.value || this.bindingStore) {
|
||
return;
|
||
}
|
||
|
||
try {
|
||
this.bindingStore = true;
|
||
uni.showLoading({
|
||
title: '绑定中...'
|
||
});
|
||
|
||
const res = await this.$http('storage.receiving.bindStore', {
|
||
id: this.receivingInfo.id,
|
||
receiving_id: this.receivingInfo.id,
|
||
store_id: option.value
|
||
});
|
||
|
||
if (res && res.code === 200) {
|
||
this.pendingStoreId = option.value;
|
||
this.pendingStoreName = option.label;
|
||
this.speakMessage('绑定成功');
|
||
uni.showToast({
|
||
title: '绑定成功',
|
||
icon: 'success'
|
||
});
|
||
this.$emit('change');
|
||
return;
|
||
}
|
||
|
||
throw new Error((res && res.message) || '绑定失败');
|
||
} catch (error) {
|
||
console.error('绑定货主失败:', error);
|
||
uni.showToast({
|
||
title: (error && error.message) || '绑定失败',
|
||
icon: 'none'
|
||
});
|
||
} finally {
|
||
this.bindingStore = false;
|
||
uni.hideLoading();
|
||
}
|
||
},
|
||
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.receivingInfo.tracking_number = rawCode;
|
||
},
|
||
fail: (error) => {
|
||
const errMsg = String(error?.errMsg || '').toLowerCase();
|
||
if (errMsg.includes('cancel')) {
|
||
return;
|
||
}
|
||
|
||
uni.showToast({
|
||
title: '扫码失败,请重试',
|
||
icon: 'none'
|
||
});
|
||
}
|
||
});
|
||
},
|
||
qrcode(data){
|
||
var qr = new UQRCode();
|
||
qr.data = data;
|
||
qr.make();
|
||
var canvasContext = uni.createCanvasContext('qrcode', this); // 如果是组件,this必须传入
|
||
// 设置uQRCode实例的canvas上下文
|
||
qr.canvasContext = canvasContext;
|
||
// 调用绘制方法将二维码图案绘制到canvas上
|
||
qr.drawCanvas();
|
||
},
|
||
formatDate(dateStr) {
|
||
if (!dateStr) return '-';
|
||
|
||
try {
|
||
const normalizedDateStr = typeof dateStr === 'string' ? dateStr.replace(/-/g, '/') : dateStr;
|
||
const date = new Date(normalizedDateStr);
|
||
|
||
if (Number.isNaN(date.getTime())) {
|
||
return dateStr;
|
||
}
|
||
|
||
const year = date.getFullYear();
|
||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||
const day = String(date.getDate()).padStart(2, '0');
|
||
const hour = String(date.getHours()).padStart(2, '0');
|
||
const minute = String(date.getMinutes()).padStart(2, '0');
|
||
const second = String(date.getSeconds()).padStart(2, '0');
|
||
|
||
return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
|
||
} catch (error) {
|
||
console.error('日期格式化错误:', error);
|
||
return dateStr;
|
||
}
|
||
},
|
||
getStatusType(status) {
|
||
const map = {
|
||
'receiving': 'primary',
|
||
'completed': 'success',
|
||
'cancelled': 'error'
|
||
};
|
||
return map[status] || 'default';
|
||
},
|
||
validateForm() {
|
||
return this.$refs.infoFormRef.validate();
|
||
},
|
||
print(){
|
||
this.$emit('print',{type:"STOCK",value:{product_barcode:this.receivingInfo.receiving_number,product_name:this.receivingInfo.creator_name}})
|
||
}
|
||
}
|
||
};
|
||
</script>
|
||
|
||
<style scoped>
|
||
.scroll-container {
|
||
height: 100%;
|
||
}
|
||
|
||
.tracking-input-wrap {
|
||
width: 100%;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 16rpx;
|
||
}
|
||
|
||
.tracking-input-wrap :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);
|
||
}
|
||
|
||
.scan-camera-btn:active {
|
||
opacity: 0.85;
|
||
}
|
||
|
||
.store-bind-trigger {
|
||
width: 100%;
|
||
min-height: 72rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: 16rpx;
|
||
}
|
||
|
||
.store-bind-text {
|
||
flex: 1;
|
||
font-size: 28rpx;
|
||
color: #303133;
|
||
}
|
||
|
||
.store-bind-action {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8rpx;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.store-bind-action-text {
|
||
font-size: 26rpx;
|
||
color: #2979ff;
|
||
}
|
||
|
||
.section {
|
||
background-color: #fff;
|
||
border-radius: 16rpx;
|
||
padding: 30rpx;
|
||
margin-bottom: 20rpx;
|
||
}
|
||
|
||
.section-title {
|
||
font-size: 32rpx;
|
||
font-weight: bold;
|
||
color: #333;
|
||
margin-bottom: 20rpx;
|
||
padding-bottom: 10rpx;
|
||
border-bottom: 2rpx solid #f0f0f0;
|
||
}
|
||
|
||
.action-buttons {
|
||
padding: 30rpx;
|
||
background: #fff;
|
||
border-radius: 16rpx;
|
||
}
|
||
|
||
.qrcode-image {
|
||
width: 200rpx;
|
||
height: 200rpx;
|
||
display: block;
|
||
margin: 0 auto;
|
||
}
|
||
</style> |