TalentRank.js
6.72 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
import React, { Component } from 'react';
import { Dimensions, Image, ScrollView, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import { connect } from 'react-redux';
import RankBody from './RankBody';
import { List } from 'immutable';
import YH_Image from '../../common/components/YH_Image';
import { getSlicedUrl } from '../../classify/utils/Utils';
const DEVICE_WIDTH_RATIO = Dimensions.get('window').width / 375;
const { width } = Dimensions.get('window');
function mapStateToProps(store) {
return {
talentRank: store.talentRank,
}
}
class TalentRank extends Component {
state = { monthRank: true }
render() {
const { monthRank } = this.state;
let monthRankData = this.props.talentRank.monthRank;
let totalRankData = this.props.talentRank.totalRank;
let myRank = monthRank ? monthRankData.toJS() : totalRankData.toJS();
let { amountStr, nickname, image, rankNum ,amount} = myRank;
return (
<View style={styles.container}>
<View style={[styles.topContainer, styles.center]}>
<View style={styles.btnWrapper}>
<TouchableOpacity onPress={() => this._toggleRank(true)}>
<View style={[styles.rankBtn, styles.center, monthRank ? styles.btnChoose : null]}>
<Text style={[styles.rankBtnFont, monthRank ? styles.btnTextChoose : null]}>本月排行</Text>
</View>
</TouchableOpacity>
<TouchableOpacity style={styles.positionFixed} onPress={() => this._toggleRank(false)}>
<View style={[styles.rankBtn, styles.center, !monthRank ? styles.btnChoose : null]}>
<Text style={[styles.rankBtnFont, !monthRank ? styles.btnTextChoose : null]}>总排行</Text>
</View>
</TouchableOpacity>
</View>
</View>
<View style={styles.myRankContainer}>
<View style={[styles.container, styles.leftContainer]}>
<Text style={styles.amountName}>{`${monthRank ? '本月' : '总'}预估佣金`}</Text>
<View style={styles.amountContainer}>
<Text style={[styles.amountUnit,styles.textLeft]}>¥</Text>
<Text style={[styles.amount,styles.textLeft]}>{amount}</Text>
</View>
</View>
<View style={[styles.container, styles.middleContainer]}>
{this._renderImage(image)}
<Text style={styles.name} numberOfLines={1}>{nickname}</Text>
</View>
<View style={[styles.container, styles.rightContainer]}>
<Text style={[styles.amountName, styles.textRight]}>排名</Text>
<Text style={[styles.amountnoRank, styles.textRight, styles.marginTop5]}>{rankNum && rankNum != 0 ? rankNum : '未上榜'}</Text>
</View>
</View>
<ScrollView ref="scrollView" style={styles.container}
contentContainerStyle={styles.contentContainerStyle}
horizontal={true}
scrollEnabled={false} showsHorizontalScrollIndicator={false}>
<RankBody
monthRank={true}
fetchNextPage={this._fetchNextPage}
dataSource={monthRankData.get('rankList').get('list')}
style={styles.container}/>
<RankBody
fetchNextPage={this._fetchNextPage}
dataSource={totalRankData.get('rankList').get('list')}
style={styles.container}/>
</ScrollView>
</View>
);
}
componentDidMount() {
this.props.actions.fetchTalentRank({
type: 1,
page: 1,
pageSize: 10,
});
this.props.actions.fetchTalentRank({
type: 2,
page: 1,
pageSize: 10,
});
}
_toggleRank(monthRank) {
// this.setState({height: 400});
this.setState({monthRank: monthRank});
const { scrollView } = this.refs;
scrollView && (monthRank ? scrollView.scrollTo({x: 0, y: 0, animated: false}) : scrollView.scrollToEnd({animated: false}))
}
_renderImage(url) {
if (url) {
url = getSlicedUrl(url, 60 * DEVICE_WIDTH_RATIO, 60 * DEVICE_WIDTH_RATIO, 2);
return <YH_Image style={styles.avatar} url={url} circle={true}></YH_Image>
} else {
return <Image source={require('../../groupPurchase/images/PT_head.png')} style={styles.avatar} />
}
}
_fetchNextPage = (type) => {
this.props.actions.fetchTalentRank({type});
}
}
export default connect(mapStateToProps)(TalentRank)
const styles = StyleSheet.create({
container: {
flex: 1
},
center: {
justifyContent: 'center',
alignItems: 'center'
},
topContainer: {
height: 67 * DEVICE_WIDTH_RATIO,
},
btnWrapper: {
width: 178 * DEVICE_WIDTH_RATIO,
borderColor: '#444444',
borderWidth: 1 * DEVICE_WIDTH_RATIO,
borderRadius: 4 * DEVICE_WIDTH_RATIO,
flexDirection: 'row',
},
rankBtn: {
width: 92 * DEVICE_WIDTH_RATIO,
height: 36 * DEVICE_WIDTH_RATIO,
borderRadius: 3 * DEVICE_WIDTH_RATIO,
},
rankBtnFont: {
fontSize: 14,
fontFamily: 'PingFang-SC-Regular',
color: '#444444',
},
btnChoose: {
backgroundColor: '#444444',
},
btnTextChoose: {
color: 'white'
},
myRankContainer: {
height: 124 * DEVICE_WIDTH_RATIO,
flexDirection: 'row',
},
leftContainer: {
paddingLeft: 30 * DEVICE_WIDTH_RATIO,
paddingTop: 27 * DEVICE_WIDTH_RATIO,
},
amountName: {
fontFamily: 'PingFang-SC-Regular',
fontSize: 12,
color: '#B0B0B0',
lineHeight: 17,
},
amountContainer: {
marginTop: 10 * DEVICE_WIDTH_RATIO,
flexDirection: 'row',
},
amountUnit: {
fontSize: 14,
lineHeight: 24,
fontWeight: '500',
textAlignVertical: 'bottom',
includeFontPadding: false,
color: '#444444',
},
amount: {
fontSize: 24,
lineHeight: 24,
fontWeight: '500',
textAlignVertical: 'bottom',
includeFontPadding: false,
color: '#000000',
},
amountnoRank: {
fontSize: 20,
lineHeight: 24,
fontWeight: '500',
textAlignVertical: 'bottom',
includeFontPadding: false,
color: '#000000',
},
middleContainer: {
paddingTop: 14 * DEVICE_WIDTH_RATIO,
alignItems: 'center',
},
avatar: {
height: 60 * DEVICE_WIDTH_RATIO,
width: 60 * DEVICE_WIDTH_RATIO,
overflow: 'hidden',
borderRadius: 30 * DEVICE_WIDTH_RATIO,
},
name: {
fontFamily: 'PingFang-SC-Medium',
fontSize: 14,
lineHeight: 20,
marginTop: 10 * DEVICE_WIDTH_RATIO,
fontWeight: '500',
},
rightContainer: {
paddingRight: 30 * DEVICE_WIDTH_RATIO,
paddingTop: 27 * DEVICE_WIDTH_RATIO,
},
textRight: {
textAlign: 'right',
},
textLeft: {
textAlign: 'left',
},
marginTop5: {
marginTop: 5 * DEVICE_WIDTH_RATIO,
},
positionFixed: {
position: 'absolute',
right: 0,
},
contentContainerStyle: {
width: 2 * width,
}
});