2026-03-19 01:39:34 +08:00
|
|
|
/**
|
|
|
|
|
* [MOCK-SUPPLIERS] Suppliers模块DataSource
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
export interface Supplier {
|
|
|
|
|
id: string;
|
|
|
|
|
name: string;
|
|
|
|
|
contact: string;
|
2026-03-20 17:53:46 +08:00
|
|
|
contactName?: string;
|
2026-03-19 01:39:34 +08:00
|
|
|
email: string;
|
|
|
|
|
phone: string;
|
|
|
|
|
address: string;
|
|
|
|
|
category: string;
|
|
|
|
|
rating: number;
|
|
|
|
|
status: 'active' | 'inactive' | 'pending';
|
|
|
|
|
paymentTerms: string;
|
|
|
|
|
leadTime: number;
|
2026-03-20 17:53:46 +08:00
|
|
|
minOrder?: number;
|
2026-03-19 01:39:34 +08:00
|
|
|
minOrderQty: number;
|
2026-03-20 17:53:46 +08:00
|
|
|
notes?: string;
|
2026-03-19 01:39:34 +08:00
|
|
|
createdAt: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface SupplierProduct {
|
|
|
|
|
id: string;
|
2026-03-20 17:53:46 +08:00
|
|
|
supplierId?: string;
|
2026-03-19 01:39:34 +08:00
|
|
|
sku: string;
|
2026-03-20 17:53:46 +08:00
|
|
|
name: string;
|
|
|
|
|
productName?: string;
|
|
|
|
|
price: number;
|
|
|
|
|
costPrice?: number;
|
|
|
|
|
stock: number;
|
2026-03-19 01:39:34 +08:00
|
|
|
moq: number;
|
|
|
|
|
leadTime: number;
|
2026-03-20 17:53:46 +08:00
|
|
|
quality?: 'A' | 'B' | 'C';
|
2026-03-19 01:39:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ISuppliersDataSource {
|
|
|
|
|
fetchSuppliers(): Promise<Supplier[]>;
|
|
|
|
|
fetchSupplierDetail(id: string): Promise<Supplier>;
|
|
|
|
|
saveSupplier(data: Partial<Supplier>): Promise<Supplier>;
|
|
|
|
|
deleteSupplier(id: string): Promise<void>;
|
|
|
|
|
fetchSupplierProducts(supplierId: string): Promise<SupplierProduct[]>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class MockSuppliersDataSource implements ISuppliersDataSource {
|
|
|
|
|
async fetchSuppliers(): Promise<Supplier[]> {
|
|
|
|
|
return [
|
|
|
|
|
{ id: 'sup_001', name: 'Shenzhen Tech Co.', contact: 'Li Wei', email: 'liwei@szttech.com', phone: '+86-138-0000-0001', address: 'Shenzhen, China', category: 'Electronics', rating: 4.8, status: 'active', paymentTerms: '30% deposit, 70% before shipping', leadTime: 15, minOrderQty: 100, createdAt: '2025-01-15' },
|
|
|
|
|
{ id: 'sup_002', name: 'Guangzhou Accessories Ltd.', contact: 'Wang Ming', email: 'wangming@gzacc.com', phone: '+86-138-0000-0002', address: 'Guangzhou, China', category: 'Accessories', rating: 4.5, status: 'active', paymentTerms: 'Net 30', leadTime: 10, minOrderQty: 50, createdAt: '2025-02-20' },
|
|
|
|
|
{ id: 'sup_003', name: 'Dongguan Manufacturing', contact: 'Zhang Hua', email: 'zhanghua@dgmfg.com', phone: '+86-138-0000-0003', address: 'Dongguan, China', category: 'Electronics', rating: 4.2, status: 'active', paymentTerms: '50% deposit, 50% on delivery', leadTime: 20, minOrderQty: 200, createdAt: '2025-03-10' },
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fetchSupplierDetail(id: string): Promise<Supplier> {
|
|
|
|
|
const suppliers = await this.fetchSuppliers();
|
|
|
|
|
return suppliers.find(s => s.id === id) || suppliers[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async saveSupplier(data: Partial<Supplier>): Promise<Supplier> {
|
|
|
|
|
return { ...data, id: data.id || `sup_${Date.now()}`, createdAt: new Date().toISOString() } as Supplier;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async deleteSupplier(id: string): Promise<void> {}
|
|
|
|
|
|
|
|
|
|
async fetchSupplierProducts(supplierId: string): Promise<SupplierProduct[]> {
|
|
|
|
|
return [
|
2026-03-20 17:53:46 +08:00
|
|
|
{ id: 'sp_001', supplierId, sku: 'SKU-001', name: 'Wireless Headphones', productName: 'Wireless Headphones', price: 12.50, costPrice: 12.50, stock: 1000, moq: 100, leadTime: 15, quality: 'A' },
|
|
|
|
|
{ id: 'sp_002', supplierId, sku: 'SKU-002', name: 'USB-C Cable', productName: 'USB-C Cable', price: 1.80, costPrice: 1.80, stock: 5000, moq: 500, leadTime: 10, quality: 'A' },
|
|
|
|
|
{ id: 'sp_003', supplierId, sku: 'SKU-003', name: 'Phone Case', productName: 'Phone Case', price: 2.50, costPrice: 2.50, stock: 2000, moq: 200, leadTime: 12, quality: 'B' },
|
2026-03-19 01:39:34 +08:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ApiSuppliersDataSource implements ISuppliersDataSource {
|
|
|
|
|
private baseUrl = '/api/suppliers';
|
|
|
|
|
|
|
|
|
|
async fetchSuppliers(): Promise<Supplier[]> {
|
|
|
|
|
const res = await fetch(this.baseUrl);
|
|
|
|
|
return res.json();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fetchSupplierDetail(id: string): Promise<Supplier> {
|
|
|
|
|
const res = await fetch(`${this.baseUrl}/${id}`);
|
|
|
|
|
return res.json();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async saveSupplier(data: Partial<Supplier>): Promise<Supplier> {
|
|
|
|
|
const res = await fetch(this.baseUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) });
|
|
|
|
|
return res.json();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async deleteSupplier(id: string): Promise<void> {
|
|
|
|
|
await fetch(`${this.baseUrl}/${id}`, { method: 'DELETE' });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fetchSupplierProducts(supplierId: string): Promise<SupplierProduct[]> {
|
|
|
|
|
const res = await fetch(`${this.baseUrl}/${supplierId}/products`);
|
|
|
|
|
return res.json();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 12:41:35 +08:00
|
|
|
const useMock = process.env.NODE_ENV === 'development' || process.env.REACT_APP_USE_MOCK === 'true';
|
2026-03-19 01:39:34 +08:00
|
|
|
export const suppliersDataSource: ISuppliersDataSource = useMock ? new MockSuppliersDataSource() : new ApiSuppliersDataSource();
|