| | |
| | | <form> |
| | | <view class="cu-form-group" v-show="!isconfirm"> |
| | | <view class="title">容器码</view> |
| | | <input placeholder="请扫描容器码" v-model="barcode" focus></input> |
| | | <input placeholder="请扫描容器码" v-model="barcode" focus @input="onBarcodeInput"></input> |
| | | <text class='cuIcon-close text-gray margin-right-xs' v-show="barcode!==''" @click="clearCode"></text> |
| | | <text class='cuIcon-search text-blue' @click="search"></text> |
| | | </view> |
| | | |
| | | </form> |
| | |
| | | backgroundColor: '#42b983', |
| | | borderColor: '#42b983' |
| | | }, |
| | | repeatClick: false |
| | | repeatClick: false, |
| | | searchTimer: null, // 防抖定时器 |
| | | isClearing: false // 标记是否正在清空 |
| | | } |
| | | }, |
| | | computed: { |
| | |
| | | return this.list.reduce((acc, row) => +row.receiptQty + acc, 0) |
| | | } |
| | | }, |
| | | watch: { |
| | | // 监听容器码变化,自动查询 |
| | | barcode(newVal, oldVal) { |
| | | // 如果正在清空,不触发查询 |
| | | if (this.isClearing) { |
| | | return; |
| | | } |
| | | // 清除之前的定时器 |
| | | if (this.searchTimer) { |
| | | clearTimeout(this.searchTimer); |
| | | } |
| | | // 如果容器码不为空,延迟300ms后自动查询(防抖处理) |
| | | if (newVal && newVal.trim() !== '') { |
| | | this.searchTimer = setTimeout(() => { |
| | | this.search(); |
| | | }, 300); |
| | | } else { |
| | | // 容器码为空时,清空列表 |
| | | this.list = []; |
| | | } |
| | | } |
| | | }, |
| | | mounted() { |
| | | this.search() |
| | | // 移除自动查询,改为监听输入自动查询 |
| | | }, |
| | | methods: { |
| | | clickTaskItem(index){ |
| | |
| | | this.typeSelect = e.value |
| | | this.search() |
| | | }, |
| | | onBarcodeInput(e) { |
| | | // 输入事件由watch处理,这里可以添加额外逻辑 |
| | | }, |
| | | async search() { |
| | | this.list = [] |
| | | if(this.barcode === '' || this.barcode ===null){ |
| | | if(this.barcode === '' || this.barcode ===null || this.barcode.trim() === ''){ |
| | | return ; |
| | | } |
| | | const { |
| | |
| | | title: msg, |
| | | icon: "success" |
| | | }) |
| | | // 确认后清空,支持再次扫描 |
| | | that.clear() |
| | | |
| | | }else if(code == 401){ |
| | |
| | | |
| | | }, |
| | | clearCode() { |
| | | this.barcode = '' |
| | | this.isClearing = true; |
| | | this.barcode = ''; |
| | | this.list = []; |
| | | // 清空后重置标记,允许下次扫描 |
| | | this.$nextTick(() => { |
| | | this.isClearing = false; |
| | | }); |
| | | }, |
| | | remove(index) { |
| | | this.list.splice(index, 1); |
| | | }, |
| | | clear() { |
| | | this.list = [] |
| | | this.barcode = '' |
| | | this.isClearing = true; |
| | | this.list = []; |
| | | this.barcode = ''; |
| | | // 清空后重置标记,允许下次扫描 |
| | | this.$nextTick(() => { |
| | | this.isClearing = false; |
| | | }); |
| | | }, |
| | | next() { |
| | | if (this.list.length) { |
| | |
| | | DateChange(e, item) { |
| | | item.prodTime = e.detail.value |
| | | } |
| | | }, |
| | | beforeDestroy() { |
| | | // 组件销毁前清除定时器 |
| | | if (this.searchTimer) { |
| | | clearTimeout(this.searchTimer); |
| | | } |
| | | } |
| | | } |
| | | </script> |