|
|
|
|
@ -7,9 +7,9 @@ import { HT_HOST } from '../config';
|
|
|
|
|
import { resultDataCb } from '../components/DateGroupRadio/date';
|
|
|
|
|
import { isEmpty } from '../utils/commons';
|
|
|
|
|
|
|
|
|
|
const defaultParams = { WebCode: 'all', IncludeTickets: 1, IncludeInternal: 1, };
|
|
|
|
|
const defaultParams = { WebCode: 'all', IncludeTickets: 1, IncludeInternal: 1 };
|
|
|
|
|
|
|
|
|
|
export const fetchBizOrderCount = async (params, type='', typeVal='') => {
|
|
|
|
|
export const fetchBizOrderCount = async (params, type = '', typeVal = '') => {
|
|
|
|
|
const { errcode, errmsg, ...result } = await fetchJSON(HT_HOST + '/service-web/QueryData/GetOrderCount_biz', {
|
|
|
|
|
...defaultParams,
|
|
|
|
|
...params,
|
|
|
|
|
@ -62,7 +62,7 @@ export const fetchBizOrderCountByType = async (type, params) => {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const _detailRes = { ordercount1: [], ordercount2: [] };
|
|
|
|
|
export const fetchBizOrderDetailByType = async (params, type='', typeVal='', orderContent='detail') => {
|
|
|
|
|
export const fetchBizOrderDetailByType = async (params, type = '', typeVal = '', orderContent = 'detail') => {
|
|
|
|
|
const { errcode, errmsg, ...result } = await fetchJSON(HT_HOST + '/service-web/QueryData/GetOrderCountByType_Sub_biz', {
|
|
|
|
|
...defaultParams,
|
|
|
|
|
SubOrderType: orderContent,
|
|
|
|
|
@ -75,9 +75,12 @@ export const fetchBizOrderDetailByType = async (params, type='', typeVal='', ord
|
|
|
|
|
OrderType_val: typeVal,
|
|
|
|
|
});
|
|
|
|
|
const res = errcode !== 0 ? _detailRes : (result || _detailRes);
|
|
|
|
|
const dateStr = [params.Date1, params.Date2].map(d => d.substring(0, 10)).join('~');
|
|
|
|
|
const dateDiffStr = isEmpty(params.DateDiff1) ? '' : [params.DateDiff1, params.DateDiff2].map(d => d.substring(0, 10)).join('~');
|
|
|
|
|
const ret = [{ dateRangeStr: dateStr, data: res.ordercount1 }, { dateRangeStr: dateDiffStr, data: res.ordercount2 }];
|
|
|
|
|
const dateStr = [params.Date1, params.Date2].map((d) => d.substring(0, 10)).join('~');
|
|
|
|
|
const dateDiffStr = isEmpty(params.DateDiff1) ? '' : [params.DateDiff1, params.DateDiff2].map((d) => d.substring(0, 10)).join('~');
|
|
|
|
|
const ret = [
|
|
|
|
|
{ dateRangeStr: dateStr, data: res.ordercount1 },
|
|
|
|
|
{ dateRangeStr: dateDiffStr, data: res.ordercount2 },
|
|
|
|
|
];
|
|
|
|
|
return ret;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
@ -125,7 +128,7 @@ const initialState = {
|
|
|
|
|
DepartmentList: -1, // -1: All
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
activeTab: 'Form',
|
|
|
|
|
activeTab: 'servicetype',
|
|
|
|
|
activeDateGroupRadio: 'day',
|
|
|
|
|
|
|
|
|
|
orderCountDataRaw: {},
|
|
|
|
|
@ -142,94 +145,90 @@ const initialState = {
|
|
|
|
|
orderDetails: [],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const useBizOrderStore = create(
|
|
|
|
|
devtools(
|
|
|
|
|
immer(
|
|
|
|
|
(set, get) => ({
|
|
|
|
|
...initialState,
|
|
|
|
|
reset: () => set(initialState),
|
|
|
|
|
|
|
|
|
|
setLoading: (loading) => set({ loading }),
|
|
|
|
|
setTypeLoading: (typeLoading) => set({ typeLoading }),
|
|
|
|
|
|
|
|
|
|
setSearchValues: (obj, values) => set((state) => ({ searchValues: values, searchValuesToSub: obj })),
|
|
|
|
|
setSearchValuesToSub: (values) => set((state) => ({ searchValuesToSub: values })),
|
|
|
|
|
setActiveTab: (tab) => set({ activeTab: tab }),
|
|
|
|
|
|
|
|
|
|
setOrderCountDataLines: (data) => set({ orderCountDataLines: data }),
|
|
|
|
|
setOrderCountDataByType: (type, data) =>
|
|
|
|
|
set((state) => {
|
|
|
|
|
state.orderCountDataByType[type] = data;
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
// data ----
|
|
|
|
|
onChangeDateGroup: (value, data, avg1) => {
|
|
|
|
|
const { lines, dateRadioValue, avgLineValue } = calculateLineData(value, data, avg1);
|
|
|
|
|
set({ orderCountDataLines: lines, avgLineValue, activeDateGroupRadio: dateRadioValue });
|
|
|
|
|
},
|
|
|
|
|
onChangeDateGroupSub: (value, data, avg1) => {
|
|
|
|
|
const { lines, dateRadioValue, avgLineValue } = calculateLineData(value, data, avg1);
|
|
|
|
|
set({ orderCountDataLinesSub: lines, avgLineValueSub: avgLineValue, activeDateGroupRadioSub: dateRadioValue });
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// site effects
|
|
|
|
|
getBizOrderCount: async (params, type, typeVal) => {
|
|
|
|
|
const { setLoading, } = get();
|
|
|
|
|
setLoading(true);
|
|
|
|
|
try {
|
|
|
|
|
const res = await fetchBizOrderCount(params, type, typeVal);
|
|
|
|
|
// 第一次得到数据
|
|
|
|
|
const { lines, dateRadioValue, avgLineValue } = resultDataCb(res, 'day', orderCountDataMapper, orderCountDataFieldMapper, calculateLineData);
|
|
|
|
|
if (isEmpty(type)) {
|
|
|
|
|
// index page
|
|
|
|
|
set({ orderCountDataRaw: res });
|
|
|
|
|
set({ orderCountDataLines: lines, avgLineValue, activeDateGroupRadio: dateRadioValue });
|
|
|
|
|
} else {
|
|
|
|
|
// sub page
|
|
|
|
|
set({ orderCountDataRawSub: res });
|
|
|
|
|
set({ orderCountDataLinesSub: lines, avgLineValueSub: avgLineValue, activeDateGroupRadioSub: dateRadioValue });
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
} finally {
|
|
|
|
|
setLoading(false);
|
|
|
|
|
immer((set, get) => ({
|
|
|
|
|
...initialState,
|
|
|
|
|
reset: () => set(initialState),
|
|
|
|
|
|
|
|
|
|
setLoading: (loading) => set({ loading }),
|
|
|
|
|
setTypeLoading: (typeLoading) => set({ typeLoading }),
|
|
|
|
|
|
|
|
|
|
setSearchValues: (obj, values) => set((state) => ({ searchValues: values, searchValuesToSub: obj })),
|
|
|
|
|
setSearchValuesToSub: (values) => set((state) => ({ searchValuesToSub: values })),
|
|
|
|
|
setActiveTab: (tab) => set({ activeTab: tab }),
|
|
|
|
|
|
|
|
|
|
setOrderCountDataLines: (data) => set({ orderCountDataLines: data }),
|
|
|
|
|
setOrderCountDataByType: (type, data) =>
|
|
|
|
|
set((state) => {
|
|
|
|
|
state.orderCountDataByType[type] = data;
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
// data ----
|
|
|
|
|
onChangeDateGroup: (value, data, avg1) => {
|
|
|
|
|
const { lines, dateRadioValue, avgLineValue } = calculateLineData(value, data, avg1);
|
|
|
|
|
set({ orderCountDataLines: lines, avgLineValue, activeDateGroupRadio: dateRadioValue });
|
|
|
|
|
},
|
|
|
|
|
onChangeDateGroupSub: (value, data, avg1) => {
|
|
|
|
|
const { lines, dateRadioValue, avgLineValue } = calculateLineData(value, data, avg1);
|
|
|
|
|
set({ orderCountDataLinesSub: lines, avgLineValueSub: avgLineValue, activeDateGroupRadioSub: dateRadioValue });
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// site effects
|
|
|
|
|
getBizOrderCount: async (params, type, typeVal) => {
|
|
|
|
|
const { setLoading } = get();
|
|
|
|
|
setLoading(true);
|
|
|
|
|
try {
|
|
|
|
|
const res = await fetchBizOrderCount(params, type, typeVal);
|
|
|
|
|
// 第一次得到数据
|
|
|
|
|
const { lines, dateRadioValue, avgLineValue } = resultDataCb(res, 'day', orderCountDataMapper, orderCountDataFieldMapper, calculateLineData);
|
|
|
|
|
if (isEmpty(type)) {
|
|
|
|
|
// index page
|
|
|
|
|
set({ orderCountDataRaw: res });
|
|
|
|
|
set({ orderCountDataLines: lines, avgLineValue, activeDateGroupRadio: dateRadioValue });
|
|
|
|
|
} else {
|
|
|
|
|
// sub page
|
|
|
|
|
set({ orderCountDataRawSub: res });
|
|
|
|
|
set({ orderCountDataLinesSub: lines, avgLineValueSub: avgLineValue, activeDateGroupRadioSub: dateRadioValue });
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getBizOrderCount_type: async (type) => {
|
|
|
|
|
const { setTypeLoading, searchValuesToSub, setOrderCountDataByType } = get();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
} finally {
|
|
|
|
|
setLoading(false);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getBizOrderCount_type: async (type) => {
|
|
|
|
|
const { setTypeLoading, searchValuesToSub, setOrderCountDataByType } = get();
|
|
|
|
|
setTypeLoading(true);
|
|
|
|
|
try {
|
|
|
|
|
const res = await fetchBizOrderCountByType(type, searchValuesToSub);
|
|
|
|
|
setOrderCountDataByType(type, res);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
} finally {
|
|
|
|
|
setTypeLoading(false);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onTabChange: async (tab) => {
|
|
|
|
|
const { setActiveTab, getBizOrderCount_type } = get();
|
|
|
|
|
setActiveTab(tab);
|
|
|
|
|
await getBizOrderCount_type(tab);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// sub
|
|
|
|
|
getBizOrderDetailByType: async (params, type, typeVal) => {
|
|
|
|
|
const { setTypeLoading } = get();
|
|
|
|
|
try {
|
|
|
|
|
setTypeLoading(true);
|
|
|
|
|
try {
|
|
|
|
|
const res = await fetchBizOrderCountByType(type, searchValuesToSub);
|
|
|
|
|
setOrderCountDataByType(type, res);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
} finally {
|
|
|
|
|
setTypeLoading(false);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onTabChange: async (tab) => {
|
|
|
|
|
const { setActiveTab, getBizOrderCount_type } = get();
|
|
|
|
|
setActiveTab(tab);
|
|
|
|
|
await getBizOrderCount_type(tab);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// sub
|
|
|
|
|
getBizOrderDetailByType: async (params, type, typeVal) => {
|
|
|
|
|
const { setTypeLoading, } = get();
|
|
|
|
|
try {
|
|
|
|
|
setTypeLoading(true);
|
|
|
|
|
const res = await fetchBizOrderDetailByType(params, type, typeVal, 'detail');
|
|
|
|
|
set({ orderDetails: res });
|
|
|
|
|
} catch (error) {
|
|
|
|
|
} finally {
|
|
|
|
|
setTypeLoading(false);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
{ name: 'bizOrder' }
|
|
|
|
|
)
|
|
|
|
|
const res = await fetchBizOrderDetailByType(params, type, typeVal, 'detail');
|
|
|
|
|
set({ orderDetails: res });
|
|
|
|
|
} catch (error) {
|
|
|
|
|
} finally {
|
|
|
|
|
setTypeLoading(false);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
})),
|
|
|
|
|
{ name: 'bizOrder' }
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
export default useBizOrderStore;
|
|
|
|
|
|