Files
WXProgram/miniprogram/pages/staff/profile.ts

218 lines
4.5 KiB
TypeScript
Raw Normal View History

2025-10-26 13:15:04 +08:00
// 个人信息页面
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'
});
}
}
});