Showing
9 changed files
with
202 additions
and
153 deletions
@@ -12,6 +12,7 @@ import ReactNative, { | @@ -12,6 +12,7 @@ import ReactNative, { | ||
12 | } from 'react-native'; | 12 | } from 'react-native'; |
13 | 13 | ||
14 | import LoadingIndicator from '../../../common/components/LoadingIndicator'; | 14 | import LoadingIndicator from '../../../common/components/LoadingIndicator'; |
15 | +import LoadMoreIndicator from '../../../common/components/LoadMoreIndicator'; | ||
15 | import ProductCell from './ProductCell'; | 16 | import ProductCell from './ProductCell'; |
16 | import CategorySelector from './CategorySelector'; | 17 | import CategorySelector from './CategorySelector'; |
17 | import NoDataView from '../product/NoDataView' | 18 | import NoDataView from '../product/NoDataView' |
@@ -89,7 +90,7 @@ export default class Browse extends Component { | @@ -89,7 +90,7 @@ export default class Browse extends Component { | ||
89 | 90 | ||
90 | 91 | ||
91 | renderSectionHeader() { | 92 | renderSectionHeader() { |
92 | - let {isFetching, selectedProductList, categoryList, selectedCategoryIndex} = this.props.data; | 93 | + let {isFetching, categoryList, selectedCategoryIndex} = this.props.data; |
93 | return ( | 94 | return ( |
94 | <CategorySelector | 95 | <CategorySelector |
95 | data={categoryList} | 96 | data={categoryList} |
@@ -104,10 +105,11 @@ export default class Browse extends Component { | @@ -104,10 +105,11 @@ export default class Browse extends Component { | ||
104 | 105 | ||
105 | render() { | 106 | render() { |
106 | 107 | ||
107 | - let {isFetching, productList, selectedProductList, categoryList, selectedCategoryIndex, isDeleting, showEmpty} = this.props.data; | 108 | + let {isFetching, productList, categoryList, selectedCategoryIndex, isDeleting, showEmpty, currentPage, page_total} = this.props.data; |
108 | 109 | ||
109 | - let isLoading = (selectedProductList.size == 0 && isFetching) || isDeleting; | 110 | + let isLoading = (productList.size == 0 && isFetching) || isDeleting; |
110 | let showList = !isFetching && productList.size > 0; | 111 | let showList = !isFetching && productList.size > 0; |
112 | + let isLoadingMore = isFetching && currentPage > 0; | ||
111 | return ( | 113 | return ( |
112 | <View style={styles.container}> | 114 | <View style={styles.container}> |
113 | {showList ? <SwipeListView | 115 | {showList ? <SwipeListView |
@@ -116,7 +118,7 @@ export default class Browse extends Component { | @@ -116,7 +118,7 @@ export default class Browse extends Component { | ||
116 | enableEmptySections={true} | 118 | enableEmptySections={true} |
117 | disableRightSwipe={true} | 119 | disableRightSwipe={true} |
118 | yh_viewVisible = {true} | 120 | yh_viewVisible = {true} |
119 | - sections={[{data:selectedProductList.toArray(),key:'browse'}]} | 121 | + sections={[{data:productList.toArray(),key:'browse'}]} |
120 | renderItem={this.renderItem} | 122 | renderItem={this.renderItem} |
121 | renderSectionHeader={this.renderSectionHeader} | 123 | renderSectionHeader={this.renderSectionHeader} |
122 | renderHiddenRow={ (data, rowMap) => ( | 124 | renderHiddenRow={ (data, rowMap) => ( |
@@ -131,6 +133,18 @@ export default class Browse extends Component { | @@ -131,6 +133,18 @@ export default class Browse extends Component { | ||
131 | )} | 133 | )} |
132 | rightOpenValue={-70} | 134 | rightOpenValue={-70} |
133 | categoryId={selectedCategoryIndex} | 135 | categoryId={selectedCategoryIndex} |
136 | + ListFooterComponent={()=>{ | ||
137 | + if (page_total == currentPage) { | ||
138 | + return <View style={styles.placeholder} />; | ||
139 | + } else { | ||
140 | + return <LoadMoreIndicator isVisible={isLoadingMore} animating={true}/>; | ||
141 | + } | ||
142 | + }} | ||
143 | + onEndReached={() => { | ||
144 | + if (productList && productList.size > 0 && currentPage < page_total) { | ||
145 | + this.props.onEndReached && this.props.onEndReached(); | ||
146 | + } | ||
147 | + }} | ||
134 | /> : null} | 148 | /> : null} |
135 | 149 | ||
136 | {showEmpty ? <NoDataView type={'browse'} onPressGuangGuang={this.props.onPressGuangGuang}/> : null} | 150 | {showEmpty ? <NoDataView type={'browse'} onPressGuangGuang={this.props.onPressGuangGuang}/> : null} |
@@ -12,6 +12,7 @@ import ReactNative, { | @@ -12,6 +12,7 @@ import ReactNative, { | ||
12 | } from 'react-native'; | 12 | } from 'react-native'; |
13 | 13 | ||
14 | import LoadingIndicator from '../../../common/components/LoadingIndicator'; | 14 | import LoadingIndicator from '../../../common/components/LoadingIndicator'; |
15 | +import LoadMoreIndicator from '../../../common/components/LoadMoreIndicator'; | ||
15 | import ProductCell from './ProductCell'; | 16 | import ProductCell from './ProductCell'; |
16 | import CategorySelector from './CategorySelector'; | 17 | import CategorySelector from './CategorySelector'; |
17 | import Swipeable from 'react-native-swipeable'; | 18 | import Swipeable from 'react-native-swipeable'; |
@@ -115,7 +116,7 @@ export default class Browse extends Component { | @@ -115,7 +116,7 @@ export default class Browse extends Component { | ||
115 | } | 116 | } |
116 | 117 | ||
117 | renderSectionHeader() { | 118 | renderSectionHeader() { |
118 | - let {isFetching, selectedProductList, categoryList, selectedCategoryIndex} = this.props.data; | 119 | + let {isFetching, categoryList, selectedCategoryIndex} = this.props.data; |
119 | return ( | 120 | return ( |
120 | <CategorySelector | 121 | <CategorySelector |
121 | data={categoryList} | 122 | data={categoryList} |
@@ -130,9 +131,10 @@ export default class Browse extends Component { | @@ -130,9 +131,10 @@ export default class Browse extends Component { | ||
130 | 131 | ||
131 | render() { | 132 | render() { |
132 | 133 | ||
133 | - let {isFetching, productList, selectedProductList, categoryList, selectedCategoryIndex, isDeleting, showEmpty} = this.props.data; | 134 | + let {isFetching, productList, categoryList, selectedCategoryIndex, isDeleting, showEmpty, currentPage, page_total} = this.props.data; |
134 | 135 | ||
135 | - let isLoading = (selectedProductList.size == 0 && isFetching) || isDeleting; | 136 | + let isLoading = (productList.size == 0 && isFetching) || isDeleting; |
137 | + let isLoadingMore = isFetching && currentPage > 0; | ||
136 | let showList = !isFetching && productList.size > 0; | 138 | let showList = !isFetching && productList.size > 0; |
137 | return ( | 139 | return ( |
138 | <View style={styles.container}> | 140 | <View style={styles.container}> |
@@ -143,10 +145,22 @@ export default class Browse extends Component { | @@ -143,10 +145,22 @@ export default class Browse extends Component { | ||
143 | scrollEnabled={!this.state.isSwiping} | 145 | scrollEnabled={!this.state.isSwiping} |
144 | enableEmptySections={true} | 146 | enableEmptySections={true} |
145 | yh_viewVisible = {true} | 147 | yh_viewVisible = {true} |
146 | - dataSource={this.dataSource.cloneWithRows(selectedProductList.toArray())} | 148 | + dataSource={this.dataSource.cloneWithRows(productList.toArray())} |
147 | renderRow={this.renderRow} | 149 | renderRow={this.renderRow} |
148 | renderSectionHeader={this.renderSectionHeader} | 150 | renderSectionHeader={this.renderSectionHeader} |
149 | - onScroll={this.handleScroll} | 151 | + onScroll={this.handleScroll}renderFooter={()=>{ |
152 | + if (page_total == currentPage) { | ||
153 | + return <View style={styles.placeholder} />; | ||
154 | + } else { | ||
155 | + return <LoadMoreIndicator isVisible={isLoadingMore} animating={true}/>; | ||
156 | + } | ||
157 | + }} | ||
158 | + onEndReached={() => { | ||
159 | + if (productList && productList.size > 0 && currentPage < page_total) { | ||
160 | + this.props.onEndReached && this.props.onEndReached(); | ||
161 | + } | ||
162 | + | ||
163 | + }} | ||
150 | /> : null} | 164 | /> : null} |
151 | 165 | ||
152 | {showEmpty ? <NoDataView type={'browse'} onPressGuangGuang={this.props.onPressGuangGuang}/> : null} | 166 | {showEmpty ? <NoDataView type={'browse'} onPressGuangGuang={this.props.onPressGuangGuang}/> : null} |
@@ -24,6 +24,7 @@ class SwipeListView extends Component { | @@ -24,6 +24,7 @@ class SwipeListView extends Component { | ||
24 | this.state = { | 24 | this.state = { |
25 | scrollState: true, | 25 | scrollState: true, |
26 | } | 26 | } |
27 | + this.getItemLayout = this.getItemLayout.bind(this); | ||
27 | 28 | ||
28 | } | 29 | } |
29 | 30 | ||
@@ -52,6 +53,12 @@ class SwipeListView extends Component { | @@ -52,6 +53,12 @@ class SwipeListView extends Component { | ||
52 | } | 53 | } |
53 | } | 54 | } |
54 | 55 | ||
56 | + getItemLayout(data, index) { | ||
57 | + let {fliter,shopsdecorator} = this.props; | ||
58 | + | ||
59 | + return {length: data.length, offset: 122 * index + 45, index};//cell高度122, 顶部偏移45 | ||
60 | + } | ||
61 | + | ||
55 | onRowOpen(rowId, rowMap) { | 62 | onRowOpen(rowId, rowMap) { |
56 | const cellIdentifier = `${rowId}`; | 63 | const cellIdentifier = `${rowId}`; |
57 | if (this.openCellId && this.openCellId !== cellIdentifier) { | 64 | if (this.openCellId && this.openCellId !== cellIdentifier) { |
@@ -146,6 +153,7 @@ class SwipeListView extends Component { | @@ -146,6 +153,7 @@ class SwipeListView extends Component { | ||
146 | yh_viewVisible = {true} | 153 | yh_viewVisible = {true} |
147 | ref={ c => this.setRefs(c) } | 154 | ref={ c => this.setRefs(c) } |
148 | renderItem={(item) => this.renderItem(item, this._rows)} | 155 | renderItem={(item) => this.renderItem(item, this._rows)} |
156 | + getItemLayout={this.getItemLayout} | ||
149 | onScroll={ e => this.onScroll(e) } | 157 | onScroll={ e => this.onScroll(e) } |
150 | /> | 158 | /> |
151 | ) | 159 | ) |
@@ -31,6 +31,10 @@ export default keyMirror({ | @@ -31,6 +31,10 @@ export default keyMirror({ | ||
31 | HISTORY_LIST_SUCCESS: null, | 31 | HISTORY_LIST_SUCCESS: null, |
32 | HISTORY_LIST_FAILURE: null, | 32 | HISTORY_LIST_FAILURE: null, |
33 | 33 | ||
34 | + HISTORY_SORT_LIST_REQUEST: null, | ||
35 | + HISTORY_SORT_LIST_SUCCESS: null, | ||
36 | + HISTORY_SORT_LIST_FAILURE: null, | ||
37 | + | ||
34 | SET_SELECTED_CATEGORY: null, | 38 | SET_SELECTED_CATEGORY: null, |
35 | 39 | ||
36 | HISTORY_DELETE_REQUEST: null, | 40 | HISTORY_DELETE_REQUEST: null, |
@@ -53,11 +53,12 @@ class BrowseContainer extends Component { | @@ -53,11 +53,12 @@ class BrowseContainer extends Component { | ||
53 | this.onPressFindSimilar = this.onPressFindSimilar.bind(this); | 53 | this.onPressFindSimilar = this.onPressFindSimilar.bind(this); |
54 | this.onPressDelete = this.onPressDelete.bind(this); | 54 | this.onPressDelete = this.onPressDelete.bind(this); |
55 | this.onPressGuangGuang = this.onPressGuangGuang.bind(this); | 55 | this.onPressGuangGuang = this.onPressGuangGuang.bind(this); |
56 | + this.onEndReached = this.onEndReached.bind(this); | ||
56 | 57 | ||
57 | this.subscription = NativeAppEventEmitter.addListener( | 58 | this.subscription = NativeAppEventEmitter.addListener( |
58 | 'ClearHistoryEvent', | 59 | 'ClearHistoryEvent', |
59 | (reminder) => { | 60 | (reminder) => { |
60 | - let selectedProducts = this.props.browse.selectedProductList; | 61 | + let selectedProducts = this.props.browse.productList; |
61 | selectedProducts = selectedProducts&&selectedProducts.toJS(); | 62 | selectedProducts = selectedProducts&&selectedProducts.toJS(); |
62 | 63 | ||
63 | if (selectedProducts.length) { | 64 | if (selectedProducts.length) { |
@@ -73,7 +74,8 @@ class BrowseContainer extends Component { | @@ -73,7 +74,8 @@ class BrowseContainer extends Component { | ||
73 | } | 74 | } |
74 | 75 | ||
75 | componentDidMount() { | 76 | componentDidMount() { |
76 | - this.props.actions.historyList(); | 77 | + this.props.actions.historySortList(); |
78 | + this.props.actions.historyList(0); | ||
77 | } | 79 | } |
78 | 80 | ||
79 | componentWillUnmount() { | 81 | componentWillUnmount() { |
@@ -114,6 +116,10 @@ class BrowseContainer extends Component { | @@ -114,6 +116,10 @@ class BrowseContainer extends Component { | ||
114 | this.props.actions.deleteOneHistory(data.get('product_skn'), index); | 116 | this.props.actions.deleteOneHistory(data.get('product_skn'), index); |
115 | } | 117 | } |
116 | 118 | ||
119 | + onEndReached() { | ||
120 | + this.props.actions.historyList(); | ||
121 | + } | ||
122 | + | ||
117 | render() { | 123 | render() { |
118 | 124 | ||
119 | return ( | 125 | return ( |
@@ -124,6 +130,7 @@ class BrowseContainer extends Component { | @@ -124,6 +130,7 @@ class BrowseContainer extends Component { | ||
124 | onPressFindSimilar={this.onPressFindSimilar} | 130 | onPressFindSimilar={this.onPressFindSimilar} |
125 | onPressDelete={this.onPressDelete} | 131 | onPressDelete={this.onPressDelete} |
126 | onPressGuangGuang={this.onPressGuangGuang} | 132 | onPressGuangGuang={this.onPressGuangGuang} |
133 | + onEndReached={this.onEndReached} | ||
127 | /> | 134 | /> |
128 | ); | 135 | ); |
129 | } | 136 | } |
@@ -6,6 +6,10 @@ import Immutable, {Map} from 'immutable'; | @@ -6,6 +6,10 @@ import Immutable, {Map} from 'immutable'; | ||
6 | import {Platform} from 'react-native'; | 6 | import {Platform} from 'react-native'; |
7 | 7 | ||
8 | const { | 8 | const { |
9 | + HISTORY_SORT_LIST_REQUEST, | ||
10 | + HISTORY_SORT_LIST_SUCCESS, | ||
11 | + HISTORY_SORT_LIST_FAILURE, | ||
12 | + | ||
9 | HISTORY_LIST_REQUEST, | 13 | HISTORY_LIST_REQUEST, |
10 | HISTORY_LIST_SUCCESS, | 14 | HISTORY_LIST_SUCCESS, |
11 | HISTORY_LIST_FAILURE, | 15 | HISTORY_LIST_FAILURE, |
@@ -24,45 +28,78 @@ const { | @@ -24,45 +28,78 @@ const { | ||
24 | 28 | ||
25 | export function setSelectedCategory(catId, index, catName) { | 29 | export function setSelectedCategory(catId, index, catName) { |
26 | return (dispatch, getState) => { | 30 | return (dispatch, getState) => { |
31 | + dispatch({ | ||
32 | + type: SET_SELECTED_CATEGORY, | ||
33 | + payload: {index} | ||
34 | + }); | ||
35 | + dispatch(historyList(catId)); | ||
36 | + }; | ||
37 | +} | ||
38 | + | ||
39 | +export function historySortListRequest() { | ||
40 | + return { | ||
41 | + type: HISTORY_SORT_LIST_REQUEST, | ||
42 | + }; | ||
43 | +} | ||
44 | + | ||
45 | +export function historySortListSuccess(json) { | ||
46 | + return { | ||
47 | + type: HISTORY_SORT_LIST_SUCCESS, | ||
48 | + payload: json | ||
49 | + }; | ||
50 | +} | ||
51 | + | ||
52 | +export function historySortListFailure(error) { | ||
53 | + return { | ||
54 | + type: HISTORY_SORT_LIST_FAILURE, | ||
55 | + payload: error | ||
56 | + }; | ||
57 | +} | ||
58 | + | ||
59 | +export function historySortList() { | ||
60 | + return (dispatch, getState) => { | ||
27 | let {app, browse} = getState(); | 61 | let {app, browse} = getState(); |
28 | - let productList = browse.productList.toJS(); | ||
29 | - let newProductList = []; | ||
30 | - if (catId == -1) { | ||
31 | - newProductList = productList; | ||
32 | - } else { | ||
33 | - productList.map((item, i) => { | ||
34 | - if (item.category_id == catId) { | ||
35 | - newProductList.push(item); | 62 | + |
63 | + if (browse.isFetching) { | ||
64 | + return; | ||
65 | + } | ||
66 | + | ||
67 | + let fetchList = (uid, sourcePage) => { | ||
68 | + dispatch(historySortListRequest()); | ||
69 | + return new BrowseService(app.host).fetchSortList(uid, sourcePage) | ||
70 | + .then(json => { | ||
71 | + if (json.length > 0) { | ||
72 | + json = [{category_id: -1, category_name: '全部'} , ...json]; | ||
36 | } | 73 | } |
74 | + dispatch(historySortListSuccess(json)); | ||
75 | + }) | ||
76 | + .catch(error => { | ||
77 | + dispatch(historySortListFailure(error)); | ||
37 | }); | 78 | }); |
38 | } | 79 | } |
39 | - let pName = 'iFP_MineBrowseHistory'; | ||
40 | - if(Platform.OS === 'android'){ | ||
41 | - pName = 'aFP_MineBrowseHistory'; | ||
42 | - } | ||
43 | - for (var i = 0; i < newProductList.length; i++) { | ||
44 | - let item = newProductList[i]; | ||
45 | - let yh_exposureData = { | ||
46 | - 'P_NAME': pName, | ||
47 | - 'TAB_ID': parseInt(index) + 1, | ||
48 | - 'TAB_NAME': catName, | ||
49 | - 'I_INDEX': i + 1, | ||
50 | - 'PRD_SKN': item.product_skn?item.product_skn:'', | ||
51 | - exposureEnd : 1, | ||
52 | - }; | ||
53 | - item.yh_exposureData = yh_exposureData; | ||
54 | - } | ||
55 | 80 | ||
56 | - dispatch({ | ||
57 | - type: SET_SELECTED_CATEGORY, | ||
58 | - payload: {productList: newProductList, index} | 81 | + let uid = 0; |
82 | + let sourcePage = ''; | ||
83 | + | ||
84 | + Promise.all([ | ||
85 | + ReactNative.NativeModules.YH_CommonHelper.sourcePage('YH_MineBrowseHistoryVC'), | ||
86 | + ]).then(result => { | ||
87 | + sourcePage = result[0]; | ||
88 | + return ReactNative.NativeModules.YH_CommonHelper.uid(); | ||
89 | + }).then(data => { | ||
90 | + uid = data; | ||
91 | + fetchList(uid, sourcePage); | ||
92 | + }) | ||
93 | + .catch(error => { | ||
94 | + fetchList(uid, sourcePage); | ||
59 | }); | 95 | }); |
60 | }; | 96 | }; |
61 | } | 97 | } |
62 | 98 | ||
63 | -export function historyListRequest() { | 99 | +export function historyListRequest(category_id) { |
64 | return { | 100 | return { |
65 | type: HISTORY_LIST_REQUEST, | 101 | type: HISTORY_LIST_REQUEST, |
102 | + payload: category_id | ||
66 | }; | 103 | }; |
67 | } | 104 | } |
68 | 105 | ||
@@ -80,21 +117,36 @@ export function historyListFailure(error) { | @@ -80,21 +117,36 @@ export function historyListFailure(error) { | ||
80 | }; | 117 | }; |
81 | } | 118 | } |
82 | 119 | ||
83 | -export function historyList() { | 120 | +export function historyList(category_id) { |
84 | return (dispatch, getState) => { | 121 | return (dispatch, getState) => { |
85 | let {app, browse} = getState(); | 122 | let {app, browse} = getState(); |
123 | + let productList = []; | ||
124 | + if (browse && browse.productList && browse.productList.size > 0) { | ||
125 | + productList = browse.productList.toJSON(); | ||
126 | + }; | ||
86 | 127 | ||
87 | if (browse.isFetching) { | 128 | if (browse.isFetching) { |
88 | return; | 129 | return; |
89 | } | 130 | } |
90 | 131 | ||
91 | - let fetchList = (uid, page, pageSize, sourcePage) => { | ||
92 | - dispatch(historyListRequest()); | ||
93 | - return new BrowseService(app.host).fetchList(uid, page, pageSize, sourcePage) | 132 | + let fetchList = (uid, category_id, page, sourcePage) => { |
133 | + dispatch(historyListRequest(category_id)); | ||
134 | + return new BrowseService(app.host).fetchPagelist(uid, category_id, page, sourcePage) | ||
94 | .then(json => { | 135 | .then(json => { |
95 | - let payload = parseHistoryList(json); | ||
96 | - dispatch(historyListSuccess(payload)); | ||
97 | - let show = payload.productList.length > 0; | 136 | + |
137 | + let currentPage = json && json.page ? json.page : 1; | ||
138 | + let page_total = json && json.page_total ? json.page_total : 1; | ||
139 | + let newproductList = json && json.product_list ? json.product_list : []; | ||
140 | + if (productList.length) { | ||
141 | + if (newproductList.length) { | ||
142 | + productList=[...productList, ...newproductList]; | ||
143 | + }; | ||
144 | + } else if (newproductList.length){ | ||
145 | + productList = newproductList; | ||
146 | + } | ||
147 | + | ||
148 | + dispatch(historyListSuccess({currentPage, page_total, productList})); | ||
149 | + let show = productList.length > 0; | ||
98 | ReactNative.NativeModules.YH_RecorderHelper.setRightClearButtonVisiblity(show); | 150 | ReactNative.NativeModules.YH_RecorderHelper.setRightClearButtonVisiblity(show); |
99 | }) | 151 | }) |
100 | .catch(error => { | 152 | .catch(error => { |
@@ -105,57 +157,25 @@ export function historyList() { | @@ -105,57 +157,25 @@ export function historyList() { | ||
105 | let uid = 0; | 157 | let uid = 0; |
106 | let sourcePage = ''; | 158 | let sourcePage = ''; |
107 | let page = browse.currentPage + 1; | 159 | let page = browse.currentPage + 1; |
108 | - let pageSize = browse.pageSize; | 160 | + if (!category_id) { |
161 | + category_id = browse.curCategoryID; | ||
162 | + }; | ||
109 | 163 | ||
110 | Promise.all([ | 164 | Promise.all([ |
111 | ReactNative.NativeModules.YH_CommonHelper.sourcePage('YH_MineBrowseHistoryVC'), | 165 | ReactNative.NativeModules.YH_CommonHelper.sourcePage('YH_MineBrowseHistoryVC'), |
112 | ]).then(result => { | 166 | ]).then(result => { |
113 | sourcePage = result[0]; | 167 | sourcePage = result[0]; |
114 | - | ||
115 | return ReactNative.NativeModules.YH_CommonHelper.uid(); | 168 | return ReactNative.NativeModules.YH_CommonHelper.uid(); |
116 | }).then(data => { | 169 | }).then(data => { |
117 | uid = data; | 170 | uid = data; |
118 | - fetchList(uid, page, pageSize, sourcePage); | 171 | + fetchList(uid, category_id, page, sourcePage); |
119 | }) | 172 | }) |
120 | .catch(error => { | 173 | .catch(error => { |
121 | - fetchList(uid, page, pageSize, sourcePage); | 174 | + fetchList(uid, category_id, page, sourcePage); |
122 | }); | 175 | }); |
123 | }; | 176 | }; |
124 | } | 177 | } |
125 | 178 | ||
126 | -function parseHistoryList(json) { | ||
127 | - let currentPage = json && json.page ? json.page : 1; | ||
128 | - | ||
129 | - let productList = json && json.product_list ? json.product_list : []; | ||
130 | - let categoryList = json && json.category_list ? json.category_list : []; | ||
131 | - | ||
132 | - let pName = 'iFP_MineBrowseHistory'; | ||
133 | - if(Platform.OS === 'android'){ | ||
134 | - pName = 'aFP_MineBrowseHistory'; | ||
135 | - } | ||
136 | - for (var i = 0; i < productList.length; i++) { | ||
137 | - let item = productList[i]; | ||
138 | - let yh_exposureData = { | ||
139 | - 'P_NAME': pName, | ||
140 | - 'TAB_ID': '1', | ||
141 | - 'TAB_NAME': '全部', | ||
142 | - 'I_INDEX': i + 1 + '', | ||
143 | - 'PRD_SKN': item.product_skn?item.product_skn:'', | ||
144 | - exposureEnd : 1, | ||
145 | - }; | ||
146 | - item.yh_exposureData = yh_exposureData; | ||
147 | - } | ||
148 | - | ||
149 | - if (categoryList.length > 0) { | ||
150 | - categoryList = [{category_id: -1, category_name: '全部'} , ...categoryList]; | ||
151 | - } | ||
152 | - | ||
153 | - return { | ||
154 | - categoryList, | ||
155 | - productList, | ||
156 | - currentPage, | ||
157 | - }; | ||
158 | -} | ||
159 | 179 | ||
160 | export function historyDeleteRequest() { | 180 | export function historyDeleteRequest() { |
161 | return { | 181 | return { |
@@ -189,9 +209,7 @@ export function deleteOneHistory(skn, index) { | @@ -189,9 +209,7 @@ export function deleteOneHistory(skn, index) { | ||
189 | dispatch(historyDeleteRequest()); | 209 | dispatch(historyDeleteRequest()); |
190 | return new BrowseService(app.host).deleteHistory(skn, uid, sourcePage) | 210 | return new BrowseService(app.host).deleteHistory(skn, uid, sourcePage) |
191 | .then(json => { | 211 | .then(json => { |
192 | - let {productList, selectedProductList} = browse; | ||
193 | - let selectedProduct = selectedProductList.toJS()[index]; | ||
194 | - selectedProductList = selectedProductList.delete(index); | 212 | + let {productList} = browse; |
195 | let lists = productList.toArray(); | 213 | let lists = productList.toArray(); |
196 | let indexInAll = productList.findIndex((item, i) => { | 214 | let indexInAll = productList.findIndex((item, i) => { |
197 | return item.get('product_skn') == skn; | 215 | return item.get('product_skn') == skn; |
@@ -199,10 +217,10 @@ export function deleteOneHistory(skn, index) { | @@ -199,10 +217,10 @@ export function deleteOneHistory(skn, index) { | ||
199 | if (indexInAll != -1) { | 217 | if (indexInAll != -1) { |
200 | productList = productList.delete(indexInAll); | 218 | productList = productList.delete(indexInAll); |
201 | } | 219 | } |
202 | - if (selectedProductList.size == 0 || selectedProductList.length == 0) { | ||
203 | - dispatch(deleteSelectedProducts([selectedProduct])); | 220 | + if (productList.size == 0 || productList.length == 0) { |
221 | + dispatch(historySortList()); | ||
204 | }else { | 222 | }else { |
205 | - dispatch(historyDeleteSuccess({productList, selectedProductList})); | 223 | + dispatch(historyDeleteSuccess({productList})); |
206 | } | 224 | } |
207 | 225 | ||
208 | let show = productList.size > 0; | 226 | let show = productList.size > 0; |
@@ -269,11 +287,9 @@ export function clearHistory(selectedProducts) { | @@ -269,11 +287,9 @@ export function clearHistory(selectedProducts) { | ||
269 | dispatch(historyClearRequest()); | 287 | dispatch(historyClearRequest()); |
270 | return new BrowseService(app.host).deleteHistory(skns, uid, sourcePage) | 288 | return new BrowseService(app.host).deleteHistory(skns, uid, sourcePage) |
271 | .then(json => { | 289 | .then(json => { |
272 | - let {productList, selectedProductList} = browse; | ||
273 | - console.log('000') | ||
274 | - dispatch(deleteSelectedProducts(selectedProducts)); | ||
275 | - let show = productList.size > 0; | ||
276 | - ReactNative.NativeModules.YH_RecorderHelper.setRightClearButtonVisiblity(show); | 290 | + dispatch(historySortList()); |
291 | + dispatch(historyList(0)); | ||
292 | + dispatch({type: HISTORY_CLEAR_SUCCESS}); | ||
277 | }) | 293 | }) |
278 | .catch(error => { | 294 | .catch(error => { |
279 | dispatch(historyClearFailure(error)); | 295 | dispatch(historyClearFailure(error)); |
@@ -299,40 +315,3 @@ export function clearHistory(selectedProducts) { | @@ -299,40 +315,3 @@ export function clearHistory(selectedProducts) { | ||
299 | }; | 315 | }; |
300 | } | 316 | } |
301 | 317 | ||
302 | -export function deleteSelectedProducts(selectedProducts) { | ||
303 | - return (dispatch, getState) => { | ||
304 | - let {app, browse} = getState(); | ||
305 | - | ||
306 | - if (browse.productList.size == 0) { | ||
307 | - return; | ||
308 | - } | ||
309 | - let {productList, selectedProductList, categoryList} = browse; | ||
310 | - let newProductList = []; | ||
311 | - let categoryId = selectedProducts[0].category_id; | ||
312 | - categoryList = categoryList.toJS(); | ||
313 | - let newCategoryList = []; | ||
314 | - categoryList.map((categoryItem, i)=> { | ||
315 | - if (categoryItem.category_id != categoryId) { | ||
316 | - newCategoryList.push(categoryItem); | ||
317 | - } | ||
318 | - }); | ||
319 | - productList = productList.toJS(); | ||
320 | - productList.map((item, j) => { | ||
321 | - let exist = false; | ||
322 | - selectedProducts.map((selectedItem, i) => { | ||
323 | - if (item.product_skn == selectedItem.product_skn) { | ||
324 | - exist = true; | ||
325 | - } | ||
326 | - }); | ||
327 | - if (!exist) { | ||
328 | - newProductList.push(item); | ||
329 | - } | ||
330 | - }); | ||
331 | - | ||
332 | - dispatch({ | ||
333 | - type: HISTORY_CLEAR_SUCCESS, | ||
334 | - payload: {productList: newProductList,categoryList:newCategoryList,index:0} | ||
335 | - }); | ||
336 | - | ||
337 | - }; | ||
338 | -} |
@@ -8,9 +8,10 @@ let InitialState = Record({ | @@ -8,9 +8,10 @@ let InitialState = Record({ | ||
8 | categoryList: List(), | 8 | categoryList: List(), |
9 | productList: List(), | 9 | productList: List(), |
10 | currentPage: 0, | 10 | currentPage: 0, |
11 | + page_total:0, | ||
11 | pageSize: 100, | 12 | pageSize: 100, |
12 | selectedCategoryIndex: 0, | 13 | selectedCategoryIndex: 0, |
13 | - selectedProductList: List(), | 14 | + curCategoryID: 0, |
14 | 15 | ||
15 | isDeleting: false, | 16 | isDeleting: false, |
16 | showEmpty: false, | 17 | showEmpty: false, |
@@ -4,6 +4,10 @@ import InitialState from './browseInitialState'; | @@ -4,6 +4,10 @@ import InitialState from './browseInitialState'; | ||
4 | import Immutable, {Map, List} from 'immutable'; | 4 | import Immutable, {Map, List} from 'immutable'; |
5 | 5 | ||
6 | const { | 6 | const { |
7 | + HISTORY_SORT_LIST_REQUEST, | ||
8 | + HISTORY_SORT_LIST_SUCCESS, | ||
9 | + HISTORY_SORT_LIST_FAILURE, | ||
10 | + | ||
7 | HISTORY_LIST_REQUEST, | 11 | HISTORY_LIST_REQUEST, |
8 | HISTORY_LIST_SUCCESS, | 12 | HISTORY_LIST_SUCCESS, |
9 | HISTORY_LIST_FAILURE, | 13 | HISTORY_LIST_FAILURE, |
@@ -25,37 +29,47 @@ export default function browseReducer(state=initialState, action) { | @@ -25,37 +29,47 @@ export default function browseReducer(state=initialState, action) { | ||
25 | switch(action.type) { | 29 | switch(action.type) { |
26 | case HISTORY_LIST_REQUEST: { | 30 | case HISTORY_LIST_REQUEST: { |
27 | return state.set('isFetching', true) | 31 | return state.set('isFetching', true) |
32 | + .set('error', null) | ||
33 | + .set('curCategoryID', action.payload); | ||
34 | + } | ||
35 | + case HISTORY_SORT_LIST_REQUEST:{ | ||
36 | + return state.set('isFetching', true) | ||
28 | .set('error', null); | 37 | .set('error', null); |
29 | } | 38 | } |
30 | 39 | ||
31 | case HISTORY_LIST_SUCCESS: { | 40 | case HISTORY_LIST_SUCCESS: { |
32 | let { | 41 | let { |
33 | - categoryList, | ||
34 | productList, | 42 | productList, |
35 | currentPage, | 43 | currentPage, |
44 | + page_total, | ||
36 | } = action.payload; | 45 | } = action.payload; |
37 | let showEmpty = productList.length == 0; | 46 | let showEmpty = productList.length == 0; |
38 | 47 | ||
39 | let newState = state.set('isFetching', false) | 48 | let newState = state.set('isFetching', false) |
40 | .set('error', null) | 49 | .set('error', null) |
41 | - .set('categoryList', Immutable.fromJS(categoryList)) | ||
42 | .set('productList', Immutable.fromJS(productList)) | 50 | .set('productList', Immutable.fromJS(productList)) |
43 | - .set('selectedProductList', Immutable.fromJS(productList)) | 51 | + .set('page_total', Immutable.fromJS(page_total)) |
44 | .set('currentPage', currentPage) | 52 | .set('currentPage', currentPage) |
45 | .set('showEmpty', showEmpty); | 53 | .set('showEmpty', showEmpty); |
46 | - | ||
47 | return newState; | 54 | return newState; |
48 | } | 55 | } |
49 | 56 | ||
50 | - case HISTORY_LIST_FAILURE: { | 57 | + case HISTORY_LIST_FAILURE: |
58 | + case HISTORY_SORT_LIST_FAILURE:{ | ||
51 | return state.set('isFetching', false) | 59 | return state.set('isFetching', false) |
52 | .set('error', action.payload); | 60 | .set('error', action.payload); |
53 | } | 61 | } |
54 | 62 | ||
63 | + case HISTORY_SORT_LIST_SUCCESS: { | ||
64 | + return state.set('isFetching', false) | ||
65 | + .set('categoryList', Immutable.fromJS(action.payload)); | ||
66 | + } | ||
67 | + | ||
55 | case SET_SELECTED_CATEGORY: { | 68 | case SET_SELECTED_CATEGORY: { |
56 | let {productList, index} = action.payload; | 69 | let {productList, index} = action.payload; |
57 | return state.set('selectedCategoryIndex', index) | 70 | return state.set('selectedCategoryIndex', index) |
58 | - .set('selectedProductList', Immutable.fromJS(productList)) | 71 | + .set('currentPage', 0) |
72 | + .set('productList',List()); | ||
59 | } | 73 | } |
60 | 74 | ||
61 | case HISTORY_DELETE_REQUEST: | 75 | case HISTORY_DELETE_REQUEST: |
@@ -66,10 +80,7 @@ export default function browseReducer(state=initialState, action) { | @@ -66,10 +80,7 @@ export default function browseReducer(state=initialState, action) { | ||
66 | case HISTORY_DELETE_SUCCESS: { | 80 | case HISTORY_DELETE_SUCCESS: { |
67 | let {productList, selectedProductList} = action.payload; | 81 | let {productList, selectedProductList} = action.payload; |
68 | let showEmpty = productList.size == 0; | 82 | let showEmpty = productList.size == 0; |
69 | - return state.set('isDeleting', false) | ||
70 | - .set('productList', productList) | ||
71 | - .set('selectedProductList', selectedProductList) | ||
72 | - .set('showEmpty', showEmpty); | 83 | + return state.set('isDeleting', false); |
73 | } | 84 | } |
74 | 85 | ||
75 | case HISTORY_DELETE_FAILURE: | 86 | case HISTORY_DELETE_FAILURE: |
@@ -80,15 +91,8 @@ export default function browseReducer(state=initialState, action) { | @@ -80,15 +91,8 @@ export default function browseReducer(state=initialState, action) { | ||
80 | 91 | ||
81 | case HISTORY_CLEAR_SUCCESS: { | 92 | case HISTORY_CLEAR_SUCCESS: { |
82 | let {productList,categoryList,index} = action.payload; | 93 | let {productList,categoryList,index} = action.payload; |
83 | - | ||
84 | let show = productList.length==0; | 94 | let show = productList.length==0; |
85 | - | ||
86 | - return state.set('isDeleting', false) | ||
87 | - .set('productList', Immutable.fromJS(productList)) | ||
88 | - .set('selectedProductList', Immutable.fromJS(productList)) | ||
89 | - .set('categoryList', Immutable.fromJS(categoryList)) | ||
90 | - .set('selectedCategoryIndex',index) | ||
91 | - .set('showEmpty', show); | 95 | + return state.set('isDeleting', false); |
92 | } | 96 | } |
93 | } | 97 | } |
94 | 98 |
@@ -12,14 +12,31 @@ export default class CategoryService { | @@ -12,14 +12,31 @@ export default class CategoryService { | ||
12 | this.api = new Request(baseURL); | 12 | this.api = new Request(baseURL); |
13 | } | 13 | } |
14 | 14 | ||
15 | - async fetchList(uid=0, page=1, limit=100, fromPage='') { | 15 | + async fetchSortList(uid=0, fromPage='') { |
16 | return await this.api.get({ | 16 | return await this.api.get({ |
17 | url: '', | 17 | url: '', |
18 | body: { | 18 | body: { |
19 | - method: 'app.browse.product', | 19 | + method: 'app.browse.sortlist', |
20 | uid, | 20 | uid, |
21 | + fromPage | ||
22 | + } | ||
23 | + }) | ||
24 | + .then((json) => { | ||
25 | + return json; | ||
26 | + }) | ||
27 | + .catch((error) => { | ||
28 | + throw(error); | ||
29 | + }); | ||
30 | + } | ||
31 | + | ||
32 | + async fetchPagelist(uid=0, category_id=0, page=1, fromPage='') { | ||
33 | + return await this.api.get({ | ||
34 | + url: '', | ||
35 | + body: { | ||
36 | + method: 'app.browse.pagelist', | ||
37 | + uid, | ||
38 | + category_id, | ||
21 | page, | 39 | page, |
22 | - limit, | ||
23 | fromPage, | 40 | fromPage, |
24 | } | 41 | } |
25 | }) | 42 | }) |
@@ -31,6 +48,7 @@ export default class CategoryService { | @@ -31,6 +48,7 @@ export default class CategoryService { | ||
31 | }); | 48 | }); |
32 | } | 49 | } |
33 | 50 | ||
51 | + | ||
34 | async deleteHistory(skn=0, uid=0, fromPage='') { | 52 | async deleteHistory(skn=0, uid=0, fromPage='') { |
35 | let param = skn ? {uid, skn, fromPage,} : {uid, fromPage,}; | 53 | let param = skn ? {uid, skn, fromPage,} : {uid, fromPage,}; |
36 | return await this.api.get({ | 54 | return await this.api.get({ |
-
Please register or login to post a comment