| | |
| | | <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> |
| | |
| | | |
| | | <!-- 任务编号单独一行 --> |
| | | <view class="task-code-row"> |
| | | <text class="task-code">{{ task.taskCode }}</text> |
| | | <text class="task-code">{{ task.showTaskCode }}</text> |
| | | </view> |
| | | |
| | | <!-- 任务详细信息 --> |
| | |
| | | <uni-icons type="info" size="40" color="#ccc"></uni-icons> |
| | | <text>暂无任务数据</text> |
| | | </view> |
| | | <!-- 加载更多提示 --> |
| | | <view class="load-more" v-if="filteredTaskList.length > 0 && hasMore"> |
| | | <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"> |
| | | <text>没有更多数据了</text> |
| | | </view> |
| | | </view> |
| | | </scroll-view> |
| | | </view> |
| | |
| | | import { listTask, changeTaskStatus } from '@/api/task' |
| | | import { mapState } from 'vuex' |
| | | import { formatDateTime } from '@/utils/common' |
| | | import { checkTaskCanDepart } from '@/utils/taskValidator' |
| | | |
| | | export default { |
| | | components: { |
| | |
| | | // 任务列表 |
| | | taskList: [], |
| | | loading: false, |
| | | refreshing: false |
| | | refreshing: false, |
| | | |
| | | // 分页相关 |
| | | currentPage: 1, |
| | | pageSize: 10, |
| | | total: 0, |
| | | hasMore: true |
| | | } |
| | | }, |
| | | computed: { |
| | |
| | | // 应用任务编号筛选 - 使用taskCode而不是taskNo |
| | | if (this.searchForm.taskNo) { |
| | | filtered = filtered.filter(task => |
| | | task.taskCode && task.taskCode.includes(this.searchForm.taskNo) |
| | | task.showTaskCode && task.showTaskCode.includes(this.searchForm.taskNo) |
| | | ); |
| | | } |
| | | |
| | |
| | | }, |
| | | onLoad() { |
| | | this.loadTaskList() |
| | | |
| | | // 监听任务列表刷新事件 |
| | | uni.$on('refreshTaskList', this.handleRefreshEvent) |
| | | }, |
| | | onShow() { |
| | | // 页面显示时刷新列表(从其他页面返回时) |
| | | this.loadTaskList() |
| | | }, |
| | | onUnload() { |
| | | // 页面销毁时移除事件监听 |
| | | uni.$off('refreshTaskList', this.handleRefreshEvent) |
| | | }, |
| | | onPullDownRefresh() { |
| | | this.refreshList() |
| | | }, |
| | | // 监听滚动到底部事件 |
| | | onReachBottom() { |
| | | if (this.hasMore && !this.loading) { |
| | | this.loadMore() |
| | | } |
| | | }, |
| | | methods: { |
| | | // 处理刷新事件 |
| | | handleRefreshEvent() { |
| | | console.log('收到刷新任务列表事件') |
| | | this.refreshList() |
| | | }, |
| | | |
| | | // 加载任务列表 |
| | | loadTaskList() { |
| | | this.loading = true |
| | | // 重置分页参数 |
| | | this.currentPage = 1 |
| | | this.hasMore = true |
| | | this.taskList = [] |
| | | |
| | | // 后端会自动获取当前用户信息,实现综合查询 |
| | | // 综合查询:当前用户所在机构任务 + 当前用户创建的任务 + 分配给当前用户的任务 |
| | | const queryParams = { |
| | | pageNum: 1, |
| | | pageSize: 100 |
| | | pageNum: this.currentPage, |
| | | pageSize: this.pageSize, |
| | | orderByColumn: 'create_time', |
| | | isAsc: 'desc' |
| | | } |
| | | |
| | | 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 = '未分配车辆' |
| | |
| | | this.loading = false |
| | | console.error('加载任务列表失败:', error) |
| | | this.$modal.showToast('加载任务列表失败') |
| | | }) |
| | | }, |
| | | |
| | | // 加载更多数据 |
| | | loadMore() { |
| | | if (!this.hasMore || this.loading) return |
| | | |
| | | this.loading = true |
| | | this.currentPage++ |
| | | |
| | | const queryParams = { |
| | | pageNum: this.currentPage, |
| | | pageSize: this.pageSize, |
| | | orderByColumn: 'create_time', |
| | | isAsc: 'desc' |
| | | } |
| | | |
| | | 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 = '未分配车辆' |
| | | if (task.assignedVehicles && task.assignedVehicles.length > 0) { |
| | | // 如果有多个车辆,显示第一个,并标注数量 |
| | | const firstVehicle = task.assignedVehicles[0] |
| | | vehicleInfo = firstVehicle.vehicleNo || '未知车牌' |
| | | if (task.assignedVehicles.length > 1) { |
| | | vehicleInfo += ` 等${task.assignedVehicles.length}辆` |
| | | } |
| | | } |
| | | |
| | | return { |
| | | ...task, |
| | | // 格式化显示字段 - 使用后端返回的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 || '未分配' |
| | | } |
| | | }) |
| | | |
| | | // 将新数据追加到现有列表中 |
| | | this.taskList = [...this.taskList, ...newTasks] |
| | | }).catch(error => { |
| | | this.loading = false |
| | | this.currentPage-- // 出错时回退页码 |
| | | console.error('加载更多任务失败:', error) |
| | | this.$modal.showToast('加载更多任务失败') |
| | | }) |
| | | }, |
| | | |
| | |
| | | this.loadTaskList() |
| | | setTimeout(() => { |
| | | this.refreshing = false |
| | | this.$modal.showToast('列表已刷新'); |
| | | // this.$modal.showToast('列表已刷新'); |
| | | // 停止下拉刷新 |
| | | uni.stopPullDownRefresh() |
| | | }, 1000) |
| | |
| | | |
| | | // 跳转到任务详情页面 - 使用uni.navigateTo |
| | | uni.navigateTo({ |
| | | url: `/pages/task/detail?id=${task.taskId}` |
| | | 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('显示带跳转按钮的弹窗,任务ID:', 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': |
| | |
| | | * { |
| | | -ms-overflow-style: none; /* IE 10+ */ |
| | | } |
| | | } |
| | | |
| | | // 总部推送标记样式 |
| | | .head-push-tag { |
| | | color: #ff0000; |
| | | font-size: 24rpx; |
| | | font-weight: bold; |
| | | margin-left: 10rpx; |
| | | padding: 2rpx 8rpx; |
| | | border: 1rpx solid #ff0000; |
| | | border-radius: 4rpx; |
| | | } |
| | | |
| | | // 任务列表区域 |
| | |
| | | margin-top: 20rpx; |
| | | } |
| | | } |
| | | |
| | | .load-more { |
| | | display: flex; |
| | | justify-content: center; |
| | | align-items: center; |
| | | padding: 20rpx 0; |
| | | color: #999; |
| | | font-size: 28rpx; |
| | | |
| | | &.no-more { |
| | | color: #666; |
| | | } |
| | | } |
| | | } |
| | | </style> |