feat: 优化移库与搜索交互
This commit is contained in:
parent
9c92291bd0
commit
dcd8ae4f68
@ -53,6 +53,12 @@
|
||||
},
|
||||
toHome() {
|
||||
console.log('跳转到首页');
|
||||
const pages = getCurrentPages();
|
||||
const currentRoute = pages.length ? `/${pages[pages.length - 1].route || ''}` : '';
|
||||
if (currentRoute === '/pages/index/index') {
|
||||
console.log('当前已在首页,取消重复跳转');
|
||||
return;
|
||||
}
|
||||
|
||||
// 根据你的路由配置调整首页路径
|
||||
// 假设首页是 tabBar 页面
|
||||
|
||||
@ -84,7 +84,9 @@ router.beforeEach(async (to, from, next) => {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(to.path==from.path){
|
||||
const hasFromPath = !!from.path;
|
||||
const isSameRoute = hasFromPath && to.path === from.path && to.fullPath === from.fullPath;
|
||||
if(isSameRoute){
|
||||
console.log('路由重复,取消跳转:', to.path);
|
||||
next(false);
|
||||
}else{
|
||||
|
||||
@ -5,6 +5,24 @@ import {
|
||||
router
|
||||
} from '@/core/router'
|
||||
export default {
|
||||
normalizeRoutePath(path = '') {
|
||||
return String(path || '')
|
||||
.trim()
|
||||
.split('?')[0]
|
||||
.split('#')[0]
|
||||
.replace(/^\/+/, '/');
|
||||
},
|
||||
getCurrentRoutePath() {
|
||||
const pages = typeof getCurrentPages === 'function' ? getCurrentPages() : [];
|
||||
const currentPage = pages[pages.length - 1];
|
||||
const route = currentPage?.route || '';
|
||||
return this.normalizeRoutePath(route ? `/${route}` : '');
|
||||
},
|
||||
isSameCurrentRoute(path = '') {
|
||||
const targetPath = this.normalizeRoutePath(path);
|
||||
const currentPath = this.getCurrentRoutePath();
|
||||
return !!targetPath && !!currentPath && targetPath === currentPath;
|
||||
},
|
||||
|
||||
/**
|
||||
* 跳转再封装,主要是为了兼容外链。
|
||||
@ -13,6 +31,11 @@ export default {
|
||||
*/
|
||||
routerTo(path, isTabbar) {
|
||||
if (path) {
|
||||
if (this.isSameCurrentRoute(path)) {
|
||||
console.log('检测到重复跳转,已拦截:', path);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 是否跳转外部链接
|
||||
if (~path.indexOf('http') || ~path.indexOf('www')) {
|
||||
// #ifdef H5
|
||||
|
||||
@ -326,10 +326,7 @@
|
||||
return;
|
||||
}
|
||||
|
||||
uni.navigateTo({
|
||||
url: targetPath,
|
||||
animationType: 'slide-in-right'
|
||||
});
|
||||
this.$tools.routerTo(targetPath);
|
||||
},
|
||||
goBack() {
|
||||
uni.navigateBack({
|
||||
|
||||
@ -1134,10 +1134,7 @@
|
||||
return;
|
||||
}
|
||||
|
||||
uni.navigateTo({
|
||||
url: targetPath,
|
||||
animationType: 'slide-in-right'
|
||||
});
|
||||
this.$tools.routerTo(targetPath);
|
||||
},
|
||||
|
||||
toMessagePage() {
|
||||
|
||||
@ -4,15 +4,26 @@
|
||||
<page-nav :title="title"></page-nav>
|
||||
|
||||
<view class="search-panel">
|
||||
<u-search
|
||||
v-model="keyword"
|
||||
placeholder="请输入商品条码或名称"
|
||||
:bg-color="'#f5f5f5'"
|
||||
shape="round"
|
||||
:show-action="false"
|
||||
@search="handleSearch"
|
||||
@clear="handleSearch"
|
||||
></u-search>
|
||||
<view class="search-input-wrap">
|
||||
<u-search
|
||||
v-model="keyword"
|
||||
placeholder="请输入商品条码或名称"
|
||||
:bg-color="'#f5f5f5'"
|
||||
shape="round"
|
||||
:show-action="false"
|
||||
@search="handleSearch"
|
||||
@clear="handleSearch"
|
||||
></u-search>
|
||||
<view class="search-actions">
|
||||
<view class="scan-btn" @click="handleCameraScan">
|
||||
<u-icon name="scan" size="38rpx" color="#2979ff"></u-icon>
|
||||
</view>
|
||||
<view class="search-divider"></view>
|
||||
<view class="search-btn" @click="handleSearch">
|
||||
<text class="search-btn__text">搜索</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<scroll-view class="list-content" scroll-y :scroll-top="restoreScrollTop" @scroll="handleListScroll">
|
||||
@ -164,8 +175,37 @@
|
||||
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 firstResult = scanResult.result.find(item => item);
|
||||
if (typeof firstResult === 'string') {
|
||||
return this.normalizeKeyword(firstResult);
|
||||
}
|
||||
if (firstResult && typeof firstResult.data === 'string') {
|
||||
return this.normalizeKeyword(firstResult.data);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof scanResult.data === 'string') {
|
||||
return this.normalizeKeyword(scanResult.data);
|
||||
}
|
||||
|
||||
return '';
|
||||
},
|
||||
handleBroadcastResult(result) {
|
||||
const scanResult = this.normalizeKeyword((result && result.data) || '');
|
||||
const scanResult = this.normalizeScanResult(result);
|
||||
if (!scanResult) {
|
||||
return;
|
||||
}
|
||||
@ -173,6 +213,36 @@
|
||||
this.keyword = scanResult;
|
||||
this.handleSearch();
|
||||
},
|
||||
handleCameraScan() {
|
||||
uni.scanCode({
|
||||
onlyFromCamera: true,
|
||||
scanType: ['barCode', 'qrCode', 'datamatrix', 'pdf417'],
|
||||
success: (res) => {
|
||||
const scanResult = this.normalizeScanResult(res);
|
||||
if (!scanResult) {
|
||||
uni.showToast({
|
||||
title: '未识别到有效条码',
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.keyword = scanResult;
|
||||
this.handleSearch();
|
||||
},
|
||||
fail: (error) => {
|
||||
const errMsg = String(error?.errMsg || '').toLowerCase();
|
||||
if (errMsg.includes('cancel')) {
|
||||
return;
|
||||
}
|
||||
|
||||
uni.showToast({
|
||||
title: '扫码失败,请重试',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
getBarcodeText(item) {
|
||||
if (!item || typeof item !== 'object') {
|
||||
return '--';
|
||||
@ -460,6 +530,71 @@
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.search-input-wrap {
|
||||
position: relative;
|
||||
|
||||
::v-deep .u-search {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
::v-deep .u-search__content {
|
||||
padding-right: 200rpx;
|
||||
}
|
||||
|
||||
::v-deep .u-search__content__close {
|
||||
margin-right: 12rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.search-actions {
|
||||
position: absolute;
|
||||
right: 24rpx;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
height: 68rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.scan-btn {
|
||||
height: 68rpx;
|
||||
padding: 0 8rpx 0 4rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
&:active {
|
||||
opacity: 0.88;
|
||||
}
|
||||
}
|
||||
|
||||
.search-divider {
|
||||
width: 1rpx;
|
||||
height: 28rpx;
|
||||
background: #dcdfe6;
|
||||
margin: 0 16rpx 0 10rpx;
|
||||
}
|
||||
|
||||
.search-btn {
|
||||
height: 68rpx;
|
||||
padding: 0 8rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
|
||||
&__text {
|
||||
font-size: 30rpx;
|
||||
font-weight: 500;
|
||||
color: #2979ff;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
&:active {
|
||||
opacity: 0.88;
|
||||
}
|
||||
}
|
||||
|
||||
.list-content {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
|
||||
@ -9,8 +9,14 @@
|
||||
<view class="search-box-inner">
|
||||
<u-search v-model="searchKeyword" placeholder="搜索运单号、货主、商品条码、车牌" bg-color="#f5f5f5" shape="round"
|
||||
:show-action="false" @search="handleSearch" @clear="handleSearch"></u-search>
|
||||
<view class="scan-camera-btn" @click="handleManualScan">
|
||||
<u-icon name="camera" size="34rpx" color="#2979ff"></u-icon>
|
||||
<view class="search-actions">
|
||||
<view class="scan-btn" @click="handleManualScan">
|
||||
<u-icon name="scan" size="38rpx" color="#2979ff"></u-icon>
|
||||
</view>
|
||||
<view class="search-divider"></view>
|
||||
<view class="search-btn" @click="handleSearch">
|
||||
<text class="search-btn__text">搜索</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@ -634,29 +640,68 @@
|
||||
margin-bottom: 20rpx;
|
||||
|
||||
.search-box-inner {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16rpx;
|
||||
position: relative;
|
||||
|
||||
::v-deep .u-search {
|
||||
flex: 1;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.scan-camera-btn {
|
||||
width: 76rpx;
|
||||
height: 76rpx;
|
||||
border-radius: 38rpx;
|
||||
background: #eef4ff;
|
||||
::v-deep .u-search__content {
|
||||
padding-right: 200rpx;
|
||||
}
|
||||
|
||||
::v-deep .u-search__content__close {
|
||||
margin-right: 12rpx;
|
||||
}
|
||||
|
||||
.search-actions {
|
||||
position: absolute;
|
||||
right: 24rpx;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
height: 68rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
box-shadow: 0 4rpx 12rpx rgba(41, 121, 255, 0.12);
|
||||
}
|
||||
|
||||
.scan-btn {
|
||||
height: 68rpx;
|
||||
padding: 0 8rpx 0 4rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
&:active {
|
||||
opacity: 0.85;
|
||||
opacity: 0.88;
|
||||
}
|
||||
}
|
||||
|
||||
.search-divider {
|
||||
width: 1rpx;
|
||||
height: 28rpx;
|
||||
background: #dcdfe6;
|
||||
margin: 0 16rpx 0 10rpx;
|
||||
}
|
||||
|
||||
.search-btn {
|
||||
height: 68rpx;
|
||||
padding: 0 8rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
|
||||
&__text {
|
||||
font-size: 30rpx;
|
||||
font-weight: 500;
|
||||
color: #2979ff;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
&:active {
|
||||
opacity: 0.88;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,152 @@
|
||||
<template>
|
||||
<view class="normar_container">
|
||||
<page-nav title="移库作业"></page-nav>
|
||||
<view class="relocation-page">
|
||||
<view class="normar_container">
|
||||
<page-nav title="移库作业"></page-nav>
|
||||
|
||||
<scroll-view class="container" scroll-y>
|
||||
<u-form class="form-box" :model="formData" ref="formRef" label-width="170rpx">
|
||||
<view class="section">
|
||||
|
||||
<u-form-item label="移库模式" required>
|
||||
<u-radio-group v-model="formData.relocationMode" @change="handleModeChange">
|
||||
<u-radio v-for="item in relocationModeOptions" :key="item.value" :name="item.value" :label="item.label"></u-radio>
|
||||
</u-radio-group>
|
||||
</u-form-item>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<view class="section-title">库位信息</view>
|
||||
|
||||
<u-form-item label="移出库位" required>
|
||||
<view class="scan-input-wrap">
|
||||
<u-input
|
||||
v-model="formData.sourceSpaceKeyword"
|
||||
placeholder="请扫描或输入移出库位"
|
||||
clearable
|
||||
@focus="setActiveScanField('sourceSpace')"
|
||||
@blur="handleSpaceBlur('sourceSpace')"
|
||||
/>
|
||||
<view class="scan-camera-btn" @click="handleFieldScan('sourceSpace')">
|
||||
<u-icon name="camera" size="34rpx" color="#2979ff"></u-icon>
|
||||
</view>
|
||||
</view>
|
||||
<text v-if="formData.sourceSpaceName" class="field-tip">已识别:{{ formData.sourceSpaceName }}</text>
|
||||
</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>
|
||||
<text v-if="formData.targetSpaceName" class="field-tip">已识别:{{ formData.targetSpaceName }}</text>
|
||||
</u-form-item>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<view class="section-title">商品信息</view>
|
||||
|
||||
<u-form-item v-if="formData.relocationMode === 'product'" label="商品/条码" required>
|
||||
<view class="scan-input-wrap">
|
||||
<u-input
|
||||
v-model="formData.productKeyword"
|
||||
placeholder="请扫描商品条码或输入关键字"
|
||||
clearable
|
||||
@focus="setActiveScanField('productKeyword')"
|
||||
@blur="handleProductBlur"
|
||||
/>
|
||||
<view class="scan-camera-btn" @click="handleFieldScan('productKeyword')">
|
||||
<u-icon name="camera" size="34rpx" color="#2979ff"></u-icon>
|
||||
</view>
|
||||
</view>
|
||||
</u-form-item>
|
||||
|
||||
<view v-if="formData.relocationMode === 'product' && selectedStock" class="stock-card">
|
||||
<view class="stock-card__header">
|
||||
<text class="stock-card__title">{{ getStockName(selectedStock) }}</text>
|
||||
<u-tag text="已选中" type="success" size="mini"></u-tag>
|
||||
</view>
|
||||
<view class="stock-card__row">
|
||||
<text class="label">条码:</text>
|
||||
<text class="value">{{ getStockBarcode(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 v-if="formData.relocationMode === 'product'" label="移库数量" required>
|
||||
<view class="quantity-input-wrap">
|
||||
<u-input
|
||||
v-model="formData.moveQuantity"
|
||||
type="number"
|
||||
placeholder="请输入移库数量"
|
||||
@input="handleMoveQuantityInput"
|
||||
@blur="handleMoveQuantityBlur"
|
||||
></u-input>
|
||||
<view class="quantity-all-view-btn" @click="handleFillAllQuantity">
|
||||
<text>全部</text>
|
||||
</view>
|
||||
</view>
|
||||
</u-form-item>
|
||||
|
||||
<view v-else class="mode-tip-card">
|
||||
<text class="mode-tip-card__title">按仓位移库</text>
|
||||
<text class="mode-tip-card__desc">当前模式下无需选择商品和数量,提交时默认按原库位整体移至目标库位。</text>
|
||||
</view>
|
||||
|
||||
<u-form-item label="备注">
|
||||
<u-input v-model="formData.remark" type="textarea" placeholder="请输入备注信息" height="120"></u-input>
|
||||
</u-form-item>
|
||||
</view>
|
||||
</u-form>
|
||||
</scroll-view>
|
||||
|
||||
<view class="submit-area">
|
||||
<u-button type="primary" :loading="submitting" @click="handleSubmit">确认移库</u-button>
|
||||
<u-button @click="handleReset">重置</u-button>
|
||||
</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">编码:{{ getSpaceCode(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>
|
||||
|
||||
@ -8,15 +154,632 @@
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
|
||||
loading: false,
|
||||
submitting: false,
|
||||
activeScanField: 'productKeyword',
|
||||
relocationModeOptions: [
|
||||
{ label: '按商品', value: 'product' },
|
||||
{ label: '按仓位', value: 'space' }
|
||||
],
|
||||
selectorVisible: false,
|
||||
selectorType: '',
|
||||
selectorField: '',
|
||||
selectorList: [],
|
||||
selectedStock: null,
|
||||
formData: {
|
||||
relocationMode: 'product',
|
||||
sourceSpaceKeyword: '',
|
||||
sourceSpaceId: null,
|
||||
sourceSpaceName: '',
|
||||
targetSpaceKeyword: '',
|
||||
targetSpaceId: null,
|
||||
targetSpaceName: '',
|
||||
productKeyword: '',
|
||||
moveQuantity: '',
|
||||
remark: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
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: {
|
||||
|
||||
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;
|
||||
},
|
||||
handleModeChange(mode) {
|
||||
this.formData.relocationMode = mode;
|
||||
if (mode === 'space') {
|
||||
this.selectedStock = null;
|
||||
this.formData.productKeyword = '';
|
||||
this.formData.moveQuantity = '';
|
||||
this.activeScanField = 'sourceSpace';
|
||||
return;
|
||||
}
|
||||
|
||||
this.activeScanField = 'productKeyword';
|
||||
},
|
||||
handleBroadcastResult(result) {
|
||||
const rawCode = this.normalizeUniScanResult(result);
|
||||
if (!rawCode) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.applyScanResult(rawCode, this.activeScanField || 'productKeyword');
|
||||
},
|
||||
handleFieldScan(field) {
|
||||
this.setActiveScanField(field);
|
||||
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.applyScanResult(rawCode, field);
|
||||
},
|
||||
fail: (error) => {
|
||||
const errMsg = String(error?.errMsg || '').toLowerCase();
|
||||
if (errMsg.includes('cancel')) {
|
||||
return;
|
||||
}
|
||||
|
||||
uni.showToast({
|
||||
title: '扫码失败,请重试',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
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;
|
||||
}
|
||||
|
||||
uni.showToast({
|
||||
title: '未找到匹配库位',
|
||||
icon: 'none'
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('搜索库位失败:', error);
|
||||
uni.showToast({
|
||||
title: '库位查询失败',
|
||||
icon: 'none'
|
||||
});
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
applySpaceSelection(field, item) {
|
||||
const isSource = field === 'sourceSpace';
|
||||
this.formData[isSource ? 'sourceSpaceId' : 'targetSpaceId'] = item?.id || item?.space_id || null;
|
||||
this.formData[isSource ? 'sourceSpaceName' : 'targetSpaceName'] = this.getSpaceName(item);
|
||||
this.formData[isSource ? 'sourceSpaceKeyword' : 'targetSpaceKeyword'] = this.getSpaceCode(item);
|
||||
},
|
||||
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;
|
||||
uni.showToast({
|
||||
title: '未找到匹配库存',
|
||||
icon: 'none'
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('搜索库存失败:', error);
|
||||
uni.showToast({
|
||||
title: '库存查询失败',
|
||||
icon: 'none'
|
||||
});
|
||||
} 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) : '';
|
||||
}
|
||||
},
|
||||
handleSelectorConfirm(item) {
|
||||
if (this.selectorType === 'stock') {
|
||||
this.applyStockSelection(item);
|
||||
} else {
|
||||
this.applySpaceSelection(this.selectorField, item);
|
||||
}
|
||||
this.selectorVisible = false;
|
||||
},
|
||||
getSpaceName(item) {
|
||||
return item?.name || item?.space_name || item?.title || 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 || '--';
|
||||
},
|
||||
getStockSpace(item) {
|
||||
return item?.space?.name || item?.space_name || item?.space_barcode || item?.space?.barcode || '--';
|
||||
},
|
||||
getStockQuantity(item) {
|
||||
return item?.available_quantity || item?.actual_quantity || item?.quantity || item?.stock || '--';
|
||||
},
|
||||
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);
|
||||
this.validateMoveQuantity(true);
|
||||
},
|
||||
validateMoveQuantity(showToast = false) {
|
||||
if (this.formData.relocationMode !== 'product') {
|
||||
return true;
|
||||
}
|
||||
|
||||
const quantity = String(this.formData.moveQuantity || '').trim();
|
||||
if (!quantity) {
|
||||
if (showToast) {
|
||||
uni.showToast({ title: '请输入移库数量', icon: 'none' });
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!/^[1-9]\d*$/.test(quantity)) {
|
||||
if (showToast) {
|
||||
uni.showToast({ title: '移库数量需为正整数', icon: 'none' });
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const maxQuantity = this.getAvailableStockNumber();
|
||||
if (maxQuantity > 0 && Number(quantity) > maxQuantity) {
|
||||
if (showToast) {
|
||||
uni.showToast({ title: '移库数量不能大于可用库存', icon: 'none' });
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
handleFillAllQuantity() {
|
||||
if (!this.selectedStock) {
|
||||
uni.showToast({
|
||||
title: '请先选择移库商品',
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const quantity = this.getStockQuantity(this.selectedStock);
|
||||
if (quantity === '--' || quantity === '' || quantity === null || quantity === undefined) {
|
||||
uni.showToast({
|
||||
title: '未获取到可用库存',
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.formData.moveQuantity = String(quantity);
|
||||
},
|
||||
async handleSubmit() {
|
||||
if (!this.formData.sourceSpaceKeyword || !this.formData.sourceSpaceName) {
|
||||
uni.showToast({ title: '请先识别移出库位', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
if (!this.formData.targetSpaceKeyword || !this.formData.targetSpaceName) {
|
||||
uni.showToast({ title: '请先识别移入库位', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
if (this.formData.relocationMode === 'product' && !this.selectedStock) {
|
||||
uni.showToast({ title: '请选择移库商品', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
if (this.formData.relocationMode === 'product' && !this.validateMoveQuantity(true)) {
|
||||
return;
|
||||
}
|
||||
if (this.formData.sourceSpaceId && this.formData.targetSpaceId && this.formData.sourceSpaceId === this.formData.targetSpaceId) {
|
||||
uni.showToast({ title: '移出库位和移入库位不能相同', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: `当前项目暂未配置${this.formData.relocationMode === 'product' ? '按商品' : '按仓位'}移库提交接口,页面和扫码流程已接入。`,
|
||||
showCancel: false
|
||||
});
|
||||
},
|
||||
handleReset() {
|
||||
this.formData = {
|
||||
relocationMode: 'product',
|
||||
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>
|
||||
<style lang="scss" scoped>
|
||||
.relocation-page {
|
||||
min-height: 100vh;
|
||||
background: #f8f8f8;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
}
|
||||
|
||||
.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: 22rpx;
|
||||
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;
|
||||
}
|
||||
|
||||
.mode-tip-card {
|
||||
margin: 10rpx 0 24rpx;
|
||||
padding: 24rpx;
|
||||
border-radius: 12rpx;
|
||||
background: #f6fdf8;
|
||||
border: 1rpx solid #d7f0df;
|
||||
|
||||
&__title {
|
||||
display: block;
|
||||
font-size: 30rpx;
|
||||
font-weight: 600;
|
||||
color: #2e7d32;
|
||||
margin-bottom: 10rpx;
|
||||
}
|
||||
|
||||
&__desc {
|
||||
display: block;
|
||||
font-size: 24rpx;
|
||||
line-height: 1.6;
|
||||
color: #606266;
|
||||
}
|
||||
}
|
||||
|
||||
.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: 30rpx;
|
||||
font-weight: 600;
|
||||
color: #303133;
|
||||
flex: 1;
|
||||
padding-right: 20rpx;
|
||||
}
|
||||
|
||||
&__row {
|
||||
display: flex;
|
||||
margin-top: 10rpx;
|
||||
|
||||
.label {
|
||||
width: 140rpx;
|
||||
font-size: 26rpx;
|
||||
color: #606266;
|
||||
}
|
||||
|
||||
.value {
|
||||
flex: 1;
|
||||
font-size: 26rpx;
|
||||
color: #303133;
|
||||
word-break: break-all;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.submit-area {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
padding: 20rpx;
|
||||
gap: 20rpx;
|
||||
border-top: 1px solid rgba(0, 0, 0, .08);
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.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>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user