RankBody.js
3.52 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
import React, { Component, PureComponent } from 'react';
import { Dimensions, Image, StyleSheet, Text, TouchableOpacity, View, VirtualizedList } from 'react-native';
import YH_Image from '../../common/components/YH_Image';
import { getSlicedUrl } from '../../classify/utils/Utils';
const DEVICE_WIDTH_RATIO = Dimensions.get('window').width / 375;
export default class RankBody extends Component {
render() {
return (
<View style={this.props.style}>
<VirtualizedList
ListHeaderComponent={this._header}
keyExtractor={(item, index) => index}
renderItem={({item, index}) => this._renderItem(item, index)}
getItemLayout={(data, index) => ({length: 70 * DEVICE_WIDTH_RATIO, offset: 70 * DEVICE_WIDTH_RATIO * index, index})}
getItemCount={(data) => data.size || 0}
getItem={(data, index) => data.get(index)}
data={this.props.dataSource}
onEndReachedThreshold={0.5}
onEndReached={() => this.props.fetchNextPage(this.props.monthRank ? 1 : 2)}
showsVerticalScrollIndicator={false}>
</VirtualizedList>
</View>
);
}
_renderItem(item, index) {
return <RankItem key={index} monthRank={this.props.monthRank} item={item}/>
}
_header() {
return <View style={styles.view10}/>
}
}
class RankItem extends PureComponent {
render() {
let { item, monthRank } = this.props;
item = item.toJS();
const { nickname, amountStr, rankNum, image } = item;
return (
<View style={styles.itemContainer}>
<View style={styles.row}>
<Text style={styles.rank} numberOfLines={1}>{rankNum}</Text>
{this._renderImage(image)}
<Text style={styles.name} numberOfLines={1}>{nickname}</Text>
<View style={styles.rightContainer}>
<Text style={styles.amount} numberOfLines={1}>{amountStr}</Text>
<Text style={styles.amountName}>{`${monthRank ? '本月' : '总'}预估佣金`}</Text>
</View>
</View>
</View>
)
}
_renderImage(url) {
if (url) {
url = getSlicedUrl(url, 40 * DEVICE_WIDTH_RATIO, 40 * DEVICE_WIDTH_RATIO, 2);
return <YH_Image style={styles.avatar} url={url} circle={true} />
} else {
return <Image source={require('../../groupPurchase/images/PT_head.png')} style={styles.avatar} />
}
}
}
let { width } = Dimensions.get('window');
const styles = StyleSheet.create({
itemContainer: {
height: 70 * DEVICE_WIDTH_RATIO,
paddingVertical: 2,
borderBottomWidth: 0.5 * DEVICE_WIDTH_RATIO,
borderColor: '#E0E0E0',
},
row: {
flexDirection: 'row',
flex: 1,
alignItems: 'center',
},
rank: {
fontSize: 18,
color: '#444444',
width: 23,
marginLeft: 18 * DEVICE_WIDTH_RATIO,
},
avatar: {
height: 40 * DEVICE_WIDTH_RATIO,
width: 40 * DEVICE_WIDTH_RATIO,
overflow: 'hidden',
borderRadius: 20 * DEVICE_WIDTH_RATIO,
marginLeft: 15 * DEVICE_WIDTH_RATIO,
},
name: {
fontFamily: 'PingFang-SC-Regular',
fontSize: 14,
marginLeft: 10 * DEVICE_WIDTH_RATIO,
maxWidth: width - 230 * DEVICE_WIDTH_RATIO,
},
rightContainer: {
flex: 1,
alignItems: 'flex-end',
paddingRight: 15 * DEVICE_WIDTH_RATIO,
justifyContent: 'center',
},
amount: {
fontSize: 16,
color: '#444444',
fontWeight: 'bold',
},
amountName: {
fontFamily: 'PingFangSC-Regular',
marginTop: 4 * DEVICE_WIDTH_RATIO,
fontSize: 12,
color: '#B0B0B0'
},
view10: {
height: 10 * DEVICE_WIDTH_RATIO,
backgroundColor: '#F0F0F0',
},
})