Commit 28c6f509 by 姜雷

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

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