Files
gao-customer-h5/src/api/CustomerAPI.ts
T
2026-09-10 14:25:53 +08:00

123 lines
3.2 KiB
TypeScript

import { axios } from "timi-web-api";
import type { Page, PageResult } from "timi-web-api";
import type { Customer, CustomerDailyStatView, CustomerGenderStatView, CustomerTrendStatReq } from "@/types/Customer";
import { getCurrentStoreId, withCurrentStoreId, withCurrentStorePage } from "@/utils/store";
const BASE_URI = "/gao/customer";
export type CustomerPage = Page<Customer> & {
keyword?: string;
storeId?: string;
tagIdList?: string[];
};
async function list(page: CustomerPage): Promise<PageResult<Customer>> {
const req = withCurrentStorePage(page);
return await axios.post(`${BASE_URI}/list`, {
index: req.index,
size: req.size,
keyword: page.keyword || page.likesExample?.code || page.likesExample?.name || page.likesExample?.telephone,
storeId: page.storeId || req.equalsExample?.storeId,
tagIdList: page.tagIdList || [],
orderMap: page.orderMap || {}
});
}
async function detail(id: string): Promise<Customer> {
return await axios.post(`${BASE_URI}/detail`, undefined, {
params: { id }
});
}
async function create(customer: Customer): Promise<string> {
return await axios.post(`${BASE_URI}/create`, withCurrentStoreId(customer));
}
async function update(page: Customer): Promise<void> {
return await axios.post(`${BASE_URI}/update`, withCurrentStoreId(page));
}
async function remove(id: string): Promise<void> {
return await axios.post(`${BASE_URI}/delete`, undefined, {
params: { id }
});
}
async function findById(id: string): Promise<Customer | undefined> {
return await axios.post(`${BASE_URI}/find/id`, null, {
params: { id }
});
}
async function findByCode(code: string, storeId = getCurrentStoreId()): Promise<Customer | undefined> {
return await axios.post(`${BASE_URI}/find/code`, null, {
params: {
storeId,
code
}
});
}
async function findByName(name: string): Promise<Customer | undefined> {
return await axios.post(`${BASE_URI}/find/name`, null, {
params: {
storeId: getCurrentStoreId(),
name
}
});
}
async function exportXSSF(page: Page<Customer>): Promise<Blob> {
return await axios.post(`${BASE_URI}/export`, withCurrentStorePage(page), {
responseType: "blob"
});
}
async function listInvited(introducerCustomerId: string): Promise<Customer[]> {
return await axios.post(`${BASE_URI}/invited/list`, undefined, {
params: { introducerCustomerId }
});
}
async function saveInvite(introducerCustomerId: string, customerId: string): Promise<void> {
return await axios.post(`${BASE_URI}/invite/save`, undefined, {
params: {
introducerCustomerId,
customerId
}
});
}
async function deleteInvite(customerId: string): Promise<void> {
return await axios.post(`${BASE_URI}/invite/delete`, undefined, {
params: { customerId }
});
}
async function dailyStat(req: CustomerTrendStatReq): Promise<CustomerDailyStatView[]> {
return await axios.post(`${BASE_URI}/state/daily`, withCurrentStoreId(req));
}
async function genderStat(): Promise<CustomerGenderStatView[]> {
return await axios.post(`${BASE_URI}/state/gender`, undefined, {
params: { storeId: getCurrentStoreId() }
});
}
export default {
list,
detail,
create,
update,
remove,
findById,
findByCode,
findByName,
exportXSSF,
listInvited,
saveInvite,
deleteInvite,
dailyStat,
genderStat
};