CourseDetails.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**
  2. * Sample React Native App
  3. * https://github.com/facebook/react-native
  4. *
  5. * @format
  6. * @flow
  7. */
  8. import React, { Component } from "react";
  9. import {
  10. StyleSheet,
  11. Text,
  12. View,
  13. Image,
  14. ScrollView,
  15. FlatList
  16. } from "react-native";
  17. import VideoExplain from './components/VideoExplain'
  18. import CourseListRow from './components/CourseListRow'
  19. import CourseListLine from './components/CourseListLine'
  20. import Comment from './components/Comment'
  21. import Order from './components/Order'
  22. import courseDetails from './services/courseDetails'
  23. export default class CourseDetails extends Component {
  24. componentDidMount() {
  25. const { courseId } = this.props.navigation.state.params;
  26. courseDetails.getCourseDetails(courseId).success(res => {
  27. console.log('列表',res.data)
  28. const courseList = res.data.course;
  29. const wareList = res.data.wareList;
  30. this.setState({
  31. courseList,
  32. wareList
  33. })
  34. });
  35. courseDetails.getPostsList(courseId).success(res => {
  36. console.log('评论列表', res.data)
  37. const postsList = res.data.list;
  38. console.log(postsList)
  39. this.setState({
  40. postsList,
  41. })
  42. }).fail(error => {
  43. console.log('失败', error)
  44. })
  45. }
  46. state = {
  47. fullStyle: {},
  48. lefts: 0,
  49. courseList: {},
  50. wareList: {},
  51. postsList: [],
  52. uri: 'http://chimee.org/vod/1.mp4'
  53. }
  54. render() {
  55. return (
  56. <View style={{backgroundColor: '#F0F1F5', width: '100%', height: '100%', position: 'relative'}}>
  57. <ScrollView keyboardShouldPersistTaps="handled">
  58. <View>
  59. <VideoExplain
  60. full={this.full.bind(this)}
  61. uri={ this.state.uri }
  62. dataList={ this.state.courseList }
  63. ref={view => (this.video = view)} //设置ID
  64. videoback={this.back.bind(this) }
  65. />
  66. </View>
  67. <View style={ this.state.fullStyle }>
  68. <CourseListRow title={'课件'} wareList={ this.state.wareList} changeUri={ this.changeUri.bind(this) }></CourseListRow>
  69. {/* <CourseListLine title={'课件'} wareList={ this.state.wareList}></CourseListLine> */}
  70. <Comment title={ '全部评论' } postsList={ this.state.postsList } courseId= { this.state.courseList.id }></Comment>
  71. </View>
  72. </ScrollView>
  73. {/* <Order left={ this.state.lefts }></Order> */}
  74. </View>
  75. );
  76. }
  77. back(){
  78. this.props.navigation.goBack()
  79. }
  80. full(isFull){
  81. if(isFull) {
  82. // 全屏时隐藏多余的view
  83. this.setState({
  84. fullStyle: {},
  85. lefts: 0
  86. })
  87. }else {
  88. // 全屏时隐藏多余的view
  89. this.setState({
  90. fullStyle: {
  91. display: 'none'
  92. },
  93. lefts: '-100%'
  94. })
  95. }
  96. }
  97. changeUri(uri) {
  98. console.log(uri)
  99. this.setState({
  100. uri
  101. })
  102. // 开始播放
  103. this.video.start();
  104. }
  105. }
  106. const styles = StyleSheet.create({
  107. });