outletActions.js
5.86 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
'use strict';
import ReactNative from 'react-native';
import OutletService from '../../services/OutletService';
import * as _ from 'lodash';
import {GetQueryString} from '../../utils/ResourceParser';
const {
SET_PLATFORM,
SET_ACTIVITY_FLITER,
SET_FLITER,
GET_CATEGORY_REQUEST,
GET_CATEGORY_SUCCESS,
GET_CATEGORY_FAILURE,
GET_OUTLETHOMERESOURCE_REQUEST,
GET_OUTLETHOMERESOURCE_SUCCESS,
GET_OUTLETHOMERESOURCE_FAILURE,
GET_PRODUCT_REQUEST,
GET_PRODUCT_SUCCESS,
GET_PRODUCT_FAILURE,
GET_OUTLET_ACTIVITY_LIST_REQUEST,
GET_OUTLET_ACTIVITY_LIST_SUCCESS,
GET_OUTLET_ACTIVITY_LIST_FAILURE,
} = require('../../constants/actionTypes').default;
export function onPressCoupon() {
return {
type: SET_PLATFORM,
payload: true
};
}
export function getCategoryRequest() {
return {
type: GET_CATEGORY_REQUEST,
};
}
export function getCategorySuccess(json) {
return {
type: GET_CATEGORY_SUCCESS,
payload: json
}
}
export function getCategoryFailure(error) {
return {
type: GET_CATEGORY_FAILURE,
payload: error
}
}
export function getCategory() {
return (dispatch, getState) => {
let {app, outlet} = getState();
let parent_id = app.categoryId;
dispatch(getCategoryRequest());
return new OutletService(app.serviceHost).getCategory(parent_id)
.then(json => {
let params = parseListFromCategory(json);
dispatch(getCategorySuccess(params));
})
.catch(error => {
dispatch(getCategoryFailure(error));
});
};
}
function parseListFromCategory(json) {
json.map((item, i) => {
let url = item.sort_url;
let content_code = GetQueryString(url,'content_code');
if (!content_code) {
content_code = item.content_code;
}
item.content_code = content_code;
})
return json;
}
export function getOutletHomeResourceRequest(content_code) {
return {
type: GET_OUTLETHOMERESOURCE_REQUEST,
payload: content_code
};
}
export function getOutletHomeResourceSuccess(json) {
return {
type: GET_OUTLETHOMERESOURCE_SUCCESS,
payload: json
}
}
export function getOutletHomeResourceFailure(content_code,error) {
return {
type: GET_OUTLETHOMERESOURCE_FAILURE,
payload: {'error':error,'content_code':content_code}
}
}
export function getOutletHomeResource(content_code,ptr) {
return (dispatch, getState) => {
let {app, outlet} = getState();
let {categoryList} = outlet;
dispatch(getOutletHomeResourceRequest({'ptr':ptr,'content_code':content_code}));
return new OutletService(app.serviceHost).getOutletHomeResource(content_code)
.then(json => {
dispatch(getOutletHomeResourceSuccess({'json':json,'content_code':content_code}));
let categoryNavigationItem;
if (json.list) {
json.list.map((item, i) => {
let template_name = item.template_name;
if (template_name == 'categoryNavigation') {
categoryNavigationItem = item.data[0];
}
});
}
dispatch(getProductList(content_code,categoryNavigationItem));
})
.catch(error => {
dispatch(getOutletHomeResourceFailure(content_code,error));
});
};
}
export function getProductListRequest(json) {
return {
type: GET_PRODUCT_REQUEST,
payload: json
};
}
export function getProductListSuccess(json) {
return {
type: GET_PRODUCT_SUCCESS,
payload: json
}
}
export function getProductListFailure(content_code,error) {
return {
type: GET_PRODUCT_FAILURE,
payload: {'error':error,'content_code':content_code,'categoryNavigationItem':categoryNavigationItem}
}
}
export function getProductList(content_code,categoryNavigationItem) {
return (dispatch, getState) => {
let {app, outlet} = getState();
let {categoryList} = outlet;
//limit,page,uid,firstProductSkn=''
// if (productList.isFetching || productList.endReached || productList.error) {
// return;
// }
let param = parseUrlForparam(categoryNavigationItem.url);
let page = 1;//productList.currentPage + 1;
let pageSize = 60;//productList.pageSize;
dispatch(getProductListRequest({'content_code':content_code,'categoryNavigationItem':categoryNavigationItem}));
return new OutletService(app.host).getProductList(pageSize,page,param)
.then(json => {
dispatch(getProductListSuccess({'json':json,'content_code':content_code,'categoryNavigationItem':categoryNavigationItem}));
})
.catch(error => {
dispatch(getProductListFailure(content_code,error,categoryNavigationItem));
});
};
}
function parseUrlForparam(url) {
let part = GetQueryString(url,'openby:yohobuy');
let param = JSON.parse(part).params;
return param;
}
export function getOutletActivityListRequest(content_code) {
return {
type: GET_OUTLET_ACTIVITY_LIST_REQUEST,
payload: content_code
};
}
export function getOutletActivityListSuccess(json) {
return {
type: GET_OUTLET_ACTIVITY_LIST_SUCCESS,
payload: json
}
}
export function getOutletActivityListFailure(content_code,error) {
return {
type: GET_OUTLET_ACTIVITY_LIST_FAILURE,
payload: {'error':error,'content_code':content_code}
}
}
export function getOutletActivityList(content_code) {
return (dispatch, getState) => {
let {app, outlet} = getState();
let {categoryList} = outlet;
dispatch(getOutletActivityListRequest(content_code));
return new OutletService(app.host).getOutletActivityList(app.yh_channel)
.then(json => {
dispatch(getOutletActivityListSuccess({'json':json,'content_code':content_code}));
})
.catch(error => {
dispatch(getOutletActivityListFailure(content_code,error));
});
};
}
export function setActivityFliter(content_code,activityMore) {
return {
type: SET_ACTIVITY_FLITER,
payload: {'activityMore':activityMore,'content_code':content_code}
};
}
export function onPressFilter(content_code,value) {
return {
type: SET_FLITER,
payload: {'value':value,'content_code':content_code}
};
}