wlzboy
4 小时以前 5f2ee03958a1a16dc27195c76ea7cffb422c95d1
app/pages/task/index.vue
@@ -213,6 +213,14 @@
            <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>
@@ -251,7 +259,13 @@
        // 任务列表
        taskList: [],
        loading: false,
        refreshing: false
        refreshing: false,
        // 分页相关
        currentPage: 1,
        pageSize: 10,
        total: 0,
        hasMore: true
      }
    },
    computed: {
@@ -342,6 +356,12 @@
    onPullDownRefresh() {
      this.refreshList()
    },
    // 监听滚动到底部事件
    onReachBottom() {
      if (this.hasMore && !this.loading) {
        this.loadMore()
      }
    },
    methods: {
      // 处理刷新事件
      handleRefreshEvent() {
@@ -352,16 +372,27 @@
      // 加载任务列表
      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 = '未分配车辆'
@@ -389,6 +420,60 @@
          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('加载更多任务失败')
        })
      },
      
@@ -1080,5 +1165,18 @@
        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>