topicInfo.js
5.26 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
import React, {Component} from 'react';
import {DeviceEventEmitter, Image, StyleSheet, Text, View} from 'react-native';
import {zoomH, zoomW} from '../../utils/getSize';
import {xnToast} from "../../utils/utils";
import AppService from "../../service/AppService";
//图片资源
const defaultIcon = require('../../img/defaultIcon.png');
const vIcon = require('../../img/v.png');
// 变量定义
{
var parm_topicId = 0
}
/**
* 话题信息
* 调用者需要传入的参数 topicInfoData : 话题信息数据源
*/
export default class topicInfo extends Component {
static navigationOptions = ({ navigation, screenProps }) => ({
header:null,
});
// 构造
constructor(props) {
super(props);
// 初始状态
this.state = {
data:[]
// data:{
// name:"最爱精油榜",
// description:"你心中最喜欢日常使用的精油是哪一款呢!快来bo出图片吧!",
// iconFileUrl:"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1541419615088&di=95ba0882b456756b2cf34708043a62ec&imgtype=0&src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F01067f55454cbf0000019ae993a3c1.jpg%403000w_1l_2o_100sh.jpg",
// readCount:1398,
// replyCount:1334
// }
}
}
componentWillMount(){
parm_topicId = this.props.id;
// 查询话题信息
this.getTopic(parm_topicId);
};
getTopic(id){
if (!global.isConnected){
xnToast('暂无网络连接,请稍后重试!');
return;
}
let params = {
id: id,
};
//console.log(params);
AppService.getTopic(params).then((data) => {
//console.log(data);
if (data.message) {
DeviceEventEmitter.emit('getTopicInfo', {});
xnToast(data.message);
return;
}
if (data.errors.length > 0) {
DeviceEventEmitter.emit('getTopicInfo', {});
xnToast(data.errors[0].message);
} else {
// ”万“”处理
//data.topic.topicStatistics.readNum = 123456;
data.topic.topicStatistics.readNum_str = data.topic.topicStatistics.readNum;
if (data.topic.topicStatistics.readNum > 100000) {
data.topic.topicStatistics.readNum_str = Math.floor(data.topic.topicStatistics.readNum/100000 * 10) / 10 + "万";
//var temp =Math.floor(data.topic.topicStatistics.readNum/100000 * 10) / 10
}
// ”万“”处理
//data.topic.topicStatistics.replyNum = 654321;
data.topic.topicStatistics.forumNum_str = data.topic.topicStatistics.forumNum;
if (data.topic.topicStatistics.forumNum > 100000) {
data.topic.topicStatistics.forumNum_str = Math.floor(data.topic.topicStatistics.forumNum/100000 * 10) / 10 + "万";
//var temp =Math.floor(data.topic.topicStatistics.readNum/100000 * 10) / 10
}
this.setState({
data:data.topic
})
DeviceEventEmitter.emit('getTopicInfo', data.topic.iconFileUrl);
}
}).catch((error) => {
this.setState({
loading: false
});
DeviceEventEmitter.emit('getTopicInfo', {});
xnToast(error)
})
}
// 话题信息
render() {
return (
<View style = {styles.background} >
<Image style={styles.img} source={{uri: this.state.data.iconFileUrl}} resizeMode="cover" />
<View style = {styles.textArea}>
<Text style = {styles.title} numberOfLines = {1}>#{this.state.data.name?this.state.data.name:""}#</Text>
<Text style = {styles.readAndDiscussion} numberOfLines = {1}>{this.state.data.topicStatistics?this.state.data.topicStatistics.readNum_str:"0"}阅读 {this.state.data.topicStatistics?this.state.data.topicStatistics.forumNum_str:"0"}讨论</Text>
<Text style = {styles.intro} numberOfLines = {2}>{this.state.data.description?this.state.data.description:""}</Text>
</View>
</View>
)
}
}
const styles = StyleSheet.create({
background:{
flex:1,
width:'100%',
height:'100%',
display: 'flex',
flexDirection: 'row',
alignItems: 'flex-start',
justifyContent: 'flex-start'
},
img : {
height:86/zoomW,
width:86/zoomW,
display: 'flex',
alignItems: 'flex-start',
justifyContent: 'flex-start',
flexDirection: 'column'
},
textArea : {
flex:1,
height: '100%',
display: 'flex',
flexDirection: 'column',
justifyContent: 'flex-start',
alignItems: 'flex-start',
marginLeft: 15 / zoomW,
marginTop: 0,
marginBottom: 0
},
title : {
height: 28 / zoomH,
fontSize:20,
color:'white'
},
readAndDiscussion:{
height: 17 / zoomH,
fontSize:12,
color:'white'
},
intro:{
fontSize:12,
color:'white'
},
});