...
|
...
|
@@ -6,9 +6,11 @@ import SearchService from '../../services/SearchService'; |
|
|
const {
|
|
|
SET_KEYWORD,
|
|
|
SET_SEARCH_STATUS,
|
|
|
SET_FILTER,
|
|
|
SEARCH_REQUEST,
|
|
|
SEARCH_SUCCESS,
|
|
|
SEARCH_FAILURE,
|
|
|
RESET_LIST_PAGE_INFO,
|
|
|
JUMP_URL_REQUEST,
|
|
|
JUMP_URL_SUCCESS,
|
|
|
JUMP_URL_FAILURE,
|
...
|
...
|
@@ -31,6 +33,7 @@ const { |
|
|
|
|
|
export function searchKeywordChanged(keyword) {
|
|
|
return (dispatch, getState) => {
|
|
|
console.log(keyword)
|
|
|
let status = 0;
|
|
|
if (keyword) {
|
|
|
status = 1;
|
...
|
...
|
@@ -49,16 +52,13 @@ export function searchButtonPressed(keyword) { |
|
|
if (!keyword) {
|
|
|
let {app, search} = getState();
|
|
|
keyword = search.placeholder
|
|
|
dispatch(setKeyword(keyword));
|
|
|
}
|
|
|
|
|
|
dispatch(setKeyword(keyword));
|
|
|
dispatch(insertSearchHistory(keyword));
|
|
|
|
|
|
ReactNative.NativeModules.YH_SearchHelper.setSearchKeyword(keyword);
|
|
|
ReactNative.NativeModules.YH_SearchHelper.resignSearchBar();
|
|
|
|
|
|
// let status = 2;
|
|
|
// dispatch(setSearchStatus(status));
|
|
|
dispatch(jumpUrl(keyword));
|
|
|
};
|
|
|
}
|
...
|
...
|
@@ -77,6 +77,19 @@ export function setSearchStatus(status) { |
|
|
};
|
|
|
}
|
|
|
|
|
|
export function setFilter(value) {
|
|
|
return {
|
|
|
type: SET_FILTER,
|
|
|
payload: value
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function resetListPageInfo() {
|
|
|
return {
|
|
|
type: RESET_LIST_PAGE_INFO,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function searchRequest() {
|
|
|
return {
|
|
|
type: SEARCH_REQUEST,
|
...
|
...
|
@@ -97,29 +110,45 @@ export function searchFailure(error) { |
|
|
};
|
|
|
}
|
|
|
|
|
|
export function searchProductList(keyword, uid, sourcePage) {
|
|
|
export function searchProductList(keyword, reload=false) {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, search} = getState();
|
|
|
// if (search.productList.isFetching) {
|
|
|
// return;
|
|
|
// }
|
|
|
let {productList} = search;
|
|
|
if (reload) {
|
|
|
|
|
|
} else {
|
|
|
if (productList.isFetching || productList.endReached || productList.error) {
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
let fetchList = (keyword, order, uid, page, sourcePage) => {
|
|
|
let fetchList = (keyword, order, uid, page, pageSize, sourcePage) => {
|
|
|
dispatch(searchRequest());
|
|
|
return new SearchService(app.host).searchProductList(keyword, order, uid, page, sourcePage)
|
|
|
return new SearchService(app.host).searchProductList(keyword, order, uid, page, pageSize, sourcePage)
|
|
|
.then(json => {
|
|
|
let payload = parseProductList(json);
|
|
|
payload.endReached = payload.currentPage == payload.pageCount;
|
|
|
|
|
|
if (productList.currentPage > 1) {
|
|
|
let oldList = productList.list.toJS();
|
|
|
let list = [...oldList, ...payload.list];
|
|
|
payload.list = list;
|
|
|
}
|
|
|
|
|
|
dispatch(setSearchStatus(2));
|
|
|
dispatch(searchSuccess(json.product_list));
|
|
|
dispatch(searchSuccess(payload));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(searchFailure(error));
|
|
|
});
|
|
|
}
|
|
|
|
|
|
|
|
|
let uid = 0;
|
|
|
let sourcePage = '';
|
|
|
let order = 's_n_desc';
|
|
|
let page = 1;
|
|
|
let order = productList.filter;
|
|
|
let page = productList.currentPage + 1;
|
|
|
let pageSize = productList.pageSize;
|
|
|
ReactNative.NativeModules.YH_CommonHelper.sourcePage('YH_SearchProListVC')
|
|
|
.then(data => {
|
|
|
sourcePage = data;
|
...
|
...
|
@@ -127,14 +156,43 @@ export function searchProductList(keyword, uid, sourcePage) { |
|
|
})
|
|
|
.then(data => {
|
|
|
uid = data;
|
|
|
fetchList(keyword, order, uid, page, sourcePage);
|
|
|
fetchList(keyword, order, uid, page, pageSize, sourcePage);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
fetchList(keyword, order, uid, page, sourcePage);
|
|
|
fetchList(keyword, order, uid, page, pageSize, sourcePage);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
function parseProductList(json) {
|
|
|
let currentPage = json && json.page ? json.page : 1;
|
|
|
let pageCount = json && json.page_total ? json.page_total : 0;
|
|
|
let total = json && json.total ? json.total : 0;
|
|
|
|
|
|
let shopOrBrand = [];
|
|
|
if (currentPage == 1) {
|
|
|
shopOrBrand = json && json.shop ? json.shop : [];
|
|
|
if (!shopOrBrand || shopOrBrand.length == 0) {
|
|
|
let brand = json && json.brand;
|
|
|
if (brand) {
|
|
|
shopOrBrand.push(brand);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
shopOrBrand = shopOrBrand ? shopOrBrand : [];
|
|
|
|
|
|
let list = json && json.product_list ? json.product_list : [];
|
|
|
|
|
|
return {
|
|
|
list,
|
|
|
shopOrBrand,
|
|
|
currentPage,
|
|
|
pageCount,
|
|
|
total,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function jumpUrlRequest() {
|
|
|
return {
|
|
|
type: JUMP_URL_REQUEST,
|
...
|
...
|
@@ -172,12 +230,12 @@ export function jumpUrl(keyword) { |
|
|
if (jumpUrl) {
|
|
|
ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(jumpUrl);
|
|
|
} else {
|
|
|
dispatch(searchProductList(keyword, uid, sourcePage));
|
|
|
dispatch(searchProductList(keyword, true));
|
|
|
}
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(jumpUrlFailure(error));
|
|
|
dispatch(searchProductList(keyword, uid, sourcePage));
|
|
|
dispatch(searchProductList(keyword, true));
|
|
|
});
|
|
|
}
|
|
|
|
...
|
...
|
|