Commit 3ca94d2f by 姜雷

添加订单查询支付组件

parent 2df8c7ad
...@@ -103,13 +103,3 @@ button[disabled]:not([type]) { ...@@ -103,13 +103,3 @@ button[disabled]:not([type]) {
.blur { .blur {
filter: blur(10px); filter: blur(10px);
} }
.OrderBox {
box-sizing: border-box;
position: absolute;
top: 0;
width: 100%;
height: 100%;
padding: 0 32px;
z-index: 100;
background-color: rgba(255, 255, 255, 0.5);
}
.OrderBox {
box-sizing: border-box;
position: absolute;
top: 0;
width: 100%;
height: 100%;
padding: 0 32px;
z-index: 100;
background-color: rgba(255, 255, 255, 0.5);
}
import './WaitPayOrder.scss';
import { View } from '@tarojs/components';
import OrderTitle from '@/pages/Order/components/OrderTitle/OrderTitle';
import OrderInfo from '@/pages/Order/components/OrderInfo/OrderInfo';
import OrderPayway from '@/pages/Order/components/OrderPayway/OrderPayway';
import useWaitPayOrderState from '@/hooks/useWaitPayOrderState';
import { useSelector, useDispatch } from '@tarojs/redux';
import { Customer } from '@/types/Customer/Customer';
import { updateOrderState } from '@/store/rootReducers/orderState';
import { PayOrderState } from '@/store/rootReducers/orderState';
const WaitPayOrderComponent = () => {
const dispatch = useDispatch();
const userinfo = useSelector(
(state: { userinfo: Customer }) => state.userinfo,
);
const payOrderState = useSelector(
(state: { orderState: PayOrderState }) =>
state.orderState.waitPayOrderState,
);
const { payInfos, accountList, orderInfo } = useWaitPayOrderState(
userinfo.customerId,
);
const payDoneHandle = () => {
dispatch(updateOrderState(false));
};
return payOrderState ? (
<View className='OrderBox'>
<OrderTitle price={orderInfo.payableMoney} />
<OrderInfo orderInfo={orderInfo} />
<OrderPayway
onPayDoneCallback={payDoneHandle}
userinfo={userinfo}
accounts={accountList}
orderInfo={orderInfo}
payInfos={payInfos}
/>
</View>
) : null;
};
export default WaitPayOrderComponent;
...@@ -21,7 +21,10 @@ let initBeanList: BeanAccount[] = []; ...@@ -21,7 +21,10 @@ let initBeanList: BeanAccount[] = [];
const useAllBeanCount = ( const useAllBeanCount = (
userinfo: Customer, userinfo: Customer,
serviceList: Service[], serviceList: Service[],
): [BeanAccount[], (userinfo: Customer) => void] => { ): [
BeanAccount[],
(customerId: number, areaId: number, customerPhone: string) => void
] => {
const [filterBeanList, setFilterBeanList] = useState(initBeanList); const [filterBeanList, setFilterBeanList] = useState(initBeanList);
const getFilterBeanList = ( const getFilterBeanList = (
...@@ -66,11 +69,15 @@ const useAllBeanCount = ( ...@@ -66,11 +69,15 @@ const useAllBeanCount = (
return arr; return arr;
}; };
const fetchDate = (userinfo: Customer) => { const fetchDate = (
customerId: number,
areaId: number,
customerPhone: string,
) => {
fetchBeanCount({ fetchBeanCount({
id: userinfo.customerId, id: customerId,
areaId: userinfo.areaId, areaId: areaId,
customerPhone: userinfo.customerPhone, customerPhone: customerPhone,
serviceIdList: [], serviceIdList: [],
}) })
.then(res => { .then(res => {
...@@ -82,8 +89,8 @@ const useAllBeanCount = ( ...@@ -82,8 +89,8 @@ const useAllBeanCount = (
}; };
useEffect(() => { useEffect(() => {
fetchDate(userinfo); fetchDate(userinfo.customerId, userinfo.areaId, userinfo.customerPhone);
}, [userinfo]); }, [userinfo.customerId, userinfo.areaId, userinfo.customerPhone]);
return [filterBeanList, fetchDate]; return [filterBeanList, fetchDate];
}; };
......
import { useState, useEffect } from '@tarojs/taro'; import { useEffect, useReducer } from '@tarojs/taro';
import { fetchPayConfig, PayConfig, PayTypeVo } from '@/api/account'; import { fetchPayConfig, PayConfig, PayTypeVo } from '@/api/account';
import Actions from '@/types/Store/Actions';
let initPayConfigList: PayConfig[] = []; enum FirstRechargeState {
let initPaywayList: PayTypeVo[] = []; isFirstRecharge = 1,
notFirstRecharge = 0,
}
type RechargePayState = {
paywayList: PayConfig[];
payConfigList: PayTypeVo[];
isFirstRecharge: FirstRechargeState;
};
const reducer = (state: RechargePayState, action: Actions) => {
switch (action.type) {
case 'updateRechargeInfo':
return action.payload;
default:
return state;
}
};
const usePaywayList = (areaId: number, customerId: number) => { const usePaywayList = (areaId: number, customerId: number) => {
const [paywayList, setPaywayList] = useState(initPaywayList); const [state, dispatch] = useReducer(reducer, {
const [payConfigList, setPayConfigList] = useState(initPayConfigList); paywayList: [],
const [isFirstRecharge, setIsFirstRecharge] = useState(0); payConfigList: [],
isFirstRecharge: 0,
});
const fetchDate = (areaId: number, customerId: number) => { const fetchDate = (areaId: number, customerId: number) => {
fetchPayConfig({ fetchPayConfig({
...@@ -21,9 +41,14 @@ const usePaywayList = (areaId: number, customerId: number) => { ...@@ -21,9 +41,14 @@ const usePaywayList = (areaId: number, customerId: number) => {
listPayList, listPayList,
listRechargeConfDetail, listRechargeConfDetail,
} = res.data; } = res.data;
setPayConfigList(listRechargeConfDetail); dispatch({
setPaywayList(listPayList); type: 'updateRechargeInfo',
setIsFirstRecharge(isFirstRecharge); payload: {
isFirstRecharge,
payConfigList: listRechargeConfDetail,
paywayList: listPayList,
},
});
}) })
.catch(console.error); .catch(console.error);
}; };
...@@ -31,11 +56,7 @@ const usePaywayList = (areaId: number, customerId: number) => { ...@@ -31,11 +56,7 @@ const usePaywayList = (areaId: number, customerId: number) => {
fetchDate(areaId, customerId); fetchDate(areaId, customerId);
}, [areaId, customerId]); }, [areaId, customerId]);
return { return state;
isFirstRecharge,
paywayList,
payConfigList,
};
}; };
export default usePaywayList; export default usePaywayList;
import { Customer } from '@/types/Customer/Customer'; import { useEffect, useReducer } from '@tarojs/taro';
import { useEffect, useState } from '@tarojs/taro';
import { fetchPayOrder, fetchOrderDetailAndPay } from '@/api/order'; import { fetchPayOrder, fetchOrderDetailAndPay } from '@/api/order';
import { PaymentAndActiveInfo, CustomerBeanAccountVo } from '@/api/baseClass';
import Order from '@/types/Order/Order';
import Actions from '@/types/Store/Actions';
import { useDispatch } from '@tarojs/redux';
import { updateOrderState } from '@/store/rootReducers/orderState';
const useWaitPayOrderState = (userinfo: Customer) => { type PayOrderData = {
const [payOrderState, setPayOrderState] = useState(false); accountList: CustomerBeanAccountVo[];
const [accountList, setAccountList] = useState([]); orderInfo: Order;
const [orderInfo, setOrderInfo] = useState(null); payInfos: {
const [payInfos, setPayInfos] = useState(null); paymentAndActiveInfos: PaymentAndActiveInfo[];
paymentConfId: number;
};
};
const initPayOrderData = {
accountList: [],
orderInfo: {
actualMoney: 0,
areaId: 0,
areaName: '',
consumeType: '',
createAt: '',
customerCellphone: '',
customerId: 0,
customerName: '',
deductionBean: 0,
deductionMoney: 0,
equipmentNum: '',
equipmentPosition: '',
id: 0,
operateId: 0,
operateName: '',
operationMode: '',
orderName: '',
orderNumber: '',
orderState: '',
outTradeNo: '',
payType: '',
payableMoney: 0,
serviceId: 0,
serviceName: '',
thirdDiscountMoney: 0,
thirdTradeNumber: '',
updateDate: '',
},
payInfos: {
paymentAndActiveInfos: [],
paymentConfId: 0,
},
};
const reducer = (state: PayOrderData, action: Actions) => {
switch (action.type) {
case 'updateOrderData':
return {
...state,
...action.payload,
};
default:
return state;
}
};
const useWaitPayOrderState = (customerId: number): PayOrderData => {
const [state, dispatch] = useReducer(reducer, initPayOrderData);
const dispatchAction = useDispatch();
useEffect(() => { useEffect(() => {
fetchPayOrder({ fetchPayOrder({
customerId: userinfo.customerId, customerId: customerId,
}) })
.then(res => { .then(res => {
if (res.data.length) { if (res.data.length) {
dispatchAction(updateOrderState(true));
fetchOrderDetailAndPay({ id: res.data[0].id }) fetchOrderDetailAndPay({ id: res.data[0].id })
.then(({ accounts, orderInfo, payInfos }) => { .then(({ accounts, orderInfo, payInfos }) => {
setAccountList(accounts); dispatch({
setOrderInfo(orderInfo); type: 'updateOrderData',
setPayInfos(payInfos); payload: {
accountList: accounts,
orderInfo: orderInfo,
payInfos: payInfos,
},
});
}) })
.catch(err => { .catch(err => {
console.log(err); console.log(err);
}); });
setPayOrderState(true);
} }
}) })
.catch(err => { .catch(err => {
console.log(err); console.log(err);
}); });
}, [userinfo]); }, [customerId]);
return { return state;
payOrderState,
accountList,
orderInfo,
payInfos,
};
}; };
export default useWaitPayOrderState; export default useWaitPayOrderState;
...@@ -89,7 +89,11 @@ export const AccountComponent = () => { ...@@ -89,7 +89,11 @@ export const AccountComponent = () => {
}) })
.then(res => { .then(res => {
console.log(res); console.log(res);
fetchNewBeanList(userinfo); fetchNewBeanList(
userinfo.customerId,
userinfo.areaId,
userinfo.customerPhone,
);
}) })
.catch(err => { .catch(err => {
Taro.showToast({ Taro.showToast({
......
...@@ -3,10 +3,12 @@ import userinfo from './rootReducers/userinfo'; ...@@ -3,10 +3,12 @@ import userinfo from './rootReducers/userinfo';
import OrderList from '../pages/Order/OrderList/store'; import OrderList from '../pages/Order/OrderList/store';
import ShowerReducer from '@/pages/Shower/store'; import ShowerReducer from '@/pages/Shower/store';
import serviceList from './rootReducers/service'; import serviceList from './rootReducers/service';
import orderState from './rootReducers/orderState';
export default combineReducers({ export default combineReducers({
userinfo, userinfo,
OrderList, OrderList,
Shower: ShowerReducer, Shower: ShowerReducer,
serviceList, serviceList,
orderState,
}); });
import Actions from '@/types/Store/Actions';
export type PayOrderState = {
waitPayOrderState: boolean;
};
const INITIAL_STATE = {
waitPayOrderState: false,
};
export const updateOrderState = (state: boolean): Actions => ({
type: 'UPDATE_ORDER_STATE',
payload: state,
});
export default function orderState(
state: PayOrderState = INITIAL_STATE,
action: Actions,
) {
switch (action.type) {
case 'UPDATE_ORDER_STATE':
return { ...state, waitPayOrderState: action.payload };
default:
return state;
}
}
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