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 & { keyword?: string; storeId?: string; tagIdList?: string[]; }; async function list(page: CustomerPage): Promise> { 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 { return await axios.post(`${BASE_URI}/detail`, undefined, { params: { id } }); } async function create(customer: Customer): Promise { return await axios.post(`${BASE_URI}/create`, withCurrentStoreId(customer)); } async function update(page: Customer): Promise { return await axios.post(`${BASE_URI}/update`, withCurrentStoreId(page)); } async function remove(id: string): Promise { return await axios.post(`${BASE_URI}/delete`, undefined, { params: { id } }); } async function findById(id: string): Promise { return await axios.post(`${BASE_URI}/find/id`, null, { params: { id } }); } async function findByCode(code: string, storeId = getCurrentStoreId()): Promise { return await axios.post(`${BASE_URI}/find/code`, null, { params: { storeId, code } }); } async function findByName(name: string): Promise { return await axios.post(`${BASE_URI}/find/name`, null, { params: { storeId: getCurrentStoreId(), name } }); } async function exportXSSF(page: Page): Promise { return await axios.post(`${BASE_URI}/export`, withCurrentStorePage(page), { responseType: "blob" }); } async function listInvited(introducerCustomerId: string): Promise { return await axios.post(`${BASE_URI}/invited/list`, undefined, { params: { introducerCustomerId } }); } async function saveInvite(introducerCustomerId: string, customerId: string): Promise { return await axios.post(`${BASE_URI}/invite/save`, undefined, { params: { introducerCustomerId, customerId } }); } async function deleteInvite(customerId: string): Promise { return await axios.post(`${BASE_URI}/invite/delete`, undefined, { params: { customerId } }); } async function dailyStat(req: CustomerTrendStatReq): Promise { return await axios.post(`${BASE_URI}/state/daily`, withCurrentStoreId(req)); } async function genderStat(): Promise { 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 };