wlzboy
16 小时以前 f08739f46afe856f60ebb1d21ab23d72947629ed
app/pages/task/index.vue
@@ -6,7 +6,10 @@
        <view class="header-title">任务列表</view>
        <view class="header-actions">
          <button class="search-toggle-btn" @click="toggleSearch">
            <uni-icons :type="showSearch ? 'close' : 'search'" size="20"></uni-icons>
            <uni-icons
              :type="showSearch ? 'close' : 'search'"
              size="20"
            ></uni-icons>
          </button>
          <button class="refresh-btn" @click="refreshList">
            <uni-icons type="refresh" size="20"></uni-icons>
@@ -19,9 +22,13 @@
        <view class="search-form">
          <view class="form-item">
            <view class="form-label">任务状态</view>
            <picker mode="selector" :range="statusOptions" @change="onStatusChange">
            <picker
              mode="selector"
              :range="statusOptions"
              @change="onStatusChange"
            >
              <view class="form-input picker-input">
                {{ selectedStatusText || '全部状态' }}
                {{ selectedStatusText || "全部状态" }}
                <uni-icons type="arrowright" size="16" color="#999"></uni-icons>
              </view>
            </picker>
@@ -108,22 +115,60 @@
      
      <scroll-view class="task-list-scroll" scroll-y="true">
        <view class="task-list">
          <view class="task-item" v-for="task in filteredTaskList" :key="task.taskId">
          <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 }}
                  <text v-if="task.isHeadPush === '1'" class="head-push-tag">总</text>
                  <text
                    v-if="
                      task.emergencyInfo &&
                      task.emergencyInfo.serviceOrdVip === '1'
                    "
                    class="vip-tag"
                    >VIP</text
                  >
                  <text
                    v-if="
                      task.emergencyInfo && task.emergencyInfo.fromHq2Is === '1'
                    "
                    class="hq-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'">
                <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>
              </view>
              
              <!-- 任务编号单独一行 -->
              <!-- 任务编号和开始时间在同一行显示,但分开一些 -->
              <view class="task-code-row">
                <text class="task-code">{{ task.showTaskCode }}</text>
                <text class="task-time">出发时间:{{ task.startTime }}</text>
              </view>
              
              <!-- 任务详细信息 -->
@@ -131,18 +176,16 @@
                <view class="info-row">
                  <view class="info-item">
                    <view class="label">出发地:</view>
                    <view class="value">{{ task.startLocation }}</view>
                  </view>
                  <view class="info-item">
                    <view class="label">目的地:</view>
                    <view class="value">{{ task.endLocation }}</view>
                    <view class="value">{{ getStartLocationDisplay(task) }}</view>
                  </view>
                </view>
                <view class="info-row">
                  <view class="info-item">
                    <view class="label">出发时间:</view>
                    <view class="value">{{ task.startTime }}</view>
                    <view class="label">目的地:</view>
                    <view class="value">{{ getEndLocationDisplay(task) }}</view>
                  </view>
                </view>
                <view class="info-row">
                  <view class="info-item">
                    <view class="label">执行人员:</view>
                    <view class="value">{{ task.assignee }}</view>
@@ -218,7 +261,10 @@
            <uni-icons type="spinner-cycle" size="20" color="#999"></uni-icons>
            <text>正在加载更多数据...</text>
          </view>
          <view class="load-more no-more" v-else-if="filteredTaskList.length > 0 && !hasMore">
          <view
            class="load-more no-more"
            v-else-if="filteredTaskList.length > 0 && !hasMore"
          >
            <text>没有更多数据了</text>
          </view>
        </view>
@@ -228,15 +274,15 @@
</template>
<script>
  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'
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: {
      uniDatetimePicker
    uniDatetimePicker,
    },
    data() {
      return {
@@ -245,16 +291,16 @@
        
        // 查询条件
        searchForm: {
          vehicle: '',
          taskNo: ''
        vehicle: "",
        taskNo: "",
        },
        statusOptions: ['全部状态', '待处理', '处理中', '已完成'],
        statusValues: ['', 'pending', 'processing', 'completed'],
        selectedStatus: '',
        selectedStatusText: '',
        startDate: '',
        endDate: '',
        currentFilter: 'all',
      statusOptions: ["全部状态", "待处理", "处理中", "已完成"],
      statusValues: ["", "pending", "processing", "completed"],
      selectedStatus: "",
      selectedStatusText: "",
      startDate: "",
      endDate: "",
      currentFilter: "all",
        
        // 任务列表
        taskList: [],
@@ -265,143 +311,137 @@
        currentPage: 1,
        pageSize: 10,
        total: 0,
        hasMore: true
      }
      hasMore: true,
    };
    },
    computed: {
      ...mapState({
        currentUser: state => state.user
      currentUser: (state) => state.user,
      }),
      filteredTaskList() {
        let filtered = this.taskList;
        // 应用筛选器
        if (this.currentFilter !== 'all') {
          filtered = filtered.filter(task => {
            if (this.currentFilter === 'pending') return task.taskStatus === 'PENDING';
            if (this.currentFilter === 'processing') return ['DEPARTING', 'ARRIVED', 'RETURNING', 'IN_PROGRESS'].includes(task.taskStatus);
            if (this.currentFilter === 'completed') return task.taskStatus === 'COMPLETED';
            return true;
          });
        }
        // 应用状态筛选
        if (this.selectedStatus) {
          const statusMap = {
            'pending': ['PENDING'],
            'processing': ['DEPARTING', 'ARRIVED', 'RETURNING', 'IN_PROGRESS'],
            'completed': ['COMPLETED']
          }
          const validStatuses = statusMap[this.selectedStatus];
          if (validStatuses) {
            filtered = filtered.filter(task => validStatuses.includes(task.taskStatus));
          }
        }
        // 应用车牌号筛选 - 搜索assignedVehicles数组中的车辆
        if (this.searchForm.vehicle) {
          filtered = filtered.filter(task => {
            // 在车辆列表中查找匹配的车牌号
            if (task.vehicleList && task.vehicleList.length > 0) {
              return task.vehicleList.some(vehicle =>
                vehicle.vehicleNo && vehicle.vehicleNo.includes(this.searchForm.vehicle)
              )
            }
            return false
          });
        }
        // 应用任务编号筛选 - 使用taskCode而不是taskNo
        if (this.searchForm.taskNo) {
          filtered = filtered.filter(task =>
            task.showTaskCode && task.showTaskCode.includes(this.searchForm.taskNo)
          );
        }
        // 应用时间范围筛选
        if (this.startDate) {
          filtered = filtered.filter(task =>
            task.plannedStartTime && task.plannedStartTime >= this.startDate
          );
        }
        if (this.endDate) {
          // 结束日期加一天,以便包含当天的数据
          const end = new Date(this.endDate);
          end.setDate(end.getDate() + 1);
          const endDateStr = end.toISOString().split('T')[0];
          filtered = filtered.filter(task =>
            task.plannedStartTime && task.plannedStartTime < endDateStr
          );
        }
        return filtered;
      }
      // 注意:这里不再进行前端过滤,而是直接返回从服务器加载的数据
      // 实际的筛选将在请求服务器时完成
      return this.taskList;
    },
    },
    onLoad() {
      this.loadTaskList()
    this.loadTaskList();
      
      // 监听任务列表刷新事件
      uni.$on('refreshTaskList', this.handleRefreshEvent)
    uni.$on("refreshTaskList", this.handleRefreshEvent);
    },
    onShow() {
      // 页面显示时刷新列表(从其他页面返回时)
      this.loadTaskList()
    this.loadTaskList();
    },
    onUnload() {
      // 页面销毁时移除事件监听
      uni.$off('refreshTaskList', this.handleRefreshEvent)
    uni.$off("refreshTaskList", this.handleRefreshEvent);
    },
    onPullDownRefresh() {
      this.refreshList()
    this.refreshList();
    },
    // 监听滚动到底部事件
    onReachBottom() {
      if (this.hasMore && !this.loading) {
        this.loadMore()
      this.loadMore();
      }
    },
    methods: {
      // 处理刷新事件
      handleRefreshEvent() {
        console.log('收到刷新任务列表事件')
        this.refreshList()
      console.log("收到刷新任务列表事件");
      this.refreshList();
      },
      
      // 加载任务列表
      loadTaskList() {
        this.loading = true
      this.loading = true;
        // 重置分页参数
        this.currentPage = 1
        this.hasMore = true
        this.taskList = []
      this.currentPage = 1;
      this.hasMore = true;
      this.taskList = [];
        
        // 后端会自动获取当前用户信息,实现综合查询
        // 综合查询:当前用户所在机构任务 + 当前用户创建的任务 + 分配给当前用户的任务
        const queryParams = {
          pageNum: this.currentPage,
          pageSize: this.pageSize,
          orderByColumn: 'create_time',
          isAsc: 'desc'
        orderByColumn: "create_time",
        isAsc: "desc",
      };
      // 根据筛选条件添加状态参数(优先使用顶部tab筛选条件)
      if (this.currentFilter === "pending") {
        queryParams.taskStatus = "PENDING";
      } else if (this.currentFilter === "processing") {
        queryParams.taskStatusList = [
          "DEPARTING",
          "ARRIVED",
          "RETURNING",
          "IN_PROGRESS",
        ].join(",");
      } else if (this.currentFilter === "completed") {
        queryParams.taskStatus = "COMPLETED";
      } else {
        // 如果没有使用顶部tab筛选,则使用查询条件中的状态筛选
        if (this.selectedStatus) {
          const statusMap = {
            pending: "PENDING",
            processing: [
              "DEPARTING",
              "ARRIVED",
              "RETURNING",
              "IN_PROGRESS",
            ].join(","),
            completed: "COMPLETED",
          };
          if (statusMap[this.selectedStatus]) {
            if (
              this.selectedStatus === "pending" ||
              this.selectedStatus === "completed"
            ) {
              queryParams.taskStatus = statusMap[this.selectedStatus];
            } else {
              queryParams.taskStatusList = statusMap[this.selectedStatus];
            }
          }
        }
        }
        
        listTask(queryParams).then(response => {
          this.loading = false
          const data = response.data || response.rows || []
          // 设置总数和是否有更多数据
          this.total = response.total || data.length || 0
          this.hasMore = data.length === this.pageSize
      if (this.searchForm.vehicle) {
        queryParams.vehicleNo = this.searchForm.vehicle;
      }
          
          this.taskList = data.map(task => {
      if (this.searchForm.taskNo) {
        queryParams.showTaskCode = this.searchForm.taskNo;
      }
      if (this.startDate) {
        queryParams.startDate = this.startDate;
      }
      if (this.endDate) {
        queryParams.endDate = this.endDate;
      }
      listTask(queryParams)
        .then((response) => {
          this.loading = false;
          const data = response.data || response.rows || [];
          // 设置总数和是否有更多数据
          this.total = response.total || data.length || 0;
          this.hasMore = data.length === this.pageSize;
          this.taskList = data.map((task) => {
            // 从assignedVehicles数组中获取车辆信息
            let vehicleInfo = '未分配车辆'
            let vehicleInfo = "未分配车辆";
            if (task.assignedVehicles && task.assignedVehicles.length > 0) {
              // 如果有多个车辆,显示第一个,并标注数量
              const firstVehicle = task.assignedVehicles[0]
              vehicleInfo = firstVehicle.vehicleNo || '未知车牌'
              const firstVehicle = task.assignedVehicles[0];
              vehicleInfo = firstVehicle.vehicleNo || "未知车牌";
              if (task.assignedVehicles.length > 1) {
                vehicleInfo += ` 等${task.assignedVehicles.length}辆`
                vehicleInfo += ` 等${task.assignedVehicles.length}辆`;
              }
            }
            
@@ -410,48 +450,110 @@
              // 格式化显示字段 - 使用后端返回的assignedVehicles数据
              vehicle: vehicleInfo,
              vehicleList: task.assignedVehicles || [],
              startLocation: this.formatAddress(task.departureAddress || task.startLocation || '未设置'),
              endLocation: this.formatAddress(task.destinationAddress || task.endLocation || '未设置'),
              startTime: task.plannedStartTime ? formatDateTime(task.plannedStartTime, 'YYYY-MM-DD HH:mm') : '未设置',
              assignee: task.assigneeName || '未分配'
            }
              startLocation: this.formatAddress(
                task.departureAddress || task.startLocation || "未设置"
              ),
              endLocation: this.formatAddress(
                task.destinationAddress || task.endLocation || "未设置"
              ),
              startTime: task.plannedStartTime
                ? formatDateTime(task.plannedStartTime, "YYYY-MM-DD HH:mm")
                : "未设置",
              assignee: task.assigneeName || "未分配",
            };
          });
          })
        }).catch(error => {
          this.loading = false
          console.error('加载任务列表失败:', error)
          this.$modal.showToast('加载任务列表失败')
        })
        .catch((error) => {
          this.loading = false;
          console.error("加载任务列表失败:", error);
          this.$modal.showToast("加载任务列表失败");
        });
      },
      
      // 加载更多数据
      loadMore() {
        if (!this.hasMore || this.loading) return
      if (!this.hasMore || this.loading) return;
        
        this.loading = true
        this.currentPage++
      this.loading = true;
      this.currentPage++;
        
        const queryParams = {
          pageNum: this.currentPage,
          pageSize: this.pageSize,
          orderByColumn: 'create_time',
          isAsc: 'desc'
        orderByColumn: "create_time",
        isAsc: "desc",
      };
      // 根据筛选条件添加状态参数(优先使用顶部tab筛选条件)
      if (this.currentFilter === "pending") {
        queryParams.taskStatus = "PENDING";
      } else if (this.currentFilter === "processing") {
        queryParams.taskStatusList = [
          "DEPARTING",
          "ARRIVED",
          "RETURNING",
          "IN_PROGRESS",
        ].join(",");
      } else if (this.currentFilter === "completed") {
        queryParams.taskStatus = "COMPLETED";
      } else {
        // 如果没有使用顶部tab筛选,则使用查询条件中的状态筛选
        if (this.selectedStatus) {
          const statusMap = {
            pending: "PENDING",
            processing: [
              "DEPARTING",
              "ARRIVED",
              "RETURNING",
              "IN_PROGRESS",
            ].join(","),
            completed: "COMPLETED",
          };
          if (statusMap[this.selectedStatus]) {
            if (
              this.selectedStatus === "pending" ||
              this.selectedStatus === "completed"
            ) {
              queryParams.taskStatus = statusMap[this.selectedStatus];
            } else {
              queryParams.taskStatusList = statusMap[this.selectedStatus];
            }
          }
        }
        }
        
        listTask(queryParams).then(response => {
          this.loading = false
          const data = response.data || response.rows || []
          // 更新是否有更多数据
          this.hasMore = data.length === this.pageSize
      if (this.searchForm.vehicle) {
        queryParams.vehicleNo = this.searchForm.vehicle;
      }
          
          const newTasks = data.map(task => {
      if (this.searchForm.taskNo) {
        queryParams.showTaskCode = this.searchForm.taskNo;
      }
      if (this.startDate) {
        queryParams.startDate = this.startDate;
      }
      if (this.endDate) {
        queryParams.endDate = this.endDate;
      }
      listTask(queryParams)
        .then((response) => {
          this.loading = false;
          const data = response.data || response.rows || [];
          // 更新是否有更多数据
          this.hasMore = data.length === this.pageSize;
          const newTasks = data.map((task) => {
            // 从assignedVehicles数组中获取车辆信息
            let vehicleInfo = '未分配车辆'
            let vehicleInfo = "未分配车辆";
            if (task.assignedVehicles && task.assignedVehicles.length > 0) {
              // 如果有多个车辆,显示第一个,并标注数量
              const firstVehicle = task.assignedVehicles[0]
              vehicleInfo = firstVehicle.vehicleNo || '未知车牌'
              const firstVehicle = task.assignedVehicles[0];
              vehicleInfo = firstVehicle.vehicleNo || "未知车牌";
              if (task.assignedVehicles.length > 1) {
                vehicleInfo += ` 等${task.assignedVehicles.length}辆`
                vehicleInfo += ` 等${task.assignedVehicles.length}辆`;
              }
            }
            
@@ -460,32 +562,65 @@
              // 格式化显示字段 - 使用后端返回的assignedVehicles数据
              vehicle: vehicleInfo,
              vehicleList: task.assignedVehicles || [],
              startLocation: this.formatAddress(task.departureAddress || task.startLocation || '未设置'),
              endLocation: this.formatAddress(task.destinationAddress || task.endLocation || '未设置'),
              startTime: task.plannedStartTime ? formatDateTime(task.plannedStartTime, 'YYYY-MM-DD HH:mm') : '未设置',
              assignee: task.assigneeName || '未分配'
            }
          })
              startLocation: this.formatAddress(
                task.departureAddress || task.startLocation || "未设置"
              ),
              endLocation: this.formatAddress(
                task.destinationAddress || task.endLocation || "未设置"
              ),
              startTime: task.plannedStartTime
                ? formatDateTime(task.plannedStartTime, "YYYY-MM-DD HH:mm")
                : "未设置",
              assignee: task.assigneeName || "未分配",
            };
          });
          
          // 将新数据追加到现有列表中
          this.taskList = [...this.taskList, ...newTasks]
        }).catch(error => {
          this.loading = false
          this.currentPage-- // 出错时回退页码
          console.error('加载更多任务失败:', error)
          this.$modal.showToast('加载更多任务失败')
          this.taskList = [...this.taskList, ...newTasks];
        })
        .catch((error) => {
          this.loading = false;
          this.currentPage--; // 出错时回退页码
          console.error("加载更多任务失败:", error);
          this.$modal.showToast("加载更多任务失败");
        });
      },
      
      // 格式化地址 - 只显示-前面的部分
      formatAddress(address) {
        if (!address) return '未设置'
      if (!address) return "未设置";
        // 如果地址包含-,只返回-前面的部分
        const dashIndex = address.indexOf('-')
      const dashIndex = address.indexOf("-");
        if (dashIndex > 0) {
          return address.substring(0, dashIndex)
        return address.substring(0, dashIndex);
        }
        return address
      return address;
    },
    // 获取出发地显示内容(转运任务显示转出医院名称)
    getStartLocationDisplay(task) {
      // 如果是转运任务且有emergencyInfo信息
      if (task.taskType === 'EMERGENCY_TRANSFER' && task.emergencyInfo && task.emergencyInfo.hospitalOutName) {
        return task.emergencyInfo.hospitalOutName;
      }
      // 其他情况使用原来的startLocation
      return this.formatAddress(task.startLocation || "未设置");
    },
    // 获取目的地显示内容(转运任务显示转入医院名称或详细地址)
    getEndLocationDisplay(task) {
      // 如果是转运任务且有emergencyInfo信息
      if (task.taskType === 'EMERGENCY_TRANSFER' && task.emergencyInfo) {
        // 优先显示转入医院名称
        if (task.emergencyInfo.hospitalInName) {
          if(task.emergencyInfo.hospitalInName.includes("家中")){
            return task.emergencyInfo.destinationAddress;
          }
          return task.emergencyInfo.hospitalInName;
        }
      }
      // 其他情况使用原来的endLocation
      return this.formatAddress(task.endLocation || "未设置");
      },
      
      // 切换查询界面显示/隐藏
@@ -501,171 +636,197 @@
      
      // 查询
      handleSearch() {
        this.loadTaskList()
        this.$modal.showToast('查询成功');
      this.loadTaskList();
      this.$modal.showToast("查询成功");
        // 查询完成后隐藏查询界面
        this.showSearch = false;
      },
      
      // 重置查询条件
      resetSearch() {
        this.selectedStatus = '';
        this.selectedStatusText = '';
        this.startDate = '';
        this.endDate = '';
        this.searchForm.vehicle = '';
        this.searchForm.taskNo = '';
      this.selectedStatus = "";
      this.selectedStatusText = "";
      this.startDate = "";
      this.endDate = "";
      this.searchForm.vehicle = "";
      this.searchForm.taskNo = "";
      },
      
      // 刷新列表
      refreshList() {
        this.refreshing = true
        this.loadTaskList()
      this.refreshing = true;
      this.loadTaskList();
        setTimeout(() => {
          this.refreshing = false
        this.refreshing = false;
          // this.$modal.showToast('列表已刷新');
          // 停止下拉刷新
          uni.stopPullDownRefresh()
        }, 1000)
        uni.stopPullDownRefresh();
      }, 1000);
      },
      
      // 筛选
      changeFilter(filter) {
        this.currentFilter = filter;
      // 重新加载数据
      this.loadTaskList();
      },
      
      // 查看任务详情
      viewTaskDetail(task) {
        // 防御性检查
        if (!task || !task.taskId) {
          console.error('任务数据无效:', task)
          this.$modal.showToast('任务数据异常')
          return
        console.error("任务数据无效:", task);
        this.$modal.showToast("任务数据异常");
        return;
        }
        
        // 跳转到任务详情页面 - 使用uni.navigateTo
        uni.navigateTo({
          url: `/pagesTask/detail?id=${task.taskId}`
        url: `/pagesTask/detail?id=${task.taskId}`,
        });
      },
      
      // 处理任务操作
      async handleTaskAction(task, action) {
        switch (action) {
          case 'depart':
        case "depart":
            // 出发 -> 状态变为出发中
            // 显示加载提示
            uni.showLoading({
              title: '检查任务状态...'
            title: "检查任务状态...",
            });
            
            try {
              // 调用工具类检查任务是否可以出发(包含基本校验和冲突检查)
              const checkResult = await checkTaskCanDepart(task)
            const checkResult = await checkTaskCanDepart(task);
              
              uni.hideLoading();
              
              console.log('出发检查结果:', checkResult);
              console.log('valid:', checkResult.valid);
              console.log('conflicts:', checkResult.conflicts);
            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);
              console.log("冲突信息:", conflictInfo);
                
                // 如果有冲突任务信息,提供跳转按钮
                if (conflictInfo && conflictInfo.taskId) {
                  console.log('显示带跳转按钮的弹窗,任务ID:', conflictInfo.taskId);
                console.log(
                  "显示带跳转按钮的弹窗,任务ID:",
                  conflictInfo.taskId
                );
                  
                  const conflictTaskId = conflictInfo.taskId;
                  const message = checkResult.message || conflictInfo.message || '存在冲突任务';
                const message =
                  checkResult.message || conflictInfo.message || "存在冲突任务";
                  
                  uni.showModal({
                    title: '提示',
                  title: "提示",
                    content: message,
                    confirmText: '去处理',
                    cancelText: '知道了',
                  confirmText: "去处理",
                  cancelText: "知道了",
                    success: function(res) {
                      console.log('弹窗点击结果:', res);
                    console.log("弹窗点击结果:", res);
                      if (res.confirm) {
                        // 用户点击"现在去处理",跳转到冲突任务详情页
                        console.log('准备跳转到任务详情页:', conflictTaskId);
                      console.log("准备跳转到任务详情页:", conflictTaskId);
                        uni.navigateTo({
                          url: `/pagesTask/detail?id=${conflictTaskId}`
                        url: `/pagesTask/detail?id=${conflictTaskId}`,
                        });
                      }
                    },
                    fail: function(err) {
                      console.error('显示弹窗失败:', err);
                    }
                    console.error("显示弹窗失败:", err);
                  },
                  });
                } else {
                  // 没有冲突任务ID,只显示提示
                  console.log('显示普通提示弹窗');
                console.log("显示普通提示弹窗");
                  uni.showModal({
                    title: '提示',
                    content: checkResult.message || '任务校验失败',
                  title: "提示",
                  content: checkResult.message || "任务校验失败",
                    showCancel: false,
                    confirmText: '知道了',
                  confirmText: "知道了",
                    fail: function(err) {
                      console.error('显示弹窗失败:', err);
                    }
                    console.error("显示弹窗失败:", err);
                  },
                  });
                }
                return;
              }
              
              // 所有检查通过,可以出发
              this.$modal.confirm('确定要出发吗?').then(() => {
                this.updateTaskStatus(task.taskId, 'DEPARTING', '任务已出发')
              }).catch(() => {});
            this.$modal
              .confirm("确定要出发吗?")
              .then(() => {
                this.updateTaskStatus(task.taskId, "DEPARTING", "任务已出发");
              })
              .catch(() => {});
            } catch (error) {
              uni.hideLoading();
              console.error('检查任务状态失败:', error);
            console.error("检查任务状态失败:", error);
              // 检查失败时,仍然允许出发
              this.$modal.confirm('检查任务状态失败,是否继续出发?').then(() => {
                this.updateTaskStatus(task.taskId, 'DEPARTING', '任务已出发')
              }).catch(() => {});
            this.$modal
              .confirm("检查任务状态失败,是否继续出发?")
              .then(() => {
                this.updateTaskStatus(task.taskId, "DEPARTING", "任务已出发");
              })
              .catch(() => {});
            }
            break;
            
          case 'cancel':
        case "cancel":
            // 取消 -> 二次确认后状态变为已取消
            this.$modal.confirm('确定要取消此任务吗?').then(() => {
              this.updateTaskStatus(task.taskId, 'CANCELLED', '任务已取消')
            }).catch(() => {});
          this.$modal
            .confirm("确定要取消此任务吗?")
            .then(() => {
              this.updateTaskStatus(task.taskId, "CANCELLED", "任务已取消");
            })
            .catch(() => {});
            break;
            
          case 'arrive':
        case "arrive":
            // 已到达 -> 状态变为已到达
            this.$modal.confirm('确认已到达目的地?').then(() => {
              this.updateTaskStatus(task.taskId, 'ARRIVED', '已到达目的地')
            }).catch(() => {});
          this.$modal
            .confirm("确认已到达目的地?")
            .then(() => {
              this.updateTaskStatus(task.taskId, "ARRIVED", "已到达目的地");
            })
            .catch(() => {});
            break;
            
          case 'forceCancel':
        case "forceCancel":
            // 强制结束 -> 状态变为已取消
            this.$modal.confirm('确定要强制结束此任务吗?').then(() => {
              this.updateTaskStatus(task.taskId, 'CANCELLED', '任务已强制结束')
            }).catch(() => {});
          this.$modal
            .confirm("确定要强制结束此任务吗?")
            .then(() => {
              this.updateTaskStatus(task.taskId, "CANCELLED", "任务已强制结束");
            })
            .catch(() => {});
            break;
            
          case 'return':
        case "return":
            // 已返程 -> 状态变为返程中
            this.$modal.confirm('确认开始返程?').then(() => {
              this.updateTaskStatus(task.taskId, 'RETURNING', '已开始返程')
            }).catch(() => {});
          this.$modal
            .confirm("确认开始返程?")
            .then(() => {
              this.updateTaskStatus(task.taskId, "RETURNING", "已开始返程");
            })
            .catch(() => {});
            break;
            
          case 'complete':
        case "complete":
            // 已完成 -> 状态变为已完成
            this.$modal.confirm('确认任务已完成?').then(() => {
              this.updateTaskStatus(task.taskId, 'COMPLETED', '任务已完成')
            }).catch(() => {});
          this.$modal
            .confirm("确认任务已完成?")
            .then(() => {
              this.updateTaskStatus(task.taskId, "COMPLETED", "任务已完成");
            })
            .catch(() => {});
            break;
        }
      },
@@ -673,106 +834,115 @@
      // 更新任务状态
      updateTaskStatus(taskId, status, remark) {
        // 获取GPS位置信息
        this.getLocationAndUpdateStatus(taskId, status, remark)
      this.getLocationAndUpdateStatus(taskId, status, remark);
      },
      
      // 获取位置信息并更新状态
      getLocationAndUpdateStatus(taskId, status, remark) {
        const that = this
      const that = this;
        
        // 使用uni.getLocation获取GPS位置
        uni.getLocation({
          type: 'gcj02',
        type: "gcj02",
          geocode: true,
          altitude: true,
          success: function(res) {
            console.log('GPS定位成功:', res)
          console.log("GPS定位成功:", res);
            
            const statusData = {
              taskStatus: status,
              remark: remark,
              latitude: res.latitude,
              longitude: res.longitude,
              locationAddress: res.address ? res.address.street || res.address.poiName || '' : '',
              locationProvince: res.address ? res.address.province || '' : '',
              locationCity: res.address ? res.address.city || '' : '',
              locationDistrict: res.address ? res.address.district || '' : '',
            locationAddress: res.address
              ? res.address.street || res.address.poiName || ""
              : "",
            locationProvince: res.address ? res.address.province || "" : "",
            locationCity: res.address ? res.address.city || "" : "",
            locationDistrict: res.address ? res.address.district || "" : "",
              gpsAccuracy: res.accuracy,
              altitude: res.altitude,
              speed: res.speed,
              heading: res.direction || res.heading
            }
            heading: res.direction || res.heading,
          };
            
            changeTaskStatus(taskId, statusData).then(response => {
              that.$modal.showToast('状态更新成功')
          changeTaskStatus(taskId, statusData)
            .then((response) => {
              that.$modal.showToast("状态更新成功");
              // 刷新任务列表
              that.loadTaskList()
            }).catch(error => {
              console.error('更新任务状态失败:', error)
              that.$modal.showToast('状态更新失败,请重试')
              that.loadTaskList();
            })
            .catch((error) => {
              console.error("更新任务状态失败:", error);
              that.$modal.showToast("状态更新失败,请重试");
            });
          },
          fail: function(err) {
            console.error('GPS定位失败:', err)
          console.error("GPS定位失败:", err);
            
            that.$modal.confirm('GPS定位失败,是否继续更新状态?').then(() => {
          that.$modal
            .confirm("GPS定位失败,是否继续更新状态?")
            .then(() => {
              const statusData = {
                taskStatus: status,
                remark: remark
              }
                remark: remark,
              };
              
              changeTaskStatus(taskId, statusData).then(response => {
                that.$modal.showToast('状态更新成功')
              changeTaskStatus(taskId, statusData)
                .then((response) => {
                  that.$modal.showToast("状态更新成功");
                // 刷新任务列表
                that.loadTaskList()
              }).catch(error => {
                console.error('更新任务状态失败:', error)
                that.$modal.showToast('状态更新失败,请重试')
                  that.loadTaskList();
              })
            }).catch(() => {})
          }
                .catch((error) => {
                  console.error("更新任务状态失败:", error);
                  that.$modal.showToast("状态更新失败,请重试");
                });
        })
            .catch(() => {});
        },
      });
      },
      
      getStatusText(status) {
        const statusMap = {
          'PENDING': '待处理',
          'DEPARTING': '出发中',
          'ARRIVED': '已到达',
          'RETURNING': '返程中',
          'COMPLETED': '已完成',
          'CANCELLED': '已取消',
          'IN_PROGRESS': '处理中' // 兼容旧数据
        }
        return statusMap[status] || '未知'
        PENDING: "待处理",
        DEPARTING: "出发中",
        ARRIVED: "已到达",
        RETURNING: "返程中",
        COMPLETED: "已完成",
        CANCELLED: "已取消",
        IN_PROGRESS: "处理中", // 兼容旧数据
      };
      return statusMap[status] || "未知";
      },
      
      // 获取状态样式类
      getStatusClass(status) {
        const statusClassMap = {
          'PENDING': 'status-pending',
          'DEPARTING': 'status-departing',
          'ARRIVED': 'status-arrived',
          'RETURNING': 'status-returning',
          'COMPLETED': 'status-completed',
          'CANCELLED': 'status-cancelled',
          'IN_PROGRESS': 'status-in-progress'
        }
        return statusClassMap[status] || 'status-default'
        PENDING: "status-pending",
        DEPARTING: "status-departing",
        ARRIVED: "status-arrived",
        RETURNING: "status-returning",
        COMPLETED: "status-completed",
        CANCELLED: "status-cancelled",
        IN_PROGRESS: "status-in-progress",
      };
      return statusClassMap[status] || "status-default";
      },
      
      getTaskTypeText(type) {
        const typeMap = {
          'MAINTENANCE': '维修保养',
          'FUEL': '加油',
          'OTHER': '其他',
          'EMERGENCY_TRANSFER': '转运任务',
          'WELFARE': '福祉车'
        }
        return typeMap[type] || '未知类型'
      }
    }
  }
        MAINTENANCE: "维修保养",
        FUEL: "加油",
        OTHER: "其他",
        EMERGENCY_TRANSFER: "转运任务",
        WELFARE: "福祉车",
      };
      return typeMap[type] || "未知类型";
    },
  },
};
</script>
<style lang="scss">
@@ -801,17 +971,6 @@
    }
  }
  
  // 总部推送标记样式
  .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;
@@ -838,7 +997,8 @@
    .header-actions {
      display: flex;
      
      .search-toggle-btn, .refresh-btn {
    .search-toggle-btn,
    .refresh-btn {
        width: 60rpx;
        height: 60rpx;
        border-radius: 50%;
@@ -913,7 +1073,8 @@
      display: flex;
      margin-top: 20rpx;
      
      .search-btn, .reset-btn {
    .search-btn,
    .reset-btn {
        flex: 1;
        height: 70rpx;
        border-radius: 10rpx;
@@ -922,7 +1083,7 @@
      }
      
      .search-btn {
        background-color: #007AFF;
      background-color: #007aff;
        color: white;
      }
    }
@@ -962,7 +1123,7 @@
        font-size: 28rpx;
        
        &.active {
          background-color: #007AFF;
        background-color: #007aff;
          color: white;
        }
      }
@@ -1032,7 +1193,7 @@
            // 出发中 - 蓝色
            &.status-departing {
              background-color: #e3f2fd;
              color: #007AFF;
            color: #007aff;
            }
            
            // 已到达 - 紫色
@@ -1050,7 +1211,7 @@
            // 已完成 - 绿色
            &.status-completed {
              background-color: #e8f5e9;
              color: #34C759;
            color: #34c759;
            }
            
            // 已取消 - 灰色
@@ -1062,7 +1223,7 @@
            // 处理中 (兼容旧数据) - 蓝色
            &.status-in-progress {
              background-color: #e3f2fd;
              color: #007AFF;
            color: #007aff;
            }
            
            // 默认样式
@@ -1073,13 +1234,22 @@
          }
        }
        
        // 任务编号单独一行
      // 任务编号和时间在同一行显示
        .task-code-row {
          margin-bottom: 15rpx;
          padding: 10rpx 0;
          border-bottom: 1rpx dashed #e0e0e0;
        display: flex;
        justify-content: space-between;
          
          .task-code {
          font-size: 28rpx;
          color: #333;
          font-weight: 500;
          font-family: monospace;
        }
        .task-time {
            font-size: 28rpx;
            color: #333;
            font-weight: 500;
@@ -1131,7 +1301,7 @@
          color: #333;
          
          &.primary {
            background-color: #007AFF;
          background-color: #007aff;
            color: white;
          }
          
@@ -1178,5 +1348,27 @@
        color: #666;
      }
    }
  .vip-tag {
    display: inline-block;
    padding: 2rpx 8rpx;
    font-size: 20rpx;
    color: #fff;
    background-color: #ff0000;
    border-radius: 4rpx;
    margin-left: 10rpx;
    vertical-align: middle;
  }
  .hq-tag {
    display: inline-block;
    padding: 2rpx 8rpx;
    font-size: 20rpx;
    color: #fff;
    background-color: #5856d6;
    border-radius: 4rpx;
    margin-left: 10rpx;
    vertical-align: middle;
  }
  }
</style>