218 lines
4.5 KiB
TypeScript
218 lines
4.5 KiB
TypeScript
|
|
// 个人信息页面
|
|||
|
|
import { UserInfo } from '../../types';
|
|||
|
|
import userService from '../../services/userService';
|
|||
|
|
import statisticsService from '../../services/statisticsService';
|
|||
|
|
|
|||
|
|
Page({
|
|||
|
|
data: {
|
|||
|
|
userInfo: null as UserInfo | null,
|
|||
|
|
// 个人统计数据
|
|||
|
|
personalStats: {
|
|||
|
|
totalOrders: 0, // 总订单数
|
|||
|
|
completedOrders: 0, // 已完成订单数
|
|||
|
|
pendingOrders: 0, // 待处理订单数
|
|||
|
|
deliveryRate: 0, // 配送成功率
|
|||
|
|
averageTime: 0 // 平均配送时间
|
|||
|
|
},
|
|||
|
|
// 系统统计数据
|
|||
|
|
systemStats: {
|
|||
|
|
employeeCount: 0, // 员工总数
|
|||
|
|
orderCount: 0, // 订单总数
|
|||
|
|
warehouseCount: 0 // 仓库总数
|
|||
|
|
},
|
|||
|
|
loading: true
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
onLoad() {
|
|||
|
|
this.loadUserInfo();
|
|||
|
|
this.loadStatistics();
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
onShow() {
|
|||
|
|
// 页面显示时重新加载数据
|
|||
|
|
this.loadUserInfo();
|
|||
|
|
this.loadStatistics();
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 加载用户信息
|
|||
|
|
*/
|
|||
|
|
async loadUserInfo() {
|
|||
|
|
try {
|
|||
|
|
const app = getApp<any>();
|
|||
|
|
if (app.globalData.userInfo) {
|
|||
|
|
this.setData({
|
|||
|
|
userInfo: app.globalData.userInfo
|
|||
|
|
});
|
|||
|
|
} else {
|
|||
|
|
// 如果没有全局用户信息,尝试从API获取
|
|||
|
|
const userInfo = await userService.getUserInfo();
|
|||
|
|
this.setData({ userInfo });
|
|||
|
|
}
|
|||
|
|
} catch (error) {
|
|||
|
|
console.error('加载用户信息失败:', error);
|
|||
|
|
wx.showToast({
|
|||
|
|
title: '加载用户信息失败',
|
|||
|
|
icon: 'none'
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 加载统计数据
|
|||
|
|
*/
|
|||
|
|
async loadStatistics() {
|
|||
|
|
this.setData({ loading: true });
|
|||
|
|
|
|||
|
|
try {
|
|||
|
|
wx.showLoading({
|
|||
|
|
title: '加载统计数据...'
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
// 强制刷新统计数据,不使用缓存
|
|||
|
|
const systemStats = await statisticsService.getSystemStats(true);
|
|||
|
|
|
|||
|
|
// 获取个人统计数据(这里需要根据用户ID获取个人统计数据)
|
|||
|
|
const personalStats = await this.getPersonalStats();
|
|||
|
|
|
|||
|
|
this.setData({
|
|||
|
|
systemStats: {
|
|||
|
|
employeeCount: systemStats.employeeCount,
|
|||
|
|
orderCount: systemStats.orderCount,
|
|||
|
|
warehouseCount: systemStats.warehouseCount
|
|||
|
|
},
|
|||
|
|
personalStats,
|
|||
|
|
loading: false
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
wx.hideLoading();
|
|||
|
|
} catch (error) {
|
|||
|
|
console.error('加载统计数据失败:', error);
|
|||
|
|
this.setData({ loading: false });
|
|||
|
|
wx.hideLoading();
|
|||
|
|
|
|||
|
|
wx.showToast({
|
|||
|
|
title: '加载统计数据失败',
|
|||
|
|
icon: 'none'
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 获取个人统计数据
|
|||
|
|
*/
|
|||
|
|
async getPersonalStats() {
|
|||
|
|
try {
|
|||
|
|
// 这里应该调用个人统计API
|
|||
|
|
// 暂时使用模拟数据
|
|||
|
|
return {
|
|||
|
|
totalOrders: 156,
|
|||
|
|
completedOrders: 142,
|
|||
|
|
pendingOrders: 14,
|
|||
|
|
deliveryRate: 91.0,
|
|||
|
|
averageTime: 45
|
|||
|
|
};
|
|||
|
|
} catch (error) {
|
|||
|
|
console.error('获取个人统计数据失败:', error);
|
|||
|
|
// 返回默认值
|
|||
|
|
return {
|
|||
|
|
totalOrders: 0,
|
|||
|
|
completedOrders: 0,
|
|||
|
|
pendingOrders: 0,
|
|||
|
|
deliveryRate: 0,
|
|||
|
|
averageTime: 0
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 刷新数据
|
|||
|
|
*/
|
|||
|
|
onRefresh() {
|
|||
|
|
this.loadStatistics();
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 返回上一页
|
|||
|
|
*/
|
|||
|
|
goBack() {
|
|||
|
|
wx.navigateBack();
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 编辑个人信息
|
|||
|
|
*/
|
|||
|
|
onEditProfile() {
|
|||
|
|
wx.showToast({
|
|||
|
|
title: '编辑功能开发中',
|
|||
|
|
icon: 'none'
|
|||
|
|
});
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 查看历史订单
|
|||
|
|
*/
|
|||
|
|
onViewHistory() {
|
|||
|
|
wx.navigateTo({
|
|||
|
|
url: '/pages/staff/order-management'
|
|||
|
|
});
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 联系客服
|
|||
|
|
*/
|
|||
|
|
onContactSupport() {
|
|||
|
|
wx.makePhoneCall({
|
|||
|
|
phoneNumber: '400-123-4567'
|
|||
|
|
});
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 退出登录
|
|||
|
|
*/
|
|||
|
|
onLogout() {
|
|||
|
|
wx.showModal({
|
|||
|
|
title: '确认退出',
|
|||
|
|
content: '确定要退出登录吗?',
|
|||
|
|
success: (res) => {
|
|||
|
|
if (res.confirm) {
|
|||
|
|
this.performLogout();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 执行退出登录操作
|
|||
|
|
*/
|
|||
|
|
async performLogout() {
|
|||
|
|
try {
|
|||
|
|
wx.showLoading({
|
|||
|
|
title: '退出中...'
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
// 调用用户服务的退出登录方法
|
|||
|
|
const userService = require('../../services/userService').default;
|
|||
|
|
await userService.logout();
|
|||
|
|
|
|||
|
|
// 清除全局用户信息
|
|||
|
|
const app = getApp<any>();
|
|||
|
|
app.globalData.userInfo = null;
|
|||
|
|
|
|||
|
|
wx.hideLoading();
|
|||
|
|
|
|||
|
|
// 跳转到首页
|
|||
|
|
wx.reLaunch({
|
|||
|
|
url: '/pages/index/index'
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
} catch (error) {
|
|||
|
|
console.error('退出登录失败:', error);
|
|||
|
|
wx.hideLoading();
|
|||
|
|
wx.showToast({
|
|||
|
|
title: '退出登录失败',
|
|||
|
|
icon: 'none'
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
});
|