1049 lines
27 KiB
Vue
1049 lines
27 KiB
Vue
<template>
|
||
<view class="relocation-page">
|
||
<view class="normar_container">
|
||
<page-nav title="移库作业">
|
||
<template #right>
|
||
<u-button
|
||
class="nav-submit-btn"
|
||
size="mini"
|
||
type="primary"
|
||
text="确认移库"
|
||
:customStyle="{ backgroundColor: '#2979ff', borderColor: '#2979ff' }"
|
||
:loading="submitting"
|
||
:disabled="submitting"
|
||
@click="handleSubmit"
|
||
>
|
||
<text class="nav-submit-btn__text">确认移库</text>
|
||
</u-button>
|
||
</template>
|
||
</page-nav>
|
||
|
||
<scroll-view class="container" scroll-y>
|
||
<u-form class="form-box" :model="formData" ref="formRef" label-width="170rpx">
|
||
<view class="section">
|
||
<view class="section-title">库位信息</view>
|
||
|
||
<u-form-item label="移出库位" required>
|
||
<view class="scan-input-wrap">
|
||
<u-input
|
||
:value="formData.sourceSpaceKeyword || formData.sourceSpaceName"
|
||
disabled
|
||
placeholder="自动带出移出库位"
|
||
/>
|
||
</view>
|
||
</u-form-item>
|
||
|
||
<u-form-item label="移入库位" required>
|
||
<view class="scan-input-wrap">
|
||
<u-input
|
||
v-model="formData.targetSpaceKeyword"
|
||
placeholder="请扫描或输入移入库位"
|
||
clearable
|
||
@focus="setActiveScanField('targetSpace')"
|
||
@blur="handleSpaceBlur('targetSpace')"
|
||
/>
|
||
<view class="scan-camera-btn" @click="handleFieldScan('targetSpace')">
|
||
<u-icon name="camera" size="34rpx" color="#2979ff"></u-icon>
|
||
</view>
|
||
</view>
|
||
</u-form-item>
|
||
|
||
<u-form-item class="move-quantity-item" label="移库数量" required label-width="200rpx">
|
||
<view class="quantity-input-wrap">
|
||
<u-input
|
||
class="move-quantity-input"
|
||
v-model="formData.moveQuantity"
|
||
type="number"
|
||
fontSize="42rpx"
|
||
placeholder="请输入移库数量"
|
||
@input="handleMoveQuantityInput"
|
||
@blur="handleMoveQuantityBlur"
|
||
></u-input>
|
||
<view class="quantity-all-view-btn" @click="handleFillAllQuantity">
|
||
<text>全部</text>
|
||
</view>
|
||
</view>
|
||
</u-form-item>
|
||
</view>
|
||
|
||
<view class="section">
|
||
<view class="section-title">商品信息</view>
|
||
|
||
<view v-if="selectedStock" class="stock-card">
|
||
<view class="stock-card__header">
|
||
<text class="stock-card__title">{{ getStockName(selectedStock) }}</text>
|
||
</view>
|
||
<view class="stock-card__row">
|
||
<text class="label">货主:</text>
|
||
<text class="value">{{ getStockOwnerText(selectedStock) }}</text>
|
||
</view>
|
||
<view class="stock-card__row">
|
||
<text class="label">条码:</text>
|
||
<text class="value">{{ getStockBarcode(selectedStock) }}</text>
|
||
</view>
|
||
<view v-if="shouldShowStockBatch(selectedStock)" class="stock-card__row">
|
||
<text class="label">批次号:</text>
|
||
<text class="value">{{ getStockBatchNumber(selectedStock) }}</text>
|
||
</view>
|
||
<view class="stock-card__row">
|
||
<text class="label">当前库位:</text>
|
||
<text class="value">{{ getStockSpace(selectedStock) }}</text>
|
||
</view>
|
||
<view class="stock-card__row">
|
||
<text class="label">可用库存:</text>
|
||
<text class="value">{{ getStockQuantity(selectedStock) }}</text>
|
||
</view>
|
||
</view>
|
||
|
||
<u-form-item class="remark-item" label="备注" label-width="110rpx">
|
||
<u-input v-model="formData.remark" type="textarea" placeholder="请输入备注信息" height="120"></u-input>
|
||
</u-form-item>
|
||
</view>
|
||
</u-form>
|
||
</scroll-view>
|
||
</view>
|
||
|
||
<u-popup :show="selectorVisible" mode="bottom" :closeable="true" border-radius="20" @close="selectorVisible = false">
|
||
<view class="selector-popup">
|
||
<view class="popup-header">
|
||
<text class="popup-title">请选择{{ selectorType === 'stock' ? '商品库存' : '库位' }}</text>
|
||
</view>
|
||
<scroll-view class="popup-list" scroll-y>
|
||
<view
|
||
v-for="(item, index) in selectorList"
|
||
:key="item.id || item.space_id || index"
|
||
class="popup-item"
|
||
@click="handleSelectorConfirm(item)"
|
||
>
|
||
<template v-if="selectorType === 'stock'">
|
||
<text class="popup-item__title">{{ getStockName(item) }}</text>
|
||
<text class="popup-item__desc">条码:{{ getStockBarcode(item) }}</text>
|
||
<text class="popup-item__desc">库位:{{ getStockSpace(item) }}</text>
|
||
</template>
|
||
<template v-else>
|
||
<text class="popup-item__title">{{ getSpaceName(item) }}</text>
|
||
<text class="popup-item__desc">库位:{{ getSpaceName(item) }}</text>
|
||
</template>
|
||
</view>
|
||
</scroll-view>
|
||
</view>
|
||
</u-popup>
|
||
|
||
<u-loading-page :loading="loading" bg-color="rgba(255,255,255,0.9)"></u-loading-page>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
export default {
|
||
data() {
|
||
return {
|
||
loading: false,
|
||
submitting: false,
|
||
activeScanField: 'productKeyword',
|
||
selectorVisible: false,
|
||
selectorType: '',
|
||
selectorField: '',
|
||
selectorList: [],
|
||
selectedStock: null,
|
||
formData: {
|
||
sourceSpaceKeyword: '',
|
||
sourceSpaceId: null,
|
||
sourceSpaceName: '',
|
||
targetSpaceKeyword: '',
|
||
targetSpaceId: null,
|
||
targetSpaceName: '',
|
||
productKeyword: '',
|
||
moveQuantity: '',
|
||
remark: ''
|
||
}
|
||
}
|
||
},
|
||
onLoad(options = {}) {
|
||
this.safeDispatchBroadcast('setCallbacks', {
|
||
onResult: this.handleBroadcastResult
|
||
});
|
||
this.safeDispatchBroadcast('start');
|
||
this.applyPrefillFromOptions(options);
|
||
},
|
||
onShow() {
|
||
this.safeDispatchBroadcast('setCallbacks', {
|
||
onResult: this.handleBroadcastResult
|
||
});
|
||
this.safeDispatchBroadcast('resume');
|
||
},
|
||
onHide() {
|
||
this.safeDispatchBroadcast('pause');
|
||
},
|
||
onUnload() {
|
||
this.safeDispatchBroadcast('stop');
|
||
},
|
||
methods: {
|
||
normalizePositiveId(value) {
|
||
const numericValue = Number(value);
|
||
if (!Number.isFinite(numericValue)) {
|
||
return null;
|
||
}
|
||
|
||
const normalized = Math.trunc(numericValue);
|
||
return normalized > 0 ? normalized : null;
|
||
},
|
||
normalizeSpeechText(message) {
|
||
const rawText = String(message || '').trim();
|
||
if (!rawText) {
|
||
return '';
|
||
}
|
||
|
||
const digitMap = {
|
||
'0': '零',
|
||
'1': '一',
|
||
'2': '二',
|
||
'3': '三',
|
||
'4': '四',
|
||
'5': '五',
|
||
'6': '六',
|
||
'7': '七',
|
||
'8': '八',
|
||
'9': '九'
|
||
};
|
||
|
||
const normalizeCodeSegment = (segment) => {
|
||
return segment
|
||
.split('-')
|
||
.map(part => String(part || '')
|
||
.split('')
|
||
.map(char => (digitMap[char] || char))
|
||
.join(''))
|
||
.join('的');
|
||
};
|
||
|
||
return rawText.replace(/([A-Za-z0-9]+(?:-[A-Za-z0-9]+)+)/g, normalizeCodeSegment);
|
||
},
|
||
speakMessage(message, options = {}) {
|
||
const text = this.normalizeSpeechText(message);
|
||
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('[Relocation] 语音播报失败:', error);
|
||
});
|
||
}
|
||
} catch (error) {
|
||
console.warn('[Relocation] 语音播报异常:', error);
|
||
}
|
||
},
|
||
showToastMessage(title, icon = 'none', options = {}) {
|
||
const message = String(title || '').trim();
|
||
if (!message) {
|
||
return;
|
||
}
|
||
|
||
uni.showToast({
|
||
title: message,
|
||
icon
|
||
});
|
||
|
||
if (options.speak !== false) {
|
||
this.speakMessage(options.speakText || message, options.voiceOptions || {});
|
||
}
|
||
},
|
||
safeDispatchBroadcast(action, payload) {
|
||
try {
|
||
const task = this.$store.dispatch(`broadcast/${action}`, payload);
|
||
if (task && typeof task.catch === 'function') {
|
||
task.catch(error => {
|
||
console.warn(`[Relocation] broadcast/${action} 调用失败:`, error);
|
||
});
|
||
}
|
||
} catch (error) {
|
||
console.warn(`[Relocation] broadcast/${action} 调用异常:`, error);
|
||
}
|
||
},
|
||
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 '';
|
||
},
|
||
setActiveScanField(field) {
|
||
this.activeScanField = field;
|
||
},
|
||
handleBroadcastResult(result) {
|
||
const rawCode = this.normalizeUniScanResult(result);
|
||
if (!rawCode) {
|
||
return;
|
||
}
|
||
|
||
const field = this.resolveBroadcastField();
|
||
this.applyScanResult(rawCode, field);
|
||
},
|
||
resolveBroadcastField() {
|
||
return 'targetSpace';
|
||
},
|
||
handleFieldScan(field) {
|
||
this.setActiveScanField(field);
|
||
uni.scanCode({
|
||
onlyFromCamera: false,
|
||
scanType: ['qrCode', 'barCode', 'datamatrix', 'pdf417'],
|
||
success: (res) => {
|
||
const rawCode = this.normalizeUniScanResult(res);
|
||
if (!rawCode) {
|
||
this.showToastMessage('未识别到有效内容');
|
||
return;
|
||
}
|
||
|
||
this.applyScanResult(rawCode, field);
|
||
},
|
||
fail: (error) => {
|
||
const errMsg = String(error?.errMsg || '').toLowerCase();
|
||
if (errMsg.includes('cancel')) {
|
||
return;
|
||
}
|
||
|
||
this.showToastMessage('扫码失败,请重试');
|
||
}
|
||
});
|
||
},
|
||
applyScanResult(rawCode, field) {
|
||
if (field === 'sourceSpace' || field === 'targetSpace') {
|
||
const keywordKey = field === 'sourceSpace' ? 'sourceSpaceKeyword' : 'targetSpaceKeyword';
|
||
this.formData[keywordKey] = rawCode;
|
||
this.searchSpace(field, rawCode);
|
||
return;
|
||
}
|
||
|
||
this.formData.productKeyword = rawCode;
|
||
this.searchStock(rawCode);
|
||
},
|
||
handleSpaceBlur(field) {
|
||
const keyword = field === 'sourceSpace' ? this.formData.sourceSpaceKeyword : this.formData.targetSpaceKeyword;
|
||
if (keyword) {
|
||
this.searchSpace(field, keyword);
|
||
}
|
||
},
|
||
handleProductBlur() {
|
||
if (this.formData.productKeyword) {
|
||
this.searchStock(this.formData.productKeyword);
|
||
}
|
||
},
|
||
async searchSpace(field, keyword) {
|
||
const rawKeyword = String(keyword || '').trim();
|
||
if (!rawKeyword) {
|
||
return;
|
||
}
|
||
|
||
this.loading = true;
|
||
try {
|
||
const res = await this.$http('common.searchSpace', {
|
||
keyword: rawKeyword
|
||
});
|
||
|
||
if (res.code !== 200) {
|
||
throw new Error(res.message || '库位搜索失败');
|
||
}
|
||
|
||
const list = Array.isArray(res.data) ? res.data : [];
|
||
if (Number(res.total || list.length) === 1 && list[0]) {
|
||
this.applySpaceSelection(field, list[0]);
|
||
return;
|
||
}
|
||
|
||
if (list.length > 1) {
|
||
this.selectorType = 'space';
|
||
this.selectorField = field;
|
||
this.selectorList = list;
|
||
this.selectorVisible = true;
|
||
return;
|
||
}
|
||
|
||
this.showToastMessage('未找到匹配库位');
|
||
} catch (error) {
|
||
console.error('搜索库位失败:', error);
|
||
this.showToastMessage('库位查询失败');
|
||
} finally {
|
||
this.loading = false;
|
||
}
|
||
},
|
||
applySpaceSelection(field, item) {
|
||
const isSource = field === 'sourceSpace';
|
||
this.formData[isSource ? 'sourceSpaceId' : 'targetSpaceId'] = item?.id || item?.space_id || null;
|
||
const spaceName = this.getSpaceName(item);
|
||
this.formData[isSource ? 'sourceSpaceName' : 'targetSpaceName'] = spaceName;
|
||
this.formData[isSource ? 'sourceSpaceKeyword' : 'targetSpaceKeyword'] = spaceName;
|
||
if (isSource) {
|
||
return;
|
||
}
|
||
|
||
const targetNameText = String(this.formData.targetSpaceName || this.formData.targetSpaceKeyword || '').trim();
|
||
this.speakMessage(`已识别移入库位,${targetNameText || spaceName}`);
|
||
},
|
||
async searchStock(keyword) {
|
||
const rawKeyword = String(keyword || '').trim();
|
||
if (!rawKeyword) {
|
||
return;
|
||
}
|
||
|
||
this.loading = true;
|
||
try {
|
||
const res = await this.$http('stock.warehouse.search', {
|
||
keyword: rawKeyword
|
||
});
|
||
|
||
if (res.code !== 200) {
|
||
throw new Error(res.message || '库存查询失败');
|
||
}
|
||
|
||
const list = Array.isArray(res.data) ? res.data : [];
|
||
if (Number(res.total || list.length) === 1 && list[0]) {
|
||
this.applyStockSelection(list[0]);
|
||
return;
|
||
}
|
||
|
||
if (list.length > 1) {
|
||
this.selectorType = 'stock';
|
||
this.selectorField = 'stock';
|
||
this.selectorList = list;
|
||
this.selectorVisible = true;
|
||
return;
|
||
}
|
||
|
||
this.selectedStock = null;
|
||
this.showToastMessage('未找到匹配库存');
|
||
} catch (error) {
|
||
console.error('搜索库存失败:', error);
|
||
this.showToastMessage('库存查询失败');
|
||
} finally {
|
||
this.loading = false;
|
||
}
|
||
},
|
||
applyStockSelection(item) {
|
||
this.selectedStock = item;
|
||
this.formData.productKeyword = this.getStockBarcode(item) || this.getStockName(item);
|
||
if (!this.formData.moveQuantity) {
|
||
const quantity = this.getStockQuantity(item);
|
||
this.formData.moveQuantity = quantity && quantity !== '--' ? String(quantity) : '';
|
||
}
|
||
},
|
||
applyPrefillFromOptions(options = {}) {
|
||
const cacheKey = String(options.cacheKey || '').trim();
|
||
if (!cacheKey) {
|
||
return;
|
||
}
|
||
|
||
const prefillData = uni.getStorageSync(cacheKey);
|
||
if (!prefillData || typeof prefillData !== 'object') {
|
||
return;
|
||
}
|
||
|
||
uni.removeStorageSync(cacheKey);
|
||
this.activeScanField = 'productKeyword';
|
||
|
||
if (prefillData.stock && typeof prefillData.stock === 'object') {
|
||
this.selectedStock = prefillData.stock;
|
||
this.formData.productKeyword = this.getStockBarcode(prefillData.stock) || this.getStockName(prefillData.stock);
|
||
}
|
||
|
||
if (prefillData.sourceSpace && typeof prefillData.sourceSpace === 'object') {
|
||
this.formData.sourceSpaceId = prefillData.sourceSpace.id || null;
|
||
this.formData.sourceSpaceName = prefillData.sourceSpace.name || '';
|
||
this.formData.sourceSpaceKeyword = prefillData.sourceSpace.name || prefillData.sourceSpace.code || '';
|
||
if (this.selectedStock && typeof this.selectedStock === 'object') {
|
||
if (!this.selectedStock.space_name && prefillData.sourceSpace.name) {
|
||
this.selectedStock.space_name = prefillData.sourceSpace.name;
|
||
}
|
||
if (!this.selectedStock.space_barcode && prefillData.sourceSpace.code) {
|
||
this.selectedStock.space_barcode = prefillData.sourceSpace.code;
|
||
}
|
||
}
|
||
}
|
||
|
||
const moveQuantity = String(prefillData.moveQuantity || '').trim();
|
||
if (moveQuantity) {
|
||
this.formData.moveQuantity = this.normalizeMoveQuantity(moveQuantity);
|
||
}
|
||
},
|
||
handleSelectorConfirm(item) {
|
||
if (this.selectorType === 'stock') {
|
||
this.applyStockSelection(item);
|
||
} else {
|
||
this.applySpaceSelection(this.selectorField, item);
|
||
}
|
||
this.selectorVisible = false;
|
||
},
|
||
getSpaceName(item) {
|
||
return item?.custom_name || item?.name || item?.space_name || item?.title || item?.space_code || item?.barcode || item?.code || '未命名库位';
|
||
},
|
||
getSpaceCode(item) {
|
||
return item?.barcode || item?.code || item?.space_code || item?.name || '';
|
||
},
|
||
getStockName(item) {
|
||
return item?.item_name || item?.product_name || item?.name || item?.goods_name || '未命名商品';
|
||
},
|
||
getStockBarcode(item) {
|
||
if (Array.isArray(item?.barcodes) && item.barcodes.length) {
|
||
return item.barcodes.filter(Boolean).join(';');
|
||
}
|
||
return item?.barcode || item?.goods_code || item?.item_code || '--';
|
||
},
|
||
getStockOwnerText(item) {
|
||
if (!item || typeof item !== 'object') {
|
||
return '--';
|
||
}
|
||
|
||
const candidates = [
|
||
item.owner_name,
|
||
item.owner,
|
||
item.ownerTitle,
|
||
item.owner_title,
|
||
item.store_remask,
|
||
item['store.store_remask'],
|
||
item['store_stock.store_remask'],
|
||
item.store_stock && item.store_stock.store_remask,
|
||
item.store && item.store.store_remask,
|
||
item.store && item.store.name,
|
||
item.store && item.store.store_name,
|
||
item.store_name
|
||
];
|
||
|
||
for (let i = 0; i < candidates.length; i++) {
|
||
const value = candidates[i];
|
||
if (value !== null && value !== undefined && String(value).trim()) {
|
||
return String(value).trim();
|
||
}
|
||
}
|
||
|
||
return '--';
|
||
},
|
||
getStockBatchNumber(item) {
|
||
if (!item || typeof item !== 'object') {
|
||
return '--';
|
||
}
|
||
|
||
return item.batch_no
|
||
|| item.batch_number
|
||
|| item.lot_no
|
||
|| item.lot_number
|
||
|| '--';
|
||
},
|
||
shouldShowStockBatch(item) {
|
||
if (!item || typeof item !== 'object') {
|
||
return false;
|
||
}
|
||
const isBatchMode = item.relocation_query_mode === 'batch';
|
||
const batchText = this.getStockBatchNumber(item);
|
||
return isBatchMode && batchText && batchText !== '--';
|
||
},
|
||
getStockSpace(item) {
|
||
return item?.space?.name
|
||
|| item?.space_name
|
||
|| item?.space?.space_name
|
||
|| item?.space_code
|
||
|| item?.space?.code
|
||
|| item?.space?.space_code
|
||
|| item?.space_barcode
|
||
|| item?.space?.barcode
|
||
|| item?.location_name
|
||
|| item?.position_name
|
||
|| '--';
|
||
},
|
||
getStockQuantity(item) {
|
||
return item?.available_quantity || item?.actual_quantity || item?.quantity || item?.stock || '--';
|
||
},
|
||
getStockStorageId(item) {
|
||
if (!item || typeof item !== 'object') {
|
||
return null;
|
||
}
|
||
|
||
const directCandidates = [
|
||
item.relocation_storage_id,
|
||
item.id
|
||
];
|
||
|
||
for (let i = 0; i < directCandidates.length; i++) {
|
||
const normalized = this.normalizePositiveId(directCandidates[i]);
|
||
if (normalized) {
|
||
return normalized;
|
||
}
|
||
}
|
||
|
||
return null;
|
||
},
|
||
getProductStockId(item) {
|
||
if (!item || typeof item !== 'object') {
|
||
return null;
|
||
}
|
||
|
||
const directCandidates = [
|
||
item.relocation_product_stock_id,
|
||
item.stock_id,
|
||
item.goods_id,
|
||
item.item_id,
|
||
item.product_id,
|
||
item.id
|
||
];
|
||
|
||
for (let i = 0; i < directCandidates.length; i++) {
|
||
const normalized = this.normalizePositiveId(directCandidates[i]);
|
||
if (normalized) {
|
||
return normalized;
|
||
}
|
||
}
|
||
|
||
return null;
|
||
},
|
||
getAvailableStockNumber() {
|
||
if (!this.selectedStock) {
|
||
return 0;
|
||
}
|
||
|
||
const quantity = this.getStockQuantity(this.selectedStock);
|
||
const normalizedQuantity = Number(String(quantity).replace(/,/g, '').trim());
|
||
return Number.isFinite(normalizedQuantity) && normalizedQuantity > 0 ? normalizedQuantity : 0;
|
||
},
|
||
normalizeMoveQuantity(value) {
|
||
const sanitized = String(value || '').replace(/\D/g, '');
|
||
if (!sanitized) {
|
||
return '';
|
||
}
|
||
|
||
return sanitized.replace(/^0+(?=\d)/, '');
|
||
},
|
||
handleMoveQuantityInput(value) {
|
||
this.formData.moveQuantity = this.normalizeMoveQuantity(value);
|
||
},
|
||
handleMoveQuantityBlur() {
|
||
this.formData.moveQuantity = this.normalizeMoveQuantity(this.formData.moveQuantity);
|
||
if (!this.validateMoveQuantity(true)) {
|
||
return;
|
||
}
|
||
|
||
const quantity = String(this.formData.moveQuantity || '').trim();
|
||
if (!quantity) {
|
||
return;
|
||
}
|
||
|
||
this.speakMessage(`移库数量,${quantity}`);
|
||
},
|
||
validateMoveQuantity(showToast = false) {
|
||
const quantity = String(this.formData.moveQuantity || '').trim();
|
||
if (!quantity) {
|
||
if (showToast) {
|
||
this.showToastMessage('请输入移库数量');
|
||
}
|
||
return false;
|
||
}
|
||
|
||
if (!/^[1-9]\d*$/.test(quantity)) {
|
||
if (showToast) {
|
||
this.showToastMessage('移库数量需为正整数');
|
||
}
|
||
return false;
|
||
}
|
||
|
||
const maxQuantity = this.getAvailableStockNumber();
|
||
if (maxQuantity > 0 && Number(quantity) > maxQuantity) {
|
||
if (showToast) {
|
||
this.showToastMessage('移库数量不能大于可用库存');
|
||
}
|
||
return false;
|
||
}
|
||
|
||
return true;
|
||
},
|
||
handleFillAllQuantity() {
|
||
if (!this.selectedStock) {
|
||
this.showToastMessage('请先选择移库商品');
|
||
return;
|
||
}
|
||
|
||
const quantity = this.getStockQuantity(this.selectedStock);
|
||
if (quantity === '--' || quantity === '' || quantity === null || quantity === undefined) {
|
||
this.showToastMessage('未获取到可用库存');
|
||
return;
|
||
}
|
||
|
||
this.formData.moveQuantity = String(quantity);
|
||
this.speakMessage(`已填充全部数量,${quantity}`);
|
||
},
|
||
async handleSubmit() {
|
||
if (!this.formData.sourceSpaceKeyword || !this.formData.sourceSpaceName) {
|
||
this.showToastMessage('请先识别移出库位');
|
||
return;
|
||
}
|
||
if (!this.formData.targetSpaceKeyword || !this.formData.targetSpaceName) {
|
||
this.showToastMessage('请先识别移入库位');
|
||
return;
|
||
}
|
||
if (!this.selectedStock) {
|
||
this.showToastMessage('请选择移库商品');
|
||
return;
|
||
}
|
||
if (!this.validateMoveQuantity(true)) {
|
||
return;
|
||
}
|
||
if (this.formData.sourceSpaceId && this.formData.targetSpaceId && this.formData.sourceSpaceId === this.formData.targetSpaceId) {
|
||
this.showToastMessage('移出库位和移入库位不能相同');
|
||
return;
|
||
}
|
||
|
||
if (!this.formData.targetSpaceId) {
|
||
this.showToastMessage('请先识别移入库位');
|
||
return;
|
||
}
|
||
|
||
const quantity = String(this.formData.moveQuantity || '').trim();
|
||
const isNonBatchMode = this.selectedStock && this.selectedStock.relocation_query_mode === 'nonBatch';
|
||
let apiName = 'storage.inventory.transferLocation';
|
||
let payload = {};
|
||
|
||
if (isNonBatchMode) {
|
||
const sourceSpaceId = this.normalizePositiveId(this.formData.sourceSpaceId);
|
||
const productStockId = this.getProductStockId(this.selectedStock);
|
||
if (!sourceSpaceId) {
|
||
this.showToastMessage('请先识别移出库位');
|
||
return;
|
||
}
|
||
if (!productStockId) {
|
||
this.showToastMessage('未获取到商品ID');
|
||
return;
|
||
}
|
||
|
||
apiName = 'storage.inventory.transferByProduct';
|
||
payload = {
|
||
space_id: Number(sourceSpaceId),
|
||
stock_id: Number(productStockId),
|
||
target_space_id: Number(this.formData.targetSpaceId),
|
||
quantity: Number(quantity)
|
||
};
|
||
} else {
|
||
const storageId = this.getStockStorageId(this.selectedStock);
|
||
if (!storageId) {
|
||
this.showToastMessage('未获取到库存记录ID');
|
||
return;
|
||
}
|
||
|
||
payload = {
|
||
storage_id: storageId,
|
||
target_space_id: Number(this.formData.targetSpaceId)
|
||
};
|
||
if (quantity) {
|
||
payload.quantity = Number(quantity);
|
||
}
|
||
}
|
||
|
||
this.submitting = true;
|
||
try {
|
||
const res = await this.$http(apiName, payload);
|
||
if (res && Number(res.code) === 200) {
|
||
const storageId = this.getStockStorageId(this.selectedStock);
|
||
uni.setStorageSync('product_query_need_refresh', Date.now());
|
||
uni.$emit('storage:relocation:success', {
|
||
timestamp: Date.now(),
|
||
storageId: storageId ? Number(storageId) : null
|
||
});
|
||
this.showToastMessage('移库完成', 'success', {
|
||
speakText: '移库完成'
|
||
});
|
||
const pages = typeof getCurrentPages === 'function' ? getCurrentPages() : [];
|
||
if (Array.isArray(pages) && pages.length > 1) {
|
||
setTimeout(() => {
|
||
uni.navigateBack({
|
||
delta: 1
|
||
});
|
||
}, 500);
|
||
return;
|
||
}
|
||
|
||
this.handleReset();
|
||
return;
|
||
}
|
||
|
||
this.showToastMessage((res && res.message) || '移库失败');
|
||
} catch (error) {
|
||
console.error('移库提交失败:', error);
|
||
this.showToastMessage((error && error.message) || '移库失败');
|
||
} finally {
|
||
this.submitting = false;
|
||
}
|
||
},
|
||
handleReset() {
|
||
this.formData = {
|
||
sourceSpaceKeyword: '',
|
||
sourceSpaceId: null,
|
||
sourceSpaceName: '',
|
||
targetSpaceKeyword: '',
|
||
targetSpaceId: null,
|
||
targetSpaceName: '',
|
||
productKeyword: '',
|
||
moveQuantity: '',
|
||
remark: ''
|
||
};
|
||
this.selectedStock = null;
|
||
this.selectorVisible = false;
|
||
this.selectorType = '';
|
||
this.selectorField = '';
|
||
this.selectorList = [];
|
||
this.activeScanField = 'productKeyword';
|
||
}
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.relocation-page {
|
||
min-height: 100vh;
|
||
background: #f8f8f8;
|
||
}
|
||
|
||
::v-deep .nav-title .right {
|
||
width: auto;
|
||
min-width: 140rpx;
|
||
display: flex;
|
||
justify-content: flex-end;
|
||
align-items: center;
|
||
}
|
||
|
||
::v-deep .nav-submit-btn {
|
||
height: 64rpx;
|
||
padding: 0 18rpx;
|
||
}
|
||
|
||
.nav-submit-btn__text {
|
||
font-size: 30rpx;
|
||
font-weight: 600;
|
||
line-height: 1;
|
||
}
|
||
|
||
::v-deep .nav-submit-btn .u-button__text {
|
||
font-size: 30rpx !important;
|
||
font-weight: 600;
|
||
line-height: 1;
|
||
}
|
||
|
||
.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;
|
||
}
|
||
}
|
||
|
||
.scan-input-wrap {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 16rpx;
|
||
width: 100%;
|
||
|
||
::v-deep .u-input {
|
||
flex: 1;
|
||
}
|
||
}
|
||
|
||
.quantity-input-wrap {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 16rpx;
|
||
width: 100%;
|
||
|
||
::v-deep .u-input {
|
||
flex: 1;
|
||
}
|
||
}
|
||
|
||
.move-quantity-item {
|
||
::v-deep .u-form-item__body__left__content__label,
|
||
::v-deep .u-form-item__body__left__content__label-text {
|
||
font-size: 40rpx !important;
|
||
font-weight: 700;
|
||
}
|
||
|
||
::v-deep .move-quantity-input .u-input__content__field-wrapper__field,
|
||
::v-deep .move-quantity-input .u-input__content__field-wrapper__field input,
|
||
::v-deep .move-quantity-input input {
|
||
font-size: 42rpx !important;
|
||
font-weight: 700 !important;
|
||
}
|
||
|
||
::v-deep .u-input__content {
|
||
min-height: 72rpx;
|
||
}
|
||
}
|
||
|
||
.quantity-all-view-btn {
|
||
width: 76rpx;
|
||
height: 76rpx;
|
||
border-radius: 12rpx;
|
||
background: #2979ff;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
flex-shrink: 0;
|
||
box-shadow: 0 4rpx 12rpx rgba(41, 121, 255, 0.18);
|
||
|
||
text {
|
||
font-size: 28rpx;
|
||
font-weight: 500;
|
||
color: #ffffff;
|
||
line-height: 1;
|
||
}
|
||
|
||
&:active {
|
||
opacity: 0.85;
|
||
}
|
||
}
|
||
|
||
.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;
|
||
}
|
||
}
|
||
|
||
.field-tip {
|
||
display: block;
|
||
margin-top: 12rpx;
|
||
font-size: 24rpx;
|
||
color: #909399;
|
||
}
|
||
|
||
.stock-card {
|
||
margin: 10rpx 0 24rpx;
|
||
padding: 24rpx;
|
||
border-radius: 12rpx;
|
||
background: #f8fbff;
|
||
border: 1rpx solid #dbeafe;
|
||
|
||
&__header {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
margin-bottom: 14rpx;
|
||
}
|
||
|
||
&__title {
|
||
font-size: 34rpx;
|
||
font-weight: 600;
|
||
color: #303133;
|
||
flex: 1;
|
||
padding-right: 20rpx;
|
||
}
|
||
|
||
&__row {
|
||
display: flex;
|
||
margin-top: 10rpx;
|
||
|
||
.label {
|
||
width: auto;
|
||
font-size: 30rpx;
|
||
color: #606266;
|
||
white-space: nowrap;
|
||
margin-right: 8rpx;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.value {
|
||
flex: 1;
|
||
font-size: 30rpx;
|
||
color: #303133;
|
||
word-break: break-all;
|
||
}
|
||
}
|
||
}
|
||
|
||
.selector-popup {
|
||
padding-bottom: env(safe-area-inset-bottom);
|
||
|
||
.popup-header {
|
||
padding: 40rpx 30rpx 20rpx;
|
||
border-bottom: 1rpx solid #f0f0f0;
|
||
}
|
||
|
||
.popup-title {
|
||
font-size: 36rpx;
|
||
font-weight: 600;
|
||
color: #333;
|
||
}
|
||
|
||
.popup-list {
|
||
max-height: 700rpx;
|
||
}
|
||
|
||
.popup-item {
|
||
padding: 28rpx 30rpx;
|
||
border-bottom: 1rpx solid #f5f5f5;
|
||
|
||
&__title {
|
||
display: block;
|
||
font-size: 30rpx;
|
||
font-weight: 600;
|
||
color: #303133;
|
||
margin-bottom: 10rpx;
|
||
}
|
||
|
||
&__desc {
|
||
display: block;
|
||
font-size: 24rpx;
|
||
color: #909399;
|
||
line-height: 1.6;
|
||
}
|
||
}
|
||
}
|
||
</style>
|