redBrandReducer.js
10.1 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
'use strict';
import InitialState from './redBrandInitialState';
import Immutable, {Map} from 'immutable';
const {
SET_SIMILAR_PRODUCT_INDEX,
SET_SHOP_ID,
SET_LAUNCHPROFILE,
SET_FILTER,
PRODUCT_LIST_REQUEST,
PRODUCT_LIST_SUCCESS,
PRODUCT_LIST_FAILURE,
PRODUCT_FILTER_ACTION,
FILTER_LIST_VIEW,
FILTER_MORE_VIEW,
SET_PRODUCT_LIST_FILTER,
RESET_LIST_PAGE_INFO,
SHOP_COUPON_LIST_REQUEST,
SHOP_COUPON_LIST_SUCCESS,
SHOP_COUPON_LIST_FAILURE,
ADD_COUPON_REQUEST,
ADD_COUPON_SUCCESS,
ADD_COUPON_FAILURE,
RESETRECEIVECOUPONRES,
ADD_FAVORITE_REQUEST,
ADD_FAVORITE_SUCCESS,
ADD_FAVORITE_FAILURE,
CANCEL_FAVORITE_REQUEST,
CANCEL_FAVORITE_SUCCESS,
CANCEL_FAVORITE_FAILURE,
GET_FAVORITE_COUNT_REQUEST,
GET_FAVORITE_COUNT_SUCCESS,
GET_FAVORITE_COUNT_FAILURE,
RED_BRAND_DECORATOR_REQUEST,
RED_BRAND_DECORATOR_SUCCESS,
RED_BRAND_DECORATOR_FAILURE,
GET_INTRO_REQUEST,
GET_INTRO_SUCCESS,
GET_INTRO_FAILURE,
PRODUCT_REQUEST,
PRODUCT_SUCCESS,
PRODUCT_FAILURE,
GET_LIVE_COUNT_REQUEST,
GET_LIVE_COUNT_SUCCESS,
GET_LIVE_COUNT_FAILURE,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function redBrandReducer(state=initialState, action) {
switch(action.type) {
case SET_SHOP_ID: {
return state.set('shopId', action.payload);
}
case SET_LAUNCHPROFILE: {
return state.set('launchProfile', action.payload);
}
case SET_FILTER: {
return state.set('fliter', action.payload);
}
case PRODUCT_FILTER_ACTION: {
let {
categoryFilterList,
filterCategoryDetailFilterList,
filterFactors,
filterNameFactors,
} = action.payload;
return state.set('categoryFilterList', Immutable.fromJS(categoryFilterList))
.set('filterCategoryDetailFilterList', Immutable.fromJS(filterCategoryDetailFilterList))
.set('filterNameFactors', Immutable.fromJS(filterNameFactors))
.set('filterFactors', Immutable.fromJS(filterFactors));
}
case PRODUCT_LIST_REQUEST: {
return state.setIn(['productList', 'isFetching'], true)
.setIn(['productList', 'error'], null);
}
case RESET_LIST_PAGE_INFO: {
return state.setIn(['productList', 'currentPage'], 0)
.setIn(['productList', 'pageCount'], 0)
.setIn(['productList', 'total'], 0)
.setIn(['productList', 'endReached'], false);
}
case PRODUCT_LIST_SUCCESS: {
let {
list,
categoryFilterList,
filterCategoryDetailFilterList,
currentPage,
pageCount,
total,
endReached,
} = action.payload;
let newState = state.setIn(['productList', 'isFetching'], false)
.setIn(['productList', 'error'], null)
.setIn(['productList', 'list'], Immutable.fromJS(list))
.setIn(['productList', 'currentPage'], currentPage)
.setIn(['productList', 'pageCount'], pageCount)
.setIn(['productList', 'total'], total)
.setIn(['productList', 'endReached'], endReached);
if (currentPage == 1 && state.categoryFilterList.size == 0 && state.filterCategoryDetailFilterList.size == 0) {
newState = newState.set('categoryFilterList', Immutable.fromJS(categoryFilterList))
.set('filterCategoryDetailFilterList', Immutable.fromJS(filterCategoryDetailFilterList));
}
return newState;
}
case FILTER_LIST_VIEW: {
return state.setIn(['productList', 'isFilter'], action.payload);
}
case FILTER_MORE_VIEW:{
return state.setIn(['productList', 'isMoreFilter'], action.payload);
}
case SET_PRODUCT_LIST_FILTER: {
return state.setIn(['productList', 'order'], action.payload);
}
case SHOP_COUPON_LIST_REQUEST: {
return state.setIn(['coupon', 'isFetching'], true)
.setIn(['coupon', 'error'], null);
}
case SHOP_COUPON_LIST_SUCCESS: {
return state.setIn(['coupon', 'isFetching'], false)
.setIn(['coupon', 'error'], null)
.setIn(['coupon', 'list'], Immutable.fromJS(action.payload));
}
case SHOP_COUPON_LIST_FAILURE: {
return state.setIn(['coupon', 'isFetching'], false)
.setIn(['coupon', 'error'], action.payload);
}
case ADD_COUPON_SUCCESS: {
return state.setIn(['coupon', 'list'], Immutable.fromJS(action.payload))
.setIn(['receiveCouponResult', 'showMessage'], ' 领取成功 ')
.setIn(['receiveCouponResult', 'isNeedShow'], true);
}
case ADD_COUPON_FAILURE: {
return state.setIn(['receiveCouponResult', 'showMessage'], Immutable.fromJS(action.payload))
.setIn(['receiveCouponResult', 'isNeedShow'], true);
}
case RESETRECEIVECOUPONRES:
{
return state.setIn(['receiveCouponResult', 'showMessage'], '')
.setIn(['receiveCouponResult', 'isNeedShow'], false);
}
case ADD_FAVORITE_SUCCESS: {
if (action.payload) {
return state.setIn(['shopIntro', 'is_addFav'], true)
.setIn(['receiveCouponResult', 'showMessage'], '收藏成功')
.setIn(['receiveCouponResult', 'isNeedShow'], true);
// .setIn(['shopIntro', 'favoriteCount'],parseInt(state.shopIntro.favoriteCount) +1);
}else {
return state.setIn(['shopIntro', 'is_addFav'], true)
}
}
case ADD_FAVORITE_FAILURE: {
if (action.payload.code == 413) {
return state.setIn(['shopIntro', 'is_addFav'], true)
.setIn(['receiveCouponResult', 'showMessage'], '已收藏')
.setIn(['receiveCouponResult', 'isNeedShow'], true);
}
return state.setIn(['shopIntro', 'is_addFav'], false)
.setIn(['receiveCouponResult', 'showMessage'], '收藏失败')
.setIn(['receiveCouponResult', 'isNeedShow'], true);
}
case CANCEL_FAVORITE_SUCCESS: {
return state.setIn(['shopIntro', 'is_addFav'], action.payload)
.setIn(['receiveCouponResult', 'showMessage'], '取消收藏成功')
.setIn(['receiveCouponResult', 'isNeedShow'], true);
// .setIn(['shopIntro', 'favoriteCount'],(parseInt(state.shopIntro.favoriteCount) -1)>0?(parseInt(state.shopIntro.favoriteCount) -1):0);
}
case GET_FAVORITE_COUNT_SUCCESS: {
return state.setIn(['shopIntro', 'favoriteCount'], action.payload);
}
case RED_BRAND_DECORATOR_REQUEST: {
return state.setIn(['shopsdecorator', 'isFetching'], true);
}
case RED_BRAND_DECORATOR_SUCCESS: {
let {
shopBanner,
json,
} = action.payload;
let {
isFetching,
error,
app_type,
shop_id,
template_id,
template_type,
modules,
} = json;
let newState = state.setIn(['shopsdecorator', 'isFetching'], false)
.setIn(['shopsdecorator', 'error'], null)
.setIn(['shopsdecorator', 'app_type'], app_type)
.setIn(['shopsdecorator', 'shop_id'], shop_id)
.setIn(['shopsdecorator', 'template_id'], template_id)
.setIn(['shopsdecorator', 'template_type'], template_type)
.setIn(['shopsdecorator', 'modules'], Immutable.fromJS(modules))
.setIn(['shopIntro', 'shopBanner'], Immutable.fromJS(shopBanner))
return newState;
}
case RED_BRAND_DECORATOR_FAILURE: {
return state.setIn(['shopsdecorator', 'error'], action.payload)
.setIn(['shopsdecorator', 'isFetching'], false);
}
case GET_INTRO_REQUEST: {
return state.setIn(['shopIntro', 'isFetching'], true);
}
case GET_INTRO_SUCCESS: {
let {
is_show_shop_name,
mult_brand_shop_type,
shop_domain,
shop_intro,
shop_logo,
shop_name,
shop_template_type,
shops_id,
} = action.payload;
let newState = state.setIn(['shopIntro', 'isFetching'], false)
.setIn(['shopIntro', 'error'], null)
.setIn(['shopIntro', 'is_show_shop_name'], is_show_shop_name)
.setIn(['shopIntro', 'mult_brand_shop_type'], mult_brand_shop_type)
.setIn(['shopIntro', 'shop_domain'], shop_domain)
.setIn(['shopIntro', 'shop_intro'], shop_intro)
.setIn(['shopIntro', 'shop_logo'], shop_logo)
.setIn(['shopIntro', 'shop_name'], shop_name)
.setIn(['shopIntro', 'shop_template_type'], shop_template_type)
.setIn(['shopIntro', 'shops_id'], shops_id);
return newState;
}
case GET_INTRO_FAILURE: {
return state.setIn(['shopIntro', 'error'], action.payload);
}
case PRODUCT_SUCCESS: {
let {
shopBanner,
json,
} = action.payload;
let {
isFetching,
error,
app_type,
shop_id,
template_id,
template_type,
modules,
} = json;
let newState = state.setIn(['shopsdecorator', 'isFetching'], false)
.setIn(['shopsdecorator', 'error'], null)
.setIn(['shopsdecorator', 'app_type'], app_type)
.setIn(['shopsdecorator', 'shop_id'], shop_id)
.setIn(['shopsdecorator', 'template_id'], template_id)
.setIn(['shopsdecorator', 'template_type'], template_type)
.setIn(['shopsdecorator', 'modules'], Immutable.fromJS(modules))
.setIn(['shopIntro', 'shopBanner'], Immutable.fromJS(shopBanner))
return newState;
}
case PRODUCT_FAILURE: {
return state.setIn(['shopsdecorator', 'isFetching'], false);
}
case GET_LIVE_COUNT_REQUEST: {
return state;
}
case GET_LIVE_COUNT_SUCCESS: {
return state.setIn(['shopsdecorator', 'counts'], Immutable.fromJS(action.payload));
}
case GET_LIVE_COUNT_FAILURE: {
return state;
}
case SET_SIMILAR_PRODUCT_INDEX: {
return state.set('similarIndex', action.payload);
}
}
return state;
}