46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import api from '@/utils/http'
|
|
|
|
export interface CrmCustomerOption {
|
|
id: string
|
|
customerName: string
|
|
customerNo?: string
|
|
}
|
|
|
|
export interface CrmProductOption {
|
|
id: string
|
|
productName: string
|
|
model?: string
|
|
unit?: string
|
|
status?: string
|
|
}
|
|
|
|
function extractOptions<T>(res: unknown): T[] {
|
|
if (Array.isArray(res)) return res as T[]
|
|
const data = (res as { list?: T[]; rows?: T[] }) || {}
|
|
return data.list || data.rows || []
|
|
}
|
|
|
|
/** CRM 客户下拉(只读,租户内不做数据权限) */
|
|
export async function fetchCustomerOptions(keyword?: string): Promise<CrmCustomerOption[]> {
|
|
const res = await api.post<CrmCustomerOption[]>({
|
|
url: '/web/crm/customer/options',
|
|
data: {
|
|
limit: keyword?.trim() ? 50 : 20,
|
|
...(keyword?.trim() ? { keyword: keyword.trim() } : {})
|
|
}
|
|
})
|
|
return extractOptions<CrmCustomerOption>(res)
|
|
}
|
|
|
|
/** CRM 产品下拉(只读,租户内不做数据权限;仅上架) */
|
|
export async function fetchProductOptions(keyword?: string): Promise<CrmProductOption[]> {
|
|
const res = await api.post<CrmProductOption[]>({
|
|
url: '/web/crm/products/options',
|
|
data: {
|
|
limit: keyword?.trim() ? 50 : 20,
|
|
...(keyword?.trim() ? { keyword: keyword.trim() } : {})
|
|
}
|
|
})
|
|
return extractOptions<CrmProductOption>(res)
|
|
}
|