fix: 配送单页面接口数据对接,去除部分失效接口调用

This commit is contained in:
admin
2026-02-06 16:02:09 +08:00
parent c89af4c6a3
commit b85833690f
10 changed files with 318 additions and 113 deletions

View File

@@ -9,8 +9,10 @@
<image class="user-avatar" @tap="sheep.$router.go('/pages/index/user')"
:src="driverInfo.avatar || defaultAvatar" mode="cover" />
<view class="user-meta">
<!-- <text class="user-name">{{ driverInfo.nickName || '骑手姓名' }}</text> -->
<text class="user-status" @click="toggleOnline">{{ driverInfo.isOnline ? '在线中' : '离线' }}</text>
<!-- <text class="user-status" @click="toggleOnline">{{ driverInfo.isOnline ? '在线中' : '离线' }}</text> -->
<text class="user-status">
{{ driverInfo.onlineStatus == 0 ? '离线' : (driverInfo.onlineStatus == 1 ? '在线' : '待审核') }}
</text>
</view>
</view>
<view class="tabs">
@@ -48,10 +50,10 @@
<view class="address-row">
<view class="icon pickup"></view>
<view class="address-content">
<text class="address-title">{{ order.pickupAddress }}</text>
<text class="address-sub">商家已出餐 · {{ order.pickupNote || '' }}</text>
<text class="address-title">{{ order.shopAddress }}</text>
<text class="address-sub">商家 · {{ order.shopPhone || '' }}</text>
</view>
<view class="nav-icon" @click="openMap(order.pickupLat, order.pickupLng, order.pickupAddress)">导航</view>
<view class="nav-icon" @click="openMap(order.shopLat, order.shopLng, order.shopAddress)">导航</view>
</view>
<view class="address-row">
<view class="icon deliver"></view>
@@ -62,11 +64,6 @@
<view class="nav-icon" @click="openMap(order.deliveryLat, order.deliveryLng, order.deliveryAddress)">导航</view>
</view>
</view>
<!-- 备注 -->
<view class="order-note" v-if="order.note">
<text>顾客{{ order.note }}</text>
</view>
</view>
<!-- 操作区 -->
@@ -74,9 +71,12 @@
<view class="contact" @click="callPhone(order.receiverPhone)">
<text>联系</text>
</view>
<view class="confirm" @click="confirmArrive(order.id)">
<view class="confirm" @click="confirmArrive(order.id)" v-if="order.deliveryStatus == 2">
<text>确认到店</text>
</view>
<view class="confirm" @click="confirmPickup(order.id)" v-if="order.deliveryStatus == 3">
<text>确认取餐</text>
</view>
</view>
</view>
</scroll-view>
@@ -94,6 +94,7 @@ import { ref, computed, onMounted } from 'vue';
import sheep from '@/sheep';
import { onShow } from '@dcloudio/uni-app';
import OrderCodePopup from './components/order-code-popup.vue';
import DeliveryOrderApi from '@/sheep/api/member/deliveryOrder';
// 驿站/骑手信息(从 store 获取或 mock
const driverInfo = ref({
@@ -107,56 +108,119 @@ const defaultAvatar = 'https://huichibao.oss-cn-guangzhou.aliyuncs.com/1/materia
// 页面状态
const activeTab = ref('pickup'); // 'pickup' | 'delivering'
const listHeight = ref(600);
const loading = ref(false);
const noMore = ref(false);
// Mock 订单数据(真实项目应从后端接口拉取 / store
const orders = ref([
{
id: 1001,
type: 'pickup',
statusText: '待取货',
shopName: '取货点店铺名称',
pickupAddress: '广东省广州市天河区学院站荷光路118-121号',
pickupLat: 23.1,
pickupLng: 113.3,
pickupNote: '商家已出餐',
deliveryAddress: '广东省广州市天河区华景新城软件园区',
deliveryLat: 23.12,
deliveryLng: 113.31,
receiverName: '张先生',
receiverPhone: '13900001234',
note: '根据餐量提供餐具'
},
{
id: 1002,
type: 'pickup',
statusText: '待取货',
shopName: '乐易购(学院店)',
pickupAddress: '广东省广州市天河区学院站荷光路118--121号',
pickupLat: 23.11,
pickupLng: 113.32,
pickupNote: '',
deliveryAddress: '广东省广州市天河区某小区',
deliveryLat: 23.13,
deliveryLng: 113.33,
receiverName: '李女士',
receiverPhone: '13900005678',
note: ''
}
]);
// 配送单列表数据
const orders = ref([]);
const pagination = ref({
pageNo: 1,
pageSize: 10,
total: 0
});
// 计算各 tab 数量与过滤列表
// deliveryStatus 到页面 type 的映射
const statusToTypeMap = {
'3': 'pickup', // 骑手待取货 -> 待取货
'4': 'delivering', // 配送中待送达交接点 -> 配送中
'5': 'delivering', // 配送中送达交接点待分配 -> 配送中
'6': 'delivering' // 配送中待送达顾客 -> 配送中
};
// deliveryStatus 状态文本映射
const deliveryStatusTextMap = {
'-1': '配送异常',
'0': '已取消',
'1': '待接单',
'2': '骑手待到店',
'3': '待取货',
'4': '待送达交接点',
'5': '送达交接点待分配',
'6': '待送达顾客',
'7': '已完成'
};
// 计算各 tab 数量
const pickupCount = computed(() => orders.value.filter(o => o.type === 'pickup').length);
const deliveringCount = computed(() => orders.value.filter(o => o.type === 'delivering').length);
const filteredOrders = computed(() => {
if (activeTab.value === 'pickup') {
return orders.value.filter(o => o.type === 'pickup');
const filteredOrders = computed(() => orders.value);
// 加载订单列表数据
async function loadOrders(isLoadMore = false) {
if (loading.value) return;
loading.value = true;
// 根据当前 tab 确定接口参数 status
const status = activeTab.value === 'pickup' ? 1 : 2;
try {
const res = await DeliveryOrderApi.getPageByDeliveryManId({
pageNo: pagination.value.pageNo,
pageSize: pagination.value.pageSize,
status: status
});
if (res.code === 0 && res.data) {
const records = res.data.records || [];
// 转换接口数据为页面所需格式
const transformedOrders = records.map(item => {
const deliveryStatus = String(item.deliveryStatus);
return {
id: item.id,
type: statusToTypeMap[deliveryStatus] || 'pickup',
statusText: deliveryStatusTextMap[deliveryStatus] || '未知状态',
shopName: item.shopName || '',
shopAddress: item.shopAddress || '',
shopLat: item.shopLatitude || null,
shopLng: item.shopLongitude || null,
shopPhone: item.shopPhone || '',
shopShipmentStatus: item.shopShipmentStatus,
deliveryAddress: item.receiverAddress || '',
deliveryLat: item.receiverLatitude || null,
deliveryLng: item.receiverLongitude || null,
receiverName: item.receiverName || '',
receiverPhone: item.receiverPhone || '',
deliveryStatus: item.deliveryStatus
};
});
if (isLoadMore) {
orders.value = [...orders.value, ...transformedOrders];
} else {
orders.value = transformedOrders;
}
// 更新分页信息
pagination.value.total = res.data.total || 0;
pagination.value.pageNo = res.data.current || 1;
// 判断是否还有更多数据
noMore.value = orders.value.length >= pagination.value.total;
} else {
sheep.$helper.toast(res.msg || '加载失败');
}
} catch (error) {
console.error('加载订单列表异常:', error);
sheep.$helper.toast('加载失败,请重试');
} finally {
loading.value = false;
}
return orders.value.filter(o => o.type === 'delivering');
});
}
// 刷新列表
function refreshOrders() {
pagination.value.pageNo = 1;
noMore.value = false;
loadOrders(false);
}
// 切换 tab
function switchTab(tab) {
if (activeTab.value === tab) return;
activeTab.value = tab;
refreshOrders();
}
// 切换上线/下线(简单 UI 切换,建议接入后端)
@@ -165,15 +229,49 @@ function toggleOnline() {
sheep.$helper && sheep.$helper.toast && sheep.$helper.toast(driverInfo.value.isOnline ? '已上线' : '已下线');
}
// 确认到店(演示:改变订单状态)
function confirmArrive(orderId) {
// 确认到店
async function confirmArrive(orderId) {
const order = orders.value.find(o => o.id === orderId);
if (!order) return;
// 示例逻辑:到店后将类型改为 delivering
if (order.type === 'pickup') {
order.type = 'delivering';
order.statusText = '配送中';
sheep.$helper && sheep.$helper.toast && sheep.$helper.toast('已确认到店,开始配送');
if (order.type !== 'pickup') return;
try {
const res = await DeliveryOrderApi.riderConfirmArrival(orderId);
if (res.code === 0 && res.data === true) {
// 接口返回成功,更新本地订单状态
order.type = 'delivering';
order.statusText = '配送中';
order.deliveryStatus = 4; // 状态更新为待送达交接点
sheep.$helper.toast('已确认到店,开始配送');
} else {
sheep.$helper.toast(res.msg || '确认到店失败');
}
} catch (error) {
console.error('确认到店异常:', error);
sheep.$helper.toast('操作异常,请重试');
}
}
// 确认取餐
async function confirmPickup(orderId) {
const order = orders.value.find(o => o.id === orderId);
if (!order) return;
try {
const res = await DeliveryOrderApi.riderConfirmPickup(orderId);
if (res.code === 0 && res.data === true) {
// 接口返回成功,更新本地订单状态为配送中
order.type = 'delivering';
order.statusText = '配送中';
order.deliveryStatus = 4; // 状态更新为待送达交接点
sheep.$helper.toast('已确认取餐,开始配送');
} else {
sheep.$helper.toast(res.msg || '确认取餐失败');
}
} catch (error) {
console.error('确认取餐异常:', error);
sheep.$helper.toast('操作异常,请重试');
}
}
@@ -262,6 +360,8 @@ onMounted(() => {
onShow(() => {
// 每次页面显示时重新计算(兼容热更或状态变化)
setHeaderSafeArea();
// 加载订单列表
refreshOrders();
});
</script>