1328 lines
34 KiB
Vue
1328 lines
34 KiB
Vue
<template>
|
||
<view class="random-storage-page">
|
||
<view class="normar_container">
|
||
<page-nav title="随机入库" :showBack="true" @back="handleBack">
|
||
<template #left>
|
||
<view class="nav-back-btn" @click="handleBack">
|
||
<u-icon name="arrow-left" size="22" color="#333"></u-icon>
|
||
</view>
|
||
<view v-if="hasInboundOrder" class="nav-cancel-btn" @click="handleCancelInbound">
|
||
<text class="nav-cancel-btn__text">取消入库</text>
|
||
</view>
|
||
</template>
|
||
<template #right>
|
||
<view v-if="hasInboundOrder" class="nav-done-btn" @click="handleInboundDone">
|
||
<text class="nav-done-btn__text">入库完成</text>
|
||
</view>
|
||
</template>
|
||
</page-nav>
|
||
|
||
<!-- 空态:未扫描入库单 -->
|
||
<view v-if="!hasInboundOrder" class="empty-wrap">
|
||
<view class="search-filter">
|
||
<view class="search-row">
|
||
<u-search
|
||
v-model="searchKeyword"
|
||
placeholder="扫描/输入入库单号"
|
||
shape="round"
|
||
:show-action="false"
|
||
:clearabled="true"
|
||
@search="handleSearchInboundOrder"
|
||
@clear="searchKeyword = ''"
|
||
></u-search>
|
||
<view class="search-scan-btn" @click="handleScanInboundOrder">
|
||
<u-icon name="scan" size="34rpx" color="#2979ff"></u-icon>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
<view class="empty-card">
|
||
<u-icon name="scan" size="72rpx" color="#c0c4cc"></u-icon>
|
||
<text class="empty-title">开始入库</text>
|
||
<text class="empty-desc">扫描或输入入库单号开始入库</text>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 已加载入库单 -->
|
||
<view v-else class="content-split">
|
||
<view class="summary-bar">
|
||
<text class="summary-label">已入总数/所有总数:</text>
|
||
<text class="summary-value">{{ summaryReceived }}</text>
|
||
<text class="summary-split">/</text>
|
||
<text class="summary-total">{{ summaryTotal }}</text>
|
||
</view>
|
||
<scroll-view class="content-top" scroll-y>
|
||
<!-- 商品详情区(占上部分80%) -->
|
||
<view class="product-detail-area">
|
||
<view class="product-detail">
|
||
<!-- 左50%:商品图片 -->
|
||
<view class="product-image-wrap">
|
||
<image
|
||
v-if="selectedStock && selectedStock.image_url"
|
||
class="product-image"
|
||
:src="selectedStock.image_url"
|
||
mode="aspectFit"
|
||
></image>
|
||
<view v-else class="product-image-placeholder">
|
||
<u-icon name="bag" size="96rpx" color="#c0c4cc"></u-icon>
|
||
<text class="product-image-text">{{ selectedStock ? selectedStock.item_name : '暂无图片' }}</text>
|
||
</view>
|
||
</view>
|
||
<!-- 右50%:商品信息 -->
|
||
<view class="product-info">
|
||
<text class="product-name">{{ selectedStock ? selectedStock.item_name : '--' }}</text>
|
||
<view class="product-info-row">
|
||
<text class="product-info-label">规格:</text>
|
||
<text class="product-info-value">{{ (selectedStock && selectedStock.spec) || '--' }}</text>
|
||
</view>
|
||
<view class="product-info-row">
|
||
<text class="product-info-label">颜色:</text>
|
||
<text class="product-info-value">{{ (selectedStock && selectedStock.color) || '--' }}</text>
|
||
</view>
|
||
<view class="product-info-row">
|
||
<text class="product-info-label">重量:</text>
|
||
<text class="product-info-value">{{ (selectedStock && selectedStock.weight) || '--' }}</text>
|
||
</view>
|
||
<view class="product-info-row">
|
||
<text class="product-info-label">条码:</text>
|
||
<text class="product-info-value">{{ selectedStock ? selectedStock.barcode : '--' }}</text>
|
||
</view>
|
||
<view class="product-info-row product-info-row-qty">
|
||
<text class="product-info-label">已入/总数:</text>
|
||
<text class="product-info-value product-info-value-qty">{{ selectedStock ? (selectedStock.received_qty || 0) + '/' + (selectedStock.plan_qty || 0) : '0/0' }}</text>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 订单信息区(占上部分20%) -->
|
||
<view class="order-info-area">
|
||
<view class="order-info-row">
|
||
<!-- 左列:蓝色背景,两行连续 -->
|
||
<view class="order-info-col order-info-col--left">
|
||
<view class="order-info-col__item order-info-col__item--blue">
|
||
<text class="order-info-label">入库编号</text>
|
||
</view>
|
||
<view class="order-info-col__item order-info-col__item--blue">
|
||
<text class="order-info-label">货主</text>
|
||
</view>
|
||
</view>
|
||
<!-- 中列:白色背景 -->
|
||
<view class="order-info-col order-info-col--middle">
|
||
<view class="order-info-col__item order-info-col__item--white">
|
||
<text class="order-info-value order-info-value--center">{{ inboundOrderNo || '--' }}</text>
|
||
</view>
|
||
<view class="order-info-col__item order-info-col__item--white">
|
||
<text class="order-info-value order-info-value--center">{{ (selectedStock && selectedStock.owner) || '--' }}</text>
|
||
</view>
|
||
</view>
|
||
<!-- 右列:上蓝下绿 -->
|
||
<view class="order-info-col order-info-col--right">
|
||
<view class="order-info-col__item order-info-col__item--blue">
|
||
<view class="shelf-btn" @click="handleShelf">
|
||
<text class="shelf-btn__text">{{ (selectedStock && selectedStock.shelf_status) || '上架' }}</text>
|
||
</view>
|
||
</view>
|
||
<view class="order-info-col__item order-info-col__item--green">
|
||
<view class="shelf-btn shelf-btn--green" @click="handleMaintain">
|
||
<text class="shelf-btn__text">{{ (selectedStock && selectedStock.maintain_info) || '维护信息' }}</text>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</scroll-view>
|
||
<view class="content-bottom">
|
||
<scroll-view class="item-list-scroll" scroll-y>
|
||
<view
|
||
v-for="(item, idx) in inboundItems"
|
||
:key="item.id"
|
||
class="item-chip"
|
||
:class="{ 'item-chip--active': idx === currentItemIndex }"
|
||
@click="selectInboundItem(idx)"
|
||
>
|
||
<text class="item-chip__no">{{ idx + 1 }}</text>
|
||
<text class="item-chip__total">{{ item.planQty || 0 }}</text>
|
||
</view>
|
||
</scroll-view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
|
||
<u-loading-page :loading="loading" bg-color="rgba(255,255,255,0.9)"></u-loading-page>
|
||
|
||
<!-- 上架抽屉 -->
|
||
<view v-if="showShelfDrawer" class="shelf-overlay" @click="handleShelfCancel">
|
||
<view class="shelf-drawer" @click.stop>
|
||
<!-- 头部 -->
|
||
<view class="shelf-drawer__header">
|
||
<text class="shelf-drawer__title">上架</text>
|
||
<text class="shelf-drawer__product-name">{{ selectedStock ? selectedStock.item_name : '--' }}</text>
|
||
</view>
|
||
<!-- 内容区 -->
|
||
<view class="shelf-drawer__body">
|
||
<view class="shelf-form-row">
|
||
<text class="shelf-form-label">可上架数</text>
|
||
<text class="shelf-form-value">{{ shelfFormData.availableQty }}</text>
|
||
</view>
|
||
<view class="shelf-form-row">
|
||
<text class="shelf-form-label">库位</text>
|
||
<input
|
||
class="shelf-form-input"
|
||
v-model="shelfFormData.spaceCode"
|
||
placeholder="请输入/扫描库位"
|
||
placeholder-style="color: #c0c4cc; font-size: 30rpx;"
|
||
@click="setActiveScanField('space')"
|
||
/>
|
||
</view>
|
||
<view class="shelf-form-row">
|
||
<text class="shelf-form-label">数量</text>
|
||
<input
|
||
class="shelf-form-input"
|
||
v-model="shelfFormData.quantity"
|
||
type="number"
|
||
placeholder="请输入数量"
|
||
placeholder-style="color: #c0c4cc; font-size: 30rpx;"
|
||
/>
|
||
</view>
|
||
<view class="shelf-form-row">
|
||
<text class="shelf-form-label">生产日期</text>
|
||
<view class="shelf-form-date" @click="showDatePicker = true">
|
||
<text class="shelf-form-date__text" :class="{ 'shelf-form-date__text--placeholder': !shelfFormData.productionDate }">{{ shelfFormData.productionDate || '请选择日期' }}</text>
|
||
<u-icon name="arrow-down" size="28rpx" color="#909399"></u-icon>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
<!-- 底部按钮 -->
|
||
<view class="shelf-drawer__footer">
|
||
<view class="shelf-btn-submit" @click="handleShelfSubmit">
|
||
<text class="shelf-btn-submit__text">上架</text>
|
||
</view>
|
||
<view class="shelf-btn-cancel" @click="handleShelfCancel">
|
||
<text class="shelf-btn-cancel__text">取消</text>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 日期选择器 -->
|
||
<u-datetime-picker
|
||
:show="showDatePicker"
|
||
v-model="datePickerValue"
|
||
mode="date"
|
||
:min-date="minDate"
|
||
:max-date="maxDate"
|
||
@confirm="handleDateConfirm"
|
||
@cancel="showDatePicker = false"
|
||
></u-datetime-picker>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
import voice from '@/core/utils/voice';
|
||
|
||
export default {
|
||
data() {
|
||
return {
|
||
loading: false,
|
||
submitting: false,
|
||
hasInboundOrder: false,
|
||
inboundOrderNo: '',
|
||
searchKeyword: '',
|
||
inboundOrderData: null,
|
||
inboundItems: [],
|
||
summaryData: null,
|
||
currentItemIndex: 0,
|
||
activeScanField: 'productKeyword',
|
||
showShelfDrawer: false,
|
||
showDatePicker: false,
|
||
datePickerValue: Number(new Date()),
|
||
minDate: new Date(2000, 0, 1).getTime(),
|
||
maxDate: new Date(2099, 11, 31).getTime(),
|
||
shelfFormData: {
|
||
availableQty: 0,
|
||
spaceCode: '',
|
||
quantity: '',
|
||
productionDate: ''
|
||
},
|
||
selectedStock: null,
|
||
formData: {
|
||
productKeyword: '',
|
||
quantity: '',
|
||
spaceKeyword: '',
|
||
remark: ''
|
||
}
|
||
}
|
||
},
|
||
computed: {
|
||
summaryReceived() {
|
||
if (this.summaryData) {
|
||
return this.summaryData.total_direct_inbound ?? this.summaryData.total_pda ?? 0;
|
||
}
|
||
return this.inboundItems.reduce((sum, item) => sum + (item.receivedQty || 0), 0);
|
||
},
|
||
summaryTotal() {
|
||
if (this.summaryData) {
|
||
return this.summaryData.total_planned ?? 0;
|
||
}
|
||
return this.inboundItems.reduce((sum, item) => sum + (item.planQty || 0), 0);
|
||
}
|
||
},
|
||
onLoad() {
|
||
this.safeDispatchBroadcast('setCallbacks', {
|
||
onResult: this.handleBroadcastResult
|
||
});
|
||
this.safeDispatchBroadcast('start');
|
||
},
|
||
onShow() {
|
||
this.safeDispatchBroadcast('setCallbacks', {
|
||
onResult: this.handleBroadcastResult
|
||
});
|
||
this.safeDispatchBroadcast('resume');
|
||
},
|
||
onHide() {
|
||
this.safeDispatchBroadcast('pause');
|
||
},
|
||
onUnload() {
|
||
this.safeDispatchBroadcast('stop');
|
||
},
|
||
methods: {
|
||
speakVoice(text) {
|
||
voice.speak(text, { minInterval: 800 });
|
||
},
|
||
safeDispatchBroadcast(action, payload) {
|
||
try {
|
||
const task = this.$store.dispatch(`broadcast/${action}`, payload);
|
||
if (task && typeof task.catch === 'function') {
|
||
task.catch(error => {
|
||
console.warn(`[RandomStorage] broadcast/${action} 调用失败:`, error);
|
||
});
|
||
}
|
||
} catch (error) {
|
||
console.warn(`[RandomStorage] broadcast/${action} 调用异常:`, error);
|
||
}
|
||
},
|
||
handleBack() {
|
||
uni.navigateBack({ delta: 1 });
|
||
},
|
||
handleShelf() {
|
||
const qty = this.selectedStock ? (this.selectedStock.remaining_qty || this.selectedStock.plan_qty || 0) : 0;
|
||
this.shelfFormData = {
|
||
availableQty: qty,
|
||
spaceCode: '',
|
||
quantity: String(qty || ''),
|
||
productionDate: ''
|
||
};
|
||
this.showShelfDrawer = true;
|
||
},
|
||
handleShelfCancel() {
|
||
this.showShelfDrawer = false;
|
||
this.showDatePicker = false;
|
||
},
|
||
handleDateConfirm(e) {
|
||
const date = new Date(e.value);
|
||
const y = date.getFullYear();
|
||
const m = String(date.getMonth() + 1).padStart(2, '0');
|
||
const d = String(date.getDate()).padStart(2, '0');
|
||
this.shelfFormData.productionDate = `${y}-${m}-${d}`;
|
||
this.showDatePicker = false;
|
||
},
|
||
async handleShelfSubmit() {
|
||
if (!this.shelfFormData.spaceCode) {
|
||
uni.showToast({ title: '请输入库位', icon: 'none' });
|
||
return;
|
||
}
|
||
const qty = Number(this.shelfFormData.quantity);
|
||
if (!qty || qty <= 0) {
|
||
uni.showToast({ title: '请输入有效数量', icon: 'none' });
|
||
return;
|
||
}
|
||
const currentItem = this.inboundItems[this.currentItemIndex];
|
||
if (!currentItem) {
|
||
uni.showToast({ title: '未选中商品', icon: 'none' });
|
||
return;
|
||
}
|
||
const stockId = currentItem.stockId;
|
||
if (!stockId) {
|
||
uni.showToast({ title: '商品ID无效', icon: 'none' });
|
||
return;
|
||
}
|
||
const spaceId = Number(this.shelfFormData.spaceCode);
|
||
const params = {
|
||
entry_order_code: this.inboundOrderNo,
|
||
stock_id: stockId,
|
||
quantity: qty,
|
||
inbound_type: 'pda'
|
||
};
|
||
if (Number.isFinite(spaceId)) {
|
||
params.space_id = spaceId;
|
||
}
|
||
uni.showLoading({ title: '上架中...' });
|
||
try {
|
||
const res = await this.$http('storage.directInbound.addItem', params);
|
||
uni.hideLoading();
|
||
if (res?.flag === 'failure') {
|
||
uni.showToast({ title: res?.message || '上架失败', icon: 'none' });
|
||
return;
|
||
}
|
||
uni.showToast({ title: '上架成功', icon: 'success' });
|
||
this.speakVoice('上架成功');
|
||
this.showShelfDrawer = false;
|
||
} catch (error) {
|
||
uni.hideLoading();
|
||
const msg = String(error?.message || error?.msg || '上架失败');
|
||
uni.showToast({ title: msg, icon: 'none' });
|
||
}
|
||
},
|
||
handleMaintain() {
|
||
// TODO: 跳转到维护信息页面
|
||
uni.showToast({ title: '维护信息功能开发中', icon: 'none' });
|
||
},
|
||
normalizeKeyword(value) {
|
||
return String(value || '').replace(/\s+/g, '');
|
||
},
|
||
normalizeScanResult(scanResult) {
|
||
if (!scanResult) return '';
|
||
if (typeof scanResult === 'string') return this.normalizeKeyword(scanResult);
|
||
if (typeof scanResult.result === 'string') return this.normalizeKeyword(scanResult.result);
|
||
if (Array.isArray(scanResult.result)) {
|
||
const first = scanResult.result.find(item => item);
|
||
if (typeof first === 'string') return this.normalizeKeyword(first);
|
||
if (first && typeof first.data === 'string') return this.normalizeKeyword(first.data);
|
||
}
|
||
if (typeof scanResult.data === 'string') return this.normalizeKeyword(scanResult.data);
|
||
return '';
|
||
},
|
||
handleBroadcastResult(result) {
|
||
const scanText = this.normalizeScanResult(result);
|
||
if (!scanText) return;
|
||
// 未绑定入库单时,扫描结果填入搜索框并触发查询
|
||
if (!this.hasInboundOrder) {
|
||
this.searchKeyword = scanText;
|
||
this.handleSearchInboundOrder();
|
||
return;
|
||
}
|
||
// 已绑定入库单,根据当前焦点字段处理
|
||
if (this.activeScanField === 'productKeyword') {
|
||
this.formData.productKeyword = scanText;
|
||
this.handleProductSearch();
|
||
} else if (this.activeScanField === 'space') {
|
||
if (this.showShelfDrawer) {
|
||
this.shelfFormData.spaceCode = scanText;
|
||
} else {
|
||
this.formData.spaceKeyword = scanText;
|
||
}
|
||
}
|
||
},
|
||
handleSearchInboundOrder() {
|
||
const code = this.normalizeKeyword(this.searchKeyword);
|
||
if (!code) {
|
||
uni.showToast({ title: '请输入入库单号', icon: 'none' });
|
||
return;
|
||
}
|
||
this.handleInboundOrderScan(code);
|
||
},
|
||
handleScanInboundOrder() {
|
||
uni.scanCode({
|
||
onlyFromCamera: true,
|
||
scanType: ['barCode', 'qrCode', 'datamatrix', 'pdf417'],
|
||
success: (res) => {
|
||
const scanText = this.normalizeScanResult(res);
|
||
if (!scanText) {
|
||
uni.showToast({ title: '未识别到有效条码', icon: 'none' });
|
||
return;
|
||
}
|
||
this.searchKeyword = scanText;
|
||
this.handleSearchInboundOrder();
|
||
},
|
||
fail: (error) => {
|
||
const errMsg = String(error?.errMsg || '').toLowerCase();
|
||
if (errMsg.includes('cancel')) return;
|
||
uni.showToast({ title: '扫码失败,请重试', icon: 'none' });
|
||
}
|
||
});
|
||
},
|
||
async handleInboundOrderScan(code) {
|
||
uni.showLoading({ title: '查询入库单...' });
|
||
try {
|
||
const res = await this.$http('storage.directInbound.getItems', { entry_order_code: code });
|
||
if (res?.flag === 'failure') {
|
||
uni.hideLoading();
|
||
uni.showToast({ title: res?.message || '未找到入库单', icon: 'none' });
|
||
this.speakVoice('无记录');
|
||
return;
|
||
}
|
||
const rawData = res?.data?.data ?? res?.data ?? res?.result;
|
||
// 判断 rawData 是数组(直接返回的明细列表)还是对象(含 items 子字段)
|
||
let items = [];
|
||
let entryOrder = {};
|
||
let summary = null;
|
||
if (Array.isArray(rawData)) {
|
||
items = rawData;
|
||
} else if (rawData && typeof rawData === 'object') {
|
||
items = rawData.items || rawData.entryOrderItems || [];
|
||
entryOrder = rawData.entryOrder || {};
|
||
summary = rawData.summary || null;
|
||
}
|
||
this.hasInboundOrder = true;
|
||
this.inboundOrderNo = entryOrder.entry_order_code || code;
|
||
this.inboundOrderData = rawData;
|
||
this.summaryData = summary;
|
||
this.inboundItems = this.normalizeInboundItems(items);
|
||
this.currentItemIndex = 0;
|
||
// 自动选中第一个商品
|
||
if (this.inboundItems.length > 0) {
|
||
this.selectInboundItem(0);
|
||
}
|
||
uni.hideLoading();
|
||
uni.showToast({ title: `已加载入库单,共 ${this.inboundItems.length} 项`, icon: 'success' });
|
||
this.speakVoice('数据一致');
|
||
} catch (error) {
|
||
uni.hideLoading();
|
||
const msg = String(error?.message || error?.msg || '查询入库单失败');
|
||
uni.showToast({ title: msg, icon: 'none' });
|
||
}
|
||
},
|
||
normalizeInboundItems(items) {
|
||
if (!Array.isArray(items)) return [];
|
||
return items
|
||
.filter(item => item && typeof item === 'object')
|
||
.map((item, index) => {
|
||
const planQty = Number(item.count ?? item.plan_qty ?? 0);
|
||
const receivedQty = Number(item.received_quantity ?? item.direct_inbound_quantity ?? item.receivedQty ?? 0);
|
||
const remainingQty = Number(item.remaining_quantity ?? item.remainingQty ?? (Math.max(0, planQty - receivedQty)));
|
||
return {
|
||
id: String(item.id || item.stock_id || `item-${index + 1}`),
|
||
stockId: Number(item.stock_id ?? 0),
|
||
lineNo: index + 1,
|
||
skuCode: String(item.item_code || item.skuCode || ''),
|
||
skuName: String(item.warehouse_item_name || item.item_name || item.skuName || '--'),
|
||
barcode: String(item.item_code || item.barcode || ''),
|
||
spec: String(item.warehouse_item_spec || item.spec || item.specification || ''),
|
||
color: String(item.color || ''),
|
||
weight: String(item.weight || ''),
|
||
image_url: String(item.image_url || item.pic || item.picture || ''),
|
||
shelf_status: String(item.shelf_status || ''),
|
||
owner: String(item.owner || item.owner_name || ''),
|
||
maintain_info: String(item.maintain_info || item.maintain || ''),
|
||
planQty: Number.isFinite(planQty) ? planQty : 0,
|
||
receivedQty: Number.isFinite(receivedQty) ? receivedQty : 0,
|
||
remainingQty: Number.isFinite(remainingQty) ? remainingQty : 0
|
||
};
|
||
});
|
||
},
|
||
handleClearOrder() {
|
||
this.hasInboundOrder = false;
|
||
this.inboundOrderNo = '';
|
||
this.searchKeyword = '';
|
||
this.inboundOrderData = null;
|
||
this.inboundItems = [];
|
||
this.summaryData = null;
|
||
this.currentItemIndex = 0;
|
||
this.selectedStock = null;
|
||
this.formData = {
|
||
productKeyword: '',
|
||
quantity: '',
|
||
spaceKeyword: '',
|
||
remark: ''
|
||
};
|
||
this.activeScanField = 'productKeyword';
|
||
},
|
||
handleCancelInbound() {
|
||
uni.showModal({
|
||
title: '提示',
|
||
content: '确定取消当前入库单吗?已入库的数据将保留。',
|
||
success: (res) => {
|
||
if (res.confirm) {
|
||
this.handleClearOrder();
|
||
}
|
||
}
|
||
});
|
||
},
|
||
handleInboundDone() {
|
||
uni.showModal({
|
||
title: '提示',
|
||
content: '确认该入库单已完成入库?',
|
||
success: async (res) => {
|
||
if (!res.confirm) return;
|
||
uni.showLoading({ title: '提交中...' });
|
||
try {
|
||
const result = await this.$http('storage.directInbound.commit', { entry_order_code: this.inboundOrderNo });
|
||
uni.hideLoading();
|
||
if (result?.flag === 'failure') {
|
||
uni.showToast({ title: result?.message || '提交失败', icon: 'none' });
|
||
return;
|
||
}
|
||
uni.showToast({ title: '入库完成', icon: 'success' });
|
||
this.speakVoice('入库完成');
|
||
this.handleClearOrder();
|
||
} catch (error) {
|
||
uni.hideLoading();
|
||
const msg = String(error?.message || error?.msg || '提交失败');
|
||
uni.showToast({ title: msg, icon: 'none' });
|
||
}
|
||
}
|
||
});
|
||
},
|
||
selectInboundItem(index) {
|
||
this.currentItemIndex = index;
|
||
const items = this.inboundItems || [];
|
||
const item = items[index];
|
||
if (!item) return;
|
||
this.selectedStock = {
|
||
item_name: item.skuName || '--',
|
||
item_code: item.skuCode || '',
|
||
barcode: item.barcode || '',
|
||
spec: item.spec || '',
|
||
color: item.color || '',
|
||
weight: item.weight || '',
|
||
image_url: item.image_url || '',
|
||
shelf_status: item.shelf_status || '',
|
||
owner: item.owner || '',
|
||
maintain_info: item.maintain_info || '',
|
||
plan_qty: Number.isFinite(item.planQty) ? item.planQty : 0,
|
||
received_qty: Number.isFinite(item.receivedQty) ? item.receivedQty : 0,
|
||
remaining_qty: Number.isFinite(item.remainingQty) ? item.remainingQty : 0
|
||
};
|
||
this.formData.productKeyword = item.skuName || '';
|
||
const fillQty = item.remainingQty > 0 ? item.remainingQty : item.planQty;
|
||
this.formData.quantity = String(Number.isFinite(fillQty) ? fillQty : '');
|
||
},
|
||
setActiveScanField(field) {
|
||
this.activeScanField = field;
|
||
},
|
||
handleFieldScan(field) {
|
||
this.activeScanField = field;
|
||
uni.scanCode({
|
||
onlyFromCamera: true,
|
||
scanType: ['barCode', 'qrCode', 'datamatrix', 'pdf417'],
|
||
success: (res) => {
|
||
const scanResult = this.normalizeScanResult(res);
|
||
if (!scanResult) {
|
||
uni.showToast({ title: '未识别到有效条码', icon: 'none' });
|
||
return;
|
||
}
|
||
if (field === 'productKeyword') {
|
||
this.formData.productKeyword = scanResult;
|
||
this.handleProductSearch();
|
||
} else if (field === 'space') {
|
||
this.formData.spaceKeyword = scanResult;
|
||
}
|
||
},
|
||
fail: (error) => {
|
||
const errMsg = String(error?.errMsg || '').toLowerCase();
|
||
if (errMsg.includes('cancel')) return;
|
||
uni.showToast({ title: '扫码失败,请重试', icon: 'none' });
|
||
}
|
||
});
|
||
},
|
||
getStockBarcode(stock) {
|
||
if (!stock) return '--';
|
||
const barcodes = stock.barcodes || stock.barcode_list || [];
|
||
if (Array.isArray(barcodes) && barcodes.length > 0) return barcodes.join(', ');
|
||
return stock.barcode || stock.item_code || '--';
|
||
},
|
||
async handleProductSearch() {
|
||
const keyword = this.normalizeKeyword(this.formData?.productKeyword || '');
|
||
if (!keyword) return;
|
||
const items = this.inboundItems || [];
|
||
// 先在入库单明细中匹配
|
||
const matchedItem = items.find(item => {
|
||
if (!item) return false;
|
||
const barcode = this.normalizeKeyword(item.barcode || '');
|
||
const skuCode = this.normalizeKeyword(item.skuCode || '');
|
||
return barcode === keyword || skuCode === keyword || item.skuName === keyword;
|
||
});
|
||
if (matchedItem) {
|
||
this.selectedStock = {
|
||
item_name: matchedItem.skuName || '--',
|
||
item_code: matchedItem.skuCode || '',
|
||
barcode: matchedItem.barcode || '',
|
||
spec: matchedItem.spec || '',
|
||
color: matchedItem.color || '',
|
||
weight: matchedItem.weight || '',
|
||
image_url: matchedItem.image_url || '',
|
||
shelf_status: matchedItem.shelf_status || '',
|
||
owner: matchedItem.owner || '',
|
||
maintain_info: matchedItem.maintain_info || '',
|
||
plan_qty: Number.isFinite(matchedItem.planQty) ? matchedItem.planQty : 0,
|
||
received_qty: Number.isFinite(matchedItem.receivedQty) ? matchedItem.receivedQty : 0,
|
||
remaining_qty: Number.isFinite(matchedItem.remainingQty) ? matchedItem.remainingQty : 0
|
||
};
|
||
this.formData.productKeyword = matchedItem.skuName || '';
|
||
const fillQty = matchedItem.remainingQty > 0 ? matchedItem.remainingQty : matchedItem.planQty;
|
||
this.formData.quantity = String(Number.isFinite(fillQty) ? fillQty : '');
|
||
uni.showToast({ title: '已匹配商品', icon: 'success' });
|
||
this.speakVoice('数据一致');
|
||
return;
|
||
}
|
||
// 不在入库单中,提示
|
||
uni.showToast({ title: '该商品不在入库单中', icon: 'none' });
|
||
this.speakVoice('无记录');
|
||
},
|
||
clearSelectedStock() {
|
||
this.selectedStock = null;
|
||
this.formData.productKeyword = '';
|
||
this.activeScanField = 'productKeyword';
|
||
},
|
||
async handleSubmit() {
|
||
if (!this.selectedStock) {
|
||
uni.showToast({ title: '请先扫描商品条码', icon: 'none' });
|
||
return;
|
||
}
|
||
const qty = Number(this.formData.quantity);
|
||
if (!qty || qty <= 0) {
|
||
uni.showToast({ title: '请输入有效入库数量', icon: 'none' });
|
||
return;
|
||
}
|
||
this.submitting = true;
|
||
uni.showLoading({ title: '提交中...' });
|
||
try {
|
||
const params = {
|
||
entry_order_code: this.inboundOrderNo,
|
||
item_code: this.selectedStock.item_code,
|
||
quantity: qty,
|
||
space_code: this.normalizeKeyword(this.formData.spaceKeyword) || undefined,
|
||
remark: this.formData.remark || undefined
|
||
};
|
||
await this.$http('storage.directInbound.inbound', params);
|
||
uni.hideLoading();
|
||
uni.showToast({ title: '入库成功', icon: 'success' });
|
||
this.speakVoice('入库成功');
|
||
// 清空表单
|
||
this.clearSelectedStock();
|
||
this.formData.quantity = '';
|
||
this.formData.spaceKeyword = '';
|
||
this.formData.remark = '';
|
||
} catch (error) {
|
||
uni.hideLoading();
|
||
const msg = String(error?.message || error?.msg || error?.errMsg || '入库失败');
|
||
uni.showToast({ title: msg, icon: 'none' });
|
||
} finally {
|
||
this.submitting = false;
|
||
}
|
||
},
|
||
|
||
}
|
||
};
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.random-storage-page {
|
||
height: 100vh;
|
||
background: #f8f9fa;
|
||
}
|
||
|
||
.normar_container {
|
||
height: 100%;
|
||
display: flex;
|
||
flex-direction: column;
|
||
overflow: hidden;
|
||
}
|
||
|
||
::v-deep .nav-title .right {
|
||
width: auto;
|
||
min-width: 160rpx;
|
||
display: flex;
|
||
justify-content: flex-end;
|
||
}
|
||
|
||
::v-deep .nav-title .left .left-back {
|
||
display: none;
|
||
}
|
||
|
||
.content-split {
|
||
flex: 1;
|
||
display: flex;
|
||
flex-direction: column;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.content-top {
|
||
flex: 6;
|
||
padding: 0 0 0;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.content-bottom {
|
||
flex: 3;
|
||
background: #1a1a1a;
|
||
display: flex;
|
||
align-items: stretch;
|
||
justify-content: flex-start;
|
||
padding: 0 24rpx 12rpx;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
/* ===== 导航按钮 ===== */
|
||
.nav-back-btn {
|
||
width: 60rpx;
|
||
height: 60rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
}
|
||
|
||
.nav-cancel-btn {
|
||
padding: 8rpx 18rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
border: 1rpx solid #f56c6c;
|
||
border-radius: 6rpx;
|
||
}
|
||
|
||
.nav-cancel-btn:active {
|
||
opacity: 0.7;
|
||
}
|
||
|
||
.nav-cancel-btn__text {
|
||
font-size: 28rpx;
|
||
color: #f56c6c;
|
||
line-height: 1.4;
|
||
}
|
||
|
||
.nav-done-btn {
|
||
padding: 8rpx 18rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
border: 1rpx solid #07c160;
|
||
border-radius: 6rpx;
|
||
background: #07c160;
|
||
}
|
||
|
||
.nav-done-btn:active {
|
||
opacity: 0.7;
|
||
}
|
||
|
||
.nav-done-btn__text {
|
||
font-size: 28rpx;
|
||
color: #ffffff;
|
||
line-height: 1.4;
|
||
}
|
||
|
||
/* ===== 空态样式 ===== */
|
||
.empty-wrap {
|
||
flex: 1;
|
||
display: flex;
|
||
flex-direction: column;
|
||
padding: 0;
|
||
}
|
||
|
||
.search-filter {
|
||
background: #ffffff;
|
||
padding: 20rpx 24rpx 16rpx;
|
||
border-bottom: 1rpx solid #f0f0f0;
|
||
}
|
||
|
||
.search-row {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10rpx;
|
||
}
|
||
|
||
.search-row ::v-deep .u-search {
|
||
flex: 1;
|
||
min-width: 0;
|
||
}
|
||
|
||
.search-scan-btn {
|
||
flex-shrink: 0;
|
||
width: 56rpx;
|
||
height: 56rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
background: #f5f5f5;
|
||
border-radius: 50%;
|
||
}
|
||
|
||
.search-scan-btn:active {
|
||
opacity: 0.7;
|
||
}
|
||
|
||
.empty-card {
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
justify-content: center;
|
||
flex: 1;
|
||
background: #ffffff;
|
||
border-radius: 16rpx;
|
||
padding: 80rpx 60rpx;
|
||
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06);
|
||
}
|
||
|
||
.empty-title {
|
||
font-size: 38rpx;
|
||
font-weight: 600;
|
||
color: #303133;
|
||
margin-top: 24rpx;
|
||
}
|
||
|
||
.empty-desc {
|
||
font-size: 30rpx;
|
||
color: #909399;
|
||
margin-top: 12rpx;
|
||
}
|
||
|
||
/* ===== 商品详情区 ===== */
|
||
.product-detail-area {
|
||
height: 75%;
|
||
background: #ffffff;
|
||
padding: 20rpx 24rpx;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.product-detail {
|
||
display: flex;
|
||
height: 100%;
|
||
gap: 24rpx;
|
||
}
|
||
|
||
/* 左 50%:商品图片 */
|
||
.product-image-wrap {
|
||
flex: 1;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
background: #f8f9fa;
|
||
border-radius: 12rpx;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.product-image {
|
||
width: 100%;
|
||
height: 100%;
|
||
}
|
||
|
||
.product-image-placeholder {
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
justify-content: center;
|
||
gap: 16rpx;
|
||
}
|
||
|
||
.product-image-text {
|
||
font-size: 26rpx;
|
||
color: #c0c4cc;
|
||
text-align: center;
|
||
padding: 0 10rpx;
|
||
}
|
||
|
||
/* 右 50%:商品信息 */
|
||
.product-info {
|
||
flex: 1;
|
||
display: flex;
|
||
flex-direction: column;
|
||
justify-content: flex-start;
|
||
gap: 14rpx;
|
||
}
|
||
|
||
.product-name {
|
||
font-size: 38rpx;
|
||
font-weight: 600;
|
||
color: #303133;
|
||
margin-bottom: 4rpx;
|
||
}
|
||
|
||
.product-info-row {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 6rpx;
|
||
}
|
||
|
||
.product-info-label {
|
||
font-size: 30rpx;
|
||
color: #303133;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.product-info-value {
|
||
font-size: 30rpx;
|
||
color: #303133;
|
||
flex: 1;
|
||
}
|
||
|
||
.product-info-row-qty {
|
||
margin-top: 4rpx;
|
||
}
|
||
|
||
.product-info-value-qty {
|
||
color: #f56c6c;
|
||
font-weight: 600;
|
||
font-size: 32rpx;
|
||
}
|
||
|
||
/* ===== 订单信息区 ===== */
|
||
.order-info-area {
|
||
height: auto;
|
||
background: #ffffff;
|
||
border-top: 1rpx solid #f2f3f5;
|
||
padding: 0;
|
||
box-sizing: border-box;
|
||
display: flex;
|
||
flex-direction: column;
|
||
justify-content: center;
|
||
}
|
||
|
||
.order-info-row {
|
||
display: flex;
|
||
align-items: stretch;
|
||
gap: 0;
|
||
}
|
||
|
||
.order-info-col {
|
||
display: flex;
|
||
flex-direction: column;
|
||
border-radius: 8rpx;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.order-info-col--left {
|
||
flex: 1;
|
||
}
|
||
|
||
.order-info-col--middle {
|
||
flex: 2;
|
||
}
|
||
|
||
.order-info-col--right {
|
||
flex: 1;
|
||
}
|
||
|
||
.order-info-col__item {
|
||
flex: 1;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
padding: 12rpx 8rpx;
|
||
}
|
||
|
||
.order-info-col__item--blue {
|
||
background: #b1cfff;
|
||
}
|
||
|
||
.order-info-col__item--white {
|
||
background: #ffffff;
|
||
}
|
||
|
||
.order-info-col__item--green {
|
||
background: #d4edda;
|
||
}
|
||
|
||
.order-info-item {
|
||
flex: 1;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 4rpx;
|
||
}
|
||
|
||
.order-info-label {
|
||
font-size: 30rpx;
|
||
color: #303133;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.order-info-value {
|
||
font-size: 30rpx;
|
||
color: #303133;
|
||
flex: 1;
|
||
}
|
||
|
||
.order-info-value--center {
|
||
text-align: center;
|
||
}
|
||
|
||
.order-info-item--center .order-info-value {
|
||
text-align: center;
|
||
}
|
||
|
||
.order-info-item--right {
|
||
flex: none;
|
||
justify-content: flex-end;
|
||
}
|
||
|
||
.shelf-btn {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
padding: 4rpx 0;
|
||
}
|
||
|
||
.shelf-btn:active {
|
||
opacity: 0.5;
|
||
}
|
||
|
||
.shelf-btn__text {
|
||
font-size: 30rpx;
|
||
color: #2979ff;
|
||
line-height: 1.4;
|
||
}
|
||
|
||
.order-info-col__item--green .shelf-btn__text {
|
||
color: #07c160;
|
||
}
|
||
|
||
.shelf-btn--green .shelf-btn__text {
|
||
color: #07c160;
|
||
}
|
||
|
||
.submit-btn-wrap {
|
||
width: 100%;
|
||
}
|
||
|
||
/* ===== 上架抽屉 ===== */
|
||
.shelf-overlay {
|
||
position: fixed;
|
||
top: 0;
|
||
left: 0;
|
||
right: 0;
|
||
bottom: 0;
|
||
background: rgba(0, 0, 0, 0.45);
|
||
z-index: 999;
|
||
display: flex;
|
||
align-items: flex-end;
|
||
justify-content: center;
|
||
}
|
||
|
||
.shelf-drawer {
|
||
width: 100%;
|
||
background: #ffffff;
|
||
border-radius: 24rpx 24rpx 0 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
height: 80vh;
|
||
overflow: hidden;
|
||
animation: slideUp 0.3s ease;
|
||
}
|
||
|
||
@keyframes slideUp {
|
||
from {
|
||
transform: translateY(100%);
|
||
}
|
||
to {
|
||
transform: translateY(0);
|
||
}
|
||
}
|
||
|
||
.shelf-drawer__header {
|
||
display: flex;
|
||
align-items: center;
|
||
padding: 30rpx 32rpx 20rpx;
|
||
border-bottom: 1rpx solid #f2f3f5;
|
||
gap: 12rpx;
|
||
}
|
||
|
||
.shelf-drawer__title {
|
||
font-size: 36rpx;
|
||
font-weight: 600;
|
||
color: #303133;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.shelf-drawer__product-name {
|
||
font-size: 34rpx;
|
||
color: #303133;
|
||
flex: 1;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
.shelf-drawer__body {
|
||
padding: 24rpx 32rpx;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 28rpx;
|
||
overflow-y: auto;
|
||
flex: 1;
|
||
}
|
||
|
||
.shelf-form-row {
|
||
display: flex;
|
||
align-items: center;
|
||
min-height: 72rpx;
|
||
}
|
||
|
||
.shelf-form-label {
|
||
font-size: 32rpx;
|
||
color: #303133;
|
||
width: 160rpx;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.shelf-form-value {
|
||
font-size: 32rpx;
|
||
color: #f56c6c;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.shelf-form-input {
|
||
flex: 1;
|
||
height: 72rpx;
|
||
background: #f5f7fa;
|
||
border-radius: 8rpx;
|
||
padding: 0 20rpx;
|
||
font-size: 30rpx;
|
||
color: #303133;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.shelf-form-date {
|
||
flex: 1;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
height: 72rpx;
|
||
background: #f5f7fa;
|
||
border-radius: 8rpx;
|
||
padding: 0 20rpx;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.shelf-form-date:active {
|
||
opacity: 0.7;
|
||
}
|
||
|
||
.shelf-form-date__text {
|
||
font-size: 30rpx;
|
||
color: #303133;
|
||
}
|
||
|
||
.shelf-form-date__text--placeholder {
|
||
color: #c0c4cc;
|
||
}
|
||
|
||
.shelf-drawer__footer {
|
||
display: flex;
|
||
padding: 20rpx 32rpx;
|
||
gap: 20rpx;
|
||
border-top: 1rpx solid #f2f3f5;
|
||
padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
|
||
}
|
||
|
||
.shelf-btn-cancel {
|
||
flex: 1;
|
||
height: 88rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
border: 2rpx solid #dcdfe6;
|
||
border-radius: 12rpx;
|
||
background: #ffffff;
|
||
}
|
||
|
||
.shelf-btn-cancel:active {
|
||
opacity: 0.7;
|
||
}
|
||
|
||
.shelf-btn-cancel__text {
|
||
font-size: 34rpx;
|
||
color: #606266;
|
||
}
|
||
|
||
.shelf-btn-submit {
|
||
flex: 1;
|
||
height: 88rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
border-radius: 12rpx;
|
||
background: #2979ff;
|
||
}
|
||
|
||
.shelf-btn-submit:active {
|
||
opacity: 0.8;
|
||
}
|
||
|
||
.shelf-btn-submit__text {
|
||
font-size: 34rpx;
|
||
color: #ffffff;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.item-list-scroll {
|
||
width: 100%;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
.item-chip {
|
||
display: inline-flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
justify-content: center;
|
||
min-width: 120rpx;
|
||
height: 80rpx;
|
||
padding: 4rpx 16rpx;
|
||
margin-right: 12rpx;
|
||
margin-top: 12rpx;
|
||
background: #f0f7ff;
|
||
border: 2rpx solid #2979ff;
|
||
border-radius: 10rpx;
|
||
}
|
||
|
||
.item-chip:active {
|
||
opacity: 0.7;
|
||
}
|
||
|
||
.item-chip--active {
|
||
background: #2979ff;
|
||
}
|
||
|
||
.item-chip--active .item-chip__no {
|
||
color: #fff;
|
||
}
|
||
|
||
.item-chip--active .item-chip__total {
|
||
color: rgba(255,255,255,0.85);
|
||
}
|
||
|
||
.item-chip__no {
|
||
font-size: 32rpx;
|
||
color: #2979ff;
|
||
font-weight: 600;
|
||
line-height: 1.4;
|
||
}
|
||
|
||
.item-chip__total {
|
||
font-size: 30rpx;
|
||
color: #606266;
|
||
margin-top: 2rpx;
|
||
}
|
||
|
||
.summary-bar {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: flex-start;
|
||
padding: 16rpx 0;
|
||
padding-top: 0;
|
||
background: #ffffff;
|
||
margin-bottom: 20rpx;
|
||
}
|
||
|
||
.summary-label {
|
||
font-size: 34rpx;
|
||
color: #f56c6c;
|
||
}
|
||
|
||
.summary-value {
|
||
color: #f56c6c;
|
||
font-weight: 600;
|
||
font-size: 36rpx;
|
||
margin-left: 6rpx;
|
||
}
|
||
|
||
.summary-split {
|
||
color: #f56c6c;
|
||
font-size: 34rpx;
|
||
margin: 0 6rpx;
|
||
}
|
||
|
||
.summary-total {
|
||
color: #f56c6c;
|
||
font-weight: 600;
|
||
font-size: 36rpx;
|
||
}
|
||
</style>
|