Commit f12d52d1 by 姜雷

改造订单页面

parent 8a561f99
......@@ -118,7 +118,7 @@ export type RechargeOrder = {
handler?: string;
/** 主键id */
id?: number;
id: number;
/** 操作类型 1入账 2出账 */
operType?: string;
......
......@@ -6,7 +6,7 @@ import {
UPDATE_ALL_LIST,
} from './actions';
export interface StoreState {
export interface OrderStoreState {
orderState: String;
payList: Order[];
allList: AllOrderItem[];
......@@ -19,7 +19,7 @@ const INITIAL_STATE = {
};
export default function OrderList(
state: StoreState = INITIAL_STATE,
state: OrderStoreState = INITIAL_STATE,
actions: Actions,
) {
switch (actions.type) {
......
import { useEffect, useReducer } from '@tarojs/taro';
import { fetchAllOrder } from '@/api/order';
import Actions from '@/types/Store/Actions';
import { AllOrderItem } from '@/types/Order/Order';
const reducer = (state: AllOrderItem[], action: Actions) => {
switch (action.type) {
case 'updateConsumeOrders':
return action.payload;
case 'appendConsumeOrders':
return [...state, ...action.payload];
default:
return state;
}
};
const useConsumeOrders = (
customerId: number,
lastOrderId: number,
pageSize: number,
): AllOrderItem[] => {
const [state, dispatch] = useReducer(reducer, []);
const fetchData = (
customerId: number,
lastOrderId: number,
pageSize: number,
) =>
fetchAllOrder({
customerId,
lastOrderId,
pageSize,
})
.then(res => {
lastOrderId
? dispatch({ type: 'appendConsumeOrders', payload: res.data })
: dispatch({ type: 'updateConsumeOrders', payload: res.data });
return res.data;
})
.catch(err => {
console.log(err);
});
useEffect(() => {
console.log('in fetch');
fetchData(customerId, lastOrderId, pageSize);
}, [customerId, lastOrderId, pageSize]);
return state;
};
export default useConsumeOrders;
......@@ -6,7 +6,8 @@ const reducer = (state: RechargeOrderItem[], action: Actions) => {
switch (action.type) {
case 'updateRechargeOrders':
return action.payload;
case 'appendRechargeOrders':
return [...state, ...action.payload];
default:
return state;
}
......@@ -28,7 +29,9 @@ const useRechargeOrders = (
pageSize,
})
.then(res => {
dispatch({ type: 'updateRechargeOrders', payload: res.data });
lastOrderId
? dispatch({ type: 'appendRechargeOrders', payload: res.data })
: dispatch({ type: 'updateRechargeOrders', payload: res.data });
return res.data;
})
.catch(err => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment