Browse Source

首页待处理工单

HD_wangm 5 months ago
parent
commit
1e300b138c
3 changed files with 91 additions and 16 deletions
  1. 73 11
      pages/index/index.uvue
  2. 2 0
      pages/order/detail/acceptIndex.uvue
  3. 16 5
      pages/order/index.uvue

+ 73 - 11
pages/index/index.uvue

@@ -6,12 +6,15 @@
 
         <!-- <view class="bg-color"></view> -->
         <scroll-view class="page-content">
-			
+
 			<view class="db-view">
-				<view class="db-box">
+				<view class="db-box" @click="navigateToAssignedOrders">
+					<view v-if="assignedCount > 0" class="badge"><text class="count">{{ assignedCount }}</text></view>
 					<view class="db-block">
+
 						<view class="db-center-1">
 							<image class="db-image" src="/static/images/map/1.png"></image>
+
 						</view>
 					</view>
 					<text class="db-text">待处理工单</text>
@@ -33,17 +36,17 @@
 					<text class="db-text">超时工单</text>
 				</view>
 			</view>
-			
+
             <!-- 支流出库流量图表 -->
            <!-- <view class="chart-section">
                 <text class="section-title">支流出库流量 (m³/s)</text>
                 <flow-chart />
             </view> -->
-			
+
 			<view>
 				<button @click="handlePush">通知</button>
 			</view>
-			
+
         </scroll-view>
 
         <!-- 底部 TabBar -->
@@ -55,10 +58,42 @@
     import { ref, onMounted } from 'vue'
     import { getUserInfo } from '../../utils/storage'
     import FlowChart from '../../components/index/flow-chart/flow-chart.uvue'
+    import { getOrderList } from '../../api/order/list'
 
     // 用户名
     const userName = ref<string>('用户')
-	
+
+	// 待接单数量
+	const assignedCount = ref<number>(0)
+
+	// 获取待接单数量
+	const loadAssignedCount = async (): Promise<void> => {
+	    try {
+	        const result = await getOrderList(1, 1, null, 'assigned')
+	        const resultObj = result as UTSJSONObject
+
+	        if (resultObj['code'] == 200) {
+	            const total = resultObj['total'] as number
+	            assignedCount.value = total
+	        }
+	    } catch (e: any) {
+	        console.error('获取待接单数量失败:', e.message)
+	    }
+	}
+
+	// 跳转到待接单列表
+	const navigateToAssignedOrders = (): void => {
+		// 使用 redirectTo 而不是 switchTab,因为工单页面不是 tabBar 页面
+		uni.redirectTo({
+		    url: '/pages/order/index'
+		})
+
+		// 延迟设置状态,确保页面已加载
+		setTimeout(() => {
+			uni.$emit('switchOrderStatus', 'assigned')
+		}, 500)
+	}
+
 	const handleCreateChannel = (showToast : boolean) => {
 	  // #ifdef APP-ANDROID
 	  const manager = uni.getPushChannelManager()
@@ -78,7 +113,7 @@
 	  }
 	  // #endif
 	}
-	
+
 	const handleCreateLocalNotification = () => {
 	  if (uni.getAppAuthorizeSetting().notificationAuthorized == "authorized") {
 	    handleCreateChannel(false)
@@ -130,7 +165,7 @@
 	    })
 	  }
 	}
-	
+
 	const handlePush =  () => {
 		// uni.navigateTo({
 		//     url: '/pages/push/index',
@@ -148,6 +183,14 @@
             const realName = userInfo['nickName'] as string | null
             userName.value = realName ?? '用户'
         }
+
+		// 加载待接单数量
+		loadAssignedCount()
+
+		// 监听工单状态更新事件
+		uni.$on('refreshAssignedCount', () => {
+			loadAssignedCount()
+		})
     })
 </script>
 
@@ -189,7 +232,7 @@
     .header {
 		flex-direction: row;
 		height: 40px;
-		
+
         &-title {
             font-size: 40rpx;
             color: #ffffff;
@@ -218,12 +261,12 @@
         box-shadow: 0 0 16rpx 0 rgba(0, 0, 0, 0.1);
         border-radius: 16rpx;
     }
-	
+
 	.db-view{
 		flex-direction: row;
 		justify-content: space-between;
 		margin-bottom: 5px;
-		
+
 		.db-box{
 			background-color: #fff;
 			width:80px;
@@ -242,6 +285,7 @@
 				border-radius: 100px;
 				width:50px;
 				height:50px;
+				position: relative;
 			}
 			.db-center-2{
 				justify-content: center;
@@ -265,4 +309,22 @@
 			height:20px;
 		}
 	}
+
+	.badge {
+		z-index: 999;
+		position: absolute;
+		top: 20rpx;
+		right: 10rpx;
+		background-color: #ff4d4f;
+		border-radius: 18rpx;
+		width: 36rpx;
+		height: 36rpx;
+		
+	}
+	.count {
+		line-height: 36rpx;
+		font-size: 24rpx;
+		text-align: center;
+		color: #ffffff;
+	}
 </style>

+ 2 - 0
pages/order/detail/acceptIndex.uvue

@@ -312,6 +312,8 @@
 
 				// 使用事件总线通知列表页面刷新
 				uni.$emit('refreshOrderList', {})
+				// 通知首页刷新待接单数量
+				uni.$emit('refreshAssignedCount')
 				// 接单成功后返回上一页
 				setTimeout(() => {
 					uni.navigateBack()

+ 16 - 5
pages/order/index.uvue

@@ -205,6 +205,11 @@ import { getDictDataByType } from '../../api/dict/index'
 
                 total.value = responseTotal
                 hasMore.value = dataList.value.length < responseTotal
+
+				// 通知首页更新待接单数量
+				if (currentStatus.value === 'assigned') {
+					uni.$emit('refreshAssignedCount')
+				}
             } else {
                 const msg = resultObj['msg'] as string | null
                 uni.showToast({
@@ -318,7 +323,7 @@ import { getDictDataByType } from '../../api/dict/index'
 	    const dictItem = statusDictList.value.find(dict => dict.dictValue == rawStatus)
 	    return dictItem!=null ? dictItem.dictLabel : rawStatus
 	}
-	
+
 	const getStatusClass = (item: any | null): string => {
 		if (item == null) return ''
 		const orderInfoItem = item as acceptOrderInfo
@@ -446,6 +451,11 @@ import { getDictDataByType } from '../../api/dict/index'
 			page.value = 1
 			loadData(true)
 		})
+
+		// 监听首页切换状态事件
+		uni.$on('switchOrderStatus', (status: string) => {
+			switchStatus(status)
+		})
 	})
 
     // 组件卸载前清理事件监听
@@ -455,6 +465,7 @@ import { getDictDataByType } from '../../api/dict/index'
 
 		// 移除事件监听
 		uni.$off('refreshOrderList',{})
+		uni.$off('switchOrderStatus',{})
     })
 
 
@@ -525,7 +536,7 @@ import { getDictDataByType } from '../../api/dict/index'
 			color: #fff;
 		}
 	}
-	
+
     .list-item {
         margin: 24rpx 30rpx;
         background-color: #ffffff;
@@ -566,7 +577,7 @@ import { getDictDataByType } from '../../api/dict/index'
         margin-bottom: 20rpx;
         line-height: 40rpx;
     }
-	
+
 	.btn-primary {
 		font-size: 14px;
 	    background-color: #165DFF;
@@ -598,12 +609,12 @@ import { getDictDataByType } from '../../api/dict/index'
   flex-direction: row;
   justify-content: space-between;
   align-items: center;
-  
+
   .info-label {
     font-size: 26rpx;
     color: #666;
   }
-  
+
   .info-value {
     font-size: 26rpx;
     // color: #666;