瀏覽代碼

feat: 待审批,做了表单校验

luoyali 11 月之前
父節點
當前提交
660cdb132c
共有 1 個文件被更改,包括 35 次插入18 次删除
  1. 35 18
      src/views/approve/components/approvedContent.vue

+ 35 - 18
src/views/approve/components/approvedContent.vue

@@ -40,7 +40,7 @@
 					<div v-show="tabName === 'ApprovalInfo'" class="scroll-wrap">
 						<!-- 系统表单-->
 						<template v-if="currentTaskRow.processType === 'business' && currentObj?.formTemplate.type === 1">
-							<component :is="dyVueComponent" ref="dyVueComponentRef"></component>
+							<component :is="dyVueComponent" ref="dyVueComponentRef" @form-valid="openComment('consentOrRefuseVisible', 'agree')"></component>
 						</template>
 
 						<!-- 表单设计 -->
@@ -135,7 +135,7 @@
 							v-if="currentTaskType === 'pendingApproval'"
 							:icon="Check"
 							type="primary"
-							@click="openComment('consentOrRefuseVisible', 'agree')"
+							@click="handleFormValid"
 							>同意</el-button
 						>
 						<el-button
@@ -324,6 +324,31 @@ const dyVueForm = ref({})
 const currentObj = ref()
 provide('dyVueForm', dyVueForm) // 这里主要是存放动态的form的属性值
 
+/**
+ * 1、校验表单
+ *  1.1 type=1 校验系统表单
+ *  1.2 type=0 校验表单设计
+ * 2、提交API
+ */
+const handleFormValid = () => {
+	const { processType } = currentTaskRow.value
+	const flag = processType === 'business' && currentObj.value.formTemplate.type === 1 // 系统表单
+	if (flag) {
+		dyVueComponentRef.value.validateForm()
+	} else {
+		validateDesignForm()
+	}
+}
+
+// 校验表单设计
+const validateDesignForm = () => {
+	const form = EReditorRef.value.getSelfFormRef()
+	form.validate(valid => {
+		if (!valid) return false
+		openComment('consentOrRefuseVisible', 'agree')
+	})
+}
+
 /**
  * 详情按钮各个操作弹窗
  * @param visibleType 评论 拒绝 同意等
@@ -339,34 +364,25 @@ const openComment = async (visibleType, item) => {
 			break
 		case 'consentOrRefuseVisible':
 			currentFormData.value = {}
-			// 点击同意
-			let bool = true
 			if (item === 'agree') {
 				const { processType } = currentTaskRow.value
 				const flag = processType === 'business' && currentObj.value.formTemplate.type === 1 // 系统表单
 				if (flag) {
-					//todo 这里的系统表单还未做必填校验,根据自己的业务做校验
 					const formData = dyVueComponentRef.value.getComponentData()
 					const saveData = {
+						// 这里要调整真实的URL
+						// formStructure: currentObj.value.formTemplate.pcUrl,
 						formStructure: '@/views/flow/test/test1.vue',
-						formData: formData
+						formData
 					}
 					currentFormData.value = { processForm: JSON.stringify(saveData) }
 				} else {
-					const form = EReditorRef.value.getSelfFormRef()
-					bool = await form.validate(valid => {
-						if (valid) {
-							// 表单验证通过 进行保存
-							const formData = EReditorRef.value.getData()
-							let processForm = JSON.parse(cur_processForm_str)
-							processForm = { ...processForm, formData }
-							currentFormData.value = { processForm: JSON.stringify(processForm) }
-							console.log('验证通过')
-						}
-					})
+					const formData = EReditorRef.value.getData()
+					let processForm = JSON.parse(cur_processForm_str)
+					processForm = { ...processForm, formData }
+					currentFormData.value = { processForm: JSON.stringify(processForm) }
 				}
 			}
-			if (!bool) return
 			currentType.value = item
 			consentOrRefuseVisible.value = !consentOrRefuseVisible.value
 			break
@@ -445,6 +461,7 @@ const getTaskDetail = () => {
 								desc: '啦啦啦'
 							}
 						}
+						// dyVueComponent.value = markRaw(defineAsyncComponent(() => import('@/views/flow/test/test1.vue')))
 						dyVueComponent.value = defineAsyncComponent(async () => await /* @vite-ignore */ modules[data.formTemplate.pcUrl]())
 						return
 					} else {