Commit f12d52d1 by 姜雷

改造订单页面

parent 8a561f99
...@@ -118,7 +118,7 @@ export type RechargeOrder = { ...@@ -118,7 +118,7 @@ export type RechargeOrder = {
handler?: string; handler?: string;
/** 主键id */ /** 主键id */
id?: number; id: number;
/** 操作类型 1入账 2出账 */ /** 操作类型 1入账 2出账 */
operType?: string; operType?: string;
......
...@@ -6,7 +6,7 @@ import { ...@@ -6,7 +6,7 @@ import {
UPDATE_ALL_LIST, UPDATE_ALL_LIST,
} from './actions'; } from './actions';
export interface StoreState { export interface OrderStoreState {
orderState: String; orderState: String;
payList: Order[]; payList: Order[];
allList: AllOrderItem[]; allList: AllOrderItem[];
...@@ -19,7 +19,7 @@ const INITIAL_STATE = { ...@@ -19,7 +19,7 @@ const INITIAL_STATE = {
}; };
export default function OrderList( export default function OrderList(
state: StoreState = INITIAL_STATE, state: OrderStoreState = INITIAL_STATE,
actions: Actions, actions: Actions,
) { ) {
switch (actions.type) { 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) => { ...@@ -6,7 +6,8 @@ const reducer = (state: RechargeOrderItem[], action: Actions) => {
switch (action.type) { switch (action.type) {
case 'updateRechargeOrders': case 'updateRechargeOrders':
return action.payload; return action.payload;
case 'appendRechargeOrders':
return [...state, ...action.payload];
default: default:
return state; return state;
} }
...@@ -28,7 +29,9 @@ const useRechargeOrders = ( ...@@ -28,7 +29,9 @@ const useRechargeOrders = (
pageSize, pageSize,
}) })
.then(res => { .then(res => {
dispatch({ type: 'updateRechargeOrders', payload: res.data }); lastOrderId
? dispatch({ type: 'appendRechargeOrders', payload: res.data })
: dispatch({ type: 'updateRechargeOrders', payload: res.data });
return res.data; return res.data;
}) })
.catch(err => { .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