diff --git a/src/components/Template/CustomTable.vue b/src/components/Template/CustomTable.vue index 8447349..873cb0a 100644 --- a/src/components/Template/CustomTable.vue +++ b/src/components/Template/CustomTable.vue @@ -216,7 +216,8 @@ import { isShowOther } from "@/utils/formPackageCommon.js"; import { EventBus } from "@/utils/eventBus"; import { getuuid } from "@/utils/index.js"; import { isRegent } from "@/utils/index.js"; -import moment from "moment"; +import { isValueEmpty } from '@/utils/index.js'; + import _ from "lodash"; export default { inject: ['templateFillType', 'getZdxgjl', 'updateZdxgjl'], @@ -415,7 +416,7 @@ export default { onCopy(rowIndex, col) { if (col.copyFrom) { - if (this.isValueEmpty(this.localDataSource[rowIndex][col.copyFrom])) {//没有值就不用复制了 + if (isValueEmpty(this.localDataSource[rowIndex][col.copyFrom])) {//没有值就不用复制了 return } this.updateDataSourceByRowIndex(rowIndex, { [col.prop]: this.localDataSource[rowIndex][col.copyFrom] }, "clickable") @@ -470,7 +471,7 @@ export default { this.columns.forEach((col, colIndex) => { if (col.headerSelectKey && col.headerOptions && col.fillType === this.templateFillType) { const headerValue = this.headerSelectFields[col.headerSelectKey]; - if (this.isValueEmpty(headerValue)) { + if (isValueEmpty(headerValue)) { const errorItem = { rowIndex: -1, // 表头特殊标记 colIndex, @@ -524,7 +525,7 @@ export default { } } } else { - if (this.isValueEmpty(mainValue) && !col.bodyDisabled && col.bodyType !== 'span' && col.bodyType !== 'button') { + if (isValueEmpty(mainValue) && !col.bodyDisabled && col.bodyType !== 'span' && col.bodyType !== 'button') { const errorItem = { rowIndex, colIndex, @@ -540,7 +541,7 @@ export default { if (col.bodySubKey && !col.bodySubDisabled && col.bodySubType !== 'span' && col.bodySubType !== "button") { const subValue = row[col.bodySubKey]; console.log(col, subValue, "subValue") - if (this.isValueEmpty(subValue)) { + if (isValueEmpty(subValue)) { const errorItem = { rowIndex, colIndex, @@ -563,7 +564,7 @@ export default { return; } const otherValue = row[col.otherCode]; - if (this.isValueEmpty(otherValue)) { + if (isValueEmpty(otherValue)) { const errorItem = { rowIndex, colIndex, @@ -636,7 +637,7 @@ export default { this.columns.forEach((col, colIndex) => { const currentValue = row[col.prop]; const compareToValue = row[col.compareTo]; - if (col.compareTo && !this.isValueEmpty(currentValue) && !this.isValueEmpty(compareToValue)) { + if (col.compareTo && !isValueEmpty(currentValue) && !isValueEmpty(compareToValue)) { // 比较当前值和compareTo值,如果不相等则设置橙色背景 if (!isEqual(currentValue, compareToValue)) { this.setOrangeBg(rowIndex, colIndex, col.prop, true); @@ -651,7 +652,7 @@ export default { const currentValue = row[col.bodySubKey]; const compareToValue = row[col.bodySubCompareTo]; - if (!this.isValueEmpty(currentValue) && !this.isValueEmpty(compareToValue)) { + if (!isValueEmpty(currentValue) && !isValueEmpty(compareToValue)) { // 比较当前值和compareTo值,如果不相等则设置橙色背景 if (!isEqual(currentValue, compareToValue)) { this.setOrangeBg(rowIndex, colIndex, col.bodySubKey, true); diff --git a/src/components/Template/HandleFormItem.vue b/src/components/Template/HandleFormItem.vue index 8ded2d0..6ba9680 100644 --- a/src/components/Template/HandleFormItem.vue +++ b/src/components/Template/HandleFormItem.vue @@ -34,16 +34,15 @@
- +
{{ option.label }} -
- +
+
@@ -197,6 +196,8 @@ import moment from "moment"; import { deepClone } from "@/utils/index"; import { getuuid } from "@/utils/index.js"; import { getToken } from "@/utils/auth" +import { isValueEmpty } from '@/utils/index.js'; + export default { inject: ['templateData', 'templateFillType', "getZdxgjl", "getFhyjjl", "updateZdxgjl", "replaceFhyjjl", "updateFhyjjl", "getFieldCheckObj", "updateFieldCheckObj"], components: { @@ -254,14 +255,14 @@ export default { }, data() { let initialValue = this.value; - let initialOtherValues = {}, checkboxTagList = [], fqyqValue = {}; - - // 如果是checkboxList类型且value是对象格式 - if (this.type === 'checkboxList' && this.value && typeof this.value === 'object') { - initialValue = this.value.checkboxValues || []; - initialOtherValues = this.value.otherValues || {}; - } else if (this.type === 'checkboxList' && !Array.isArray(this.value)) { - initialValue = []; + let initialOtherValues = {}, checkboxTagList = []; + + if(this.type === 'checkboxList' && !this.value) { + initialValue = { + checkboxValues: [], + otherValues: {} + }; + } else if (this.type === 'checkboxTag' && Array.isArray(this.value)) { // checkboxTag类型,value是数组格式 checkboxTagList = this.value.map(tag => ({ @@ -274,8 +275,6 @@ export default { return { inputValue: initialValue, oldValue: initialValue, // 记录上一次的值 - otherValues: initialOtherValues, // 存储checkboxList中otherCode对应的输入值 - oldOtherValues: { ...initialOtherValues }, // 记录上一次的otherValues showModal: false, // 控制模态框显示 modificationRecords: [], // 存储修改记录 modalTimer: null, // 用于延迟隐藏模态框 @@ -289,6 +288,8 @@ export default { oldCheckboxTagList: JSON.parse(JSON.stringify(checkboxTagList)), // 记录上一次的checkboxTagList fqyqValue: initialValue, // fqyq类型的值 oldFqyqValue: {...initialValue}, // 记录上一次的fqyq值 + checkboxListValue: initialValue, // checkboxList类型的值 + oldCheckboxListValue: JSON.parse(JSON.stringify(initialValue)), // 记录上一次的checkboxList值 uuid: getuuid(), // 唯一标识符,用于EventBus事件匹配 regentType: ['sj', 'gsp', 'mix', 'xj', 'xb', 'gyzj', 'mjy', 'yq', 'jcb', 'qxbd'], //试剂/仪器/供试品等类型 selectRegentInfo: {},//选择的试剂/仪器/供试品等信息 @@ -300,15 +301,17 @@ export default { pendingUploadFile: null, // 用于存储待上传的文件 pendingRemoveFile: null, // 用于存储待删除的文件 currentTagIndex:-1,//当前选中的checkboxTag索引 - currentFqyqType:'',//当前选中的fqyq操作的类型 + currentHandleType:'',//当前操作的类型 + currentOtherCode:'',//当前操作的otherCode } }, watch: { value(newVal) { - console.log(newVal, "newVal") if (this.type === 'checkboxList' && newVal && typeof newVal === 'object') { - this.inputValue = newVal.checkboxValues || []; - this.otherValues = newVal.otherValues || {}; + this.checkboxListValue = { + checkboxValues: newVal.checkboxValues || [], + otherValues: newVal.otherValues || {} + }; } else if (this.type === 'checkboxTag' && Array.isArray(newVal)) { // checkboxTag类型,value是数组格式 this.checkboxTagList = newVal.map(tag => ({ @@ -323,7 +326,7 @@ export default { subRadio: newVal.subRadio || '' }; } else { - this.inputValue = this.type === 'checkboxList' && !Array.isArray(newVal) ? [] : newVal; + this.inputValue = newVal; } } }, @@ -800,49 +803,17 @@ export default { // 统一处理输入变化 onInputChange(val) { let value = val !== undefined ? val : this.inputValue; - // 如果是checkboxList类型,需要同时发送checkboxValues和otherValues - if (this.type === 'checkboxList') { - // 检查是否有被取消选中的checkbox - if (this.oldValue && Array.isArray(this.oldValue)) { - const uncheckedValues = this.oldValue.filter(oldVal => !this.inputValue.includes(oldVal)); - - // 清除被取消选中的checkbox对应的otherValues - if (uncheckedValues.length > 0) { - this.item.options.forEach(option => { - if (uncheckedValues.includes(option.value) && option.otherCode) { - this.$delete(this.otherValues, option.otherCode); - } - }); - } - } - value = { - checkboxValues: this.inputValue, - otherValues: this.otherValues - }; - if (val) { - - this.onCommonHandleSaveRecord(); - } - } - this.$emit('input', value); this.$emit('change', value); - - // 根据输入值判断是否显示错误状态 - const isEmpty = this.isValueEmpty(value); + const isEmpty = isValueEmpty(value); if (this.error && !isEmpty) { this.$emit('update:error', false); } else if (!this.error && isEmpty) { this.$emit('update:error', true); } }, - // 处理checkboxList中otherCode对应的输入框变化 - onOtherInputChange(code, value) { - this.otherValues[code] = value; - this.onInputChange(); - }, // checkboxTag的checkbox变化处理 onCheckboxTagChange(tagIndex, e) { this.currentTagIndex = tagIndex; @@ -850,6 +821,20 @@ export default { this.emitCheckboxTagValue(); this.onCommonHandleSaveRecord(); }, + // 检查是否显示显示checkboxList的其他输入框 + isShowCheckboxListOther(option) { + const {checkboxValues } = this.checkboxListValue + if (!checkboxValues) { + return false; + } + return option.otherCode && checkboxValues.includes(option.value); + }, + // checkboxList的checkbox变化处理 + onCheckboxListChange(val) { + this.currentHandleType = 'checkboxListValue'; + this.checkboxListValue.checkboxValues = val; + this.onCommonHandleSaveRecord(); + }, // tag输入框失去焦点 onTagBlur(tagIndex) { @@ -875,14 +860,14 @@ export default { // fqyq 主radio变化处理 onFqyqRadioChange(val, radioType) { this.fqyqValue[radioType] = val; - this.currentFqyqType = radioType; + this.currentHandleType = radioType; this.onCommonHandleSaveRecord(); }, // fqyq 输入框失去焦点 onFqyqInputBlur(e) { this.fqyqValue.inputValue = e.target.value; - this.currentFqyqType = 'inputValue'; + this.currentHandleType = 'inputValue'; this.onCommonHandleSaveRecord(this.fqyqValue.inputValue); }, @@ -890,6 +875,13 @@ export default { onBlur(e) { this.onCommonHandleSaveRecord(e.target.value); }, + // checkboxList的其他输入框失去焦点处理 + onCheckboxListOtherBlur(e, otherCode) { + this.currentHandleType = "checkboxListOther"; + this.currentOtherCode = otherCode; + this.checkboxListValue.otherValues[otherCode] = e.target.value; + this.onCommonHandleSaveRecord(e.target.value); + }, // 点击question图标 onClickQuestion() { const { templateFillType } = this; @@ -918,6 +910,15 @@ export default { this.visible = true; } }, + getCheckboxListInfo(){ + const { otherValues,checkboxValues } = this.checkboxListValue; + const { otherValues: oldOtherValues,checkboxValues: oldCheckboxValues } = this.oldCheckboxListValue; + const o = { + "checkboxListValue":{oldValue:oldCheckboxValues,newValue:checkboxValues,des:""}, + "checkboxListOther":{oldValue:oldOtherValues[this.currentOtherCode],newValue:otherValues[this.currentOtherCode],des:""}, + } + return o[this.currentHandleType]; + }, getFqyqInfo(){ const { mainRadio,inputValue,subRadio } = this.fqyqValue; const { mainRadio: oldMainRadio,inputValue: oldInputValue,subRadio: oldSubRadio } = this.oldFqyqValue; @@ -926,10 +927,10 @@ export default { "inputValue":{oldValue:oldInputValue,newValue:inputValue,des:""}, "subRadio":{oldValue:oldSubRadio,newValue:subRadio,des:"是否在规定时间完成:"} } - return o[this.currentFqyqType]; + return o[this.currentHandleType]; }, async onCommonHandleSaveRecord(val) { - const isEmpty = this.isValueEmpty(this.inputValue); + const isEmpty = isValueEmpty(this.inputValue); if (this.error && !isEmpty) { this.$emit('update:error', false); } else if (!this.error && isEmpty) { @@ -974,23 +975,25 @@ export default { // 值发生了变化,需要弹出密码输入框 let isSame = true, isOldValueEmpty = true; + const { currentHandleType } = this; // 如果是checkboxList类型,需要同时比较otherValues - if (this.type === 'checkboxList' && this.otherValues) { - isSame = this.isEqual(this.oldOtherValues, this.otherValues); - isOldValueEmpty = this.isValueEmpty(this.oldOtherValues); + if (this.type === 'checkboxList') { + const current = this.getCheckboxListInfo(); + isSame = this.isEqual(current.oldValue,current.newValue); + isOldValueEmpty = isValueEmpty(current.oldValue); } else if (this.type === "checkboxTag") { // checkboxTag类型,只比较当前tagIndex的数据 const currentTag = this.checkboxTagList[this.currentTagIndex]; const oldTag = this.oldCheckboxTagList[this.currentTagIndex] || {}; isSame = this.isEqual(oldTag.checked, currentTag.checked); - isOldValueEmpty = this.isValueEmpty(oldTag.checked); + isOldValueEmpty = isValueEmpty(oldTag.checked); } else if (this.type === "fqyq") { const current = this.getFqyqInfo(); isSame = this.isEqual(current.oldValue,current.newValue); - isOldValueEmpty = this.isValueEmpty(current.oldValue); + isOldValueEmpty = isValueEmpty(current.oldValue); } else { isSame = this.isEqual(this.oldValue, this.inputValue) - isOldValueEmpty = this.isValueEmpty(this.oldValue); + isOldValueEmpty = isValueEmpty(this.oldValue); } console.log(isSame,isOldValueEmpty,this.fqyqValue,this.oldFqyqValue,"isSame") if (isSame) { @@ -1010,8 +1013,8 @@ export default { let oldValue = this.oldValue; if (this.type === 'checkboxList') { oldValue = { - checkboxValues: oldValue.checkboxValues || oldValue, - otherValues: this.oldOtherValues + checkboxValues: this.oldCheckboxListValue.checkboxValues, + otherValues: this.oldCheckboxListValue.otherValues }; } else if (this.type === "checkboxTag") { // checkboxTag类型,只回退当前tagIndex的数据 @@ -1061,6 +1064,11 @@ export default { recordOldVlaue = `${current.des+current.oldValue}`; recordValue = `${current.des+current.newValue}`; isModify = !!this.oldFqyqValue.mainRadio + }else if(this.type === "checkboxList"){ + const current = this.getCheckboxListInfo(); + recordOldVlaue = `${current.des+current.oldValue}`; + recordValue = `${current.des+current.newValue}`; + isModify = !!current.oldValue; } const record = { ...baseInfo, @@ -1081,8 +1089,7 @@ export default { // 更新oldValue和oldOtherValues if (this.type === 'checkboxList') { - this.oldValue = [...this.inputValue]; - this.oldOtherValues = { ...this.otherValues }; + this.oldCheckboxListValue = JSON.parse(JSON.stringify(this.checkboxListValue)); } else if (this.type === "checkboxTag") { // checkboxTag类型,只更新当前tagIndex的数据 if (this.currentTagIndex >= 0 && this.currentTagIndex < this.checkboxTagList.length) { @@ -1098,8 +1105,8 @@ export default { let value = this.inputValue; if (this.type === 'checkboxList') { value = { - checkboxValues: this.inputValue, - otherValues: this.otherValues + checkboxValues: this.checkboxListValue.checkboxValues, + otherValues: this.checkboxListValue.otherValues }; } else if (this.type === "checkboxTag") { value = [...this.checkboxTagList]; @@ -1178,6 +1185,9 @@ export default { if (Array.isArray(value) && value.length === 0) { return true; } + if (Object.keys(value).length === 0) { + return true; + } return false; }, // 判断checkboxList中特定otherCode输入框是否有错误 @@ -1186,7 +1196,7 @@ export default { return false; } // 检查该otherCode对应的输入框是否为空 - return this.isValueEmpty(this.otherValues[otherCode]); + return isValueEmpty(this.otherValues[otherCode]); }, handleClickable(item, event) { if (this.templateFillType !== 'actFill') { diff --git a/src/utils/index.js b/src/utils/index.js index 7c1eceb..0212fd7 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -441,6 +441,9 @@ export function isValueEmpty(value) { if (Array.isArray(value) && value.length === 0) { return true } + if (Object.keys(value).length === 0) { + return true; + } return false } diff --git a/src/views/business/comps/template/formConfig/sp/SP0019.js b/src/views/business/comps/template/formConfig/sp/SP0019.js index c8afdc7..4f1080b 100644 --- a/src/views/business/comps/template/formConfig/sp/SP0019.js +++ b/src/views/business/comps/template/formConfig/sp/SP0019.js @@ -93,18 +93,15 @@ export const getYqColumns = ($this) => { } //溶液 -export const getRyColumns = () => { +export const getRyColumns = ($this) => { return [ { label: '溶液类型', prop: "rylx", bodyType: "select", - bodyOptions: [ - { - label: '溶液', - value: '溶液' - }, - ], + otherCode:'rylxOther', + width:380, + bodyOptions: $this.getDictOptions('business_rylx'), bodyFillType: 'preFill', }, { diff --git a/src/views/business/comps/template/mixins/templateMixin.js b/src/views/business/comps/template/mixins/templateMixin.js index 6bf2fa5..5ef6a2a 100644 --- a/src/views/business/comps/template/mixins/templateMixin.js +++ b/src/views/business/comps/template/mixins/templateMixin.js @@ -39,6 +39,7 @@ export default { 'business_sydd', // 毒理-Ames实验地点 'business_dl_ameswrqk', // 毒理-Ames污染情况 'business_dl_amescltj', // 毒理-Ames处理条件 + 'business_rylx', // 溶液类型 ], props: { templateData: {