一、新增共享搜索组件 SearchBar - 新增 src/components/SearchBar/SearchBar.vue - 将各页面内联的「搜索输入 + 扫码按钮 + 搜索按钮」统一封装 - 支持 input-font-size / search-text-font-size / show-scan / show-search / focus / disabled / scan-icon 等属性 - 统一输入框与搜索文字字号为 34rpx 二、各页面搜索框接入 SearchBar 组件(删除重复样式代码) - 首页快捷操作、工作台配置 - 商品查询、库位查询、库内转移、随机上架、收货及子组件 - 盘点相关组件(工具栏、搜索面板、明细选择、记录新增、实盘数量) - 订单复核、复核列表、称重、包材绑定、拦截登记 - 散单/团单拣货详情、退单记录、发货标签、打印补打、缺货补货 三、通用样式调整 - page-nav 页面标题字号 32rpx -> 36rpx 四、拆单页面(src/pages/packing/splitOrder.vue)功能完善 - 未绑定按钮字号与输入框按钮统一为 36rpx - 未查询时显示空态提示(参考绑定包材页面),并固定定位避免跳动 - 修复空态遮挡导致搜索输入框无法聚焦的问题 - 快递号面板样式参考拦截登记页面,子单号标签白底黑字并对齐 - 面板与操作按钮分隔,左右留白统一 24rpx - 子单号列表支持滚动查看(最大高度 400rpx) - 拆单按钮改为蓝色、36rpx、不加粗 - 拆单数量弹窗参考完成盘点弹窗(640rpx、20rpx 圆角、88rpx 按钮), 新增右上角关闭图标,点击遮罩不关闭 - 拆单失败时从 order.detail 日志提取「子单号分配」失败 message, 使用自定义 u-popup 弹窗完整展示失败信息
443 lines
11 KiB
Vue
443 lines
11 KiB
Vue
<template>
|
||
<u-popup :show="show" mode="bottom" round="20" :closeable="true" :safeAreaInsetBottom="true" :customStyle="popupKeyboardStyle" @open="handleOpen" @close="handleClose">
|
||
<view class="space-entry">
|
||
<view class="space-entry__header">
|
||
<text class="space-entry__title">登记实盘数量</text>
|
||
<text class="space-entry__subtitle">{{ subtitle }}</text>
|
||
</view>
|
||
|
||
<!-- 扫描/输入库位码 → 查询库位 -->
|
||
<view class="space-entry__search">
|
||
<SearchBar
|
||
v-model="keyword"
|
||
placeholder="扫描/输入库位编码、自定义名称"
|
||
:show-scan="false"
|
||
:input-font-size="'34rpx'"
|
||
:search-text-font-size="'34rpx'"
|
||
@search="handleSearch"
|
||
@clear="handleSearch"
|
||
></SearchBar>
|
||
</view>
|
||
|
||
<scroll-view class="space-entry__scroll" scroll-y>
|
||
<view v-if="loading" class="space-entry__empty">加载中...</view>
|
||
<view v-else-if="!list.length" class="space-entry__empty">
|
||
{{ searched ? '未找到匹配库位' : '请输入关键字或扫码查询库位' }}
|
||
</view>
|
||
<view
|
||
v-for="item in list"
|
||
:key="item.key"
|
||
class="space-item"
|
||
:class="{ 'space-item--selected': selectedKey === item.key }"
|
||
@click="selectItem(item)"
|
||
>
|
||
<view class="space-item__main">
|
||
<text class="space-item__title">{{ item.title }}</text>
|
||
<text v-if="item.customBarcode" class="space-item__subtitle">条码:{{ item.customBarcode }}</text>
|
||
</view>
|
||
<view class="space-item__radio" :class="{ 'space-item__radio--checked': selectedKey === item.key }">
|
||
<u-icon v-if="selectedKey === item.key" name="checkmark" size="24rpx" color="#ffffff"></u-icon>
|
||
</view>
|
||
</view>
|
||
</scroll-view>
|
||
|
||
<view class="space-entry__qty">
|
||
<text class="space-entry__label">实盘数量</text>
|
||
<input
|
||
class="space-entry__qty-input"
|
||
type="number"
|
||
v-model="quantity"
|
||
placeholder="请输入数量"
|
||
placeholder-style="color: #c0c4cc;"
|
||
:focus="quantityFocus"
|
||
:adjust-position="false"
|
||
confirm-type="done"
|
||
@confirm="handleConfirm"
|
||
@focus="onQuantityFocus"
|
||
@blur="onQuantityBlur"
|
||
/>
|
||
</view>
|
||
|
||
<view class="space-entry__footer">
|
||
<view class="space-entry__btn" :class="{ 'space-entry__btn--disabled': !canConfirm || submitting }" @click="handleConfirm">
|
||
<text class="space-entry__btn-text">确认登记</text>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</u-popup>
|
||
</template>
|
||
|
||
<script>
|
||
import { normalizeSpaceSearchRows } from './countModel.js';
|
||
|
||
/**
|
||
* 商品作业页的「选库位 + 录数量」底部抽屉(check.report)
|
||
* 流程:扫描/输入库位 → 查询(common.searchSpace)→ 选中库位 → 输入实盘数量 → 确认登记
|
||
* 父页负责实际上报;支持扫码连续录入:已打开时父页调 applyKeyword(code) 重新查询
|
||
*/
|
||
export default {
|
||
name: 'CountSpaceEntryPopup',
|
||
props: {
|
||
show: {
|
||
type: Boolean,
|
||
default: false
|
||
},
|
||
// 预填关键字(扫码得到库位码后带进抽屉并自动查询)
|
||
prefillKeyword: {
|
||
type: String,
|
||
default: ''
|
||
},
|
||
// 副标题展示用(商品名 / 单号)
|
||
itemName: {
|
||
type: String,
|
||
default: ''
|
||
},
|
||
submitting: {
|
||
type: Boolean,
|
||
default: false
|
||
}
|
||
},
|
||
data() {
|
||
return {
|
||
keyword: '',
|
||
list: [],
|
||
selectedKey: '',
|
||
quantity: '',
|
||
loading: false,
|
||
searched: false,
|
||
quantityFocus: false,
|
||
quantityFocused: false,
|
||
keyboardHeight: 0
|
||
};
|
||
},
|
||
computed: {
|
||
subtitle() {
|
||
return this.itemName ? `商品:${this.itemName}` : '按库位登记该商品实盘数量';
|
||
},
|
||
selectedItem() {
|
||
return this.list.find(item => item.key === this.selectedKey) || null;
|
||
},
|
||
canConfirm() {
|
||
return !!this.selectedKey && String(this.quantity).trim() !== '';
|
||
},
|
||
// 键盘弹出时只上移弹窗自身,不推整页(仅在实盘数量输入框聚焦时上移,聚焦顶部搜索框不上移)
|
||
popupKeyboardStyle() {
|
||
return (this.keyboardHeight && this.quantityFocused) ? { transform: `translateY(-${this.keyboardHeight}px)` } : {};
|
||
}
|
||
},
|
||
watch: {
|
||
show(value) {
|
||
if (value) {
|
||
this.resetForm();
|
||
if (this.prefillKeyword) this.applyKeyword(this.prefillKeyword);
|
||
}
|
||
}
|
||
},
|
||
created() {
|
||
this.initKeyboardHeightListener();
|
||
},
|
||
beforeDestroy() {
|
||
this.destroyKeyboardHeightListener();
|
||
},
|
||
methods: {
|
||
initKeyboardHeightListener() {
|
||
// H5 端:监听 visualViewport 高度变化,差值即键盘高度(仅垫高弹窗,不整页上推)
|
||
// #ifdef H5
|
||
if (typeof window !== 'undefined' && window.visualViewport) {
|
||
this._baseViewportHeight = window.visualViewport.height;
|
||
this._onViewportResize = () => {
|
||
const vh = window.visualViewport ? window.visualViewport.height : window.innerHeight;
|
||
const diff = this._baseViewportHeight - vh;
|
||
this.keyboardHeight = diff > 0 ? Math.round(diff) : 0;
|
||
};
|
||
window.visualViewport.addEventListener('resize', this._onViewportResize);
|
||
}
|
||
// #endif
|
||
// #ifndef H5
|
||
this._keyboardHeightCb = (res) => {
|
||
this.keyboardHeight = (res && res.height) || 0;
|
||
};
|
||
if (typeof uni.onKeyboardHeightChange === 'function') {
|
||
uni.onKeyboardHeightChange(this._keyboardHeightCb);
|
||
}
|
||
// #endif
|
||
},
|
||
destroyKeyboardHeightListener() {
|
||
// #ifdef H5
|
||
if (typeof window !== 'undefined' && window.visualViewport && this._onViewportResize) {
|
||
window.visualViewport.removeEventListener('resize', this._onViewportResize);
|
||
this._onViewportResize = null;
|
||
}
|
||
// #endif
|
||
// #ifndef H5
|
||
if (this._keyboardHeightCb && typeof uni.offKeyboardHeightChange === 'function') {
|
||
uni.offKeyboardHeightChange(this._keyboardHeightCb);
|
||
this._keyboardHeightCb = null;
|
||
}
|
||
// #endif
|
||
},
|
||
handleClose() {
|
||
this.$emit('close');
|
||
},
|
||
/** 语音播报(复用全局 $tools.speakText,受 voice.enabled 开关控制) */
|
||
speakMessage(message, options = {}) {
|
||
const text = String(message || '').trim();
|
||
if (!text) return;
|
||
const tools = this.$tools;
|
||
if (!tools || typeof tools.speakText !== 'function') return;
|
||
try {
|
||
const task = tools.speakText(text, options);
|
||
if (task && typeof task.catch === 'function') {
|
||
task.catch(error => console.warn('[CountSpaceEntryPopup] 语音播报失败:', error));
|
||
}
|
||
} catch (error) {
|
||
console.warn('[CountSpaceEntryPopup] 语音播报异常:', error);
|
||
}
|
||
},
|
||
resetForm() {
|
||
this.keyword = '';
|
||
this.list = [];
|
||
this.selectedKey = '';
|
||
this.quantity = '';
|
||
this.loading = false;
|
||
this.searched = false;
|
||
this.quantityFocus = false;
|
||
this.quantityFocused = false;
|
||
},
|
||
/** 清空后用指定关键字重新查询(扫码/重复扫码时由父页调用) */
|
||
applyKeyword(code) {
|
||
const keyword = String(code || '').trim();
|
||
this.resetForm();
|
||
if (!keyword) return;
|
||
this.keyword = keyword;
|
||
this.handleSearch();
|
||
},
|
||
async handleSearch() {
|
||
const keyword = String(this.keyword || '').trim();
|
||
if (!keyword) {
|
||
this.list = [];
|
||
this.selectedKey = '';
|
||
this.searched = false;
|
||
return;
|
||
}
|
||
this.loading = true;
|
||
try {
|
||
const response = await this.$http('common.searchSpace', { keyword });
|
||
this.list = normalizeSpaceSearchRows(response);
|
||
this.searched = true;
|
||
// 唯一命中直接选中,扫一次就能接着输入数量
|
||
if (this.list.length === 1) {
|
||
this.selectItem(this.list[0]);
|
||
} else {
|
||
this.selectedKey = '';
|
||
if (!this.list.length) {
|
||
this.speakMessage('无记录', { force: true, minInterval: 0 });
|
||
}
|
||
}
|
||
} catch (error) {
|
||
console.error('[CountSpaceEntryPopup] 库位查询失败:', error);
|
||
this.list = [];
|
||
this.selectedKey = '';
|
||
uni.showToast({ title: '库位查询失败', icon: 'none' });
|
||
} finally {
|
||
this.loading = false;
|
||
}
|
||
},
|
||
selectItem(item) {
|
||
if (!item) return;
|
||
this.selectedKey = item.key;
|
||
this.focusQuantity();
|
||
},
|
||
focusQuantity() {
|
||
this.quantityFocus = false;
|
||
this.$nextTick(() => {
|
||
// 延时确保输入框渲染完成、弹窗动画结束,软键盘能稳定弹出
|
||
setTimeout(() => {
|
||
this.quantityFocus = true;
|
||
}, 100);
|
||
});
|
||
},
|
||
onQuantityFocus() {
|
||
this.quantityFocused = true;
|
||
},
|
||
onQuantityBlur() {
|
||
this.quantityFocused = false;
|
||
},
|
||
/** 弹窗上滑动画结束后:扫码自动选中库位时,再自动聚焦一次保证软键盘弹出 */
|
||
handleOpen() {
|
||
if (this.selectedKey) {
|
||
this.focusQuantity();
|
||
}
|
||
},
|
||
handleConfirm() {
|
||
if (this.submitting) return;
|
||
if (!this.selectedKey) {
|
||
uni.showToast({ title: '请先选择库位', icon: 'none' });
|
||
return;
|
||
}
|
||
const raw = String(this.quantity).trim();
|
||
const quantity = Number(raw);
|
||
if (raw === '' || !Number.isInteger(quantity) || quantity < 0) {
|
||
uni.showToast({ title: '请输入不小于0的整数数量', icon: 'none' });
|
||
this.focusQuantity();
|
||
return;
|
||
}
|
||
const item = this.selectedItem || {};
|
||
this.$emit('confirm', {
|
||
location: item.code || this.keyword,
|
||
locationId: item.id === undefined || item.id === null ? '' : item.id,
|
||
quantity
|
||
});
|
||
}
|
||
}
|
||
};
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.space-entry {
|
||
display: flex;
|
||
flex-direction: column;
|
||
max-height: 80vh;
|
||
padding: 32rpx 24rpx calc(24rpx + env(safe-area-inset-bottom));
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.space-entry__header {
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
}
|
||
|
||
.space-entry__title {
|
||
flex-shrink: 0;
|
||
font-size: 38rpx;
|
||
font-weight: bold;
|
||
color: #303133;
|
||
}
|
||
|
||
.space-entry__subtitle {
|
||
margin-top: 8rpx;
|
||
font-size: 32rpx;
|
||
color: #909399;
|
||
}
|
||
|
||
.space-entry__search {
|
||
margin-top: 24rpx;
|
||
}
|
||
|
||
.space-entry__scroll {
|
||
flex: 1;
|
||
min-height: 200rpx;
|
||
max-height: 40vh;
|
||
margin-top: 16rpx;
|
||
}
|
||
|
||
.space-entry__empty {
|
||
padding: 60rpx 0;
|
||
text-align: center;
|
||
font-size: 38rpx;
|
||
color: #c0c4cc;
|
||
}
|
||
|
||
.space-item {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
padding: 20rpx 8rpx;
|
||
border-bottom: 1rpx solid #f2f4f7;
|
||
|
||
&:last-child {
|
||
border-bottom: none;
|
||
}
|
||
|
||
&--selected {
|
||
background: #f5f9ff;
|
||
}
|
||
}
|
||
|
||
.space-item__main {
|
||
flex: 1;
|
||
min-width: 0;
|
||
margin-right: 16rpx;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
|
||
.space-item__title {
|
||
font-size: 40rpx;
|
||
color: #303133;
|
||
line-height: 1.4;
|
||
word-break: break-all;
|
||
}
|
||
|
||
.space-item__subtitle {
|
||
margin-top: 4rpx;
|
||
font-size: 30rpx;
|
||
color: #909399;
|
||
}
|
||
|
||
.space-item__radio {
|
||
flex-shrink: 0;
|
||
width: 40rpx;
|
||
height: 40rpx;
|
||
border-radius: 50%;
|
||
border: 2rpx solid #dcdfe6;
|
||
background: #ffffff;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
}
|
||
|
||
.space-item__radio--checked {
|
||
background: #2979ff;
|
||
border-color: #2979ff;
|
||
}
|
||
|
||
.space-entry__qty {
|
||
margin-top: 20rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
}
|
||
|
||
.space-entry__label {
|
||
flex-shrink: 0;
|
||
margin-right: 20rpx;
|
||
font-size: 40rpx;
|
||
color: #606266;
|
||
}
|
||
|
||
.space-entry__qty-input {
|
||
flex: 1;
|
||
min-width: 0;
|
||
height: 76rpx;
|
||
padding: 0 24rpx;
|
||
box-sizing: border-box;
|
||
font-size: 42rpx;
|
||
color: #303133;
|
||
background: #f5f5f5;
|
||
border-radius: 12rpx;
|
||
}
|
||
|
||
.space-entry__footer {
|
||
margin-top: 24rpx;
|
||
}
|
||
|
||
.space-entry__btn {
|
||
height: 84rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
background: #2979ff;
|
||
border-radius: 12rpx;
|
||
}
|
||
|
||
.space-entry__btn--disabled {
|
||
opacity: 0.5;
|
||
}
|
||
|
||
.space-entry__btn-text {
|
||
font-size: 36rpx;
|
||
color: #ffffff;
|
||
}
|
||
</style>
|