You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

238 lines
6.6 KiB
Vue

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<template>
<view class="order-page">
<uni-data-select
v-model="value"
:localdata="range"
style="
margin-bottom: 5px;
"
placeholder="请选择巷道"
@change="change"
></uni-data-select>
<!-- 下拉刷新 -->
<u-pull-refresh
:refreshing="refreshing" @refresh="onRefresh">
<!-- 订单卡片列表 -->
<view v-for="(item, index) in orderList" :key="index" class="order-card">
<view class="order-info">
<!-- 详情链接 -->
<text class="detail-link" @click="goToDetail(item)">详情</text>
<text class="order-name">任务号:{{ item.taskId }}</text>
<text class="order-time">状态:{{ item.statusName }}</text>
<text class="order-time">地址:{{ this.position(item) }}</text>
<text class="order-time">时间:{{ this.formatTime(item.createTime) }}</text>
<!-- 图片显示 -->
<view class="pics-container" v-if="item.urlResources">
<u-image
v-for="(pic, picIndex) in item.urlResources"
:key="picIndex"
:title="pic.url"
:src="pic.url" width="80px" height="80px"
class="order-pic"
mode="aspectFill"
/>
</view>
</view>
</view>
<!-- 上拉加载更多 -->
<u-loadmore :status="loadStatus" @loadmore="onLoadMore" />
</u-pull-refresh>
</view>
</template>
<script>
import request from '@/utils/request';
export default {
data() {
return {
orderList: [], // 订单列表
pageNum: 1, // 当前页码
pageSize: 15, // 每页条数
streetId:null,
range: [
],
refreshing: false,
loadStatus: 'loadmore', // 加载状态loadmore/loading/nomore
total: 0 // 总数据量
}
},
onLoad() {
this.getStreetList();
this.loadOrders(); // 初始化加载
},
methods: {
formatTime(timestamp) {
const date = new Date(timestamp);
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
const seconds = String(date.getSeconds()).padStart(2, '0');
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
},
position(row) {
const from = row.fromSide == 2 ? "库外" : row.streetName + "-" + (row.direction ? "左侧-" : "右侧-") + row.row + '层-' + row.column + '列' + (row.side == 2 ? "深货位" : "");
return from;
},
// 跳转到详情页
goToDetail(item) {
uni.navigateTo({
url: `/pages/tabbar/stock/detail?data=${encodeURIComponent(JSON.stringify(item))}`
});
},
async getStreetList() {
try {
const res = await request({
url: '/admin-api/logistics/street/list',
method: 'GET',
data: {
}
});
if (res.data.code === 200) {
console.log(res.data.data);
this.range = res.data.data;
} else {
uni.showToast({ title: res.data.msg || '加载失败', icon: 'none' });
this.loadStatus = 'loadmore';
}
} catch (error) {
console.error('加载订单失败:', error);
uni.showToast({ title: '网络错误', icon: 'none' });
this.loadStatus = 'loadmore';
}
},
/**
* 加载订单数据
*
* 该方法用于异步加载订单列表数据,支持分页加载和追加数据。
*
* @async
* @function loadOrders
* @description
* 1. 设置加载状态为 'loading'。
* 2. 发起 GET 请求获取订单数据,请求参数包括页码、每页数量和街道 ID。
* 3. 处理响应数据:
* - 如果响应成功code === 200更新订单列表和总数
* - 如果是第一页,直接覆盖订单列表。
* - 如果是后续页,追加数据到现有列表。
* - 如果响应失败,显示错误提示。
* 4. 捕获异常时,显示网络错误提示。
*
* @throws {Error} 如果请求失败或网络异常,抛出错误并显示提示。
*
* @example
* await loadOrders();
*/
// 加载订单数据
async loadOrders() {
this.loadStatus = 'loading';
try {
const res = await request({
url: '/admin-api/logistics/check-log/page',
method: 'GET',
data: {
pageNo: this.pageNum,
pageSize: this.pageSize,
streetId: this.streetId
}
});
if (res.data.code === 200) {
const { list, total } = res.data.data;
this.total = total;
if (this.pageNum === 1) {
this.orderList = list; // 第一页直接覆盖
} else {
this.orderList = [...this.orderList, ...list]; // 追加数据
}
this.pageNum++;
// 判断是否还有更多数据
this.loadStatus = this.orderList.length < total ? 'loadmore' : 'nomore';
} else {
uni.showToast({ title: res.data.msg || '加载失败', icon: 'none' });
this.loadStatus = 'loadmore';
}
} catch (error) {
console.error('加载订单失败:', error);
uni.showToast({ title: '网络错误', icon: 'none' });
this.loadStatus = 'loadmore';
}
},
// 下拉刷新
onRefresh() {
this.refreshing = true;
this.pageNum = 1;
this.loadOrders().finally(() => {
this.refreshing = false;
});
console.log('下拉刷新');
},
// 上拉加载更多
onLoadMore() {
if (this.loadStatus === 'nomore') return;
this.loadOrders();
}
}
}
</script>
<style scoped>
.order-page {
padding: 20rpx;
background-color: #f7f7f7;
}
.order-card {
display: flex;
margin-bottom: 20rpx;
padding: 20rpx;
background: #fff;
border-radius: 10rpx;
box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
position: relative;
}
.order-info {
flex: 1;
margin-left: 20rpx;
}
.order-name {
display: block;
font-size: 32rpx;
font-weight: bold;
}
.order-time {
display: block;
margin-top: 10rpx;
color: #999;
font-size: 24rpx;
}
/* 详情链接样式 */
.detail-link {
position: absolute;
top: 20rpx;
right: 20rpx;
color: #007AFF;
font-size: 28rpx;
}
/* 图片样式 - 横向排列 */
.pics-container {
display: flex;
flex-direction: row;
flex-wrap: wrap;
margin-top: 10rpx;
gap: 10rpx;
}
.order-pic {
width: 80px;
height: 80px;
border-radius: 8rpx;
}
</style>