diff --git a/src/components/Template/HandleFormItem.vue b/src/components/Template/HandleFormItem.vue index 49b53b7..4ebc52e 100644 --- a/src/components/Template/HandleFormItem.vue +++ b/src/components/Template/HandleFormItem.vue @@ -1355,12 +1355,14 @@ export default { this.updateZdxgjl(record); this.updateSubmittedCodes(finallyKey); } + if (isRegent(this.item)) { + this.$emit("onRegentSubmit", this.selectRegentInfo, this.inputValue); + } this.$nextTick(() => { - EventBus.$emit('onModifyRecord', params,) - console.log(params, "onModifyRecord") - if (isRegent(this.item)) { - this.$emit("onRegentSubmit", this.selectRegentInfo, this.inputValue); - } + setTimeout(() => { + EventBus.$emit('onModifyRecord', params,) + }, 100); + }) }, diff --git a/src/components/Template/mixins/formPackageMixins.js b/src/components/Template/mixins/formPackageMixins.js index a112da5..20e4b8c 100644 --- a/src/components/Template/mixins/formPackageMixins.js +++ b/src/components/Template/mixins/formPackageMixins.js @@ -1,5 +1,5 @@ import _ from 'lodash' -import { getuuid, isEqual, isValueEmpty } from '@/utils/index.js' +import { getuuid, isEqual, isValueEmpty,isRegent } from '@/utils/index.js' import { isShowOtherByCheckboxTree } from '@/utils/formPackageCommon.js' import moment from 'moment' @@ -52,8 +52,8 @@ export default { if (currentConfig?.selectTo) { this.formFields[currentConfig?.selectTo] = val if (this.errors[currentConfig?.selectTo]) { - this.$set(this.errors, currentConfig?.selectTo, false) - } + this.$set(this.errors, currentConfig?.selectTo, false) + } } this.onValueChangeCompareTo(key, val) this.formFields[key] = val @@ -76,10 +76,9 @@ export default { }, //试剂/仪器等弹窗提交 onRegentSubmit(data, inputValue, key, item) { - this.updateFormData(key, inputValue) - this.formFields[`selectInfo_${key}`] = data.selectInfo; - if(data.type === "yq"){ - this.formFields[`yqInfo_${key}`] = data.row; + this.formFields[`selectInfo_${key}`] = JSON.parse(JSON.stringify(data.selectInfo)); + if (data.type === "yq") { + this.formFields[`yqInfo_${key}`] = JSON.parse(JSON.stringify(data.row)); } this.$emit('onRegentSubmit', { selectInfo: data, @@ -87,9 +86,10 @@ export default { key, config: item }) + this.updateFormData(key, inputValue) }, onBeforeReagentSubmit(data, callback, key) { - this.$emit('beforeReagentSubmit', { selectData: data, callback, key, formFields: this.formFields }) + this.$emit('beforeReagentSubmit', { selectData: data, callback, key, formFields: this.formFields }) }, getRegentItem(item, fieldCode = 'type') { const type = item[fieldCode] @@ -139,7 +139,7 @@ export default { }, //更新表单数据 updateFormData(key, value, data) { - const { isUpdateRecord, signData,record } = data || {} + const { isUpdateRecord, signData, record } = data || {} // 深拷贝当前表单数据,避免直接修改原数据 const cloneFormFields = JSON.parse(JSON.stringify(this.formFields)) @@ -149,10 +149,10 @@ export default { if (this.errors[key]) { this.$set(this.errors, key, false) } - const re = record||{ - oldValue: this.oldFormFields[key], - inputValue: value - } + const re = record || { + oldValue: this.oldFormFields[key], + inputValue: value + } if (isUpdateRecord) { setTimeout(() => { this.$refs[key][0].handleUpdateRecord(signData, re) @@ -392,36 +392,40 @@ export default { if (item.config?.thirdOtherCode) { config[item.config?.thirdOtherCode] = item.config?.thirdOtherCode } + if (isRegent(item.config) || isRegent(item.config,"subType")) { + // 处理selectInfo_开头的字段,步骤表单需要保留selectInfo_开头的字段 + // 优先使用this.formFields中以selectInfo_开头的字段 + let selectInfoKeys = [], yqInfoKeys = []; + if (this.formFields) { + selectInfoKeys = Object.keys(this.formFields).filter((key) => + key.startsWith('selectInfo_') + ) + yqInfoKeys = Object.keys(this.formFields).filter((key) => + key.startsWith('yqInfo_') + ) + } + // 如果this.formFields中没有,则使用formData中的 + if (selectInfoKeys.length === 0 && formData) { + selectInfoKeys = Object.keys(formData).filter((key) => + key.startsWith('selectInfo_') + ) + } + if (yqInfoKeys.length === 0 && formData) { + yqInfoKeys = Object.keys(formData).filter((key) => + key.startsWith('yqInfo_') + ) + } + selectInfoKeys.forEach((key) => { + result[key] = this.formFields[key] || formData[key] || '' + }) + yqInfoKeys.forEach((key) => { + result[key] = this.formFields[key] || formData[key] || '' + }) + } + } }) - // 处理selectInfo_开头的字段,步骤表单需要保留selectInfo_开头的字段 - // 优先使用this.formFields中以selectInfo_开头的字段 - let selectInfoKeys = [],yqInfoKeys = []; - if (this.formFields) { - selectInfoKeys = Object.keys(this.formFields).filter((key) => - key.startsWith('selectInfo_') - ) - yqInfoKeys = Object.keys(this.formFields).filter((key) => - key.startsWith('yqInfo_') - ) - } - // 如果this.formFields中没有,则使用formData中的 - if (selectInfoKeys.length === 0 && formData) { - selectInfoKeys = Object.keys(formData).filter((key) => - key.startsWith('selectInfo_') - ) - } - if (yqInfoKeys.length === 0 && formData) { - yqInfoKeys = Object.keys(formData).filter((key) => - key.startsWith('yqInfo_') - ) - } - selectInfoKeys.forEach((key) => { - result[key] = this.formFields[key] || formData[key] || '' - }) - yqInfoKeys.forEach((key) => { - result[key] = this.formFields[key] || formData[key] || '' - }) + // 更新表单字段 this.formFields = { ...result } this.allFieldsConfig = config @@ -661,8 +665,8 @@ export default { getFormDataByKey(key) { return this.formFields[key] }, - onBeforeSaveRecord(data, callback, item){ - this.$emit('beforeSaveRecord', {data, callback,item}) + onBeforeSaveRecord(data, callback, item) { + this.$emit('beforeSaveRecord', { data, callback, item }) }, onBlur(key, val) { // compareTo 功能:当fillType==="actFill"时,判断当前值是否与compareTo字段的值一样,如果不一样则将当前input框的背景色标记成橙色 diff --git a/src/utils/conConverter.js b/src/utils/conConverter.js index dcbb164..baac790 100644 --- a/src/utils/conConverter.js +++ b/src/utils/conConverter.js @@ -1,8 +1,30 @@ /** * 浓度单位转换 (同一类别内转换) */ +import { Message } from 'element-ui'; class ConcentrationConverter { + // 用于防抖的消息缓存 + messageCache = {}; + + /** + * 防抖显示消息,相同消息在指定时间内只显示一次 + * @param {string} message - 消息内容 + * @param {string} type - 消息类型 + * @param {number} delay - 防抖时间(毫秒),默认2000ms + */ + showDebouncedMessage(message, type = 'warning', delay = 2000) { + const now = Date.now(); + const cacheKey = `${message}_${type}`; + + if (!this.messageCache[cacheKey] || now - this.messageCache[cacheKey] > delay) { + this.messageCache[cacheKey] = now; + Message({ + message: message, + type: type + }); + } + } // 单位换算系数 unitFactors = { // 质量单位(以g为基准) @@ -128,11 +150,13 @@ class ConcentrationConverter { // 3. 检查是否为%单位 if (inputUnit === '%' || normalizedTargetUnit === '%') { // %单位是单独的系列,不进行转换 + this.showDebouncedMessage(`单位类别不匹配: ${inputUnit} 不能转换为 ${targetUnit},请重新选择`); throw new Error(`单位类别不匹配: ${inputUnit} 不能转换为 ${targetUnit}`); } // 4. 验证单位类别 if (!this.isSameCategory(inputUnit, normalizedTargetUnit)) { + this.showDebouncedMessage(`单位类别不匹配: ${inputUnit} 不能转换为 ${targetUnit},请重新选择`); throw new Error(`单位类别不匹配: ${inputUnit} 不能转换为 ${targetUnit}`); } diff --git a/src/views/business/comps/template/mixins/templateMixin.js b/src/views/business/comps/template/mixins/templateMixin.js index f69c221..604560b 100644 --- a/src/views/business/comps/template/mixins/templateMixin.js +++ b/src/views/business/comps/template/mixins/templateMixin.js @@ -307,7 +307,7 @@ export default { } else if (nd === 'NA') { callback.prevent('当前实际浓度为NA,请重新选择') } else if (ytndArr.length !== sjndArr.length) { - callback.prevent('起始溶液浓度和目标溶液浓度格式不一致,请重新输入') + callback.prevent('起始溶液浓度和目标溶液浓度格式不一致,请重新选择') } }, getFormDataByTemplateData() {