2025-10-18 22:21:04 +08:00
|
|
|
|
// 员工模块 - 处理所有员工(管理员和货运人员)管理、位置跟踪、交互
|
|
|
|
|
import employeeService from '../../../services/employeeService';
|
|
|
|
|
import { Role } from '../../../utils/roleUtils';
|
|
|
|
|
// getApp是微信小程序全局函数,无需导入
|
2025-10-16 21:32:16 +08:00
|
|
|
|
|
|
|
|
|
import { showToast } from '../../../utils/helpers';
|
|
|
|
|
import { DataModule } from './dataModule';
|
|
|
|
|
|
2025-10-18 22:21:04 +08:00
|
|
|
|
export class EmployeeModule {
|
2025-10-16 21:32:16 +08:00
|
|
|
|
private pageContext: any;
|
|
|
|
|
private dataModule: DataModule;
|
|
|
|
|
|
|
|
|
|
constructor(pageContext: any, dataModule: DataModule) {
|
|
|
|
|
this.pageContext = pageContext;
|
|
|
|
|
this.dataModule = dataModule;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-10-18 22:21:04 +08:00
|
|
|
|
* 加载所有员工数据(包括管理员和货运人员)
|
2025-10-16 21:32:16 +08:00
|
|
|
|
*/
|
2025-10-18 22:21:04 +08:00
|
|
|
|
async loadAllEmployees(): Promise<void> {
|
2025-10-16 21:32:16 +08:00
|
|
|
|
try {
|
2025-10-18 22:21:04 +08:00
|
|
|
|
// 获取所有员工数据
|
|
|
|
|
const allEmployees = await employeeService.getEmployees();
|
2025-10-16 21:32:16 +08:00
|
|
|
|
|
2025-10-18 22:21:04 +08:00
|
|
|
|
console.log('所有员工数据加载完成,数量:', allEmployees.length);
|
2025-10-16 21:32:16 +08:00
|
|
|
|
} catch (error) {
|
2025-10-18 22:21:04 +08:00
|
|
|
|
console.error('加载员工数据失败:', error);
|
|
|
|
|
showToast('加载员工数据失败');
|
2025-10-16 21:32:16 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-10-18 22:21:04 +08:00
|
|
|
|
* 获取员工角色对应的图标
|
2025-10-16 21:32:16 +08:00
|
|
|
|
*/
|
2025-10-18 22:21:04 +08:00
|
|
|
|
private getEmployeeIcon(role: string): string {
|
|
|
|
|
console.log(`获取员工图标,角色: ${role}`);
|
2025-10-16 21:32:16 +08:00
|
|
|
|
|
2025-10-18 22:21:04 +08:00
|
|
|
|
// 根据角色使用不同的图标
|
2025-10-16 21:32:16 +08:00
|
|
|
|
let iconPath = '';
|
|
|
|
|
|
2025-10-18 22:21:04 +08:00
|
|
|
|
switch (role) {
|
|
|
|
|
case Role.ADMIN:
|
|
|
|
|
// 管理员使用皇冠图标
|
|
|
|
|
iconPath = '/images/crown.png';
|
|
|
|
|
console.log('使用管理员图标(👑)');
|
2025-10-16 21:32:16 +08:00
|
|
|
|
break;
|
2025-10-18 22:21:04 +08:00
|
|
|
|
case Role.DELIVERY_PERSON:
|
|
|
|
|
// 货运人员使用货车图标
|
|
|
|
|
iconPath = '/images/truck.png';
|
|
|
|
|
console.log('使用货运人员图标(🚚)');
|
2025-10-16 21:32:16 +08:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2025-10-18 22:21:04 +08:00
|
|
|
|
// 默认使用货车图标
|
|
|
|
|
iconPath = '/images/truck.png';
|
|
|
|
|
console.log('使用默认图标(🚚)');
|
2025-10-16 21:32:16 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log(`最终使用图标路径: ${iconPath}`);
|
|
|
|
|
|
|
|
|
|
return iconPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 显示货运人员详情面板
|
|
|
|
|
*/
|
|
|
|
|
showDeliveryPersonPanel(person: any, position: { x: number, y: number }): void {
|
|
|
|
|
// 关闭其他面板
|
|
|
|
|
this.pageContext.hideAllPanels();
|
|
|
|
|
|
|
|
|
|
this.dataModule.setCurrentDeliveryPerson(person);
|
|
|
|
|
this.dataModule.setPanelPosition(position);
|
|
|
|
|
this.dataModule.toggleDeliveryPersonModal(true, 'bottom');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 隐藏货运人员详情面板
|
|
|
|
|
*/
|
|
|
|
|
hideDeliveryPersonPanel(): void {
|
|
|
|
|
this.dataModule.toggleDeliveryPersonModal(false);
|
|
|
|
|
this.dataModule.setCurrentDeliveryPerson(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 展开货运人员详情面板
|
|
|
|
|
*/
|
|
|
|
|
expandDeliveryPersonPanel(): void {
|
|
|
|
|
this.dataModule.toggleDeliveryPersonModal(true, 'full');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 收起货运人员详情面板
|
|
|
|
|
*/
|
|
|
|
|
collapseDeliveryPersonPanel(): void {
|
|
|
|
|
this.dataModule.toggleDeliveryPersonModal(true, 'bottom');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 处理货运人员标记点点击
|
|
|
|
|
*/
|
|
|
|
|
onDeliveryPersonMarkerClick(person: any, position: { x: number, y: number }): void {
|
|
|
|
|
console.log('货运人员被点击:', person);
|
|
|
|
|
|
|
|
|
|
// 显示货运人员详情面板
|
|
|
|
|
this.showDeliveryPersonPanel(person, position);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取货运人员状态文本
|
|
|
|
|
*/
|
|
|
|
|
getDeliveryPersonStatusText(status: string): string {
|
|
|
|
|
const statusMap: Record<string, string> = {
|
|
|
|
|
'idle': '空闲',
|
|
|
|
|
'busy': '忙碌',
|
|
|
|
|
'offline': '离线'
|
|
|
|
|
};
|
|
|
|
|
return statusMap[status] || status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取货运人员状态颜色
|
|
|
|
|
*/
|
|
|
|
|
getDeliveryPersonStatusColor(status: string): string {
|
|
|
|
|
switch (status) {
|
|
|
|
|
case 'idle':
|
|
|
|
|
return '#52c41a'; // 绿色
|
|
|
|
|
case 'busy':
|
|
|
|
|
return '#faad14'; // 橙色
|
|
|
|
|
case 'offline':
|
|
|
|
|
return '#d9d9d9'; // 灰色
|
|
|
|
|
default:
|
|
|
|
|
return '#d9d9d9'; // 灰色
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取货运人员当前订单信息
|
|
|
|
|
*/
|
|
|
|
|
getCurrentOrderInfo(person: any): string {
|
|
|
|
|
if (!person.currentOrder) {
|
|
|
|
|
return '暂无订单';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const order = person.currentOrder;
|
|
|
|
|
return `订单 #${order.id} - ${this.getOrderStatusText(order.status)}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取订单状态文本
|
|
|
|
|
*/
|
|
|
|
|
private getOrderStatusText(status: string): string {
|
|
|
|
|
const statusMap: Record<string, string> = {
|
|
|
|
|
'pending': '未分配',
|
|
|
|
|
'assigned': '已分配',
|
|
|
|
|
'in_transit': '配送中',
|
|
|
|
|
'delivered': '已完成',
|
|
|
|
|
'cancelled': '已取消'
|
|
|
|
|
};
|
|
|
|
|
return statusMap[status] || status;
|
|
|
|
|
}
|
|
|
|
|
}
|