RedBrand.ios.js.backup
28.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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
'use strict'
import React, {Component} from 'react';
import {
StyleSheet,
Dimensions,
Platform,
View,
Text,
Image,
SectionList,
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 ProductCategoryList from './ProductCategoryList';
import LoadingIndicator from '../../../common/components/LoadingIndicator';
import LoadMoreIndicator from '../../../common/components/LoadMoreIndicator';
import RedBrandTwoProductCell from './RedBrandTwoProductCell';
import BrandProductFilter from './BrandProductFilter';
import BrandProductMoreFilter from './BrandProductMoreFilter';
import CouponCell from '../../../brandStore/components/brandStore/brandStoreSubView/Cells/CouponCell';
import Prompt from '../../../coupon/components/coupon/Prompt';
import FourImages from './FourImages';
import GoodsGroupList from './GoodsGroupList';
const VIEWABILITY_CONFIG = {
minimumViewTime: 3000,
viewAreaCoveragePercentThreshold: 100,
waitForInteraction: true,
};
export default class RedBrand extends Component {
constructor(props) {
super(props);
this.renderSectionHeader = this.renderSectionHeader.bind(this);
this.renderItem = this.renderItem.bind(this);
this._onPressProductFilter = this._onPressProductFilter.bind(this);
this._onPressFilter = this._onPressFilter.bind(this);
this._onPressLaunchProfile = this._onPressLaunchProfile.bind(this);
this.getItemLayout = this.getItemLayout.bind(this);
this._calculateSectionRealHeight = this._calculateSectionRealHeight.bind(this);
this.containerHeight = 0;
this.sectionData = [];
this.layoutLenghtOffesetForIndex = {};
this.productListUpOffset = 0;
}
_onPressLaunchProfile(value){
this.refs.redBrandList && this.refs.redBrandList.scrollToLocation({itemIndex: 0,sectionIndex: 0, viewPosition: 0, animated: false});
this.props.onPressLaunchProfile && this.props.onPressLaunchProfile(value);
}
_onPressProductFilter(value){
let {fliter} = this.props;
let sectionIndex = 1;
if (fliter != 0) {
let height = headerHeight + 84; //header
this.refs.redBrandList && this.refs.redBrandList.scrollToLocation({itemIndex: 0,sectionIndex: 1, viewPosition: height, animated: false});
} else {
let height = headerHeight + 84;
this.refs.redBrandList && this.refs.redBrandList.scrollToLocation({itemIndex: 0,sectionIndex: 0, viewOffset: -this.productListUpOffset + 104, animated: false});
}
this.props.onPressProductFilter && this.props.onPressProductFilter(value);
}
_onPressFilter(value){
let height = headerHeight + 44; //header
this.refs.redBrandList && this.refs.redBrandList.scrollToLocation({itemIndex: 0,sectionIndex: 1, viewPosition: height, animated: false});
this.props.onPressProductFilter && this.props.onPressStoreFilter(value);
}
_calculateSectionRealHeight(dataSource, layoutIndex) {
let {
productList,
launchProfile,
productListForNew,
shopsdecorator,
fliter,
} = this.props;
let result = {
length: 0,
offset: 0,
};
let realContainerHeight = 0;
let countNumb = 0;
for (let i = 0; i < dataSource.length; i++) {
let item = dataSource[i];
if (item.key == 'ShopBanner') {
if (!shopsdecorator || shopsdecorator.template_type != '1') {
result.length = headerHeight; //header
if (countNumb == layoutIndex) {
return result;
}
realContainerHeight += headerHeight; //header
}
} else if (item.key == 'brandReource') {
realContainerHeight += 44; //height of RedBrandStoreFilter
countNumb++;
if (countNumb == layoutIndex) {
result.offset = realContainerHeight - 44;
result.length = 44;
return result;
}
let sectionDataSource = item.data;
if (sectionDataSource.length == 0) {
result.offset = realContainerHeight;
result.length = 0;
return result;
}
for (let i = 0; i < sectionDataSource.length; i++) {
let shopsdecoratorItem = sectionDataSource[i];
let validFloorData = false;
result.offset = realContainerHeight;
if (shopsdecoratorItem.get('module_type') == 'coupon') {
if (shopsdecoratorItem.list > 0) {
validFloorData = true;
result.length = 90;
realContainerHeight += 90; //height for coupon
}
} else if (shopsdecoratorItem.get('module_type') == 'CarouselImage') {
let swiperHeight = Math.ceil((234 / 750) * width);
let properties = shopsdecoratorItem.get('module_data').get('properties').toJS();
let isModuleMargin = properties.isModuleMargin;
let backgroundHeight = isModuleMargin=='1'?(swiperHeight+10):swiperHeight;
validFloorData = true;
result.length = backgroundHeight;
realContainerHeight += backgroundHeight; //height for RedBrandSwiper
} else if (shopsdecoratorItem.get('module_type') == 'Title') {
let properties = shopsdecoratorItem.get('module_data').get('properties').toJS();
let isModuleMargin = properties.isModuleMargin;
let heightDiff = isModuleMargin=='1'?40+10:40;
validFloorData = true;
result.length = heightDiff;
realContainerHeight += heightDiff; //height for title
} else if (shopsdecoratorItem.get('module_type') == 'SingleImage') {
let properties = shopsdecoratorItem.get('module_data').get('properties').toJS();
let imageW = properties.width;
let imageH = properties.height;
imageW = imageW ? imageW : width;
imageH = imageH ? imageH : 400
let isModuleMargin = properties.isModuleMargin;
let imageHeight = (imageH*width)/(imageW==0?1:imageW);//根据返回信息计算出高度
let backgroundHeight = isModuleMargin=='1'?(imageHeight+10):imageHeight;
validFloorData = true;
result.length = backgroundHeight;
realContainerHeight += backgroundHeight;
} else if (shopsdecoratorItem.get('module_type') == 'DoubleImage') {
let properties = shopsdecoratorItem.get('module_data').get('properties').toJS();
let isModuleMargin = properties.isModuleMargin;
let backgroundHeight = isModuleMargin=='1'?(width/2+10):width/2;
validFloorData = true;
result.length = backgroundHeight;
realContainerHeight += backgroundHeight;
} else if (shopsdecoratorItem.get('module_type') == 'Video') {
let properties = shopsdecoratorItem.get('module_data').get('properties').toJS();
let isModuleMargin = properties.isModuleMargin;
let backgroundHeight = Math.ceil(((363+190)/750)*width);
let heigthW = isModuleMargin=='1'?backgroundHeight+10:backgroundHeight;
validFloorData = true;
result.length = backgroundHeight;
realContainerHeight += backgroundHeight;
} else if (shopsdecoratorItem.get('module_type') == 'TripleImage') {
let properties = shopsdecoratorItem.get('module_data').get('properties').toJS();
let isModuleMargin = properties.isModuleMargin;
let displayType = properties.displayType;
let nullHeigth = 10;
let heightDiff = 0;
switch (displayType) {
case '1': {
let containerHeigth = Math.ceil((333/750)*width);
heightDiff = isModuleMargin=='1'?containerHeigth+nullHeigth:containerHeigth;
}
break;
case '2': {
let containerHeigth = Math.ceil(width/3);
heightDiff = isModuleMargin=='1'?containerHeigth+nullHeigth:containerHeigth;
}
break;
case '3':
case '4': {
let containerHeigth = Math.ceil((468/750)*width);
heightDiff = isModuleMargin=='1'?containerHeigth+nullHeigth:containerHeigth;
}
break;
default:
break;
}
validFloorData = true;
result.length = heightDiff;
realContainerHeight += heightDiff;
} else if (shopsdecoratorItem.get('module_type') == 'FourImage') {
let list = shopsdecoratorItem.get('module_data').get('data').toArray();
let properties = shopsdecoratorItem.get('module_data').get('properties').toJS();
let isModuleMargin = properties.isModuleMargin;
if (list && list.length > 0) {
let itemWidth = (width - 4)/4;
let rowHeightArray = [];
for (let i = 0; i < Math.ceil(list.length / 4); i++) {
rowHeightArray.push(itemWidth);
}
list.map((item, i) => {
if (item.get('text') && item.get('text') != '') {
rowHeightArray[Math.floor(i/list.length)] = itemWidth + 20;
}
});
let backgroundWidth = width;
let backgroundHeight = 0;
for (let i = 0; i < rowHeightArray.length; i++) {
backgroundHeight += rowHeightArray[i];
}
if (isModuleMargin == '1') {
backgroundHeight += 10;
}
validFloorData = true;
result.length = backgroundHeight;
realContainerHeight += backgroundHeight;
}
} else if (shopsdecoratorItem.get('module_type') == 'AppRecommendProduct') {
let properties = shopsdecoratorItem.get('module_data').get('properties').toJS();
let isModuleMargin = properties.isModuleMargin;
let list = shopsdecoratorItem.get('list');
if (list && list.size > 0) {
let backgroundWidth = width;
let rowWidth = Math.ceil(137.5 * width / 320);
let rowMarginHorizontal = (width - rowWidth * 2) / 3;
const DEVICE_WIDTH_RATIO = width / 320;
let rowHeight = Math.ceil(254 * DEVICE_WIDTH_RATIO);
let backgroundHeight = Math.ceil(list.size / 2) * (rowHeight+rowMarginHorizontal) + 20;
validFloorData = true;
result.length = backgroundHeight;
realContainerHeight += backgroundHeight;
}
}
if (validFloorData) {
countNumb++;
}
if (validFloorData && countNumb == layoutIndex) {
return result;
}
}
} else if (item.key == 'productList') {
let brandFilterContainerHeight = this.props.fliter == '2' ? 84 : 40;
countNumb++; // filter
this.productListUpOffset = realContainerHeight;
if (countNumb == layoutIndex) {
result = {
length: brandFilterContainerHeight,
offset: realContainerHeight
};
return result;
} else if (layoutIndex > countNumb) {
let rowHeight = Math.ceil(254 * width / 320);
let rowMarginTop = Math.ceil(10 * DEVICE_WIDTH_RATIO);
let rowMarginBottom = Math.ceil(4 * DEVICE_WIDTH_RATIO);
realContainerHeight += brandFilterContainerHeight;
result.length = rowHeight + rowMarginTop + rowMarginBottom;
result.offset = realContainerHeight + (layoutIndex - countNumb) * result.length;
return result;
}
}
}
return {
length: 0,
offset: realContainerHeight,
}
}
getItemLayout(data, index) {
let {fliter,shopsdecorator} = this.props;
let key = 'fliter' + fliter + 'row' + index;
let sectionInfo = {
length: 0,
offset: 0,
};
if (shopsdecorator.isFetching) {
sectionInfo = this._calculateSectionRealHeight(this.sectionData, index);
}else {
if (this.layoutLenghtOffesetForIndex[key]) {
sectionInfo = this.layoutLenghtOffesetForIndex[key];
} else {
sectionInfo = this._calculateSectionRealHeight(this.sectionData, index);
this.layoutLenghtOffesetForIndex[key] = sectionInfo;
}
}
return {length: sectionInfo.length, offset: sectionInfo.offset, index};
}
renderSectionHeader(section) {
let sectionID = section.section.key;
let {fliter,shopsdecorator} = this.props;
switch(sectionID) {
case 'brandReource': {
if (shopsdecorator && shopsdecorator.template_type == '1') {
return <View style={{height:0}}></View>;
} else {
return (<RedBrandStoreFilter style={{zIndex: 999}} key={'sec' + sectionID} 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 key={'sec' + sectionID} style={[styles.brandFilterContainer,{height:brandFilterContainerHeight,zIndex: 999}]} onLayout={
(evt) => {yPosition = evt.nativeEvent.layout.y;}}>
{this.props.fliter != '0' ?
<RedBrandStoreFilter resource={fliter} onPressStoreFilter={this._onPressFilter}/>
:null
}
{this.props.fliter == '2' || this.props.fliter == '0' ?
<BrandProductFilter
onPressFilter={this._onPressProductFilter}
lastSelected={this.props.productList.isFilter}
moreFilter={this.props.productList.isMoreFilter}
selectOrder={this.props.productList.order}
moreFilterSelectOrder={this.props.moreFilterSelectOrder}
/>
:null
}
</View>
);
}
default:
return null;
}
return null;
}
renderItem(item) {
let pageName = 'iFP_RedPersonBrand';
if (Platform.OS === 'android') {
pageName = 'aFP_RedPersonBrand';
}
let rowData = item.item;
let rowID = item.index;
let sectionID = item.section.key;
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 {
return (
<View
style={{height:0,width:width,backgroundColor:'red'}}
/>
);
}
} else if (sectionID == 'productList' || sectionID == 'newProductList') {
return (
<RedBrandTwoProductCell
left={rowData.left}
right={rowData.right}
key={'row'+ sectionID + rowID}
index={rowID}
onPressProduct={this.props.onPressProductCell}
/>
);
}
return null;
}
getCellKey(item, index) {
if (!item) {
return index + '';
}
let type = item.get('recommend_type', '');
if (type) {
return type + index + '';
} else {
let skn = item.get('product_skn', '');
if (skn) {
return skn + '';
}
}
return index + '';
}
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 curPageProductList = productList.list?productList.list.toArray():[];
if (fliter == 1) {
curPageProductList = productListForNew.list?productListForNew.list.toArray():[];
}
let productListSize = curPageProductList.length / 2;
let newCurPageProductList = [];
for(let i = 0; i < productListSize; i ++) {
let leftIndex = i * 2;
let rightIndex = i * 2 + 1;
let left = curPageProductList[leftIndex];
let right = curPageProductList[rightIndex];
let key = this.getCellKey(left, leftIndex) + this.getCellKey(right, rightIndex);
newCurPageProductList.push({
left,
right,
key,
});
}
let dataSource = null;
if (fliter == 0) {
dataSource = [{data: [shopIntro],key:'ShopBanner'},
{data: resList, key:'brandReource'},
{data: newCurPageProductList, key:'productList'}
];
} else if (fliter == 1) {
dataSource = [{data: [shopIntro],key:'ShopBanner'},
{data: newCurPageProductList, key:'productList'}
];
} else if (fliter == 2) {
dataSource = [{data: [shopIntro],key:'ShopBanner'},
{data: newCurPageProductList, key:'productList'}
];
}
this.sectionData = dataSource;
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}>
<SectionList
ref='redBrandList'
contentContainerStyle={styles.contentContainer}
removeClippedSubviews={true}
enableVirtualization={true}
debug={false}
disableVirtualization={false}
refreshing={false}
sections={dataSource}
renderItem={this.renderItem}
renderSectionHeader={this.renderSectionHeader}
ListFooterComponent={()=>{
if (fliter == 0) {
return <View style={styles.placeholder} />;
}
if (endReached) {
return <View style={styles.placeholder} />;
} else {
return <LoadMoreIndicator isVisible={isLoadingMore} animating={true}/>;
}
}}
onEndReached={() => {
if (productList && productList.list && productList.list.size > 0) {
this.props.onEndReached && this.props.onEndReached(fliter);
}
}}
getItemLayout={this.getItemLayout}
viewabilityConfig={VIEWABILITY_CONFIG}
/>
{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}
moreFilterSelectOrder={this.props.moreFilterSelectOrder}/> : null}
{needShowToast ? <Prompt
text={showToastMessage}
duration={1000}
onPromptHidden={this.props.resetReceiveCouponResult}
/> : null}
{productList.isMoreFilter ?
<BrandProductMoreFilter
productList={productList}
onPressCloseMoreFilter={this.props.onPressCloseMoreFilter}
onPressMoreFilter={this.props.onPressMoreFilter}
moreFilterSelectOrder={this.props.moreFilterSelectOrder}/> : null}
<LoadingIndicator
isVisible={isFetching}
/>
</View>
);
}
}
let {width, height} = Dimensions.get('window');
let headerHeight = Math.ceil((234/750)*width);
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 realHeight = rowHeight + rowMarginTop;
let featuredHight = Math.ceil(((width-30)*220)/690);
const DEVICE_WIDTH_RATIO = width / 320;
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,
},
});