RedBrand.js
14.5 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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
'use strict'
import React, {Component} from 'react';
import {
StyleSheet,
Dimensions,
Platform,
View,
Text,
Image,
ListView,
TouchableOpacity,
} from 'react-native';
import Immutable,{Map,Record} from 'immutable';
import Header from './Header';
import RedBrandStoreFilter from './RedBrandStoreFilter';
import Title from './Title';
import Video from './Video';
import SingleImage from './SingleImage';
import DoubleImage from './DoubleImage';
import TripleImage from './TripleImage';
import RedBrandSwiper from './RedBrandSwiper';
import BrandProductMoreFilter from '../../../brandStore/components/brandStore/brandStoreSubView/Cells/BrandProductMoreFilter';
import ProductCategoryList from '../../../brandStore/components/brandStore/brandStoreSubView/Cells/ProductCategoryList';
import LoadingIndicator from '../../../common/components/LoadingIndicator';
import LoadMoreIndicator from '../../../common/components/LoadMoreIndicator';
import BrandProductListCell from '../../../common/components/ListCell/ProductListCell';
import BrandProductFilter from '../../../brandStore/components/brandStore/brandStoreSubView/Cells/BrandProductFilter';
import CouponCell from '../../../brandStore/components/brandStore/brandStoreSubView/Cells/CouponCell';
import Prompt from '../../../coupon/components/coupon/Prompt';
import FourImages from './FourImages';
import GoodsGroupList from './GoodsGroupList';
export default class RedBrand extends Component {
constructor(props) {
super(props);
this.renderSectionHeader = this.renderSectionHeader.bind(this);
this.renderRow = this.renderRow.bind(this);
this._onPressProductFilter = this._onPressProductFilter.bind(this);
this._onPressFilter = this._onPressFilter.bind(this);
this._onPressLaunchProfile = this._onPressLaunchProfile.bind(this);
this._onChangeVisibleRows = this._onChangeVisibleRows.bind(this);
this._onMomentumScrollBegin = this._onMomentumScrollBegin.bind(this);
this._onMomentumScrollEnd = this._onMomentumScrollEnd.bind(this);
this.dataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
sectionHeaderHasChanged: (s1, s2) => !Immutable.is(s1, s2),
});
this.state = {
selectedVisibleIndex: -1,
scrollEnd: false,
};
}
_onPressLaunchProfile(value){
this.refs.redBrandList && this.refs.redBrandList.scrollTo({x: 0, y: 0, animated: false});
this.props.onPressLaunchProfile && this.props.onPressLaunchProfile(value);
}
_onPressProductFilter(value){
this.refs.redBrandList && this.refs.redBrandList.scrollTo({x: 0, y: yPosition, animated: false});
this.props.onPressProductFilter && this.props.onPressProductFilter(value);
}
_onPressFilter(value){
this.refs.redBrandList && this.refs.redBrandList.scrollTo({x: 0, y: 0, animated: false});
this.props.onPressProductFilter && this.props.onPressStoreFilter(value);
}
renderSectionHeader(sectionData, sectionID) {
let {fliter} = this.props;
switch(sectionID) {
case 'newProductList':
case 'brandReource': {
return(<RedBrandStoreFilter resource={fliter} onPressStoreFilter={this._onPressFilter}/>);
}
case 'productList': {
let noFilterValue = true;
this.props.filterFactors.map((value, key) => {
if (value) {
noFilterValue = false;
}
});
let productListIsEmpty = !this.props.productList || !this.props.productList.list || this.props.productList.list.size == 0;
if (productListIsEmpty && noFilterValue) {
return null;
}
let brandFilterContainerHeight = this.props.fliter == '2' ? 84 : 40;
return (
<View style={[styles.brandFilterContainer,{height:brandFilterContainerHeight}]} onLayout={(evt) => {yPosition = evt.nativeEvent.layout.y;}}>
{this.props.fliter == '2' ?
<RedBrandStoreFilter resource={fliter} onPressStoreFilter={this._onPressFilter}/>
:null
}
<BrandProductFilter
onPressFilter={this._onPressProductFilter}
lastSelected={this.props.productList.isFilter}
moreFilter={this.props.productList.isMoreFilter}
selectOrder={this.props.productList.order}
/>
</View>
);
}
default:
return null;
}
return null;
}
renderRow(rowData, sectionID, rowID, highlightRow) {
let pageName = 'iFP_RedPersonBrand';
if (Platform.OS === 'android') {
pageName = 'aFP_RedPersonBrand';
}
if (sectionID == 'ShopBanner') {
let {launchProfile, shopsdecorator} = this.props;
let resList = shopsdecorator.modules?shopsdecorator.modules.toArray():[];
return(<Header resource={rowData} launchProfile={launchProfile} onPressLaunchProfile={this._onPressLaunchProfile} onPressCollection={this.props.onPressCollection} onPressLink={this.props.onPressLink}/>);
} else if(sectionID == 'brandReource'){
let params = {
P_NAME : pageName,
F_ID : rowID,
TAB_NAME : '首页',
TAB_ID : 0,
F_NAME : rowData.get('module_type'),
P_PARAM: this.props.shopId,
exposureEnd : 1,
};
if (rowData.get('module_type') == 'coupon') {
return(<CouponCell yh_exposureData={params} resource={rowData} onPressCoupon={this.props.onPressCoupon}/>);
}else if (rowData.get('module_type') == 'CarouselImage') {
return(<RedBrandSwiper yh_exposureData={params} resource={rowData} onPressSlideItem={this.props.onPressProduct}/>);
}else if (rowData.get('module_type') == 'Title') {
return(<Title yh_exposureData={params} resource={rowData} onPressProduct={this.props.onPressProduct}/>);
}else if (rowData.get('module_type') == 'SingleImage') {
return(<SingleImage yh_exposureData={params} resource={rowData} onPressProduct={this.props.onPressProduct}/>);
}else if (rowData.get('module_type') == 'DoubleImage') {
return(<DoubleImage yh_exposureData={params} resource={rowData} onPressProduct={this.props.onPressProduct}/>);
}else if (rowData.get('module_type') == 'Video') {
return(<Video yh_exposureData={params} resource={rowData} videoCounts={videoCounts} onPressVideo={this.props.onPressVideo}/>);
}else if (rowData.get('module_type') == 'TripleImage') {
return(<TripleImage yh_exposureData={params} resource={rowData} onPressProduct={this.props.onPressProduct}/>);
}else if (rowData.get('module_type') == 'FourImage') {
return(<FourImages yh_exposureData={params} resource={rowData} onPressProduct={this.props.onPressProduct}/>);
}else if (rowData.get('module_type') == 'AppRecommendProduct') {
return(<GoodsGroupList yh_exposureData={params} resource={rowData} onPressProductRecommend={this.props.onPressProductRecommend}/>);
}
} else if (sectionID == 'productList' || sectionID == 'newProductList') {
let similarIndex = this.props.similarIndex;
let paddingLeft = rowID % 2 == 1 ? rowMarginHorizontal / 2 : rowMarginHorizontal;
let customStyle = rowID == 0 || rowID == 1 ? {paddingLeft} : {paddingLeft};
let showSimilarGuider = this.props.showSimilarGuider
&& this.state.scrollEnd
&& rowID == this.state.selectedVisibleIndex
&& rowID != similarIndex;
return (
<BrandProductListCell
style={[styles.listContainer, customStyle]}
key={'row' + rowID}
rowID={rowID}
data={rowData}
similarIndex={similarIndex}
onPressProduct={this.props.onPressProductCell}
onLongPressProduct={this.props.onLongPressProduct}
onPressFindSimilar={this.props.onPressFindSimilar}
onPressDislike={this.props.onPressDislike}
showSimilarGuider={showSimilarGuider}
/>
);
}
return null;
}
_onChangeVisibleRows(visibleRows, changedRows) {
if (Object.keys(visibleRows).length == 0) {
return;
}
let selectedIndex = -1;
let sectionIDs = Object.keys(visibleRows);
let targetSection = 'productList';
if (!sectionIDs.includes(targetSection)) {
return;
}
let rowIndexs = Object.keys(visibleRows[targetSection]);
if (rowIndexs.length > 0) {
selectedIndex = rowIndexs[0];
}
if (rowIndexs.length > 3) {
selectedIndex = rowIndexs[2];
}
this.setState({selectedVisibleIndex: selectedIndex});
}
_onMomentumScrollBegin(event) {
this.setState({scrollEnd: false});
}
_onMomentumScrollEnd(event) {
this.setState({scrollEnd: true});
}
render() {
let {
shopId,
productList,
launchProfile,
productListForNew,
fliter,
categoryFilterList,
filterCategoryDetailFilterList,
filterNameFactors,
filterFactors,
shopIntro,
shopsdecorator,
receiveCouponResult,
coupon,
} = this.props;
let isFetching = (productList.list.size > 0 && productList.isFetching && productList.currentPage == 0);
videoCounts = shopsdecorator.counts;
let resList = shopsdecorator.modules?shopsdecorator.modules.toArray():[];
coupon?resList.unshift(coupon):null;
let dataSource = null;
if (fliter == 0) {
dataSource = {
ShopBanner: [shopIntro],
brandReource: resList,
productList: productList.list.toArray(),
};
} else if (fliter == 1) {
dataSource = {
ShopBanner: [shopIntro],
newProductList: productListForNew.list.toArray(),
};
} else if (fliter == 2) {
dataSource = {
ShopBanner: [shopIntro],
productList: productList.list.toArray(),
};
}
let isLoadingMore = productList.isFetching && productList.currentPage > 0;
let endReached = productList.endReached;
let needShowToast = this.props.receiveCouponResult.isNeedShow;
let showToastMessage = this.props.receiveCouponResult.showMessage;
return (
<View style={styles.container}>
<ListView
ref='redBrandList'
yh_viewVisible = {true}
contentContainerStyle={styles.contentContainer}
enableEmptySections={true}
dataSource={this.dataSource.cloneWithRowsAndSections(dataSource)}
renderRow={this.renderRow}
renderSectionHeader={this.renderSectionHeader}
renderFooter={()=>{
if (fliter == 0) {return <View style={styles.placeholder} />;}
if (endReached) {
return <View style={styles.placeholder} />;
} else {
return <LoadMoreIndicator isVisible={isLoadingMore} animating={true}/>;
}
}}
onEndReached={() => {
if (fliter == 0) {
return;
}
if (productList && productList.list && productList.list.size > 0) {
this.props.onEndReached && this.props.onEndReached();
}
}}
/>
{productList.isFilter ?
<ProductCategoryList
productList={productList}
onPressFilter={this._onPressProductFilter}
lastSelected={this.props.productList.isFilter}
moreFilter={this.props.productList.isMoreFilter}
selectOrder={this.props.productList.order}
categoryFilterList={categoryFilterList}
filterCategoryDetailFilterList={filterCategoryDetailFilterList}
onPressProductFilterLeftItem={this.props.onPressProductFilterLeftItem}
filterNameFactors={filterNameFactors}
onPressProductFilterRightItem={this.props.onPressProductFilterRightItem}
onPressCloseMoreFilter={this.props.onPressCloseMoreFilter}
onPressMoreFilter={this.props.onPressMoreFilter}/> : null}
{productList.isMoreFilter ?
<BrandProductMoreFilter
productList={productList}
onPressCloseMoreFilter={this.props.onPressCloseMoreFilter}
onPressMoreFilter={this.props.onPressMoreFilter}/> : null}
{needShowToast ? <Prompt
text={showToastMessage}
duration={1000}
onPromptHidden={this.props.resetReceiveCouponResult}
/> : null}
<LoadingIndicator
isVisible={isFetching}
/>
</View>
);
}
}
let {width, height} = Dimensions.get('window');
let rowWidth = Math.ceil(137.5 * width / 320);
let rowHeight = Math.ceil(254 * width / 320);
let rowMarginTop = Math.ceil(10 * width / 320);
let rowMarginHorizontal = (width - rowWidth * 2) / 3;
let yPosition = 0;
let videoCounts;
let styles = StyleSheet.create({
container: {
flex: 1,
},
contentContainer:{
flexDirection: 'row',
flexWrap: 'wrap',
},
listContainer: {
width: width / 2,
},
brandFilterContainer: {
marginLeft: -1,
width: width + 2,
height: 84,
},
placeholder: {
width,
height: 15,
},
});