Commit 28c6f509 by 姜雷

修改设备以及支付配置更新逻辑

parent 285a907f
...@@ -10,7 +10,11 @@ import { getDeviceConfig } from '../../api/device'; ...@@ -10,7 +10,11 @@ import { getDeviceConfig } from '../../api/device';
import { UserState, updateUserInfo } from '../../store/rootReducers/userinfo'; import { UserState, updateUserInfo } from '../../store/rootReducers/userinfo';
import { connect } from '@tarojs/redux'; import { connect } from '@tarojs/redux';
import { Customer } from '../../types/Customer/Customer'; import { Customer } from '../../types/Customer/Customer';
import { DeviceState, updateDeviceData } from '../../store/rootReducers/device'; import {
DeviceState,
updateDeviceData,
resetDeviceData,
} from '../../store/rootReducers/device';
import PrepayConfig from '../../types/Order/Order'; import PrepayConfig from '../../types/Order/Order';
import { updatePayData } from '../../store/rootReducers/prepayConfig'; import { updatePayData } from '../../store/rootReducers/prepayConfig';
...@@ -27,6 +31,7 @@ type PageDispatchProps = { ...@@ -27,6 +31,7 @@ type PageDispatchProps = {
updateUserInfo: (e: UserState) => void; updateUserInfo: (e: UserState) => void;
updateDeviceData: (e: DeviceState) => void; updateDeviceData: (e: DeviceState) => void;
updatePayData: (e: PrepayConfig[]) => void; updatePayData: (e: PrepayConfig[]) => void;
resetDeviceData: () => void;
}; };
type PageOwnProps = {}; type PageOwnProps = {};
...@@ -53,6 +58,9 @@ interface Index { ...@@ -53,6 +58,9 @@ interface Index {
updatePayData(data: PrepayConfig[]) { updatePayData(data: PrepayConfig[]) {
dispatch(updatePayData(data)); dispatch(updatePayData(data));
}, },
resetDeviceData() {
dispatch(resetDeviceData());
},
}), }),
) )
class Index extends Component { class Index extends Component {
...@@ -133,7 +141,12 @@ class Index extends Component { ...@@ -133,7 +141,12 @@ class Index extends Component {
getDeviceConfigHandle({ equipmentNum, serviceId }: DeviceEntity) { getDeviceConfigHandle({ equipmentNum, serviceId }: DeviceEntity) {
Taro.showLoading(); Taro.showLoading();
const { userinfo, updateDeviceData, updatePayData } = this.props; const {
userinfo,
updateDeviceData,
updatePayData,
resetDeviceData,
} = this.props;
return getDeviceConfig({ return getDeviceConfig({
customerId: userinfo.customerId, customerId: userinfo.customerId,
equipmentNum: equipmentNum, equipmentNum: equipmentNum,
...@@ -147,8 +160,16 @@ class Index extends Component { ...@@ -147,8 +160,16 @@ class Index extends Component {
console.log('设备使用中'); console.log('设备使用中');
return; return;
} }
deviceInfoResponse && updateDeviceData(deviceInfoResponse); if (deviceInfoResponse) {
prepayConfigs && updatePayData(prepayConfigs); updateDeviceData(deviceInfoResponse);
} else {
resetDeviceData();
}
if (prepayConfigs) {
updatePayData(prepayConfigs);
} else {
updatePayData([]);
}
Taro.navigateTo({ Taro.navigateTo({
url: '/pages/pay/pay', url: '/pages/pay/pay',
}); });
......
...@@ -13,12 +13,17 @@ export const INITIAL_STATE = { ...@@ -13,12 +13,17 @@ export const INITIAL_STATE = {
position: '', position: '',
positionId: '', positionId: '',
rates: [], rates: [],
serviceId: 0,
serviceName: '',
}; };
export const updateDeviceData = (entity: DeviceState): Action => ({ export const updateDeviceData = (entity: DeviceState): Action => ({
type: 'UPDATE_DEVICE_DATA', type: 'UPDATE_DEVICE_DATA',
payload: entity, payload: entity,
}); });
export const resetDeviceData = (): Action => ({
type: 'UPDATE_DEVICE_DATA',
});
export default function device( export default function device(
state: Device = INITIAL_STATE, state: Device = INITIAL_STATE,
...@@ -30,6 +35,10 @@ export default function device( ...@@ -30,6 +35,10 @@ export default function device(
...state, ...state,
...actions.payload, ...actions.payload,
}; };
case 'UPDATE_DEVICE_DATA':
return {
...INITIAL_STATE,
};
default: default:
return state; return state;
} }
......
...@@ -14,7 +14,7 @@ export default function prepayConfig( ...@@ -14,7 +14,7 @@ export default function prepayConfig(
): PrepayConfig[] { ): PrepayConfig[] {
switch (actions.type) { switch (actions.type) {
case 'UPDATE_PAY_DATA': case 'UPDATE_PAY_DATA':
return [...state, ...actions.payload]; return [...actions.payload];
default: default:
return state; 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