...
|
...
|
@@ -6,6 +6,10 @@ import Immutable, {Map} from 'immutable'; |
|
|
import {Platform} from 'react-native';
|
|
|
|
|
|
const {
|
|
|
HISTORY_SORT_LIST_REQUEST,
|
|
|
HISTORY_SORT_LIST_SUCCESS,
|
|
|
HISTORY_SORT_LIST_FAILURE,
|
|
|
|
|
|
HISTORY_LIST_REQUEST,
|
|
|
HISTORY_LIST_SUCCESS,
|
|
|
HISTORY_LIST_FAILURE,
|
...
|
...
|
@@ -24,45 +28,78 @@ const { |
|
|
|
|
|
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, browse} = getState();
|
|
|
let productList = browse.productList.toJS();
|
|
|
let newProductList = [];
|
|
|
if (catId == -1) {
|
|
|
newProductList = productList;
|
|
|
} else {
|
|
|
productList.map((item, i) => {
|
|
|
if (item.category_id == catId) {
|
|
|
newProductList.push(item);
|
|
|
|
|
|
if (browse.isFetching) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
let fetchList = (uid, sourcePage) => {
|
|
|
dispatch(historySortListRequest());
|
|
|
return new BrowseService(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 pName = 'iFP_MineBrowseHistory';
|
|
|
if(Platform.OS === 'android'){
|
|
|
pName = 'aFP_MineBrowseHistory';
|
|
|
}
|
|
|
for (var i = 0; i < newProductList.length; i++) {
|
|
|
let item = newProductList[i];
|
|
|
let yh_exposureData = {
|
|
|
'P_NAME': pName,
|
|
|
'TAB_ID': parseInt(index) + 1,
|
|
|
'TAB_NAME': catName,
|
|
|
'I_INDEX': i + 1,
|
|
|
'PRD_SKN': item.product_skn?item.product_skn:'',
|
|
|
exposureEnd : 1,
|
|
|
};
|
|
|
item.yh_exposureData = yh_exposureData;
|
|
|
}
|
|
|
|
|
|
dispatch({
|
|
|
type: SET_SELECTED_CATEGORY,
|
|
|
payload: {productList: newProductList, index}
|
|
|
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() {
|
|
|
export function historyListRequest(category_id) {
|
|
|
return {
|
|
|
type: HISTORY_LIST_REQUEST,
|
|
|
payload: category_id
|
|
|
};
|
|
|
}
|
|
|
|
...
|
...
|
@@ -80,21 +117,36 @@ export function historyListFailure(error) { |
|
|
};
|
|
|
}
|
|
|
|
|
|
export function historyList() {
|
|
|
export function historyList(category_id) {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, browse} = getState();
|
|
|
let productList = [];
|
|
|
if (browse && browse.productList && browse.productList.size > 0) {
|
|
|
productList = browse.productList.toJSON();
|
|
|
};
|
|
|
|
|
|
if (browse.isFetching) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
let fetchList = (uid, page, pageSize, sourcePage) => {
|
|
|
dispatch(historyListRequest());
|
|
|
return new BrowseService(app.host).fetchList(uid, page, pageSize, sourcePage)
|
|
|
let fetchList = (uid, category_id, page, sourcePage) => {
|
|
|
dispatch(historyListRequest(category_id));
|
|
|
return new BrowseService(app.host).fetchPagelist(uid, category_id, page, sourcePage)
|
|
|
.then(json => {
|
|
|
let payload = parseHistoryList(json);
|
|
|
dispatch(historyListSuccess(payload));
|
|
|
let show = payload.productList.length > 0;
|
|
|
|
|
|
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 => {
|
...
|
...
|
@@ -105,57 +157,25 @@ export function historyList() { |
|
|
let uid = 0;
|
|
|
let sourcePage = '';
|
|
|
let page = browse.currentPage + 1;
|
|
|
let pageSize = browse.pageSize;
|
|
|
if (!category_id) {
|
|
|
category_id = browse.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, page, pageSize, sourcePage);
|
|
|
fetchList(uid, category_id, page, sourcePage);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
fetchList(uid, page, pageSize, sourcePage);
|
|
|
fetchList(uid, category_id, page, sourcePage);
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function parseHistoryList(json) {
|
|
|
let currentPage = json && json.page ? json.page : 1;
|
|
|
|
|
|
let productList = json && json.product_list ? json.product_list : [];
|
|
|
let categoryList = json && json.category_list ? json.category_list : [];
|
|
|
|
|
|
let pName = 'iFP_MineBrowseHistory';
|
|
|
if(Platform.OS === 'android'){
|
|
|
pName = 'aFP_MineBrowseHistory';
|
|
|
}
|
|
|
for (var i = 0; i < productList.length; i++) {
|
|
|
let item = productList[i];
|
|
|
let yh_exposureData = {
|
|
|
'P_NAME': pName,
|
|
|
'TAB_ID': '1',
|
|
|
'TAB_NAME': '全部',
|
|
|
'I_INDEX': i + 1 + '',
|
|
|
'PRD_SKN': item.product_skn?item.product_skn:'',
|
|
|
exposureEnd : 1,
|
|
|
};
|
|
|
item.yh_exposureData = yh_exposureData;
|
|
|
}
|
|
|
|
|
|
if (categoryList.length > 0) {
|
|
|
categoryList = [{category_id: -1, category_name: '全部'} , ...categoryList];
|
|
|
}
|
|
|
|
|
|
return {
|
|
|
categoryList,
|
|
|
productList,
|
|
|
currentPage,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function historyDeleteRequest() {
|
|
|
return {
|
...
|
...
|
@@ -189,9 +209,7 @@ export function deleteOneHistory(skn, index) { |
|
|
dispatch(historyDeleteRequest());
|
|
|
return new BrowseService(app.host).deleteHistory(skn, uid, sourcePage)
|
|
|
.then(json => {
|
|
|
let {productList, selectedProductList} = browse;
|
|
|
let selectedProduct = selectedProductList.toJS()[index];
|
|
|
selectedProductList = selectedProductList.delete(index);
|
|
|
let {productList} = browse;
|
|
|
let lists = productList.toArray();
|
|
|
let indexInAll = productList.findIndex((item, i) => {
|
|
|
return item.get('product_skn') == skn;
|
...
|
...
|
@@ -199,10 +217,10 @@ export function deleteOneHistory(skn, index) { |
|
|
if (indexInAll != -1) {
|
|
|
productList = productList.delete(indexInAll);
|
|
|
}
|
|
|
if (selectedProductList.size == 0 || selectedProductList.length == 0) {
|
|
|
dispatch(deleteSelectedProducts([selectedProduct]));
|
|
|
if (productList.size == 0 || productList.length == 0) {
|
|
|
dispatch(historySortList());
|
|
|
}else {
|
|
|
dispatch(historyDeleteSuccess({productList, selectedProductList}));
|
|
|
dispatch(historyDeleteSuccess({productList}));
|
|
|
}
|
|
|
|
|
|
let show = productList.size > 0;
|
...
|
...
|
@@ -269,11 +287,9 @@ export function clearHistory(selectedProducts) { |
|
|
dispatch(historyClearRequest());
|
|
|
return new BrowseService(app.host).deleteHistory(skns, uid, sourcePage)
|
|
|
.then(json => {
|
|
|
let {productList, selectedProductList} = browse;
|
|
|
console.log('000')
|
|
|
dispatch(deleteSelectedProducts(selectedProducts));
|
|
|
let show = productList.size > 0;
|
|
|
ReactNative.NativeModules.YH_RecorderHelper.setRightClearButtonVisiblity(show);
|
|
|
dispatch(historySortList());
|
|
|
dispatch(historyList(0));
|
|
|
dispatch({type: HISTORY_CLEAR_SUCCESS});
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(historyClearFailure(error));
|
...
|
...
|
@@ -299,40 +315,3 @@ export function clearHistory(selectedProducts) { |
|
|
};
|
|
|
}
|
|
|
|
|
|
export function deleteSelectedProducts(selectedProducts) {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, browse} = getState();
|
|
|
|
|
|
if (browse.productList.size == 0) {
|
|
|
return;
|
|
|
}
|
|
|
let {productList, selectedProductList, categoryList} = browse;
|
|
|
let newProductList = [];
|
|
|
let categoryId = selectedProducts[0].category_id;
|
|
|
categoryList = categoryList.toJS();
|
|
|
let newCategoryList = [];
|
|
|
categoryList.map((categoryItem, i)=> {
|
|
|
if (categoryItem.category_id != categoryId) {
|
|
|
newCategoryList.push(categoryItem);
|
|
|
}
|
|
|
});
|
|
|
productList = productList.toJS();
|
|
|
productList.map((item, j) => {
|
|
|
let exist = false;
|
|
|
selectedProducts.map((selectedItem, i) => {
|
|
|
if (item.product_skn == selectedItem.product_skn) {
|
|
|
exist = true;
|
|
|
}
|
|
|
});
|
|
|
if (!exist) {
|
|
|
newProductList.push(item);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
dispatch({
|
|
|
type: HISTORY_CLEAR_SUCCESS,
|
|
|
payload: {productList: newProductList,categoryList:newCategoryList,index:0}
|
|
|
});
|
|
|
|
|
|
};
|
|
|
} |
...
|
...
|
|