From 08f95b2f159b56fa3bd4f4b348855989de8aa456 Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期四, 18 十二月 2025 21:48:18 +0800
Subject: [PATCH] feat: vehicle

---
 app/pages/task/index.vue |  157 +++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 131 insertions(+), 26 deletions(-)

diff --git a/app/pages/task/index.vue b/app/pages/task/index.vue
index 6fa2349..559b246 100644
--- a/app/pages/task/index.vue
+++ b/app/pages/task/index.vue
@@ -108,11 +108,14 @@
       
       <scroll-view class="task-list-scroll" scroll-y="true">
         <view class="task-list">
-          <view class="task-item" v-for="task in filteredTaskList" :key="task.id">
+          <view class="task-item" v-for="task in filteredTaskList" :key="task.taskId">
             <view class="task-main" @click="viewTaskDetail(task)">
               <!-- 浠诲姟澶撮儴锛氭爣棰樺拰鐘舵�佹爣绛� -->
               <view class="task-header">
-                <view class="task-title">{{ getTaskTypeText(task.taskType) }} - {{ task.vehicle }}</view>
+                <view class="task-title">
+                  {{ getTaskTypeText(task.taskType) }} - {{ task.vehicle }}
+                  <text v-if="task.isHeadPush === '1'" class="head-push-tag">鎬�</text>
+                </view>
                 <view class="task-status" :class="task.taskStatus === 'PENDING' ? 'status-pending' : task.taskStatus === 'DEPARTING' ? 'status-departing' : task.taskStatus === 'ARRIVED' ? 'status-arrived' : task.taskStatus === 'RETURNING' ? 'status-returning' : task.taskStatus === 'COMPLETED' ? 'status-completed' : task.taskStatus === 'CANCELLED' ? 'status-cancelled' : task.taskStatus === 'IN_PROGRESS' ? 'status-in-progress' : 'status-default'">
                   {{ getStatusText(task.taskStatus) }}
                 </view>
@@ -120,7 +123,7 @@
               
               <!-- 浠诲姟缂栧彿鍗曠嫭涓�琛� -->
               <view class="task-code-row">
-                <text class="task-code">{{ task.taskCode }}</text>
+                <text class="task-code">{{ task.showTaskCode }}</text>
               </view>
               
               <!-- 浠诲姟璇︾粏淇℃伅 -->
@@ -220,6 +223,8 @@
   import uniDatetimePicker from '@/uni_modules/uni-datetime-picker/components/uni-datetime-picker/uni-datetime-picker.vue'
   import { listTask, changeTaskStatus } from '@/api/task'
   import { mapState } from 'vuex'
+  import { formatDateTime } from '@/utils/common'
+  import { checkTaskCanDepart } from '@/utils/taskValidator'
   
   export default {
     components: {
@@ -295,7 +300,7 @@
         // 搴旂敤浠诲姟缂栧彿绛涢�� - 浣跨敤taskCode鑰屼笉鏄痶askNo
         if (this.searchForm.taskNo) {
           filtered = filtered.filter(task => 
-            task.taskCode && task.taskCode.includes(this.searchForm.taskNo)
+            task.showTaskCode && task.showTaskCode.includes(this.searchForm.taskNo)
           );
         }
         
@@ -322,11 +327,28 @@
     },
     onLoad() {
       this.loadTaskList()
+      
+      // 鐩戝惉浠诲姟鍒楄〃鍒锋柊浜嬩欢
+      uni.$on('refreshTaskList', this.handleRefreshEvent)
+    },
+    onShow() {
+      // 椤甸潰鏄剧ず鏃跺埛鏂板垪琛紙浠庡叾浠栭〉闈㈣繑鍥炴椂锛�
+      this.loadTaskList()
+    },
+    onUnload() {
+      // 椤甸潰閿�姣佹椂绉婚櫎浜嬩欢鐩戝惉
+      uni.$off('refreshTaskList', this.handleRefreshEvent)
     },
     onPullDownRefresh() {
       this.refreshList()
     },
     methods: {
+      // 澶勭悊鍒锋柊浜嬩欢
+      handleRefreshEvent() {
+        console.log('鏀跺埌鍒锋柊浠诲姟鍒楄〃浜嬩欢')
+        this.refreshList()
+      },
+      
       // 鍔犺浇浠诲姟鍒楄〃
       loadTaskList() {
         this.loading = true
@@ -359,7 +381,7 @@
               vehicleList: task.assignedVehicles || [],
               startLocation: this.formatAddress(task.departureAddress || task.startLocation || '鏈缃�'),
               endLocation: this.formatAddress(task.destinationAddress || task.endLocation || '鏈缃�'),
-              startTime: task.plannedStartTime ? this.formatDateTime(task.plannedStartTime) : '鏈缃�',
+              startTime: task.plannedStartTime ? formatDateTime(task.plannedStartTime, 'YYYY-MM-DD HH:mm') : '鏈缃�',
               assignee: task.assigneeName || '鏈垎閰�'
             }
           })
@@ -367,19 +389,6 @@
           this.loading = false
           console.error('鍔犺浇浠诲姟鍒楄〃澶辫触:', error)
           this.$modal.showToast('鍔犺浇浠诲姟鍒楄〃澶辫触')
-        })
-      },
-      
-      // 鏍煎紡鍖栨棩鏈熸椂闂�
-      formatDateTime(dateTime) {
-        if (!dateTime) return ''
-        const date = new Date(dateTime)
-        return date.toLocaleString('zh-CN', {
-          year: 'numeric',
-          month: '2-digit',
-          day: '2-digit',
-          hour: '2-digit',
-          minute: '2-digit'
         })
       },
       
@@ -429,7 +438,7 @@
         this.loadTaskList()
         setTimeout(() => {
           this.refreshing = false
-          this.$modal.showToast('鍒楄〃宸插埛鏂�');
+          // this.$modal.showToast('鍒楄〃宸插埛鏂�');
           // 鍋滄涓嬫媺鍒锋柊
           uni.stopPullDownRefresh()
         }, 1000)
@@ -442,18 +451,101 @@
       
       // 鏌ョ湅浠诲姟璇︽儏
       viewTaskDetail(task) {
-        // 璺宠浆鍒颁换鍔¤鎯呴〉闈� - 淇:浣跨敤taskId鑰屼笉鏄痠d
-        this.$tab.navigateTo(`/pages/task/detail?id=${task.taskId}`);
+        // 闃插尽鎬ф鏌�
+        if (!task || !task.taskId) {
+          console.error('浠诲姟鏁版嵁鏃犳晥:', task)
+          this.$modal.showToast('浠诲姟鏁版嵁寮傚父')
+          return
+        }
+        
+        // 璺宠浆鍒颁换鍔¤鎯呴〉闈� - 浣跨敤uni.navigateTo
+        uni.navigateTo({
+          url: `/pagesTask/detail?id=${task.taskId}`
+        });
       },
       
       // 澶勭悊浠诲姟鎿嶄綔
-      handleTaskAction(task, action) {
+      async handleTaskAction(task, action) {
         switch (action) {
           case 'depart':
             // 鍑哄彂 -> 鐘舵�佸彉涓哄嚭鍙戜腑
-            this.$modal.confirm('纭畾瑕佸嚭鍙戝悧锛�').then(() => {
-              this.updateTaskStatus(task.taskId, 'DEPARTING', '浠诲姟宸插嚭鍙�')
-            }).catch(() => {});
+            // 鏄剧ず鍔犺浇鎻愮ず
+            uni.showLoading({
+              title: '妫�鏌ヤ换鍔$姸鎬�...'
+            });
+            
+            try {
+              // 璋冪敤宸ュ叿绫绘鏌ヤ换鍔℃槸鍚﹀彲浠ュ嚭鍙戯紙鍖呭惈鍩烘湰鏍¢獙鍜屽啿绐佹鏌ワ級
+              const checkResult = await checkTaskCanDepart(task)
+              
+              uni.hideLoading();
+              
+              console.log('鍑哄彂妫�鏌ョ粨鏋�:', checkResult);
+              console.log('valid:', checkResult.valid);
+              console.log('conflicts:', checkResult.conflicts);
+              
+              if (!checkResult.valid) {
+                // 鏍¢獙澶辫触锛屾樉绀烘彁绀轰俊鎭苟鎻愪緵璺宠浆閫夐」
+                const conflicts = checkResult.conflicts || [];
+                const conflictInfo = conflicts.length > 0 ? conflicts[0] : null;
+                
+                console.log('鍐茬獊淇℃伅:', conflictInfo);
+                
+                // 濡傛灉鏈夊啿绐佷换鍔′俊鎭紝鎻愪緵璺宠浆鎸夐挳
+                if (conflictInfo && conflictInfo.taskId) {
+                  console.log('鏄剧ず甯﹁烦杞寜閽殑寮圭獥锛屼换鍔D:', conflictInfo.taskId);
+                  
+                  const conflictTaskId = conflictInfo.taskId;
+                  const message = checkResult.message || conflictInfo.message || '瀛樺湪鍐茬獊浠诲姟';
+                  
+                  uni.showModal({
+                    title: '鎻愮ず',
+                    content: message,
+                    confirmText: '鍘诲鐞�',
+                    cancelText: '鐭ラ亾浜�',
+                    success: function(res) {
+                      console.log('寮圭獥鐐瑰嚮缁撴灉:', res);
+                      if (res.confirm) {
+                        // 鐢ㄦ埛鐐瑰嚮"鐜板湪鍘诲鐞�"锛岃烦杞埌鍐茬獊浠诲姟璇︽儏椤�
+                        console.log('鍑嗗璺宠浆鍒颁换鍔¤鎯呴〉:', conflictTaskId);
+                        uni.navigateTo({
+                          url: `/pagesTask/detail?id=${conflictTaskId}`
+                        });
+                      }
+                    },
+                    fail: function(err) {
+                      console.error('鏄剧ず寮圭獥澶辫触:', err);
+                    }
+                  });
+                } else {
+                  // 娌℃湁鍐茬獊浠诲姟ID锛屽彧鏄剧ず鎻愮ず
+                  console.log('鏄剧ず鏅�氭彁绀哄脊绐�');
+                  uni.showModal({
+                    title: '鎻愮ず',
+                    content: checkResult.message || '浠诲姟鏍¢獙澶辫触',
+                    showCancel: false,
+                    confirmText: '鐭ラ亾浜�',
+                    fail: function(err) {
+                      console.error('鏄剧ず寮圭獥澶辫触:', err);
+                    }
+                  });
+                }
+                return;
+              }
+              
+              // 鎵�鏈夋鏌ラ�氳繃锛屽彲浠ュ嚭鍙�
+              this.$modal.confirm('纭畾瑕佸嚭鍙戝悧锛�').then(() => {
+                this.updateTaskStatus(task.taskId, 'DEPARTING', '浠诲姟宸插嚭鍙�')
+              }).catch(() => {});
+              
+            } catch (error) {
+              uni.hideLoading();
+              console.error('妫�鏌ヤ换鍔$姸鎬佸け璐�:', error);
+              // 妫�鏌ュけ璐ユ椂锛屼粛鐒跺厑璁稿嚭鍙�
+              this.$modal.confirm('妫�鏌ヤ换鍔$姸鎬佸け璐ワ紝鏄惁缁х画鍑哄彂锛�').then(() => {
+                this.updateTaskStatus(task.taskId, 'DEPARTING', '浠诲姟宸插嚭鍙�')
+              }).catch(() => {});
+            }
             break;
             
           case 'cancel':
@@ -528,6 +620,7 @@
             
             changeTaskStatus(taskId, statusData).then(response => {
               that.$modal.showToast('鐘舵�佹洿鏂版垚鍔�')
+              // 鍒锋柊浠诲姟鍒楄〃
               that.loadTaskList()
             }).catch(error => {
               console.error('鏇存柊浠诲姟鐘舵�佸け璐�:', error)
@@ -545,6 +638,7 @@
               
               changeTaskStatus(taskId, statusData).then(response => {
                 that.$modal.showToast('鐘舵�佹洿鏂版垚鍔�')
+                // 鍒锋柊浠诲姟鍒楄〃
                 that.loadTaskList()
               }).catch(error => {
                 console.error('鏇存柊浠诲姟鐘舵�佸け璐�:', error)
@@ -587,7 +681,7 @@
           'MAINTENANCE': '缁翠慨淇濆吇',
           'FUEL': '鍔犳补',
           'OTHER': '鍏朵粬',
-          'EMERGENCY_TRANSFER': '鎬ユ晳杞繍',
+          'EMERGENCY_TRANSFER': '杞繍浠诲姟',
           'WELFARE': '绂忕杞�'
         }
         return typeMap[type] || '鏈煡绫诲瀷'
@@ -622,6 +716,17 @@
     }
   }
   
+  // 鎬婚儴鎺ㄩ�佹爣璁版牱寮�
+  .head-push-tag {
+    color: #ff0000;
+    font-size: 24rpx;
+    font-weight: bold;
+    margin-left: 10rpx;
+    padding: 2rpx 8rpx;
+    border: 1rpx solid #ff0000;
+    border-radius: 4rpx;
+  }
+  
   // 浠诲姟鍒楄〃鍖哄煙
   .task-list-section {
     flex: 1;

--
Gitblit v1.9.1