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

@@ -6,9 +6,13 @@
<view class="header-inner">
<image class="avatar" :src="userInfo.avatar || defautAvatar" @tap="sheep.$router.go('/pages/user/info')"></image>
<view class="user-meta" v-if="userInfo.nickname">
<view class="user-name">{{ userInfo.nickname + `(${userInfo.mobile})` }}</view>
<!-- <view class="user-name">{{ userInfo.nickname + `(${userInfo.mobile})` }}</view> -->
<view class="user-name">{{ userInfo.nickname }}</view>
<view class="user-status" @click="handleStatusToggle">
{{ userInfo.isOnline ? '在线' : '离线' }}<uni-icons style="margin-left:10rpx;" type="right" size="13" color="#fff"></uni-icons>
<text>
{{ userInfo.onlineStatus == 0 ? '离线' : (userInfo.onlineStatus == 1 ? '在线' : '待审核') }}
</text>
<uni-icons style="margin-left:10rpx;" type="right" size="13" color="#fff"></uni-icons>
</view>
</view>
<view class="user-meta" v-else>
@@ -88,14 +92,13 @@
import {
showAuthModal,
} from '@/sheep/hooks/useModal';
import DeliveryApi from '@/sheep/api/member/delivery';
// 现有 store / 模板数据
const template = computed(() => sheep.$store('app').template.user);
const isLogin = computed(() => sheep.$store('user').isLogin);
const userInfo = computed(() => sheep.$store('user').userInfo);
const todayIncome = ref(0);
const todayOrders = ref(0);
const showBind = ref(false);
// 动态 header 内联样式,用于兼容不同平台的状态栏高度
const headerStyle = ref({});
@@ -124,9 +127,6 @@
onShow(async () => {
const data = userInfo.value;
if (data) {
// 兼容后端字段名,优先使用 data.todayIncome / data.income / placeholder
todayIncome.value = data.todayIncome ?? data.income ?? 137.9;
todayOrders.value = data.todayOrders ?? data.orders ?? 39;
if (data?.status == 1) {
console.log("清空缓存");
uni.clearStorageSync();
@@ -161,25 +161,30 @@
// 点击状态:根据当前状态弹不同的确认框
function handleStatusToggle() {
if (userInfo.value.isOnline) {
const status = userInfo.value.onlineStatus;
// 在线状态(1) -> 申请离线
if (status === 1) {
confirmType.value = 'offline';
modalTitle.value = '确认线?';
modalMsg.value = '线需平台进行核准\n此时正常接单请留意核准信息';
modalTitle.value = '确认申请离线?';
modalMsg.value = '线需平台进行核准\n此时无法接单请留意核准信息';
showStatusPopup.value = true;
return;
}
// 如果被禁止接单
if (isUserForbidden()) {
confirmType.value = 'forbidden';
modalTitle.value = '您处于禁止接单状态';
modalMsg.value = '暂无法上线上线';
// 待审核状态(2) -> 提示等待
if (status === 2) {
confirmType.value = 'pending';
modalTitle.value = '等待平台审核';
modalMsg.value = '您的申请正在审核中\n请留意审核结果';
showStatusPopup.value = true;
return;
}
// 普通从离线 -> 上线
// 离线状态(0) -> 申请上线
confirmType.value = 'online';
modalTitle.value = '确认上线?';
modalMsg.value = '';
modalMsg.value = '上线后即可开始接单';
showStatusPopup.value = true;
}
@@ -190,19 +195,34 @@
async function confirmAction() {
const type = confirmType.value;
showStatusPopup.value = false;
if (type === 'online') {
// TODO: 调用后端接口变更上线状态
userInfo.value.isOnline = true;
sheep.$helper && sheep.$helper.toast && sheep.$helper.toast('已上线');
} else if (type === 'offline') {
userInfo.value.isOnline = false;
sheep.$helper && sheep.$helper.toast && sheep.$helper.toast('已下线');
} else if (type === 'forbidden') {
// 仅展示信息,无操作
sheep.$helper && sheep.$helper.toast && sheep.$helper.toast('无法上线(禁止接单)');
try {
if (type === 'online') {
// 调用后端接口变更上线状态
const res = await DeliveryApi.postOnline();
if (res.code === 0) {
userInfo.value.onlineStatus = 2; // 变为待审核状态
sheep.$helper.toast('已提交上线申请,请等待平台核准');
} else {
sheep.$helper.toast(res.msg || '上线申请失败');
}
} else if (type === 'offline') {
// 调用后端接口申请离线
const res = await DeliveryApi.offlineApply();
if (res.code === 0) {
userInfo.value.onlineStatus = 0; // 变为离线状态
sheep.$helper.toast('已提交离线申请,请等待平台核准');
} else {
sheep.$helper.toast(res.msg || '离线申请失败');
}
} else if (type === 'pending') {
// 待审核状态,仅提示
sheep.$helper.toast('请等待平台审核');
}
} catch (error) {
console.error('上下线操作异常:', error);
sheep.$helper.toast('操作异常,请重试');
}
// 可在此处调用 store 或 API 同步服务端状态,例如:
// await sheep.$store('user').setOnline(user.value.isOnline);
}
onPullDownRefresh(() => {