Преглед на файлове

小程序非发起环节重复表可编辑

ouyj преди 5 дни
родител
ревизия
70a1d31b4c
променени са 2 файла, в които са добавени 105 реда и са изтрити 54 реда
  1. 78 36
      pages/process/detail/index.vue
  2. 27 18
      pages/work/edit/index.vue

+ 78 - 36
pages/process/detail/index.vue

@@ -136,7 +136,8 @@
 			<!-- <uni-card v-if="flowInfo.seModel == '0' && repeatingFormNotEmpty" spacing="0" padding="0">
 				<button @click="handleRepeatingForm" type="primary">查看明细</button>
 			</uni-card> -->
-			<uni-card v-if="!(flowInfo.seModel == '0' && repeatingFormNotEmpty)"
+			<!-- <uni-card v-if="!(flowInfo.seModel == '0' && repeatingFormNotEmpty)" -->
+			<uni-card v-if="groupCanEdit && repeatingForm.elementItem.length > 0"
 				v-for="(table, tableIndex) in repeatingForm.elements" spacing="0" :key="tableIndex">
 				<uni-forms label-position="left" :label-width="125" :border="true">
 					<uni-forms-item :name="elem.tableField" v-for="(elem, itemIndex) in table"
@@ -155,7 +156,7 @@
 							placeholderStyle="font-size: calc(14px + 1.2*(1rem - 16px))"></uni-easyinput>
 					</uni-forms-item>
 				</uni-forms>
-				<!-- <view class="repeating_table_button_container">
+				<view class="repeating_table_button_container">
 					<uni-row>
 						<uni-col :span="10" :offset="1">
 							<button @click="addrepeatingFormItem(tableIndex)" type="primary">新增</button>
@@ -165,7 +166,7 @@
 								:disabled="repeatingForm.elements.length <= 1" type="warn">删除</button>
 						</uni-col>
 					</uni-row>
-				</view> -->
+				</view>
 			</uni-card>
 			<!-- <uni-popup v-if="flowInfo.seModel == '0' && repeatingFormNotEmpty" ref="repeatingFormPopup">
 				<uni-card margin="0px" spacing="0px" padding="0px">
@@ -199,7 +200,8 @@
 			</uni-card>
 		</view> -->
 		<view class="repeating_table_detail">
-			<uni-card v-if="flowInfo.seModel == '0' && repeatingFormNotEmpty">
+			<!--<uni-card v-if="flowInfo.seModel == '0' && repeatingFormNotEmpty">-->
+			<uni-card v-if="!groupCanEdit && repeatingFormNotEmpty">
 				<uni-section titleFontSize="1.3rem" title="明细" type="line"></uni-section>
 				<view class="repeating_table_container">
 					<uni-table :border="true" stripe>
@@ -452,14 +454,19 @@
 	}
 	// 新增重复表表单
 	function addrepeatingFormItem(index) {
-		// parseCalculation(repeatingForm.value.elementItem)
-		const table = repeatingForm.value.elementItem.map(({ tableField, bddzText }) => {
-			const item = {
-				name: tableField,
-				defaultValue: ""
+		// 直接克隆模板对象,并确保 groupid 正确
+		const table = repeatingForm.value.elementItem.map((templateItem) => {
+			const item = Object.assign({}, templateItem);
+			item.defaultValue = "";
+			
+			// 关键修复:确保新行拥有和模板一样的 groupid
+			// 兼容大小写:优先使用 groupId,如果没有则使用 groupid
+			if (!item['groupid']) {
+				item['groupid'] = item['groupId'] || '';
 			}
-			if (bddzText != '') {
-				const mulItem = bddzText.split('*')
+			
+			if (templateItem.bddzText != '') {
+				const mulItem = templateItem.bddzText.split('*')
 				// 保存关联数据索引
 				item['bddzText'] = mulItem.map(item => {
 					// item['operation '].operands = mulItem.map(item => {
@@ -486,6 +493,7 @@
 	})
 	const fileList = ref([])
 	const isCancel = ref(false)
+	const groupCanEdit = ref(false)
 	// 获取流程表单
 	function initProcessForm() {
 		//debugger
@@ -511,6 +519,13 @@
 				if (returnParams.isCancel == 1) {
 					isCancel.value = true
 				}
+				if (returnParams.groupCanEdit == 1) {
+					groupCanEdit.value = true
+				}
+        if (groupCanEdit.value && repeatingForm.value.elements.length <= 0){
+          addrepeatingFormItem(0)
+          //console.log('repeatingForm.value.elements', repeatingForm.value.elements);
+        }
 				repeatingFormHasValue()
 				bindTimeRangeData()
 				remark.value = flowInfo.value.seModel == '0' ? '同意' : '重新提交'
@@ -1143,32 +1158,38 @@
 	}
 	function validateRepeatingForm2() {
 		// 设置重复表校验数据
-		const filterElements = repeatingForm.value.elements.filter(item => item.canEdit == "1")
-		if (filterElements.length == 0) return true
-		repeatingFormsValue.value = filterElements.map((item, index) => {
+		// repeatingForm.value.elements 是二维数组,需要检查每一行是否有可编辑字段
+		/*const hasEditableRows = repeatingForm.value.elements.some(row =>
+			row.some(field => field.canEdit == "1")
+		)
+		if (!hasEditableRows) return true*/
+		
+		repeatingFormsValue.value = repeatingForm.value.elements.map((item, index) => {
 			return computed(() => {
 				const obj = {};
-				item.forEach(({ name, defaultValue }) => {
-					obj[name] = defaultValue;
+				item.forEach(({ tableField, defaultValue }) => {
+					obj[tableField] = defaultValue;
 				});
 				return obj;
 			}).value
 		})
-		let flag = false
-		repeatingFormsValue.value.forEach((item, index) => {
-			let ItemIndex = 0
-			for (const elem in item) {
-				if (item[elem] == '') {
-					const name = repeatingForm.value.elementItem[ItemIndex].elementName.slice(3)
-					$modal.msgError(`详情表 ${name} 数据填写错误`)
-					flag = false
-					return
-				}
-				ItemIndex++
-			}
-			flag = true
-		})
-		return flag
+    let flag = true
+    for (let i = 0; i < repeatingFormsValue.value.length; i++) {
+      const item = repeatingFormsValue.value[i]
+      // 遍历 elementItem 来获取字段名称,确保顺序一致
+      for (let j = 0; j < repeatingForm.value.elementItem.length; j++) {
+        const fieldElement = repeatingForm.value.elementItem[j]
+        const fieldName = fieldElement.tableField || fieldElement.name
+        const fieldValue = item[fieldName]
+        
+        if (fieldValue == '' || fieldValue === undefined || fieldValue === null) {
+          const name = fieldElement.elementName.slice(3)
+          $modal.msgError(`详情表${name}不能为空`)
+          return false
+        }
+      }
+    }
+    return flag
 	}
 	const button_state = ref(true)
 	const remark = ref('')
@@ -1201,14 +1222,25 @@
 				// 主表数据校验
 				$mainForm.value.validate().then(res => {
 					// 重复表数据校验
-					if (repeatingFormNotEmpty.value && !validateRepeatingForm2()) {
+          /*const isGroupEditable = groupCanEdit.value;
+					const repeatingFormValid = isGroupEditable ? validateRepeatingForm2() : true;
+          console.log('groupCanEdit.value: ', groupCanEdit.value);
+          console.log('validateRepeatingForm2: ', repeatingFormValid);
+					if (isGroupEditable && !repeatingFormValid) {
 						button_state.value = true
 						return
-					}
+					}*/
+          if (groupCanEdit.value){
+            if (!validateRepeatingForm2()) {
+              button_state.value = true
+              return
+            }
+          }
 					submitProcess(result)
 				})
 					.catch(err => {
-						button_state.value = true
+            console.log('验证发生错误', err);
+            button_state.value = true
 						$modal.msgError('表单填写错误')
 					})
 			} else {
@@ -1218,22 +1250,32 @@
 	}
 	function submitProcess(result) {
 		let flow = Object.assign({}, flowInfo.value)
+		// 1. 处理主表字段:保留 isGroup 标记
 		formInfo.value.formElements = formElements.value
 			// 过滤不可编辑的表单项
 			.filter(({ canEdit }) => canEdit == '1')
-			.map(({ tableField, defaultValue, type }) => {
+			.map(({ tableField, defaultValue, type, elementId }) => {
 				let value = defaultValue
 				if ('5' == type && Array.isArray(defaultValue)) {
 					value = defaultValue.join(",")
 				}
 				return {
 					name: tableField,
-					value
+					value,
+					/*isGroup: '0', // 明确标记为主表字段
+					elementId: elementId*/
 				}
 			})
+		
+		// 2. 处理重复表字段:补充 value, isGroup 和 groupuid
 		repeatingForm.value.elements.forEach((table, index) => {
 			const newItem = table.map((item) => {
 				item['value'] = item.defaultValue
+				//item['isGroup'] = '1'
+				// 确保 groupuid 存在(行的唯一身份证),新增的行 groupuid 为空,后端会自动生成
+				if (!item['groupuid']) {
+					item['groupuid'] = ''
+				}
 				return item
 			})
 			formInfo.value.formElements.push(...newItem)

+ 27 - 18
pages/work/edit/index.vue

@@ -115,7 +115,7 @@
 			</view>
 		</uni-card>
 		<!-- 重复表单 -->
-		<view v-if="repeatingForm.elementItem.length > 0" class="repeating_table">
+		<view v-if="groupCanEdit && repeatingForm.elementItem.length > 0" class="repeating_table">
 			<uni-card v-for="(form, tableIndex) in repeatingForm.elements" spacing="0" :key="tableIndex">
 				<uni-forms :ref="(el) => $repeatingForms[tableIndex] = el" :modelValue="repeatingFormsValue[tableIndex]"
 					:rules="$repFormRules" label-position="left" :label-width="125" :border="true">
@@ -292,6 +292,7 @@ const repeatingForm = ref({
 	elements: []
 })
 const hideArr=['冲','借款','借款单号','结余','申请日期']
+const groupCanEdit = ref(false)
 function initProcessForm() {
 	getProcessForm(userStore.user, processInfo).then(({ returnParams }) => {
 		returnParams.formElements.forEach(element => {
@@ -327,10 +328,13 @@ function initProcessForm() {
 		}
 		repeatingForm.value = returnParams.repeatingForm
 		// console.log('formElements', formElements.value);
+    if (returnParams.groupCanEdit == 1) {
+      groupCanEdit.value = true
+    }
 		getValidateRules()
 		computedMainFormValue()
 		// 生成第一个重复表数据
-		if (repeatingForm.value) {
+		if (groupCanEdit.value && repeatingForm.value) {
 			addRepeatingFormItem(0)
 		}
 		bindTimeRangeData()
@@ -778,20 +782,23 @@ function validateRepeatingForm2() {
 			return obj;
 		}).value
 	})
-	let flag = false
-	repeatingFormsValue.value.forEach((item, index) => {
-		let ItemIndex = 0
-		for (const elem in item) {
-			if (item[elem] == '') {
-				const name = repeatingForm.value.elementItem[ItemIndex].elementName.slice(3)
-				$modal.msgError(`详情表${name}数据填写错误`)
-				flag = false
-				return
+	// 验证重复表单数据
+	let flag = true
+	for (let i = 0; i < repeatingFormsValue.value.length; i++) {
+		const item = repeatingFormsValue.value[i]
+		// 遍历 elementItem 来获取字段名称,确保顺序一致
+		for (let j = 0; j < repeatingForm.value.elementItem.length; j++) {
+			const fieldElement = repeatingForm.value.elementItem[j]
+			const fieldName = fieldElement.tableField || fieldElement.name
+			const fieldValue = item[fieldName]
+			
+			if (fieldValue == '' || fieldValue === undefined || fieldValue === null) {
+				const name = fieldElement.elementName.slice(3)
+				$modal.msgError(`详情表${name}不能为空`)
+				return false
 			}
-			ItemIndex++
 		}
-		flag = true
-	})
+	}
 	return flag
 }
 // 设置表单校验规则
@@ -861,10 +868,12 @@ function submitProcess() { // 提交表单
 
 		// 重复表数据校验
 		// validateRepeatingForm()
-		if (!validateRepeatingForm2()) {
-			button_state.value = true
-			return
-		}
+    if (groupCanEdit.value){
+      if (!validateRepeatingForm2()) {
+        button_state.value = true
+        return
+      }
+    }
 		// 保存表单数据
 
 		// processInfo.form = formElements.value.map(({ checkBox, tableField, defaultValue }) => {