|
@@ -7,16 +7,24 @@ import {
|
|
|
TextInput,
|
|
|
TouchableOpacity
|
|
|
} from "react-native";
|
|
|
-
|
|
|
+import courseDetails from '../services/courseDetails'
|
|
|
export default class Comment extends Component {
|
|
|
constructor(props) {
|
|
|
super(props);
|
|
|
this.state = {
|
|
|
text: '',
|
|
|
input: false,
|
|
|
- default: '写评论'
|
|
|
+ default: '写评论',
|
|
|
+ postsList: [],
|
|
|
+ postsId: ''
|
|
|
};
|
|
|
}
|
|
|
+ componentWillReceiveProps(nextProps) {
|
|
|
+ console.log('--------', nextProps)
|
|
|
+ this.setState({
|
|
|
+ postsList: nextProps.postsList
|
|
|
+ })
|
|
|
+ }
|
|
|
render() {
|
|
|
return (
|
|
|
<View style={styles.courseComment}>
|
|
@@ -29,28 +37,11 @@ export default class Comment extends Component {
|
|
|
</View>
|
|
|
</TouchableOpacity>
|
|
|
</View>
|
|
|
- <View style={[ styles.padding ]}>
|
|
|
- <View style={[ styles.title ]}>
|
|
|
- <View style={[ styles.center ]}>
|
|
|
- <Image style={[styles.headImg ]}></Image>
|
|
|
- <View>
|
|
|
- <Text style={{ fontSize: 16, color: '#373737' }}>小幸运</Text>
|
|
|
- <Text style={{ fontSize: 14, color: '#7F7F7F' } }>2019-07-05</Text>
|
|
|
- </View>
|
|
|
- </View>
|
|
|
- <View style={[ styles.center ]}>
|
|
|
- <Image source={require('../images/courseDetails/reply.png')} style={styles.reply} />
|
|
|
- <Text>回复</Text>
|
|
|
- </View>
|
|
|
- </View>
|
|
|
- <View style={ styles.padding }>
|
|
|
- <Text>爱上识字爱上文字的美,了解文字,幽默风趣的画风,动画识字展示让识字更有趣,跟喜欢。</Text>
|
|
|
- </View>
|
|
|
- <View style={[ styles.padding, styles.column ]}>
|
|
|
- <Text style={ styles.color }>卡通小熊</Text>
|
|
|
- <Text>爱上识字爱上文字的美,了解文字,幽默风趣的画风,动画识字展示让识字更有趣,跟喜欢。</Text>
|
|
|
- </View>
|
|
|
- </View>
|
|
|
+ {
|
|
|
+ this.state.postsList.map((item, index) =>
|
|
|
+ this.listRender(item, index)
|
|
|
+ )
|
|
|
+ }
|
|
|
{
|
|
|
this.state.input ?
|
|
|
<View style={[ styles.input, this.state.fullStyle]}>
|
|
@@ -63,7 +54,7 @@ export default class Comment extends Component {
|
|
|
autoFocus = {true}
|
|
|
defaultValue= {this.state.default}
|
|
|
/>
|
|
|
- <Text style={{ color: '#58A8FA', fontSize: 18}}>发送</Text>
|
|
|
+ <Text style={{ color: '#58A8FA', fontSize: 18}} onPress={() => this.send()}>发送</Text>
|
|
|
</View>
|
|
|
:
|
|
|
null
|
|
@@ -71,10 +62,103 @@ export default class Comment extends Component {
|
|
|
</View>
|
|
|
);
|
|
|
}
|
|
|
- comments() {
|
|
|
+ listRender(item, index) {
|
|
|
+ return (
|
|
|
+ <View style={[ styles.padding ]} key={ index }>
|
|
|
+ <View style={[ styles.title ]}>
|
|
|
+ <View style={[ styles.center ]}>
|
|
|
+ <Image style={[styles.headImg ]}></Image>
|
|
|
+ <View>
|
|
|
+ <Text style={{ fontSize: 16, color: '#373737' }}>{item.posts.columnNames}</Text>
|
|
|
+ <Text style={{ fontSize: 14, color: '#7F7F7F' } }>2019-07-05</Text>
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ <TouchableOpacity onPress={() => this.comments(item.posts.id)}>
|
|
|
+ <View style={[ styles.center ]}>
|
|
|
+ <Image source={require('../images/courseDetails/reply.png')} style={styles.reply} />
|
|
|
+ <Text>回复</Text>
|
|
|
+ </View>
|
|
|
+ </TouchableOpacity>
|
|
|
+ </View>
|
|
|
+ <View style={ styles.padding }>
|
|
|
+ <Text>{item.posts.content}</Text>
|
|
|
+ </View>
|
|
|
+ {
|
|
|
+ item.replies.map((items, indexs) =>
|
|
|
+ this.repliesList(items, indexs)
|
|
|
+ )
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+ )
|
|
|
+ }
|
|
|
+ repliesList (items, indexs) {
|
|
|
+ return (
|
|
|
+ <View style={[ styles.padding, styles.column ]} key={ indexs }>
|
|
|
+ <Text style={ styles.color }>卡通小熊</Text>
|
|
|
+ <Text>{ items.content }</Text>
|
|
|
+ </View>
|
|
|
+ )
|
|
|
+ }
|
|
|
+ comments(id) {
|
|
|
this.setState({
|
|
|
input: true
|
|
|
})
|
|
|
+ if (id) {
|
|
|
+ this.setState({
|
|
|
+ postsId: id
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ send() {
|
|
|
+ const columnId = this.props.courseId;
|
|
|
+ const content = this.state.text;
|
|
|
+ const postsId = this.state.postsId;
|
|
|
+ console.log(postsId)
|
|
|
+ if (!content) {
|
|
|
+ alert('请输入内容')
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if (!postsId) {
|
|
|
+ courseDetails.addCommentList({
|
|
|
+ columnId,
|
|
|
+ columnNames: "卡通小熊",
|
|
|
+ content
|
|
|
+ }).then(res => {
|
|
|
+ console.log(res)
|
|
|
+ if ( res.code == 200) {
|
|
|
+ courseDetails.getPostsList(columnId).success(res => {
|
|
|
+ const postsList = res.data.list;
|
|
|
+ this.setState({
|
|
|
+ input: false,
|
|
|
+ postsList,
|
|
|
+ text: ''
|
|
|
+ })
|
|
|
+ }).fail(error => {
|
|
|
+ console.log('失败', error)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }).catch( err => console.log(err))
|
|
|
+ }else {
|
|
|
+ courseDetails.addReplyList({
|
|
|
+ postsId,
|
|
|
+ content
|
|
|
+ }).then(res => {
|
|
|
+ console.log(res)
|
|
|
+ if ( res.code == 200) {
|
|
|
+ courseDetails.getPostsList(columnId).success(res => {
|
|
|
+ const postsList = res.data.list;
|
|
|
+ console.log('==========', postsList)
|
|
|
+ this.setState({
|
|
|
+ input: false,
|
|
|
+ postsList,
|
|
|
+ text: ''
|
|
|
+ })
|
|
|
+ }).fail(error => {
|
|
|
+ console.log('失败', error)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }).catch( err => console.log(err))
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|