No Description

AnswerDetailViewController.js 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /**
  2. * Created by zack on 2018/4/29.
  3. */
  4. import {
  5. View,
  6. Text,
  7. StyleSheet,
  8. FlatList,
  9. TouchableOpacity,
  10. Image
  11. } from 'react-native'
  12. import React, {Component} from 'react'
  13. import {NavigationBarHeight, TabBarHeight, ScreenDimensions} from '../../../utils/DimensionsTools'
  14. import AnswerQuestionItem from './View/AnswerQuestionItem'
  15. import AnswerQuestionCommentItem from './View/AnswerQuestionCommentItem'
  16. import BaseNavigationBarStyle from '../../base/BaseNavigationBarStyle'
  17. import HttpTools from '../../../network/HttpTools'
  18. import {auth, question, comment} from '../../../network/API'
  19. export default class AnswerDetailViewController extends Component {
  20. constructor(props) {
  21. super(props)
  22. this.state = {
  23. dataSources: [],
  24. questionId: props.questionId,
  25. questionTitle: ''
  26. }
  27. }
  28. componentDidMount() {
  29. //this.getQuestionDetailById(this.state.questionId)
  30. }
  31. getQuestionDetailById(questionId) {
  32. HttpTools.get(question + '/' + questionId, {}, (response) => {
  33. if (!response) {
  34. return
  35. }
  36. let headerItem = Object.assign(response, {key: 0})
  37. this.setState({
  38. dataSources: this.state.dataSources.concat([headerItem]),
  39. questionTitle: response.title
  40. }, () => {
  41. this.getQuestionCommentListById(this.state.questionId)
  42. })
  43. }, (error) => {
  44. console.log(error)
  45. })
  46. }
  47. getQuestionCommentListById(questionId) {
  48. const param = {
  49. model_id: this.state.questionId,
  50. model_type: 'question',
  51. page: 1,
  52. limit: 10,
  53. }
  54. HttpTools.get(comment, param, (response) => {
  55. if (response && response.length) {
  56. let commentListWithIndex = response.map((item, index) => {
  57. return Object.assign(item, {key: index + 1})
  58. })
  59. this.setState({
  60. dataSources: this.state.dataSources.concat(commentListWithIndex),
  61. })
  62. }
  63. }, (error) => {
  64. })
  65. }
  66. crateQuestion() {
  67. this.props.navigator.showModal({
  68. screen: 'QuestionCreateViewController',
  69. title: '提问',
  70. backButtonTitle: '',
  71. passProps: {
  72. questionName: '如何学习英语?'
  73. },
  74. navigatorStyle: BaseNavigationBarStyle
  75. })
  76. }
  77. createAnswer() {
  78. this.props.navigator.showModal({
  79. screen: 'AnswerCreateViewController',
  80. title: '回答',
  81. backButtonTitle: '',
  82. passProps: {
  83. title: this.state.questionTitle,
  84. questionId: this.state.questionId
  85. },
  86. navigatorStyle: BaseNavigationBarStyle
  87. })
  88. }
  89. clickItemBottomButton(index) {
  90. }
  91. renderItem(item) {
  92. if (item.key === 0) {
  93. return(
  94. <AnswerQuestionItem
  95. title = {item.title}
  96. subTitle = {item.content}
  97. imageUrls = {item.img_urls}
  98. commentCount = {0}
  99. likes = {item.likes}
  100. />
  101. )
  102. }else {
  103. return (
  104. <AnswerQuestionCommentItem
  105. headerImageUrl= {item.user_avatar}
  106. likes= {item.likes}
  107. shares= {item.shares}
  108. commentCount= {item.comment_count}
  109. userName= {item.user_name}
  110. commentContent= {item.content}
  111. read= {12}
  112. clickItemBottomButton = {(index) => {
  113. this.clickItemBottomButton(index)
  114. }}
  115. />
  116. )
  117. }
  118. }
  119. render() {
  120. return(
  121. <View style={styles.View}>
  122. <View style={styles.ListView}>
  123. <FlatList
  124. data = {this.state.dataSources}
  125. renderItem={({item}) => this.renderItem(item)}
  126. keyExtractor = {(item,index) =>{
  127. return 'key' + item.key + index
  128. }}
  129. ListFooterComponent = {() => {
  130. return(
  131. <View style={{width: ScreenDimensions.width, height: 44, backgroundColor: 'white'}} />
  132. )
  133. }}
  134. />
  135. </View>
  136. <TouchableOpacity style = {styles.BottomTagBgView}>
  137. <TouchableOpacity onPress={() => {
  138. }} style={styles.BottomButtonView}>
  139. <Image source={require('../../../resources/images/TabBar/Community/Answer/doc.png')} style={[styles.BottomButtonImageView]}/>
  140. <Text style={styles.BottomButtonText}>{'更多'}</Text>
  141. </TouchableOpacity>
  142. <TouchableOpacity onPress={() => [
  143. this.crateQuestion()
  144. ]} style={styles.BottomButtonView}>
  145. <Image source={require('../../../resources/images/TabBar/Community/Answer/fill.png')} style={styles.BottomButtonImageView}/>
  146. <Text style={styles.BottomButtonText}>{'提问'}</Text>
  147. </TouchableOpacity>
  148. <TouchableOpacity onPress={() => {
  149. this.createAnswer()
  150. }} style={styles.BottomButtonView}>
  151. <Image source={require('../../../resources/images/TabBar/Community/Answer/pen.png')} style={[styles.BottomButtonImageView]}/>
  152. <Text style={[styles.BottomButtonText,]}>{'回答'}</Text>
  153. </TouchableOpacity>
  154. <View style={styles.BottomLineView} />
  155. </TouchableOpacity>
  156. </View>
  157. )
  158. }
  159. }
  160. const styles = StyleSheet.create({
  161. View: {
  162. width: ScreenDimensions.width,
  163. height: ScreenDimensions.height,
  164. backgroundColor: 'white'
  165. },
  166. ListView: {
  167. marginTop: NavigationBarHeight.height,
  168. width: ScreenDimensions.width,
  169. height: ScreenDimensions.height - NavigationBarHeight.height - 48,
  170. backgroundColor: 'white'
  171. },
  172. BottomTagBgView: {
  173. width: ScreenDimensions.width,
  174. height: 48,
  175. backgroundColor: '#eef0ef',
  176. flexDirection: 'row',
  177. },
  178. BottomButtonView: {
  179. width: ScreenDimensions.width/3.0,
  180. height: 48,
  181. flexDirection: 'row',
  182. justifyContent: 'center',
  183. alignItems: 'center',
  184. backgroundColor: 'white'
  185. },
  186. BottomButtonImageView: {
  187. marginRight: 13,
  188. },
  189. BottomButtonText: {
  190. fontSize: 13,
  191. color: '#000000'
  192. },
  193. BottomLineView: {
  194. position: 'absolute',
  195. width: ScreenDimensions.width,
  196. height: 0.5,
  197. backgroundColor: '#d7d7d7',
  198. left: 0,
  199. top: 0,
  200. },
  201. })