diff --git a/src/components/Template/BaseInfoFormPcakge.vue b/src/components/Template/BaseInfoFormPackage.vue similarity index 55% rename from src/components/Template/BaseInfoFormPcakge.vue rename to src/components/Template/BaseInfoFormPackage.vue index c7598b3..5d965cf 100644 --- a/src/components/Template/BaseInfoFormPcakge.vue +++ b/src/components/Template/BaseInfoFormPackage.vue @@ -180,14 +180,16 @@ diff --git a/src/components/Template/Step.vue b/src/components/Template/Step.vue index 675f218..cb23d36 100644 --- a/src/components/Template/Step.vue +++ b/src/components/Template/Step.vue @@ -1,399 +1,332 @@ \ No newline at end of file diff --git a/src/components/Template/StepComponents/AddSolutionStep.vue b/src/components/Template/StepComponents/AddSolutionStep.vue deleted file mode 100644 index 3313f85..0000000 --- a/src/components/Template/StepComponents/AddSolutionStep.vue +++ /dev/null @@ -1,66 +0,0 @@ - - - \ No newline at end of file diff --git a/src/components/Template/StepComponents/AutoWeighStep.vue b/src/components/Template/StepComponents/AutoWeighStep.vue deleted file mode 100644 index e0c4f01..0000000 --- a/src/components/Template/StepComponents/AutoWeighStep.vue +++ /dev/null @@ -1,89 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/src/components/Template/StepComponents/CentrifugeStep.vue b/src/components/Template/StepComponents/CentrifugeStep.vue deleted file mode 100644 index 52d5b07..0000000 --- a/src/components/Template/StepComponents/CentrifugeStep.vue +++ /dev/null @@ -1,62 +0,0 @@ - - - \ No newline at end of file diff --git a/src/components/Template/StepComponents/CoatStep.vue b/src/components/Template/StepComponents/CoatStep.vue deleted file mode 100644 index bc94107..0000000 --- a/src/components/Template/StepComponents/CoatStep.vue +++ /dev/null @@ -1,152 +0,0 @@ - - - \ No newline at end of file diff --git a/src/components/Template/StepComponents/FiltrationStep.vue b/src/components/Template/StepComponents/FiltrationStep.vue deleted file mode 100644 index 4dbf33c..0000000 --- a/src/components/Template/StepComponents/FiltrationStep.vue +++ /dev/null @@ -1,84 +0,0 @@ - - - \ No newline at end of file diff --git a/src/components/Template/StepComponents/ManualWeighStep.vue b/src/components/Template/StepComponents/ManualWeighStep.vue deleted file mode 100644 index cc471a5..0000000 --- a/src/components/Template/StepComponents/ManualWeighStep.vue +++ /dev/null @@ -1,50 +0,0 @@ - - - \ No newline at end of file diff --git a/src/components/Template/StepComponents/MixStep.vue b/src/components/Template/StepComponents/MixStep.vue deleted file mode 100644 index 305bdb0..0000000 --- a/src/components/Template/StepComponents/MixStep.vue +++ /dev/null @@ -1,59 +0,0 @@ - - - \ No newline at end of file diff --git a/src/components/Template/StepComponents/PackageStep.vue b/src/components/Template/StepComponents/PackageStep.vue deleted file mode 100644 index fbf505c..0000000 --- a/src/components/Template/StepComponents/PackageStep.vue +++ /dev/null @@ -1,90 +0,0 @@ - - - \ No newline at end of file diff --git a/src/components/Template/StepComponents/Seal2Step.vue b/src/components/Template/StepComponents/Seal2Step.vue deleted file mode 100644 index c7b68f6..0000000 --- a/src/components/Template/StepComponents/Seal2Step.vue +++ /dev/null @@ -1,113 +0,0 @@ - - - \ No newline at end of file diff --git a/src/components/Template/StepComponents/Seal3Step.vue b/src/components/Template/StepComponents/Seal3Step.vue deleted file mode 100644 index ebc9cfd..0000000 --- a/src/components/Template/StepComponents/Seal3Step.vue +++ /dev/null @@ -1,114 +0,0 @@ - - - \ No newline at end of file diff --git a/src/components/Template/StepComponents/StaticEndStep.vue b/src/components/Template/StepComponents/StaticEndStep.vue deleted file mode 100644 index a02c8dd..0000000 --- a/src/components/Template/StepComponents/StaticEndStep.vue +++ /dev/null @@ -1,144 +0,0 @@ - - - \ No newline at end of file diff --git a/src/components/Template/StepComponents/StaticStartStep.vue b/src/components/Template/StepComponents/StaticStartStep.vue deleted file mode 100644 index 3957a40..0000000 --- a/src/components/Template/StepComponents/StaticStartStep.vue +++ /dev/null @@ -1,142 +0,0 @@ - - - \ No newline at end of file diff --git a/src/components/Template/StepComponents/TakePlateStep.vue b/src/components/Template/StepComponents/TakePlateStep.vue deleted file mode 100644 index 530065b..0000000 --- a/src/components/Template/StepComponents/TakePlateStep.vue +++ /dev/null @@ -1,147 +0,0 @@ - - - \ No newline at end of file diff --git a/src/components/Template/StepComponents/UltrasoundStep.vue b/src/components/Template/StepComponents/UltrasoundStep.vue deleted file mode 100644 index 08eeece..0000000 --- a/src/components/Template/StepComponents/UltrasoundStep.vue +++ /dev/null @@ -1,50 +0,0 @@ - - - \ No newline at end of file diff --git a/src/components/Template/StepComponents/VortexStep.vue b/src/components/Template/StepComponents/VortexStep.vue deleted file mode 100644 index 8fe6df6..0000000 --- a/src/components/Template/StepComponents/VortexStep.vue +++ /dev/null @@ -1,124 +0,0 @@ - - - \ No newline at end of file diff --git a/src/components/Template/StepComponents/ry/czdd.vue b/src/components/Template/StepComponents/ry/czdd.vue new file mode 100644 index 0000000..bd95bf5 --- /dev/null +++ b/src/components/Template/StepComponents/ry/czdd.vue @@ -0,0 +1,49 @@ + + + + + \ No newline at end of file diff --git a/src/components/Template/StepFormPackage.vue b/src/components/Template/StepFormPackage.vue new file mode 100644 index 0000000..cc086ab --- /dev/null +++ b/src/components/Template/StepFormPackage.vue @@ -0,0 +1,104 @@ + + + + + \ No newline at end of file diff --git a/src/components/Template/mixins/formPackageMixins.js b/src/components/Template/mixins/formPackageMixins.js new file mode 100644 index 0000000..316403d --- /dev/null +++ b/src/components/Template/mixins/formPackageMixins.js @@ -0,0 +1,349 @@ +import { isEqual } from "@/utils/index.js"; +export default { + watch: { + formData: { + immediate: true, + deep: true, // 深度监听,以便检测嵌套对象变化 + handler(v) { + if (v) { + this.handleFormField(true); + } + } + }, + fieldItemLabel: { + immediate: true, + deep: true, // 深度监听,以便检测嵌套对象变化 + handler(v) { + if (v) { + console.log(v,"fieldItemLabel") + } + } + }, + formConfig: { + immediate: true, + deep: true, // 深度监听,以便检测嵌套对象变化 + handler(v) { + this.handleFormField(); + } + } + }, + mounted() { + this.handleFormField(); + }, + unmounted() { + console.log("unmounted") + this.formFields = {};//清空当前填写的数据 + }, + + methods: { + getFillType(type) { + const typeObj = { + actFill: "orange-border",//实际填写的边框颜色 + green: "green-border", + preFill: "blue-border",//预填写的边框颜色 + } + return typeObj[type] || "" + }, + onInputNumberChange(key, val) { + this.formFields[key] = val; + // 清除该表单项的错误状态 + if (this.errors[key]) { + this.$set(this.errors, key, false); + } + }, + //更新表单数据 + updateFormData(key, value,oldKeys = []) { + + if(oldKeys.length){ + // 深拷贝当前表单数据,避免直接修改原数据 + const cloneFormFields = JSON.parse(JSON.stringify(this.formFields)); + oldKeys.forEach(oldKey => { + //需要把记录一下被更新的旧值,用于取消的时候回填,主要用于clickable类型 + this.oldFormFields[oldKey] = cloneFormFields[oldKey]; + }) + } + this.formFields[key] = value; + // 清除该表单项的错误状态 + if (this.errors[key]) { + this.$set(this.errors, key, false); + } + }, + //批量更新表单数据 + batchUpdateFormData(data) { + Object.keys(data).forEach(key => { + this.formFields[key] = data[key]; + // 清除该表单项的错误状态 + if (this.errors[key]) { + this.$set(this.errors, key, false); + } + }) + }, + handleClickable(sItem, event) { + console.log("clickable", sItem) + if (this.templateFillType !== 'actFill') { + return + } + this.$emit("clickable", sItem) + }, + //根据span判断一行显示几列 + getSpanClass(sItem) { + const spanArr = ["full-row", "", "three-row"] + if (sItem.span) { + return spanArr[sItem.span - 1] + } + return "" + }, + //获取其他下拉框的配置 + getOtherItem(sItem) { + return { + label: sItem.otherLabel ? this.$t(sItem.otherLabel) : this.$t("template.common.other"), + fillType: sItem.fillType, + maxlength: sItem.otherMaxlength || 50, + parentLabel: sItem.label, + } + }, + getClickableItem(sItem) { + return { + label: "", + type: "clickable", + fillType: sItem.subFillType || sItem.fillType, + parentLabel: sItem.label, + } + }, + getSubItem(sItem) { + return { + label: "", + options: sItem.subOptions || [], + fillType: sItem.subFillType || sItem.fillType, + parentLabel: sItem.label, + } + }, + // 根据formConfig回填form表单数据 + handleFormField(update = false) { + const result = {}; + let config = {}; + const { formConfig, formData, formFields } = this; + // 遍历配置 + formConfig.forEach((item) => { + if (item.config) { + // 合并配置项 + config = { ...config, ...item.config } + + // 处理每个配置项 + Object.keys(item.config).forEach(key => { + const currentConfig = item.config[key]; + let value = formData[key]; + + // 如果formFields中已经有值,保持原值(用户输入或之前设置的值) + if (formFields[key] !== null && + formFields[key] !== undefined && + formFields[key] !== '' + // typeof formFields[key] !== 'object' + ) { + + // 保留原值,不使用formData中的值 + result[key] = formFields[key]; + + } else { + // 使用formData中的值 + result[key] = value; + } + + // 处理特殊字段 - "其他"字段 + if (currentConfig.otherCode) { + const { otherCode } = currentConfig; + //如果是更新的话,优先使用formFields中的值 + if (update) { + result[otherCode] = formFields[otherCode] || formData[otherCode] || ''; + } else { + result[otherCode] = formData[otherCode] || formFields[otherCode] || ''; + } + config[otherCode] = { label: "template.common.other", parentKey: key, type: "input", fillType: currentConfig.fillType } + } + if (currentConfig.subKey) { + const { subKey } = currentConfig; + if (update) { + result[subKey] = formFields[subKey] || formData[subKey] || ''; + } else { + result[subKey] = formData[subKey] || formFields[subKey] || ''; + } + config[subKey] = { label: currentConfig.label, subKey, type: currentConfig.subType, fillType: currentConfig.subFillType || currentConfig.fillType, selectTo: currentConfig.selectTo } + } + + // 检查compareTo字段 + if (currentConfig.compareTo && formData[currentConfig.compareTo] && result[key]) { + const compareToValue = formData[currentConfig.compareTo]; + const currentValue = result[key]; + this.compareFieldsIsEqual(currentValue,compareToValue,key) + + } + }); + + // 处理可能存在的直接otherCode字段 + if (item.config?.otherCode) { + config[item.config?.otherCode] = item.config?.otherCode; + } + } + }); + // 更新表单字段 + this.formFields = result; + this.allFieldsConfig = config; + }, + //比较值是否相等 + compareFieldsIsEqual(currentValue,compareToValue,key) { + if(!currentValue || !compareToValue) return; + // 如果当前值与compareTo字段的值不相等,则设置橙色背景 + if (isEqual(currentValue,compareToValue)) { + // 如果相等,移除橙色背景(如果之前设置了的话) + this.$set(this.orangeBgFields, key, false); + } else { + this.$set(this.orangeBgFields, key, true); + } + }, + //判断是否禁用 + getDisabled() { + const { item } = this; + const { fillType } = item; + if (item.hasOwnProperty("disabled")) { + return item.disabled + } else { + if (fillType === "actFill") {//当模板状态是实际填写时,只有当fillType是actFill时才能填写 + return this.templateFillType !== "actFill" + } else if (fillType === "preFill") {//当模板状态是预填写时,只有当fillType是preFill才能填写 + return this.templateFillType !== "preFill" + } else { + return true + } + } + }, + // 表单数据校验 + validateFormData() { + const { formFields, allFieldsConfig } = this; + const errors = []; + + // 清空之前的错误状态 + this.errors = {}; + + for (const key in allFieldsConfig) { + const o = allFieldsConfig[key]; + if (o.otherCode) {// + if (o.type === "select") { + const isSelectedOther = this.isShowOther(formFields[key]); + if (!isSelectedOther) {//如果其他选项没有被选择,清空其他字段 + formFields[o.otherCode] = ""; + } + } else if (o.subType === "select") { + const isSelectedOther = this.isShowOther(formFields[o.subKey]); + if (!isSelectedOther) {//如果其他选项没有被选择,清空其他字段 + formFields[o.otherCode] = ""; + } + } + + } + if (this.isValueEmpty(formFields[key])) { + // 其他字段需要判断是否显示再校验 + if (o.label === "template.common.other" && !this.isShowOther(formFields[o.parentKey])) { + continue + } + //span的字段不校验 + if (o.type === "span") { + continue + } + if (o.fillType === this.templateFillType && !o.disabled) { + let prefix = ""; + if (o.type === "input" || o.type === "inputNumber" || o.type === "textarea") { + prefix = "填写"; + } else { + prefix = "选择"; + } + + const errorItem = { + field: key, + label: o.label, + error: `请${prefix}${o.label}` + }; + + errors.push(errorItem); + this.$set(this.errors, key, true); + } + } + } + return { + valid: errors.length === 0, + errors: errors + }; + }, + // 判断值是否为空 + isValueEmpty(value) { + if (value === null || value === undefined || value === '') { + return true; + } + if (typeof value === 'string' && value.trim() === '') { + return true; + } + if (Array.isArray(value) && value.length === 0) { + return true; + } + return false; + }, + getFormData() { + // 数据校验 + const validateResult = this.validateFormData(); + return new Promise((resolve, reject) => { + if (validateResult.valid) { + resolve(this.formFields); + } else { + // this.$message.error("表单内容未填完,请填写后再提交"); + reject(validateResult.errors[0].error); + } + }); + }, + //直接获取表单数据,不做校验 + getFilledFormData() { + return this.formFields; + }, + getFormDataByKey(key) { + return this.formFields[key]; + }, + onBlur(key, val) { + // compareTo 功能:当fillType==="actFill"时,判断当前值是否与compareTo字段的值一样,如果不一样则将当前input框的背景色标记成橙色 + this.onValueChangeCompareTo(key, val); + + this.$emit("blur", { key, value: val, ...this.formFields }); + }, + onValueChangeCompareTo(key, val, compKey) { + // compareTo 功能:当fillType==="actFill"时,判断当前值是否与compareTo字段的值一样,如果不一样则将当前input框的背景色标记成橙色 + const currentFieldConfig = this.allFieldsConfig[key]; + if (currentFieldConfig && currentFieldConfig.fillType === "actFill" && (currentFieldConfig.compareTo || compKey)) { + const compareToKey = compKey || currentFieldConfig.compareTo; + const compareToValue = this.formFields[compareToKey]; + this.compareFieldsIsEqual(val,compareToValue,key); + } + }, + onSelectChange(key, val, type) { + // 获取对应的配置 + const currentConfig = this.allFieldsConfig[key]; + if(currentConfig.selectTo){ + this.formFields[currentConfig.selectTo] = val; + } + this.onValueChangeCompareTo(key, val); + this.formFields[key] = val; + this.$emit("select", { key, value: val, type }); + // 清除该表单项的错误状态 + if (this.errors[key]) { + this.$set(this.errors, key, false); + } + }, + //复制 + onCopy(config, key) { + const { formFields } = this; + if (config.copyFrom) { + formFields[key] = formFields[config.copyFrom]; + this.onBlur(key, formFields[key]); + } + }, + resetRecord(key){ + this.formFields = {...this.formFields, ...this.oldFormFields} + }, + } +} \ No newline at end of file diff --git a/src/components/Template/operation/TableOpertaion.vue b/src/components/Template/operation/TableOpertaion.vue index dbc61be..0175703 100644 --- a/src/components/Template/operation/TableOpertaion.vue +++ b/src/components/Template/operation/TableOpertaion.vue @@ -9,8 +9,8 @@ @@ -79,7 +79,7 @@ export default { onPrintTag(data) { if(data) { if(data.rowIndex === this.rowIndex){ - this.$emit("printTag", { printCode: data.printCode,type:"subPackage" }) + this.$emit("printTag", { printCode: data.printCode,type:"subPackage",row: this.innerRow }) } }else{ this.$emit("printTag", { row: this.innerRow,type:"row" }) @@ -92,6 +92,10 @@ export default { const col = columnsData.find((item) => item.myCodeFields); const { myCodeFields, maxVolumeField, maxVolumeFieldUnit } = col; const fields = [], cols = [], units = []; + if(!myCodeFields || myCodeFields.length === 0){ + console.warn("请先配置myCodeFields字段") + return + } myCodeFields.forEach((key) => { fields.push(innerRow[key]) }); diff --git a/src/lang/zh/template/commonTemplate.js b/src/lang/zh/template/commonTemplate.js index 8318a85..71f9342 100644 --- a/src/lang/zh/template/commonTemplate.js +++ b/src/lang/zh/template/commonTemplate.js @@ -19,7 +19,7 @@ export default { testConfigurationConditions: '试验配制条件', preFill: '预填', actualFill: '实际', - configurationTime: '配置时间', + configurationTime: '配制时间', startTime: '开始时间', endTime: '结束时间', targetSolutionName: '目标溶液名称', diff --git a/src/views/business/comps/template/TemplateTable.vue b/src/views/business/comps/template/TemplateTable.vue index d1b5ca0..c97472e 100644 --- a/src/views/business/comps/template/TemplateTable.vue +++ b/src/views/business/comps/template/TemplateTable.vue @@ -1,6 +1,6 @@