recommendActions.js
5.03 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
'use strict';
import ReactNative from 'react-native';
import RecommendService from '../../services/RecommendService';
const {
HISTORY_SORT_LIST_REQUEST,
HISTORY_SORT_LIST_SUCCESS,
HISTORY_SORT_LIST_FAILURE,
HISTORY_LIST_REQUEST,
HISTORY_LIST_SUCCESS,
HISTORY_LIST_FAILURE,
SET_SELECTED_CATEGORY,
} = require('../../constants/actionTypes').default;
export function setSelectedCategory(catId, index, catName) {
return (dispatch, getState) => {
dispatch({
type: SET_SELECTED_CATEGORY,
payload: {index}
});
dispatch(historyList(catId));
};
}
export function historySortListRequest() {
return {
type: HISTORY_SORT_LIST_REQUEST,
};
}
export function historySortListSuccess(json) {
return {
type: HISTORY_SORT_LIST_SUCCESS,
payload: json
};
}
export function historySortListFailure(error) {
return {
type: HISTORY_SORT_LIST_FAILURE,
payload: error
};
}
export function historySortList() {
return (dispatch, getState) => {
let {app, recommend} = getState();
if (recommend.isFetching) {
return;
}
let fetchList = (uid, sourcePage) => {
dispatch(historySortListRequest());
return new RecommendService(app.host).fetchSortList(uid, sourcePage)
.then(json => {
if (json.length > 0) {
json = [{category_id: -1, category_name: '全部'}, ...json];
}
dispatch(historySortListSuccess(json));
})
.catch(error => {
dispatch(historySortListFailure(error));
});
}
let uid = 0;
let sourcePage = '';
Promise.all([
ReactNative.NativeModules.YH_CommonHelper.sourcePage('YH_MineBrowseHistoryVC'),
]).then(result => {
sourcePage = result[0];
return ReactNative.NativeModules.YH_CommonHelper.uid();
}).then(data => {
uid = data;
fetchList(uid, sourcePage);
})
.catch(error => {
fetchList(uid, sourcePage);
});
};
}
export function historyListRequest(category_id) {
return {
type: HISTORY_LIST_REQUEST,
payload: category_id
};
}
export function historyListSuccess(json) {
return {
type: HISTORY_LIST_SUCCESS,
payload: json
};
}
export function historyListFailure(error) {
return {
type: HISTORY_LIST_FAILURE,
payload: error
};
}
export function historyList(category_id) {
return (dispatch, getState) => {
let {app, recommend} = getState();
let productList = [];
if (recommend && recommend.productList && recommend.productList.size > 0) {
productList = recommend.productList.toJSON();
}
;
if (recommend.isFetching) {
return;
}
let fetchList = (uid, category_id, page, sourcePage) => {
dispatch(historyListRequest(category_id));
return new RecommendService(app.host).fetchPagelist(uid, category_id, page, sourcePage)
.then(json => {
let currentPage = json && json.page ? json.page : 1;
let page_total = json && json.page_total ? json.page_total : 1;
let newproductList = json && json.product_list ? json.product_list : [];
if (productList.length) {
if (newproductList.length) {
productList = [...productList, ...newproductList];
}
;
} else if (newproductList.length) {
productList = newproductList;
}
dispatch(historyListSuccess({currentPage, page_total, productList}));
let show = productList.length > 0;
ReactNative.NativeModules.YH_RecorderHelper.setRightClearButtonVisiblity(show);
})
.catch(error => {
dispatch(historyListFailure(error));
});
}
let uid = 0;
let sourcePage = '';
let page = recommend.currentPage + 1;
if (!category_id && category_id != 0) {
category_id = recommend.curCategoryID;
}
;
Promise.all([
ReactNative.NativeModules.YH_CommonHelper.sourcePage('YH_MineBrowseHistoryVC'),
]).then(result => {
sourcePage = result[0];
return ReactNative.NativeModules.YH_CommonHelper.uid();
}).then(data => {
uid = data;
fetchList(uid, category_id, page, sourcePage);
})
.catch(error => {
fetchList(uid, category_id, page, sourcePage);
});
};
}