This commit is contained in:
2026-04-02 16:35:12 +08:00
parent af024d28a0
commit 80538ee62c
4 changed files with 199 additions and 79 deletions

View File

@@ -36,10 +36,10 @@
this.focusState = true
},
handleBlur (e) {
this.$emit('input', e.target.value)
// if (e.target.value.length) {
// this.$emit('handleChange', e.target.value)
// }
const newVal = e.target.value
if (newVal !== this.value) {
this.$emit('input', newVal)
}
this.focusState = false
},
toDel () {

View File

@@ -0,0 +1,126 @@
<template>
<view class="search_wraper">
<input
type="text"
class="filter_input pdr120"
confirm-type="go"
:value="value"
:focus="focusState"
@focus="handleFocus"
@blur="handleBlur"
@input="handleInput"
@confirm="handleConfirm">
<view class="zd-row buttons_wraper">
<uni-icons v-show="value !== '' && value !== null && value !== undefined" class="pdr10" type="clear" size="24" color="#666" @tap="toDel"></uni-icons>
<uni-icons type="scan" size="22" :color="focusState ? '#ff6a00' : '#4e6ef2'" @tap="focusState=true"></uni-icons>
</view>
</view>
</template>
<script>
import permision from "@/utils/permission.js"
export default {
data() {
return {
focusState: false,
inputTimestamps: [], // 记录每次输入的时间戳
autoTimer: null, // 自动提交定时器
lastEmittedValue: '' // 上一次触发 handleChange 的值,用于去重
};
},
model: {
prop: 'value',
event: 'input'
},
props: {
value: String
},
methods: {
handleFocus () {
this.focusState = true;
},
handleBlur (e) {
this.$emit('input', e.target.value);
this.focusState = false;
},
handleInput(e) {
const newValue = e.detail.value;
// 更新 v-model
this.$emit('input', newValue);
// 记录当前输入时间戳
const now = Date.now();
this.inputTimestamps.push(now);
// 只保留最近10次记录避免数组过长
if (this.inputTimestamps.length > 10) this.inputTimestamps.shift();
// 清除之前的自动提交定时器
if (this.autoTimer) clearTimeout(this.autoTimer);
// 启动新定时器,等待输入稳定后判断
this.autoTimer = setTimeout(() => {
this.checkAutoSubmit(newValue);
}, 150);
},
checkAutoSubmit(currentValue) {
if (!currentValue) return;
if (currentValue === this.lastEmittedValue) return;
const timestamps = this.inputTimestamps;
if (timestamps.length < 2) {
// 只有一次输入,认为是手动输入,不自动提交
return;
}
// 计算最近两次输入的最大间隔
let maxInterval = 0;
for (let i = 1; i < timestamps.length; i++) {
const interval = timestamps[i] - timestamps[i-1];
if (interval > maxInterval) maxInterval = interval;
}
// 如果最大间隔小于80ms认为是扫码快速输入自动提交
if (maxInterval < 80) {
this.emitChange(currentValue);
}
// 否则认为手动输入,不自动提交,等待回车
},
handleConfirm(e) {
const newValue = e.detail.value;
// 清除自动提交定时器,防止重复
if (this.autoTimer) clearTimeout(this.autoTimer);
this.$emit('input', newValue);
this.emitChange(newValue);
},
emitChange(val) {
if (!val) return;
if (val === this.lastEmittedValue) return;
this.lastEmittedValue = val;
this.$emit('handleChange', val);
// 提交后清空时间戳记录,避免影响下一次输入
this.inputTimestamps = [];
},
toDel() {
// 清空时清除定时器,重置状态
if (this.autoTimer) clearTimeout(this.autoTimer);
this.$emit('input', '');
this.lastEmittedValue = '';
this.inputTimestamps = [];
}
}
}
</script>
<style lang="stylus">
@import '../common/style/mixin.styl';
.search_wraper
position relative
_wh(100%, 80rpx)
.pdr120
padding-right: 120rpx;
.buttons_wraper
position absolute
top 0
right 10rpx
_wh(auto, 80rpx)
.pdr10
padding-right 10rpx
</style>

View File

@@ -2,8 +2,8 @@
"name" : "西门子",
"appid" : "__UNI__EF964CB",
"description" : "西门子LMS手持系统",
"versionName" : "1.0.9",
"versionCode" : 109,
"versionName" : "1.1.4",
"versionCode" : 114,
"transformPx" : false,
/* 5+App */
"app-plus" : {

View File

@@ -10,7 +10,6 @@
<view class="zd-col-17">
<search-box
v-model="point"
@handleChange="handlePointChange"
/>
</view>
</view>
@@ -21,10 +20,10 @@
<view class="zd-col-17">
<search-box
v-model="vehicle"
@handleChange="handleVehicleChange"
/>
</view>
</view>
<button type="primary" class="mgt20" @tap="handleAddItem">添加</button>
</view>
<view class="zd_wrapper grid-wraper">
<view class="slide_new">
@@ -42,21 +41,14 @@
<td>{{e.vehicle_code}}</td>
<td><view class="delete-btn" @tap="deleteItem(i)">删除</view></td>
</tr>
<tr v-if="uncompletedItem" class="uncompleted-row">
<td>{{uncompletedItem.point_code || '待扫描'}}</td>
<td>{{uncompletedItem.vehicle_code || '待扫描'}}</td>
<td>
<view class="clear-btn" @tap="clearUncompleted">清空</view>
</td>
</tr>
</tbody>
</table>
<view v-if="dataList.length === 0 && !uncompletedItem" class="tip">请扫描点位和载具编码</view>
<view v-if="dataList.length === 0" class="tip">请扫描点位和载具编码</view>
</view>
</view>
</view>
<view class="zd-row submit-bar">
<button class="zd-col-24 button-primary" :class="{'button-info': !dataList.length}" :disabled="disabled" @tap="_emptyVehicleWarehousing">提交</button>
<button class="zd-col-24 button-primary" :class="{'button-info': !canSubmit}" :disabled="disabled" @tap="_emptyVehicleWarehousing">提交</button>
</view>
</view>
</template>
@@ -75,73 +67,76 @@
title: '',
point: '',
vehicle: '',
uncompletedItem: null,
dataList: [],
disabled: false
};
},
computed: {
canSubmit() {
return this.dataList.length > 0 || (this.point && this.vehicle);
}
},
onLoad (options) {
this.title = options.title
},
methods: {
handlePointChange(value) {
if (value) {
setTimeout(() => { this.point = '' }, 500)
if (!this.uncompletedItem) {
this.uncompletedItem = { point_code: value }
} else {
this.uncompletedItem.point_code = value
}
this.checkAndAddToList()
}
},
handleVehicleChange(value) {
if (value) {
setTimeout(() => { this.vehicle = '' }, 500)
if (!this.uncompletedItem) {
this.uncompletedItem = { vehicle_code: value }
} else {
this.uncompletedItem.vehicle_code = value
}
this.checkAndAddToList()
}
},
checkAndAddToList() {
if (!this.uncompletedItem) return
const { point_code, vehicle_code } = this.uncompletedItem
if (point_code && vehicle_code) {
const exists = this.dataList.some(item =>
item.point_code === point_code && item.vehicle_code === vehicle_code
)
if (!exists) {
this.dataList.push({
point_code,
vehicle_code
handleAddItem() {
if (!this.point || !this.vehicle) {
uni.showToast({
title: '请完整填写点位和载具编码',
icon: 'none'
})
this.uncompletedItem = null
} else {
return
}
const exists = this.dataList.some(item =>
item.point_code === this.point && item.vehicle_code === this.vehicle
)
if (exists) {
uni.showToast({
title: '该组合已存在',
icon: 'none'
})
this.uncompletedItem = null
return
}
}
},
clearUncompleted() {
this.uncompletedItem = null
this.dataList.push({
point_code: this.point,
vehicle_code: this.vehicle
})
this.$nextTick(() => {
this.point = ''
this.vehicle = ''
})
},
deleteItem(index) {
this.dataList.splice(index, 1)
},
async _emptyVehicleWarehousing () {
this.disabled = true
if (!this.dataList.length) {
let submitData = []
if (this.dataList.length > 0) {
submitData = this.dataList
}
else if (this.point && this.vehicle) {
submitData = [{
point_code: this.point,
vehicle_code: this.vehicle
}]
}
else {
uni.showToast({
title: '请填写点位和载具编码或添加列表数据',
icon: 'none'
})
this.disabled = false
return
}
try {
let res = await emptyVehicleWarehousing(this.dataList)
let res = await emptyVehicleWarehousing(submitData)
this.clearUp()
uni.showToast({
title: res.message,
@@ -155,7 +150,6 @@
clearUp () {
this.point = ''
this.vehicle = ''
this.uncompletedItem = null
this.disabled = false
this.dataList = []
}