deliverGoodsReducer.js
2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
'use strict';
/**
* ## Imports
*
* InitialState
*/
import InitialState from './deliverGoodsInitialState';
import Immutable, {List, Record} from 'immutable';
const {
LOGOUT,
DELIVERY_GOODS_REQUEST,
DELIVERY_GOODS_SUCCESS,
DELIVERY_GOODS_FAILURE,
GET_EXPRESS_LIST_REQUEST,
GET_EXPRESS_LIST_SUCCESS,
GET_EXPRESS_LIST_FAILURE,
QUERYBYSUPPLIER_REQUEST,
QUERYBYSUPPLIER_SUCCESS,
QUERYBYSUPPLIER_FAILURE,
SET_EXPRESS_NUM,
SET_EXPRESS_VALUE,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
/**
* ## guideReducer function
* @param {Object} state - initialState
* @param {Object} action - type and payload
*/
export default function userReducer(state = initialState, action) {
if (!(state instanceof InitialState)) return initialState.merge(state);
switch (action.type) {
case DELIVERY_GOODS_REQUEST:{
return state;
}
case DELIVERY_GOODS_SUCCESS:{
return state;
}
case DELIVERY_GOODS_FAILURE:{
return state;
}
case GET_EXPRESS_LIST_REQUEST:{
return state.setIn(['expressList', 'isFetching'], true)
.setIn(['expressList', 'error'], null);
}
case GET_EXPRESS_LIST_SUCCESS:{
return state.setIn(['expressList', 'isFetching'], false)
.setIn(['expressList', 'error'], null)
.setIn(['expressList', 'list'], Immutable.fromJS(action.payload));
}
case GET_EXPRESS_LIST_FAILURE:{
return state.setIn(['expressList', 'isFetching'], false)
.setIn(['expressList', 'error'], action.payload);
}
case QUERYBYSUPPLIER_REQUEST:{
return state.setIn(['storehouse', 'isFetching'], true)
.setIn(['storehouse', 'error'], null);
}
case QUERYBYSUPPLIER_SUCCESS:{
return state.setIn(['storehouse', 'isFetching'], false)
.setIn(['storehouse', 'adminName'], action.payload.adminName)
.setIn(['storehouse', 'address'], action.payload.address)
.setIn(['storehouse', 'phone'], action.payload.phone)
.setIn(['storehouse', 'storehouseName'], action.payload.storehouseName)
.setIn(['storehouse', 'id'], action.payload.id)
.setIn(['storehouse', 'status'], action.payload.status)
.setIn(['storehouse', 'error'], null)
}
case QUERYBYSUPPLIER_FAILURE:{
return state.setIn(['storehouse', 'isFetching'], false)
.setIn(['storehouse', 'error'], action.payload);
}
case SET_EXPRESS_NUM:{
return state.set('expressNum', action.payload);
}
case SET_EXPRESS_VALUE:{
return state.set('expressValue', Immutable.fromJS(action.payload.value))
.set('deliverData', Immutable.fromJS(action.payload.initialRes));
}
return state;
}
return state;
}