Browse Source

feat:[模板管理][update]

lkf
luojie 2 months ago
parent
commit
b93bcd8eb6
10 changed files with 163 additions and 74 deletions
  1. +1
    -1
      src/components/Template/HandleFormItem.vue
  2. +64
    -46
      src/components/Template/Step.vue
  3. +6
    -11
      src/components/Template/StepComponents/ry/czdd.vue
  4. +40
    -3
      src/components/Template/StepFormPackage.vue
  5. +2
    -5
      src/components/Template/mixins/formPackageMixins.js
  6. +16
    -0
      src/components/Template/mixins/stepMixins.js
  7. +5
    -0
      src/utils/index.js
  8. +17
    -3
      src/views/business/comps/template/TemplateTable.vue
  9. +2
    -2
      src/views/business/comps/template/comps/sp/SWYPFXRYPZB.vue
  10. +10
    -3
      src/views/business/comps/template/dialog/SelectReagentDialog.vue

+ 1
- 1
src/components/Template/HandleFormItem.vue View File

@ -687,7 +687,7 @@ export default {
}
.handle-row {
margin-left: 10px;
margin-left: 5px;
display: flex;
align-items: center;
cursor: pointer;

+ 64
- 46
src/components/Template/Step.vue View File

@ -11,8 +11,9 @@
v-model="step.type" @change="onTypeChange(index)" />
<!-- 根据步骤类型显示对应的表单 -->
<component :is="getStepComponent(step.type)" :step-data="step.formData"
@update="onFormUpdate(index, $event)">
<!-- 根据步骤类型显示对应的表单 -->
<component :is="getStepComponent(step.type)" :formData="step.formData"
@update="onFormUpdate(index, $event)" :ref="'stepCompRef_' + index">
</component>
<div class="step-header-item">
<el-button type="text" @click="removeStep(index)" icon="el-icon-delete"
@ -25,12 +26,10 @@
</template>
<script>
import ContainerStep from './StepComponents/ContainerStep.vue'
import HandleFormItem from './HandleFormItem.vue';
import Czdd from './StepComponents/ry/czdd.vue';//-
const stepTypes = [
{ label: '容器选择', value: 'container' },
{ label: '操作地点', value: 'czdd' },
];
@ -57,14 +56,12 @@ export default {
},
components: {
HandleFormItem,
ContainerStep,
Czdd,
},
computed: {
stepComponentMap() {
if (!this.componentMap) {
this.componentMap = {
'container': 'ContainerStep',
'czdd': 'Czdd',
}
}
@ -86,24 +83,19 @@ export default {
// }
},
watch: {
steps: {
handler(newVal) {
this.$emit('input', newVal.map(step => ({
type: step.type,
formData: step.formData
})))
},
deep: true
},
'formData': {
// steps: {
// handler(newVal) {
// this.$emit('input', newVal.map(step => ({
// type: step.type,
// formData: step.formData
// })))
// },
// deep: true
// },
formData: {
handler(newVal) {
console.log('stepValue', newVal)
if (!newVal || newVal.length === 0) return
this.steps = newVal.map((step) => ({
id: this.stepId++,
type: step.type || '',
formData: step
}))
this.steps = newVal;
},
deep: true,
immediate: true
@ -149,8 +141,6 @@ export default {
},
onFormUpdate(stepIndex, formData) {
console.log('stepIndex', stepIndex)
console.log('formData', formData)
this.steps[stepIndex].formData = formData
},
@ -161,15 +151,7 @@ export default {
//
getFormData() {
return new Promise((resolve, reject) => {
//
const validation = this.validateSteps()
if (!validation.isValid) {
// this.$message.error(validation.errors[0])
reject(validation.errors[0])
return
}
return new Promise(async (resolve, reject) => {
//
if (this.steps.length === 0) {
// this.$message.error(this.$t('template.common.addStepError'))
@ -177,20 +159,42 @@ export default {
return
}
const stepData = this.steps.map(step => ({
type: step.type,
...step.formData
}))
resolve({ stepData })
try {
const stepData = await Promise.all(
this.steps.map(async (step, index) => {
const stepComponentRef = this.$refs[`stepCompRef_${index}`];
if (stepComponentRef && stepComponentRef.length > 0) {
try {
const stepFormData = await stepComponentRef[0].getFormData();
return { type: step.type, formData: stepFormData }
} catch (error) {
// getFormData
throw error;
}
} else {
//
return { type: step.type, formData: step.formData }
}
})
);
resolve({ stepData });
} catch (error) {
reject(error);
}
})
},
//
getFilledFormData() {
const stepData = this.steps.map(step => ({
type: step.type,
...step.formData
}))
const stepData = this.steps.map((step, index) => {
const stepComponentRef = this.$refs[`stepCompRef_${index}`];
if(stepComponentRef && stepComponentRef.length > 0){
const stepFormData = this.$refs[`stepCompRef_${index}`][0]?.getFilledFormData();
return { type: step.type, formData: stepFormData }
}else{
return { type: step.type, formData: step.formData }
}
})
return { stepData }
},
@ -227,14 +231,28 @@ export default {
},
//
validateSteps() {
async validateSteps() {
const errors = []
this.steps.forEach((step, index) => {
for (let index = 0; index < this.steps.length; index++) {
const step = this.steps[index];
if (!step.type) {
errors.push(`步骤 ${index + 1}: 请选择步骤类型`)
continue;
}
//
})
//
const stepComponentRef = this.$refs[`stepCompRef_${index}`];
if (stepComponentRef && stepComponentRef.length > 0) {
try {
// getFormData
await stepComponentRef[0].validateAndMarkRed();
} catch (error) {
// validateAndMarkRed
console.error(`步骤 ${index + 1} 验证时出错:`, error);
}
}
}
return {
isValid: errors.length === 0,
errors

+ 6
- 11
src/components/Template/StepComponents/ry/czdd.vue View File

@ -1,13 +1,17 @@
<template>
<StepFormPackage :form-config="formConfig" :form-data = "formData" />
<StepFormPackage ref = "stepFormPackageRef" :form-config="formConfig" :formData = "formData" />
</template>
<script>
import StepFormPackage from '@/components/Template/StepFormPackage.vue'
import StepFormPackage from '@/components/Template/StepFormPackage.vue';
import stepMixins from '@/components/Template/mixins/stepMixins.js';
export default {
mixins: [stepMixins],
components: {
StepFormPackage
},
computed: {
formConfig() {
return [{
@ -32,15 +36,6 @@ import StepFormPackage from '@/components/Template/StepFormPackage.vue'
}]
}
},
data() {
return {
formData: {
ddsys: "xxx",
yq: "",
}
}
},
}
</script>

+ 40
- 3
src/components/Template/StepFormPackage.vue View File

@ -20,9 +20,17 @@
@copy="onCopy(sItem, key)" :error="errors[key]" @update:error="errors[key] = false"
:orange-bg="orangeBgFields[key]" />
</template>
<!-- 仪器 -->
<template v-else-if="sItem.type === 'instrument'">
<HandleFormItem class="step-row" :field-item-label="fieldItemLabel" :field-key="prefixKey + '_' + key"
type="clickable" @clickable="handleClickable(sItem, $event)" :error="errors[key]"
type="clickable" @clickable="handleClickInstrument(key,'instrument')" :error="errors[key]"
@update:error="errors[key] = false" @resetRecord="resetRecord(key)" :item="getClickableItem(sItem)"
:value="formFields[key]" />
</template>
<!-- 仪器 -->
<template v-else-if="sItem.type === 'regent'">
<HandleFormItem class="step-row" :field-item-label="fieldItemLabel" :field-key="prefixKey + '_' + key"
type="clickable" @clickable="handleClickInstrument(key,'regent')" :error="errors[key]"
@update:error="errors[key] = false" @resetRecord="resetRecord(key)" :item="getClickableItem(sItem)"
:value="formFields[key]" />
</template>
@ -34,6 +42,7 @@
</template>
</div>
</div>
</div>
</template>
@ -41,7 +50,10 @@
import HandleFormItem from '@/components/Template/HandleFormItem.vue'
import formPackageMixins from '@/components/Template/mixins/formPackageMixins.js'
import { isShowOther } from "@/utils/formPackageCommon.js";
import { EventBus } from "@/utils/eventBus";
import { getuuid } from "@/utils/index.js";
export default {
inject: ['templateFillType','templateData'],
components: {
HandleFormItem,
},
@ -65,6 +77,12 @@ export default {
default: ""
}
},
mounted() {
EventBus.$on("onReagentSubmit",this.onReagentSubmit)
},
unmounted() {
EventBus.$off("onReagentSubmit",this.onReagentSubmit)
},
data() {
return {
formFields: {},//
@ -72,15 +90,34 @@ export default {
errors: {},//
orangeBgFields: {},//
isShowOther,
currentClickKey: "",//key
uuid:getuuid(),
}
},
methods: {
//
onReagentSubmit(data){
if(data.uuid !== this.uuid) return;
this.formFields[this.currentClickKey] = data.selectedId;
},
getClickableItem(sItem) {
return {
...sItem,
type:"clickable"
}
}
},
handleClickInstrument(key,type) {
this.currentClickKey = key;
if(type === 'regent'){
EventBus.$emit("showSelectReagentDialog",{
studyFormId:this.templateData.id,
uuid:this.uuid,
})
}
},
onSelectReagentSubmit(reagent){
this.formFields[this.currentClickKey] = reagent
},
}
}
</script>
@ -93,7 +130,7 @@ export default {
}
.step-row {
width: 180px;
min-width: 180px;
}
.step-item {

+ 2
- 5
src/components/Template/mixins/formPackageMixins.js View File

@ -31,7 +31,6 @@ export default {
this.handleFormField();
},
unmounted() {
console.log("unmounted")
this.formFields = {};//清空当前填写的数据
},
@ -79,7 +78,6 @@ export default {
})
},
handleClickable(sItem, event) {
console.log("clickable", sItem)
if (this.templateFillType !== 'actFill') {
return
}
@ -220,10 +218,8 @@ export default {
validateFormData() {
const { formFields, allFieldsConfig } = this;
const errors = [];
// 清空之前的错误状态
this.errors = {};
for (const key in allFieldsConfig) {
const o = allFieldsConfig[key];
if (o.otherCode) {//
@ -246,7 +242,7 @@ export default {
continue
}
//span的字段不校验
if (o.type === "span") {
if (o.type === "span" || o.type ==="text") {
continue
}
if (o.fillType === this.templateFillType && !o.disabled) {
@ -268,6 +264,7 @@ export default {
}
}
}
console.log(errors,"errors")
return {
valid: errors.length === 0,
errors: errors

+ 16
- 0
src/components/Template/mixins/stepMixins.js View File

@ -0,0 +1,16 @@
export default {
props: {
formData: {
type: Object,
default: () => ({})
}
},
methods: {
async getFormData() {
return await this.$refs.stepFormPackageRef.getFormData();
},
getFilledFormData() {
return this.$refs.stepFormPackageRef?.getFilledFormData();
}
},
}

+ 5
- 0
src/utils/index.js View File

@ -418,3 +418,8 @@ export const getExpireDate = (startDate, effectivePeriod, effectivePeriodUnit) =
.format('YYYY-MM-DD HH:mm:ss');
return end;
}
export function getuuid() {
return Math.random().toString(36).substring(2) +
Date.now().toString(36);
}

+ 17
- 3
src/views/business/comps/template/TemplateTable.vue View File

@ -4,11 +4,17 @@
</component>
<SubPackageDialog ref = "subPackageDialogRef"></SubPackageDialog>
<TagPrintDialog ref = "tagPrintDialogRef"></TagPrintDialog>
<SelectReagentDialog ref="selectReagentDialogRef">
</SelectReagentDialog>
</div>
</template>
<script>
import { EventBus } from "@/utils/eventBus";
import SubPackageDialog from "./dialog/SubPackageDialog.vue";//
import TagPrintDialog from "./dialog/PrintTagDialog.vue";//
import SelectReagentDialog from "./dialog/SelectReagentDialog.vue";//
//
import SWYPFXRYPZB from "./comps/sp/SWYPFXRYPZB.vue";
import SWYPFXCBYPZB from "./comps/sp/SWYPFXCBYPZB.vue";
@ -30,13 +36,13 @@ import Demo from "./comps/sp/Demo.vue";
//
import SYWZPZJHB from "./comps/gsp/SYWZPZJHB.vue";
import MJYLQSQD from "./comps/gsp/MJYLQSQD.vue";
import SubPackageDialog from "./dialog/SubPackageDialog.vue";//
import TagPrintDialog from "./dialog/PrintTagDialog.vue";//
export default {
name: "TemplateTable",
components: {
SubPackageDialog,TagPrintDialog,
SubPackageDialog,TagPrintDialog,SelectReagentDialog,
//
MJYLQSQD, SYWZPZJHB,
//
@ -119,6 +125,7 @@ export default {
provide() {
return {
//fillType
templateData: this.templateData,
templateFillType: this.fillType,
getZdxgjl: () => this.zdxgjl ,
getFhyjjl: () => this.fhyjjl,
@ -154,18 +161,25 @@ export default {
EventBus.$on('onModifyRecord', (data) => {
this.$emit(this.emitName, data)
});
//
EventBus.$on("showSubPackageDialog",(data)=>{
this.$refs.subPackageDialogRef.show(data)
})
//
EventBus.$on("showTagPrintDialog",(data)=>{
this.$refs.tagPrintDialogRef.show(data)
})
//
EventBus.$on("showSelectReagentDialog",(data)=>{
this.$refs.selectReagentDialogRef.show(data.studyFormId,data)
})
},
beforeDestroy() {
//
EventBus.$off('onModifyRecord');
EventBus.$off("showSubPackageDialog");
EventBus.$off("showTagPrintDialog");
EventBus.$off("showSelectReagentDialog");
},
methods: {
async getFormData() {

+ 2
- 2
src/views/business/comps/template/comps/sp/SWYPFXRYPZB.vue View File

@ -28,7 +28,7 @@
</div>
</div>
</div>
<!-- <button @click = "onSave">保存</button> -->
<button @click = "onSave">保存</button>
</div>
</template>
@ -308,7 +308,7 @@ export default {
return content;
},
async onSave() {
const formData = await this.getFilledFormData();
const formData = await this.validFormFields(["stepRef"]);
console.log(formData, "formData")
},

+ 10
- 3
src/views/business/comps/template/dialog/SelectReagentDialog.vue View File

@ -29,7 +29,7 @@
import SelectTable from '@/components/Template/SelectTable.vue';
import SelectDept from "@/views/business/comps/select/SelectDept";
import { public_sjList,public_bzList } from '@/api/business/public/public';
import { EventBus } from "@/utils/eventBus";
export default {
components: {
SelectTable,
@ -107,7 +107,8 @@ export default {
bzList:[],
depart:"",
studyFormId:''//studyFormId
studyFormId:'',//studyFormId
uuid:'',//eventBusid,
}
},
computed: {
@ -129,7 +130,10 @@ export default {
}
},
methods: {
show(studyFormId){
show(studyFormId,data){
if(data && data.uuid) {//eventBusid
this.uuid = data.uuid
}
this.visible = true
this.studyFormId = studyFormId
this.showTableData()
@ -173,6 +177,9 @@ export default {
}
}
this.$emit('submit', this.selectedId,row);
// eventBus
EventBus.$emit("onReagentSubmit",{uuid:this.uuid,selectedId:this.selectedId,row});
this.visible = false;
},
handleSelect(code,row) {
this.selectedId = code;

Loading…
Cancel
Save