| | |
| | | </button> |
| | | <input v-if="(tableData.length < formData.checkQyt) && formData.fupAllow && formData.fdownAllow" |
| | | @input="onNumberInput" |
| | | @confirm="onEnterSave" |
| | | v-model="formData.fcheckResu" |
| | | type="text" |
| | | class="result-input" |
| | |
| | | placeholder-class="placeholder" /> |
| | | <input v-else |
| | | @input="search($event)" |
| | | @confirm="onEnterSave" |
| | | v-model="inputTxt" |
| | | type="text" |
| | | class="result-input" |
| | |
| | | <view class="input-wrapper" style="margin-top: 15px;"> |
| | | |
| | | <input v-if="(tableData.length < formData.checkQyt)" @input="search($event)" |
| | | @confirm="onEnterSave" |
| | | v-model="inputTxt" type="text" class="result-input" placeholder="请输入检验结果..." |
| | | placeholder-class="placeholder" /> |
| | | <button v-if="(tableData.length < formData.checkQyt)" |
| | |
| | | meomPopup: false, |
| | | showMeom:false, |
| | | meom: '', |
| | | autoSaveTimer: null, // 自动保存定时器 |
| | | } |
| | | }, |
| | | methods: { |
| | | // 防抖自动保存方法 |
| | | autoSaveResult() { |
| | | // 清除之前的定时器 |
| | | if (this.autoSaveTimer) { |
| | | clearTimeout(this.autoSaveTimer); |
| | | } |
| | | |
| | | // 设置新的定时器,1秒后自动保存 |
| | | this.autoSaveTimer = setTimeout(() => { |
| | | // 检查是否已经达到检验数量上限 |
| | | if (this.tableData.length >= this.formData.checkQyt) { |
| | | return; |
| | | } |
| | | |
| | | // 验证输入并保存 |
| | | if (this.validateAndSave()) { |
| | | this.saveResult(); |
| | | } |
| | | }, 2000); |
| | | }, |
| | | |
| | | // 验证输入是否有效 |
| | | validateAndSave() { |
| | | // 有上下限的情况 |
| | | if (this.formData.fupAllow && this.formData.fdownAllow) { |
| | | const value = this.formData.fcheckResu; |
| | | if (!value || value.trim() === '') { |
| | | return false; |
| | | } |
| | | |
| | | // 验证是否为有效数字 |
| | | if (isNaN(parseFloat(value)) || !/^-?\d+(\.\d+)?$/.test(value)) { |
| | | return false; |
| | | } |
| | | |
| | | return true; |
| | | } else { |
| | | // 无上下限的情况,检验结果存储在 formData.fcheckResu 中 |
| | | const value = this.formData.fcheckResu; |
| | | if (!value || value.trim() === '') { |
| | | return false; |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | }, |
| | | |
| | | // 处理回车键保存事件 |
| | | onEnterSave() { |
| | | // 检查是否已经达到检验数量上限 |
| | | if (this.tableData.length >= this.formData.checkQyt) { |
| | | this.$showMessage("已达到检验数量上限"); |
| | | return; |
| | | } |
| | | |
| | | // 清除自动保存定时器 |
| | | if (this.autoSaveTimer) { |
| | | clearTimeout(this.autoSaveTimer); |
| | | this.autoSaveTimer = null; |
| | | } |
| | | |
| | | // 直接保存结果 |
| | | this.saveResult(); |
| | | }, |
| | | |
| | | switchTab(index, mainIds) { |
| | | this.currentTab = index |
| | | this.mainId = mainIds; |
| | |
| | | //检测输入框的输入,并给变量赋值 |
| | | search(event) { |
| | | this.formData.fcheckResu = event.detail.value; |
| | | this.inputTxt = event.detail.value; |
| | | |
| | | // 触发自动保存 |
| | | this.autoSaveResult(); |
| | | }, |
| | | onNumberInput(e) { |
| | | // 只允许输入数字和小数点 |
| | |
| | | val = val.replace(/\.{2,}/g, '.'); |
| | | val = val.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.'); |
| | | this.formData.fcheckResu = val; |
| | | |
| | | // 触发自动保存 |
| | | this.autoSaveResult(); |
| | | }, |
| | | toggleResult(item) { |
| | | let fstand = "√"; |
| | |
| | | this.$nextTick(() => { |
| | | this.validateBatchInput(); |
| | | }); |
| | | }, |
| | | |
| | | // 页面卸载时清除定时器 |
| | | onUnload() { |
| | | if (this.autoSaveTimer) { |
| | | clearTimeout(this.autoSaveTimer); |
| | | this.autoSaveTimer = null; |
| | | } |
| | | } |
| | | } |
| | | </script> |