Files
WXProgram/miniprogram/services/warehouseService.ts

234 lines
7.2 KiB
TypeScript
Raw Normal View History

2025-10-16 21:32:16 +08:00
import { WarehouseInfo } from '../types';
import apiService from './apiService';
import { isMockMode } from './apiService';
/**
*
*
*/
class WarehouseService {
// 模拟仓库数据
private warehouses: WarehouseInfo[];
/**
*
*/
constructor() {
this.warehouses = [
{
id: 1,
name: '瓦尔塔蓄电池昆明总店',
address: '昆明市五华区二环西路599号',
contact: '刘经理',
phone: '0871-65123456',
description: '瓦尔塔蓄电池云南总代理,提供全系列蓄电池产品',
status: 'open',
capacity: 2000, // 仓库容量(吨)
longitude: 102.705745,
latitude: 25.055281
},
{
id: 2,
name: '瓦尔塔蓄电池盘龙区分店',
address: '昆明市盘龙区北京路1188号',
contact: '张经理',
phone: '0871-65678901',
description: '专业销售瓦尔塔汽车蓄电池,提供安装和售后服务',
status: 'open',
capacity: 800, // 仓库容量(吨)
longitude: 102.728421,
latitude: 25.042498
},
{
id: 3,
name: '瓦尔塔蓄电池西山区分店',
address: '昆明市西山区滇池路1234号',
contact: '李经理',
phone: '0871-65234567',
description: '瓦尔塔蓄电池授权经销商,专业汽车电池解决方案',
status: 'open',
capacity: 600, // 仓库容量(吨)
longitude: 102.689190,
latitude: 25.028234
},
{
id: 4,
name: '瓦尔塔蓄电池官渡区分店',
address: '昆明市官渡区春城路456号',
contact: '王经理',
phone: '0871-65345678',
description: '瓦尔塔蓄电池专卖店,各类车型电池齐全',
status: 'open',
capacity: 700, // 仓库容量(吨)
longitude: 102.725745,
latitude: 25.025281
},
{
id: 5,
name: '瓦尔塔蓄电池呈贡区分店',
address: '昆明市呈贡区春融街789号',
contact: '赵经理',
phone: '0871-65456789',
description: '瓦尔塔蓄电池呈贡区授权经销商,提供专业安装服务',
status: 'open',
capacity: 500, // 仓库容量(吨)
longitude: 102.788421,
latitude: 24.902498
},
{
id: 6,
name: '瓦尔塔蓄电池五华区服务中心',
address: '昆明市五华区一二一大街200号',
contact: '陈经理',
phone: '0871-65567890',
description: '瓦尔塔蓄电池专业售后服务中心,提供电池检测和更换',
status: 'open',
capacity: 400, // 仓库容量(吨)
longitude: 102.722745,
latitude: 25.040281
},
{
id: 7,
name: '瓦尔塔蓄电池安宁市分店',
address: '昆明市安宁市金方路300号',
contact: '杨经理',
phone: '0871-65678902',
description: '瓦尔塔蓄电池安宁市授权经销商,各类车型电池销售',
status: 'open',
capacity: 300, // 仓库容量(吨)
longitude: 102.458421,
latitude: 24.902498
},
{
id: 8,
name: '瓦尔塔蓄电池晋宁区分店',
address: '昆明市晋宁区昆阳大街120号',
contact: '黄经理',
phone: '0871-65789012',
description: '瓦尔塔蓄电池晋宁区销售点,提供汽车和电动车电池',
status: 'open',
capacity: 250, // 仓库容量(吨)
longitude: 102.519190,
latitude: 24.688234
},
{
id: 9,
name: '瓦尔塔蓄电池宜良县分店',
address: '昆明市宜良县匡远镇汇东路88号',
contact: '吴经理',
phone: '0871-65890123',
description: '瓦尔塔蓄电池宜良县授权经销商,专业汽车电池服务',
status: 'open',
capacity: 200, // 仓库容量(吨)
longitude: 103.115745,
latitude: 24.905281
},
{
id: 10,
name: '瓦尔塔蓄电池嵩明县分店',
address: '昆明市嵩明县嵩阳镇玉明路66号',
contact: '郑经理',
phone: '0871-65901234',
description: '瓦尔塔蓄电池嵩明县销售中心,各类蓄电池产品齐全',
status: 'open',
capacity: 180, // 仓库容量(吨)
longitude: 103.048421,
latitude: 25.362498
}
];
}
/**
*
*/
private getAllWarehousesSync(): WarehouseInfo[] {
return [...this.warehouses];
}
/**
* ID获取仓库信息
*/
private getWarehouseByIdSync(id: number): WarehouseInfo | undefined {
return this.warehouses.find(warehouse => warehouse.id === id);
}
/**
*
*/
getWarehouseStatusText(status: WarehouseInfo['status']): string {
const statusMap = {
'open': '营业中',
'closed': '已关闭',
'maintenance': '维护中'
};
return statusMap[status || 'open'] || '未知状态';
}
/**
*
*/
async getWarehouses(): Promise<WarehouseInfo[]> {
if (isMockMode) {
return this.getAllWarehousesSync();
}
return apiService.getWarehouses();
}
/**
* ID获取仓库信息
*/
async getWarehouseById(id: number): Promise<WarehouseInfo | null> {
if (isMockMode) {
return this.getWarehouseByIdSync(id) || null;
}
return apiService.getWarehouseById(id);
}
/**
*
*/
async createWarehouse(warehouseData: Partial<WarehouseInfo>): Promise<WarehouseInfo> {
try {
// 模拟API请求延迟
await new Promise(resolve => setTimeout(resolve, 600));
console.log('创建新仓库:', warehouseData);
// 实际应用中这里应该调用后端API
// 这里我们创建一个模拟的仓库对象返回
const newWarehouse: WarehouseInfo = {
id: Date.now(), // 使用时间戳作为临时ID
name: warehouseData.name || '新建仓库',
address: warehouseData.address || '',
contact: warehouseData.contact,
phone: warehouseData.phone,
description: warehouseData.description,
status: 'open',
capacity: warehouseData.capacity || 500,
longitude: warehouseData.longitude || 0,
latitude: warehouseData.latitude || 0
};
return newWarehouse;
} catch (error) {
console.error('创建仓库失败:', error);
throw new Error('创建仓库失败');
}
}
/**
*
*/
async deleteWarehouse(warehouseId: number): Promise<boolean> {
try {
// 模拟API请求延迟
await new Promise(resolve => setTimeout(resolve, 400));
console.log(`删除仓库 ${warehouseId}`);
// 实际应用中这里应该调用后端API
return true;
} catch (error) {
console.error('删除仓库失败:', error);
throw new Error('删除仓库失败');
}
}
}
// 导出单例实例
export default new WarehouseService();