Commit 696da627 by 姜雷

修改我的订单

parent f4e54789
......@@ -12,24 +12,20 @@ import {
const useConsumeOrders = (
customerId: number,
pageSize: number,
): [AllOrderItem[], () => void, () => void] => {
): [AllOrderItem[], () => Promise<any>, () => Promise<any>] => {
const state = useSelector(
(state: { OrderList: OrderStoreState }) => state.OrderList.consume,
);
const dispatch = useDispatch();
const fetchData = (
customerId: number,
lastOrderId: number,
pageSize: number,
) =>
const fetchData = (customerId: number, pageSize: number) =>
fetchAllOrder({
customerId,
lastOrderId,
lastOrderId: state.lastOrderId,
pageSize,
})
.then(res => {
lastOrderId
state.lastOrderId
? dispatch(appendConsumeOrders(res.data))
: dispatch(updateConsumeOrders(res.data));
return res.data;
......@@ -44,18 +40,20 @@ const useConsumeOrders = (
const orderIdx = arr[itemIdx].data.length - 1;
if (orderIdx >= 0) {
dispatch(updateConsumeLastId(arr[itemIdx].data[orderIdx].id));
return;
return fetchData(customerId, pageSize);
}
}
dispatch(updateConsumeLastId(0));
return fetchData(customerId, pageSize);
};
const resetOrders = () => {
dispatch(updateConsumeLastId(0));
return fetchData(customerId, pageSize);
};
useEffect(() => {
fetchData(customerId, state.lastOrderId, pageSize);
}, [customerId, state.lastOrderId, pageSize]);
fetchData(customerId, pageSize);
}, [customerId, pageSize]);
return [state.consumeOrders, fetchMore, resetOrders];
};
......
......@@ -11,23 +11,19 @@ import {
const useRechargeOrders = (
customerId: number,
pageSize: number,
): [RechargeOrderItem[], () => void, () => void] => {
): [RechargeOrderItem[], () => Promise<any>, () => Promise<any>] => {
const state = useSelector(
(state: { OrderList: OrderStoreState }) => state.OrderList.recharge,
);
const dispatch = useDispatch();
const fetchData = (
customerId: number,
lastOrderId: number,
pageSize: number,
) =>
const fetchData = (customerId: number, pageSize: number) =>
fetchRechargeOrders({
customerId,
lastOrderId,
lastOrderId: state.lastOrderId,
pageSize,
})
.then(res => {
lastOrderId
state.lastOrderId
? dispatch(appendRechargeOrders(res.data))
: dispatch(updateRechargeOrders(res.data));
return res.data;
......@@ -42,18 +38,20 @@ const useRechargeOrders = (
const orderIdx = arr[itemIdx].data.length - 1;
if (orderIdx >= 0) {
dispatch(updateRechargeLastId(arr[itemIdx].data[orderIdx].id));
return;
return fetchData(customerId, pageSize);
}
}
dispatch(updateRechargeLastId(0));
return fetchData(customerId, pageSize);
};
const resetOrders = () => {
dispatch(updateRechargeLastId(0));
return fetchData(customerId, pageSize);
};
useEffect(() => {
fetchData(customerId, state.lastOrderId, pageSize);
}, [customerId, state.lastOrderId, pageSize]);
fetchData(customerId, pageSize);
}, [customerId, pageSize]);
return [state.rechargeOrders, fetchMore, resetOrders];
};
......
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