Browse Source

办理防止重复提交

HD_wangm 4 months ago
parent
commit
0ecfa104da

+ 25 - 15
pages/order/detail/acceptIndex.uvue

@@ -154,7 +154,7 @@
 
         <!-- 接单按钮 -->
         <view class="accept-button-container" v-if="checkPermi(detailData.orderType == 2 ? ['gxt:maintenance:order:accept'] : ['gxt:repairOrder:accept'] )">
-            <button class="accept-button" @click="handleAcceptOrder">接 单</button>
+            <button class="accept-button" @click.stop="handleAcceptOrder">{{ isDealing ? '接单中...' : '接 单' }}</button>
         </view>
 
         <!-- 加载中状态 -->
@@ -315,6 +315,8 @@
 	    }
 	}
 
+	const isDealing = ref(false)
+	const hasDealed = ref(false)
 	// 处理接单操作
 	const handleAcceptOrder = async (): Promise<void> => {
 		if (selectedTeamLeaderName.value.trim() === '') {
@@ -324,7 +326,8 @@
 			})
 			return
 		}
-
+		if (isDealing.value || hasDealed.value) return // 双重保险
+		isDealing.value = true
 		// const subOrder = {
 		// 	id: detailData.value.id,
 		// 	orderType: detailData.value.orderType,
@@ -334,16 +337,16 @@
 		// 	// gxtRepairOrder:
 		// } as UTSJSONObject
 		detailData.value.workOrderStatus = 'to_finish'
-			try {
-				const result = await acceptOrder(detailData.value)
-				const resultObj = result as UTSJSONObject
-				const code = resultObj['code'] as number
-				if (code == 200) {
-					uni.showToast({
-						title: '接单成功',
-						icon: 'success'
-					})
-
+		try {
+			const result = await acceptOrder(detailData.value)
+			const resultObj = result as UTSJSONObject
+			const code = resultObj['code'] as number
+			if (code == 200) {
+				uni.showToast({
+					title: '接单成功',
+					icon: 'success'
+				})
+				hasDealed.value = true
 				// 使用事件总线通知列表页面刷新
 				uni.$emit('refreshOrderList', {})
 				// 通知首页刷新待处理工单数量
@@ -354,12 +357,19 @@
 				// 接单成功后返回上一页
 				setTimeout(() => {
 					uni.navigateBack()
-				}, 1000)
+				}, 800)
+			} else {
+			    // 处理业务错误
+			    uni.showToast({
+				    title: resultObj['msg'] as string,
+				    icon: 'none'
+			    })
 			}
 		} catch (error) {
-		  console.error('请求失败:', error);
+		    console.error('请求失败:', error);
+		} finally {
+			isDealing.value = false // 无论成功失败都解锁
 		}
-
 	}
 
 

+ 27 - 5
pages/order/detail/approveIndex.uvue

@@ -271,7 +271,9 @@
 	        dictLoaded.value = true
 	    }
 	}
-
+	
+	const isDealing = ref(false)
+	const hasDealed = ref(false)
 	// 处理驳回操作
 	const handleRejectOrder = async (): Promise<void> => {
 		if (rejectReason.value.trim() === '' ) {
@@ -281,6 +283,8 @@
 			})
 			return
 		}
+		if (isDealing.value || hasDealed.value) return // 双重保险
+		isDealing.value = true
 		detailData.value.rejectionReason = rejectReason.value
 		detailData.value.workOrderStatus = 'to_finish'
 		try {
@@ -292,7 +296,7 @@
 					title: '审批成功',
 					icon: 'success'
 				})
-
+				hasDealed.value = true
 				// 使用事件总线通知列表页面刷新
 				uni.$emit('refreshOrderList', {})
 				uni.$emit('refreshAssignedCount')
@@ -300,16 +304,26 @@
 				// 审批成功后返回上一页
 				setTimeout(() => {
 					uni.navigateBack()
-				}, 1000)
+				}, 800)
+			} else {
+			    // 处理业务错误
+			    uni.showToast({
+				    title: resultObj['msg'] as string,
+				    icon: 'none'
+			    })
 			}
 		} catch (error) {
 		  console.error('请求失败:', error);
+		} finally {
+			isDealing.value = false // 无论成功失败都解锁
 		}
 
 	}
 
 	// 处理接单操作
 	const handleAcceptOrder = async (): Promise<void> => {
+		if (isDealing.value || hasDealed.value) return // 双重保险
+		isDealing.value = true
 		detailData.value.rejectionReason = rejectReason.value
 		detailData.value.workOrderStatus = 'suspended'
 		try {
@@ -321,7 +335,7 @@
 					title: '审批成功',
 					icon: 'success'
 				})
-
+				hasDealed.value = true
 				// 使用事件总线通知列表页面刷新
 				uni.$emit('refreshOrderList', {})
 				uni.$emit('refreshAssignedCount')
@@ -329,10 +343,18 @@
 				// 接单成功后返回上一页
 				setTimeout(() => {
 					uni.navigateBack()
-				}, 1000)
+				}, 800)
+			} else {
+			    // 处理业务错误
+			    uni.showToast({
+				    title: resultObj['msg'] as string,
+				    icon: 'none'
+			    })
 			}
 		} catch (error) {
 		  console.error('请求失败:', error);
+		} finally {
+			isDealing.value = false // 无论成功失败都解锁
 		}
 
 	}

+ 16 - 4
pages/order/detail/resumeIndex.uvue

@@ -78,7 +78,7 @@
 
         <!-- 接单按钮 -->
         <view class="accept-button-container" v-if="checkPermi(detailData.orderType == 2 ? ['gxt:maintenance:order:resume'] : ['gxt:repairOrder:resume'])">
-            <button class="accept-button" @click="handleResumeOrder">恢 复</button>
+            <button class="accept-button" @click="handleResumeOrder">{{ isDealing ? '恢复中...' : '恢 复' }}</button>
         </view>
 
         <!-- 加载中状态 -->
@@ -239,9 +239,13 @@
 	    }
 	}
 
+	const isDealing = ref(false)
+	const hasDealed = ref(false)
 	// 处理恢复操作
 	const handleResumeOrder = async (): Promise<void> => {
-		detailData.value.rejectionReason = rejectReason.value
+		if (isDealing.value || hasDealed.value) return // 双重保险
+		isDealing.value = true
+		// detailData.value.rejectionReason = rejectReason.value
 		detailData.value.workOrderStatus = 'to_finish'
 		try {
 			const result = await resumeOrder(detailData.value)
@@ -252,7 +256,7 @@
 					title: '恢复成功',
 					icon: 'success'
 				})
-
+				hasDealed.value = true
 				// 使用事件总线通知列表页面刷新
 				uni.$emit('refreshOrderList', {})
 				uni.$emit('refreshAssignedCount')
@@ -260,10 +264,18 @@
 				// 接单成功后返回上一页
 				setTimeout(() => {
 					uni.navigateBack()
-				}, 1000)
+				}, 800)
+			} else {
+			    // 处理业务错误
+			    uni.showToast({
+				    title: resultObj['msg'] as string,
+				    icon: 'none'
+			    })
 			}
 		} catch (error) {
 		  console.error('请求失败:', error);
+		} finally {
+			isDealing.value = false // 无论成功失败都解锁
 		}
 
 	}

+ 25 - 13
pages/order/detail/suspendIndex.uvue

@@ -128,7 +128,7 @@
 
         <!-- 接单按钮 -->
         <view class="accept-button-container" v-if="checkPermi(detailData.orderType == 2 ? ['gxt:maintenance:order:suspend'] : ['gxt:repairOrder:suspend'])">
-            <button class="accept-button" @click="handleSuspendOrder">挂 起</button>
+            <button class="accept-button" @click="handleSuspendOrder">{{ isDealing ? '挂起中...' : '挂 起' }}</button>
         </view>
 
         <!-- 加载中状态 -->
@@ -289,7 +289,9 @@
 	        dictLoaded.value = true
 	    }
 	}
-
+	
+	const isDealing = ref(false)
+	const hasDealed = ref(false)
 	// 处理接单操作
 	const handleSuspendOrder = async (): Promise<void> => {
 		if (suspendReason.value == null || suspendReason.value.trim() === '') {
@@ -299,17 +301,19 @@
 			})
 			return
 		}
-
+		if (isDealing.value || hasDealed.value) return // 双重保险
+		isDealing.value = true
 		detailData.value.workOrderStatus = 'to_approve'
-			try {
-				const result = await suspendOrder(detailData.value)
-				const resultObj = result as UTSJSONObject
-				const code = resultObj['code'] as number
-				if (code == 200) {
-					uni.showToast({
-						title: '挂起成功',
-						icon: 'success'
-					})
+		try {
+			const result = await suspendOrder(detailData.value)
+			const resultObj = result as UTSJSONObject
+			const code = resultObj['code'] as number
+			if (code == 200) {
+				uni.showToast({
+					title: '挂起成功',
+					icon: 'success'
+				})
+				hasDealed.value = true
 
 				// 使用事件总线通知列表页面刷新
 				uni.$emit('refreshOrderList', {})
@@ -318,10 +322,18 @@
 				// 接单成功后返回上一页
 				setTimeout(() => {
 					uni.navigateBack()
-				}, 1000)
+				}, 800)
+			} else {
+			    // 处理业务错误
+			    uni.showToast({
+				    title: resultObj['msg'] as string,
+				    icon: 'none'
+			    })
 			}
 		} catch (error) {
 		  console.error('请求失败:', error);
+		} finally {
+			isDealing.value = false // 无论成功失败都解锁
 		}
 
 	}