From d5bc8a639f6983b711ca4a811a092cb8b78aa6d3 Mon Sep 17 00:00:00 2001 From: Lei OT Date: Fri, 9 Jan 2026 16:34:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=B0=E6=8E=A5=E6=8E=A5=E5=9B=A2=20-->=20zu?= =?UTF-8?q?stand?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/zustand/CustomerServices.js | 132 ++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 src/zustand/CustomerServices.js diff --git a/src/zustand/CustomerServices.js b/src/zustand/CustomerServices.js new file mode 100644 index 0000000..4324319 --- /dev/null +++ b/src/zustand/CustomerServices.js @@ -0,0 +1,132 @@ +import { create } from 'zustand'; +import { devtools } from 'zustand/middleware'; +import { immer } from 'zustand/middleware/immer'; +import { fetchJSON } from '@haina/utils-request'; +import { HT_HOST } from '../config'; +import { isEmpty } from '@haina/utils-commons'; + +const defaultParams = {}; + +export const fetchAgentGroupCount = async (params) => { + const { errcode, errmsg, ...result } = await fetchJSON(HT_HOST + '/service-web/QueryData/GetAgentGroupInfoALL', { + ...defaultParams, + // ...params, + DateType: params.DateType, + VEI_SN: params.agency || '', + DepList: params.DepartmentList || '', + Country: params.countryArea || '', + Date1: params.Date1, + Date2: params.Date2, + OldDate1: params.DateDiff1 || '', + OldDate2: params.DateDiff2 || '', + }); + if (errcode !== 0) { + return {}; + } + const { result1, result2, total1, total2 } = result; + const result1Mapped = result1.reduce((r, v) => ({ ...r, [v.EOI_ObjSN]: v }), {}); + const ret = {}; + if (isEmpty(params.DateDiff1)) { + ret.result1 = Object.values(result1Mapped).filter((row) => row.EOI_ObjSN !== -1); + ret.total1 = { ...result1Mapped['-1'] }; + return ret; + } else { + const allKeys = [...new Set([...result1.map((e) => e.EOI_ObjSN), ...result2.map((e) => e.EOI_ObjSN)])]; + const result2Mapped = result2.reduce((r, v) => ({ ...r, [v.EOI_ObjSN]: v }), {}); + + const x = {}; + allKeys.forEach((key) => { + x[key] = { ...(result1Mapped?.[key] || { EOI_ObjSN: key, vi: key, key, VendorName: result2Mapped[key]?.VendorName || '--' }), diff: result2Mapped[key] || {} }; + }); + ret.result1 = Object.values(x).filter((row) => row.EOI_ObjSN !== -1); + ret.total1 = { ...result1Mapped['-1'], diff: result2Mapped['-1'] || {} }; + return ret; + } +}; + +export const fetchGroupListByAgentId = async (params) => { + const { agentId, DateType, Date1, Date2, DateDiff1, DateDiff2, DepartmentList, countryArea } = params; + const { errcode, errmsg, ...result } = await fetchJSON(HT_HOST + '/service-web/QueryData/GetAgentGroupInfo', { + VEI_SN: agentId || '', + DateType: DateType || '', + Date1: Date1 || '', + Date2: Date2 || '', + OldDate1: DateDiff1 || '', + OldDate2: DateDiff2 || '', + DepList: DepartmentList || '', + }); + if (errcode !== 0) { + return {}; + } + result.title1 = Date1 ? `${Date1}~${Date2}` : ''; + result.title2 = DateDiff1 ? `${DateDiff1}~${DateDiff2}` : ''; + return result; +}; + +/** + * -------------------------------------------------------------------------------------------------------- + */ +const initialState = { + loading: false, + typeLoading: false, + searchValues: { + DateType: { key: 'departureDate', label: '抵达日期' }, + WebCode: { key: 'all', label: '所有来源' }, + IncludeTickets: { key: '1', label: '含门票' }, + DepartmentList: { key: 'All', label: '所有来源' }, + countryArea: { key: 'china', label: '国内' }, + }, + searchValuesToSub: { + DateType: 'departureDate', + WebCode: 'all', + IncludeTickets: '1', + DepartmentList: 'All', + }, + + agentCountList: [], + agentCountTotal: {}, + + agencyName: '', + agencyGroups: { total1: {}, result1: [], total2: {}, result2: [] }, + +}; + +const useCustomerServicesStore = create( + devtools( + immer((set, get) => ({ + ...initialState, + reset: () => set(initialState), + + setLoading: (loading) => set({ loading }), + setSearchValues: (obj, values) => set((state) => ({ searchValues: values, searchValuesToSub: obj })), + setSearchValuesToSub: (values) => set((state) => ({ searchValuesToSub: values })), + + getAgentGroupCount: async (params) => { + const { setLoading } = get(); + setLoading(true); + try { + const res = await fetchAgentGroupCount(params); + set({ agentCountList: res.result1 || [], agentCountTotal: res.total1 || {} }); + } catch (error) { + } finally { + setLoading(false); + } + }, + + getGroupListByAgentId: async (agentId) => { + const { setLoading, searchValuesToSub } = get(); + setLoading(true); + try { + const res = await fetchGroupListByAgentId({ ...searchValuesToSub, agentId }); + set({ agencyGroups: res, agencyName: res.result1?.[0]?.VendorName || '' }); + } catch (error) { + } finally { + setLoading(false); + } + }, + })), + { name: 'CustomerServices' } + ) +); + +export default useCustomerServicesStore;