234 lines
5.1 KiB
TypeScript
234 lines
5.1 KiB
TypeScript
// 员工界面 - 全屏工作面板
|
||
import { UserInfo } from '../../types';
|
||
import userService from '../../services/userService';
|
||
import statisticsService from '../../services/statisticsService';
|
||
|
||
Page({
|
||
data: {
|
||
userInfo: null as UserInfo | null,
|
||
// Grid布局的功能菜单
|
||
menuItems: [
|
||
{
|
||
id: 'orders',
|
||
name: '我的订单',
|
||
icon: '📦',
|
||
color: '#3498db',
|
||
description: '查看分配订单'
|
||
},
|
||
{
|
||
id: 'location',
|
||
name: '位置上报',
|
||
icon: '📍',
|
||
color: '#e74c3c',
|
||
description: '上报当前位置'
|
||
},
|
||
{
|
||
id: 'schedule',
|
||
name: '工作安排',
|
||
icon: '📅',
|
||
color: '#f39c12',
|
||
description: '查看工作计划'
|
||
},
|
||
{
|
||
id: 'profile',
|
||
name: '个人信息',
|
||
icon: '👤',
|
||
color: '#9b59b6',
|
||
description: '个人资料管理'
|
||
},
|
||
{
|
||
id: 'messages',
|
||
name: '消息通知',
|
||
icon: '📨',
|
||
color: '#34495e',
|
||
description: '查看系统消息'
|
||
},
|
||
{
|
||
id: 'help',
|
||
name: '帮助中心',
|
||
icon: '❓',
|
||
color: '#27ae60',
|
||
description: '使用帮助文档'
|
||
}
|
||
],
|
||
// 工作统计
|
||
workStats: {
|
||
todayOrders: 0,
|
||
completedOrders: 0,
|
||
pendingOrders: 0
|
||
}
|
||
},
|
||
|
||
onLoad() {
|
||
this.getUserInfo();
|
||
this.loadWorkStats();
|
||
},
|
||
|
||
onShow() {
|
||
this.loadWorkStats();
|
||
},
|
||
|
||
/**
|
||
* 获取用户信息
|
||
*/
|
||
getUserInfo() {
|
||
const app = getApp<any>();
|
||
if (app.globalData.userInfo) {
|
||
const userInfo = app.globalData.userInfo;
|
||
this.setData({ userInfo });
|
||
}
|
||
},
|
||
|
||
/**
|
||
* 加载工作统计数据
|
||
*/
|
||
async loadWorkStats() {
|
||
try {
|
||
// 调用API获取工作统计数据
|
||
const workStats = await statisticsService.getWorkStats();
|
||
this.setData({ workStats });
|
||
} catch (error) {
|
||
console.error('加载工作统计数据失败:', error);
|
||
// 如果API调用失败,设置默认值
|
||
this.setData({
|
||
workStats: {
|
||
todayOrders: 0,
|
||
completedOrders: 0,
|
||
pendingOrders: 0
|
||
}
|
||
});
|
||
}
|
||
},
|
||
|
||
/**
|
||
* 菜单项点击事件
|
||
*/
|
||
onMenuItemTap(e: any) {
|
||
const itemId = e.currentTarget.dataset.id;
|
||
|
||
switch (itemId) {
|
||
case 'orders':
|
||
wx.navigateTo({
|
||
url: '/pages/staff/my-orders'
|
||
});
|
||
break;
|
||
case 'location':
|
||
wx.navigateTo({
|
||
url: '/pages/staff/location-report'
|
||
});
|
||
break;
|
||
case 'schedule':
|
||
wx.navigateTo({
|
||
url: '/pages/staff/work-schedule'
|
||
});
|
||
break;
|
||
case 'profile':
|
||
wx.navigateTo({
|
||
url: '/pages/staff/profile'
|
||
});
|
||
break;
|
||
case 'messages':
|
||
wx.navigateTo({
|
||
url: '/pages/staff/messages'
|
||
});
|
||
break;
|
||
case 'help':
|
||
wx.navigateTo({
|
||
url: '/pages/staff/help'
|
||
});
|
||
break;
|
||
}
|
||
},
|
||
|
||
/**
|
||
* 返回首页
|
||
*/
|
||
goBack() {
|
||
wx.navigateBack();
|
||
},
|
||
|
||
/**
|
||
* 刷新数据
|
||
*/
|
||
onRefresh() {
|
||
this.loadWorkStats();
|
||
wx.showToast({
|
||
title: '数据已刷新',
|
||
icon: 'success'
|
||
});
|
||
},
|
||
|
||
/**
|
||
* 紧急联系
|
||
*/
|
||
onEmergencyContact() {
|
||
wx.makePhoneCall({
|
||
phoneNumber: '400-123-4567'
|
||
});
|
||
},
|
||
|
||
/**
|
||
* 解绑微信处理
|
||
*/
|
||
async onUnbindWechat() {
|
||
try {
|
||
// 确认对话框
|
||
wx.showModal({
|
||
title: '确认解绑',
|
||
content: '解绑微信后,您将需要重新登录并绑定账号。确定要继续吗?',
|
||
confirmText: '确定解绑',
|
||
confirmColor: '#e74c3c',
|
||
cancelText: '取消',
|
||
success: async (res) => {
|
||
if (res.confirm) {
|
||
// 显示加载中
|
||
wx.showLoading({
|
||
title: '解绑中...',
|
||
mask: true
|
||
});
|
||
|
||
try {
|
||
// 调用解绑服务
|
||
const result = await userService.unbindWechat();
|
||
|
||
wx.hideLoading();
|
||
|
||
if (result.success) {
|
||
wx.showToast({
|
||
title: '解绑成功',
|
||
icon: 'success',
|
||
duration: 2000
|
||
});
|
||
|
||
// 延迟跳转到登录页面
|
||
setTimeout(() => {
|
||
wx.reLaunch({
|
||
url: '/pages/login/login'
|
||
});
|
||
}, 2000);
|
||
} else {
|
||
wx.showToast({
|
||
title: result.message || '解绑失败',
|
||
icon: 'none'
|
||
});
|
||
}
|
||
} catch (error) {
|
||
wx.hideLoading();
|
||
wx.showToast({
|
||
title: '解绑失败,请重试',
|
||
icon: 'none'
|
||
});
|
||
console.error('解绑微信错误:', error);
|
||
}
|
||
}
|
||
}
|
||
});
|
||
} catch (error) {
|
||
console.error('解绑微信处理错误:', error);
|
||
wx.showToast({
|
||
title: '操作失败,请重试',
|
||
icon: 'none'
|
||
});
|
||
}
|
||
}
|
||
}); |