Browse Source

fix(process/detail):数据选择器数据回显
fix(process/detail):数值输入框前面输入多个0
fix(process/detail):退回流程附件数据重复提交

wangpx 1 year ago
parent
commit
06c207a7cf
1 changed files with 108 additions and 54 deletions
  1. 108 54
      pages/process/detail/index.vue

+ 108 - 54
pages/process/detail/index.vue

@@ -271,8 +271,8 @@ import $modal from '@/plugins/modal.js'
 import { getProcessFlowInfo, getProcessFormInfo, getProcessFormInfoInFlow, getProcessFlow, submitProcessFlow, cancelProcessFlow, uploadSignatureImg, uploadSignatureBoardImg, uploadFile } from '@/api/process.js'
 import { getAttendanceSegment } from '@/api/work.js'
 import { useUserStore } from '@/store/user.js'
-import {getLoginInfo,getSession,setSession} from '@/utils/auth.js'
-import {reLogin,keepSession} from '@/api/login.js'
+import { getLoginInfo, getSession, setSession } from '@/utils/auth.js'
+import { reLogin, keepSession } from '@/api/login.js'
 import { convertToChineseCurrency } from '@/utils/ygoa.js'
 import { calCommonExp } from '@/utils/rpn.js'
 const fieldTypeDict = {
@@ -394,7 +394,17 @@ function initProcessForm() {
 	if (processInfo.tinsId) {
 		// 待办审批流程表单数据
 		getProcessFormInfoInFlow(userStore.user.useId, processInfo).then(({ returnParams }) => {
-			formElements.value = returnParams.formElements
+			
+			const modifyReturnParams = (returnParams) => {
+			  return returnParams.formElements.map(element => {
+			    if (element.type === "5") {
+			      // 将 defaultValue 按逗号分割成数组
+			      element.defaultValue = element.defaultValue.split(",");
+			    }
+			    return element;
+			  });
+			};
+			formElements.value = modifyReturnParams(returnParams)
 			formInfo.value = returnParams.formInfo[0]
 			repeatingForm.value = returnParams.repeatingForm
 			getMainFormRule()
@@ -467,18 +477,17 @@ function formatDict(dict) {
 	return dict.map(({ enumVname }) => enumVname)
 }
 //数据选择器
-function formatCheckbox(elem){
+function formatCheckbox(elem) {
 	let dict = elem.typeDetail.enum
-	elem['checkBox'] = true
+	// elem['checkBox'] = ''
 	return dict.map((item, index) => ({
 		text: item.enumVname,
-		value: item.enumVname 
+		value: item.enumVname
 	}));
 }
-const testValue=ref('')
-function changeDataCheckBox(e,elem){
-	// elem.checkBox=e.detail.value.join(",")
-	testValue.value=e.detail.value.join(",")
+function changeDataCheckBox(e, elem) {
+	elem['checkBox'] = e.detail.value.join(",")
+	console.log(e)
 }
 
 const timeRangeItems = ref([
@@ -497,15 +506,19 @@ function bindTimeRangeData() {
 			// 找到 startName 和 endName 的索引
 			const startIndex = formElements.value.findIndex((item) => item.elementName === startName);
 			const endIndex = formElements.value.findIndex((item) => item.elementName === endName);
-			
+
 			const formatDate = (date) => {
-			    const pad = (num) => num.toString().padStart(2, '0');
-			    return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
+				const pad = (num) => num.toString().padStart(2, '0');
+				return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
 			}
-			
+
 			// 只有找到 startName 和 endName 后,才检查 bindName
 			if (startIndex !== -1 && endIndex !== -1) {
-				formElements.value[startIndex].defaultValue = formatDate(new Date())
+				if (formElements.value[startIndex].defaultValue == '') {
+					formElements.value[startIndex].defaultValue = formatDate(new Date())
+				} else {
+					formElements.value[startIndex].defaultValue = formatDate(new Date(formElements.value[startIndex].defaultValue))
+				}
 				if (bindName) {
 					const bindIndex = formElements.value.findIndex((item) => item.elementName === bindName);
 					if (bindIndex !== -1) {
@@ -562,12 +575,17 @@ function calculateTimeDifference(item, form) {
 	// 保存到 defaultValue
 	return item.defaultValue = Number(timeDifferenceInHours.toFixed(2));
 }
-let workingPeriods = []
-let workDays = [] // 0为周日
+let workingPeriods = [
+	{ start: "09:00", end: "12:00" }, // 上午
+	{ start: "13:30", end: "17:30" }, // 下午
+]
+let workDays = [1, 2, 3, 4, 5, 6, 0] // 0为周日
+// 获取考勤时间段
 function setAttendanceSegment() {
 	getAttendanceSegment(userStore.user.unitId).then(({ returnParams }) => {
 		const workTime = returnParams[0].work_time.split(';')
-		workDays = returnParams[0].work_days.split(',')
+		let workDayArr = returnParams[0].work_days.split(',')
+		let workTimeArr = []
 		for (const time of workTime) {
 			if (time == '') continue
 			const times = time.split(',')
@@ -575,22 +593,19 @@ function setAttendanceSegment() {
 				start: times[0],
 				end: times[1]
 			}
-			workingPeriods.push(obj)
+			workTimeArr.push(obj)
 		}
-		if (workingPeriods.length == 0) {
-			workingPeriods = [
-				{ start: "09:00", end: "12:00" }, // 上午
-				{ start: "13:30", end: "17:30" }, // 下午
-			]
+		if (workTimeArr.length != 0) {
+			workingPeriods = workTimeArr
 		}
-		workDays = workDays.map(item => Number(item))
-		const sundayIndex = workDays.findIndex(item => item == 7)
-		console.log('workDays: ',workDays);
+		workDayArr = workDayArr.map(item => Number(item))
+		const sundayIndex = workDayArr.findIndex(item => item == 7)
+		console.log('workDays: ', workDayArr);
 		if (sundayIndex != -1) {
-			workDays[sundayIndex] = 0
+			workDayArr[sundayIndex] = 0
 		}
-		if (workDays.length == 0) {
-			workDays = [1, 2, 3, 4, 5, 6, 0] // 0为周日
+		if (workDayArr.length != 0) {
+			workDays = workDayArr
 		}
 	})
 }
@@ -684,6 +699,7 @@ function computedNumberToChineseCurrency(item, form) {
 	const elem = form.find(elem => elem.elementName == item.BddzText.slice(3))
 	return item.defaultValue = convertToChineseCurrency(elem.defaultValue)
 }
+// 按照公式统计数据
 function computedBddzTextValue(item) {
 	const mainIndex = formElements.value.findIndex(({ elementName }) => elementName == item.BddzText.slice(3))
 	const reIndex = repeatingForm.value.elementItem.findIndex(({ elementName }) => elementName == item.BddzText)
@@ -694,6 +710,7 @@ function computedBddzTextValue(item) {
 		return computedValueToRepeatingForm(item)
 	}
 }
+// 统计重复表数据
 function computedValueToRepeatingForm(item) {
 	const index = repeatingForm.value.elementItem.findIndex(({ elementName }) => elementName.slice(3) == item.BddzText.slice(3))
 	let result = 0
@@ -704,31 +721,42 @@ function computedValueToRepeatingForm(item) {
 }
 function digitInput(event, item) {
 	// 获取输入框当前的值
-	const currentValue = event;
+	let currentValue = event;
 
 	// 过滤非数字和小数点的字符
-	const filteredValue = currentValue.replace(/[^0-9.]/g, '');
+	currentValue = currentValue.replace(/[^0-9.]/g, '');
+
+	// 处理前导零的情况:
+	// 如果当前值没有小数点(即是整数),去掉前导零
+	if (currentValue.indexOf('.') === -1) {
+		currentValue = currentValue.replace(/^0+(?=\d)/, ''); // 只有当有数字跟随时才去掉前导零
+	} else {
+		// 如果包含小数点,处理整数部分的前导零,保留小数部分
+		let parts = currentValue.split('.');
+		parts[0] = parts[0].replace(/^0+(?=\d)/, ''); // 只去掉整数部分的前导零
+		currentValue = parts.join('.'); // 重新拼接
+	}
 
 	// 防止多个小数点
-	const parts = filteredValue.split('.');
+	const parts = currentValue.split('.');
 	let finalValue;
-	// console.log('event: ',event);
 	if (parts.length > 2) {
 		// 如果有多个小数点,保留第一个小数点及后续数字
 		finalValue = parts[0] + '.' + parts[1];
 	} else {
-		finalValue = filteredValue;
+		finalValue = currentValue;
 	}
-		
-	// console.log('finalValue: ',finalValue);
-	// console.log('item: ',item.defaultValue);
+
+	// 更新最终结果到 item
 	nextTick(() => {
-		// 更新最终结果到 item
-		item.defaultValue = finalValue
-		event = finalValue
-	})
+		item.defaultValue = finalValue;
+		event = finalValue; // 更新输入框的值
+	});
+
 	return event;
 }
+
+
 // 计算重复表关联变量表达式结果值
 function calculateRepeatingFormExpression(item, form) {
 	// 提取表达式中的变量名
@@ -842,7 +870,7 @@ function handleRepeatingForm() {
 // 附件管理
 function deleteFile(file) {
 	// console.log('deleteFile: ',file);
-	fileList.value[0].files = fileList.value[0].files.filter(({fileId}) => !(fileId == file.fileId))
+	fileList.value[0].files = fileList.value[0].files.filter(({ fileId }) => !(fileId == file.fileId))
 }
 // 上传附件
 const subFileList = ref([]) // 文件列表
@@ -972,18 +1000,24 @@ function handleSubmitProcess(result) {
 	$modal.confirm(content).then(() => {
 		button_state.value = false
 		if (result == "1") {
+			// 处理主表校验数据
 			mainFormValue.value = computed(() => {
 				const obj = {};
 				formElements.value.forEach(elem => {
+					let value = elem.defaultValue
 					if (!('0' != elem.canEdit && '8' != elem.type)) return
-					obj[elem.elementId] = elem.defaultValue;
+					if('5' == elem.type && Array.isArray(elem.defaultValue)){
+						value = elem.defaultValue.join(",")
+					}
+					obj[elem.elementId] = value;
 				});
 				return obj;
 			}).value
+			console.log('$mainForm.value: ',$mainForm.value);
 			// 主表数据校验
 			$mainForm.value.validate().then(res => {
 				// 重复表数据校验
-				if (!validateRepeatingForm2()) {
+				if (repeatingFormNotEmpty.value && !validateRepeatingForm2()) {
 					button_state.value = true
 					return
 				}
@@ -1002,11 +1036,15 @@ function submitProcess(result) {
 	let flow = Object.assign({}, flowInfo.value)
 	formInfo.value.formElements = formElements.value
 		// 过滤不可编辑的表单项
-		.filter(({canEdit}) => canEdit == '1')
-		.map(({ tableField, defaultValue }) => {
+		.filter(({ canEdit }) => canEdit == '1')
+		.map(({ tableField, defaultValue,type }) => {
+			let value = defaultValue
+			if('5' == type && Array.isArray(defaultValue)){
+				value = defaultValue.join(",")
+			}
 			return {
 				name: tableField,
-				value: defaultValue
+				value
 			}
 		})
 	repeatingForm.value.elements.forEach((table, index) => {
@@ -1021,7 +1059,7 @@ function submitProcess(result) {
 	flow['groupId'] = flowInfo.value.groupid
 	if (result == "1") {
 		const seqs = subFileSeqs.value.map(({ seq }) => seq)
-		if (processInfo.reqOffice == 1 && seqs.length == 0) {
+		if (flowInfo.value.seModel == '0' && processInfo.reqOffice == 1 && seqs.length == 0) {
 			button_state.value = true
 			$modal.msgError('请上传附件')
 			return
@@ -1033,6 +1071,9 @@ function submitProcess(result) {
 			$modal.msgError('请填写备注')
 			return
 		}
+	} else {
+		flow.fileIds = []
+		flow.files = []
 	}
 	flow['remark'] = remark.value
 	// result: 1通过 2退回发起人 0退回上一级
@@ -1185,28 +1226,29 @@ function cancelProcess() {
 				line-height: calc(1rem + 0px) !important;
 				font-weight: 700;
 			}
-		
+
 			.uni-forms-item__content {
 				font-size: calc(14px + (1rem - 16px)) !important;
 				font-weight: 500;
+
 				.uni-easyinput__content-textarea {
 					font-size: calc(14px + (1rem - 16px)) !important;
 					font-weight: 500;
 				}
-		
+
 				.uni-easyinput__content-input {
 					height: calc(35px + .5*(1rem - 16px)) !important;
 					font-size: calc(14px + (1rem - 16px)) !important;
 					font-weight: 500;
 					color: #333;
 				}
-		
+
 				.uni-date {
 					.uni-icons {
 						font-size: calc(22px + 1.2*(1rem - 16px)) !important;
 						font-weight: 500;
 					}
-		
+
 					.uni-date__x-input {
 						height: auto;
 						font-size: calc(14px + 1.2*(1rem - 16px)) !important;
@@ -1217,7 +1259,7 @@ function cancelProcess() {
 		}
 
 		.element_value_container {
-			
+
 			.signature_img {
 				width: 180px;
 			}
@@ -1244,12 +1286,14 @@ function cancelProcess() {
 					font-weight: bold;
 					color: #fcfcfc;
 				}
+
 				.uni-table-td {
 					font-size: calc(14px + 1.2*(1rem - 16px)) !important;
 				}
 			}
 		}
 	}
+
 	::v-deep .file_picker_container {
 		.uni-card {
 			.uni-card__header-content-title {
@@ -1261,6 +1305,7 @@ function cancelProcess() {
 			}
 		}
 	}
+
 	::v-deep .flow_step_container {
 		min-height: 200px;
 
@@ -1351,18 +1396,22 @@ function cancelProcess() {
 		}
 	}
 }
+
 ::v-deep .uni-calendar__content {
 	margin: -20px;
 	margin-top: 20px;
+
 	.uni-calendar__header {
 		.uni-calendar__header-text {
 			font-size: calc(14px + .5*(1rem - 16px)) !important;
 		}
+
 		.uni-calendar__backtoday {
 			padding: 2px 8px 2px 10px !important;
 			font-size: calc(0.75rem + 0px) !important;
 		}
 	}
+
 	.uni-calendar__box {
 		.uni-calendar__weeks {
 			.uni-calendar__weeks-day {
@@ -1370,6 +1419,7 @@ function cancelProcess() {
 					font-size: calc(14px + .5*(1rem - 16px)) !important;
 				}
 			}
+
 			.uni-calendar__weeks-item {
 				.uni-calendar-item__weeks-box-item {
 					.uni-calendar-item__weeks-box-circle {
@@ -1378,9 +1428,11 @@ function cancelProcess() {
 						top: calc(5px - .25*(1rem - 16px)) !important;
 						right: calc(5px - .25*(1rem - 16px)) !important;
 					}
+
 					.uni-calendar-item__weeks-box-text {
 						font-size: calc(14px + .5*(1rem - 16px)) !important;
 					}
+
 					.uni-calendar-item__weeks-lunar-text {
 						font-size: calc(12px + .5*(1rem - 16px)) !important;
 					}
@@ -1388,10 +1440,12 @@ function cancelProcess() {
 			}
 		}
 	}
+
 	.uni-date-changed {
 		.uni-date-changed--time-date {
 			font-size: calc(14px + 1*(1rem - 16px)) !important;
 		}
+
 		.uni-datetime-picker-text {
 			font-size: calc(14px + 1*(1rem - 16px)) !important;
 		}