CourseDetails.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. console.log(courseId)
  27. courseDetails.getCourseDetails(courseId).success(res => {
  28. console.log('列表',res.data)
  29. const courseList = res.data.course;
  30. const wareList = res.data.wareList;
  31. this.setState({
  32. courseList,
  33. wareList
  34. })
  35. });
  36. courseDetails.getPostsList(courseId).success(res => {
  37. console.log('评论列表', res.data)
  38. const postsList = res.data.list;
  39. console.log(postsList)
  40. this.setState({
  41. postsList,
  42. })
  43. }).fail(error => {
  44. console.log('失败', error)
  45. })
  46. }
  47. state = {
  48. fullStyle: {},
  49. lefts: 0,
  50. courseList: {},
  51. wareList: {},
  52. postsList: [],
  53. uri: 'http://chimee.org/vod/1.mp4'
  54. }
  55. render() {
  56. return (
  57. <View style={{backgroundColor: '#F0F1F5', width: '100%', height: '100%', position: 'relative'}}>
  58. <ScrollView keyboardShouldPersistTaps="handled">
  59. <View>
  60. <VideoExplain
  61. full={this.full.bind(this)}
  62. uri={ this.state.uri }
  63. dataList={ this.state.courseList }
  64. ref={view => (this.video = view)} //设置ID
  65. videoback={this.back.bind(this) }
  66. />
  67. </View>
  68. <View style={ this.state.fullStyle }>
  69. <CourseListRow title={'课件'} wareList={ this.state.wareList} changeUri={ this.changeUri.bind(this) }></CourseListRow>
  70. {/* <CourseListLine title={'课件'} wareList={ this.state.wareList}></CourseListLine> */}
  71. <Comment title={ '全部评论' } courseId= { this.state.courseList.id }></Comment>
  72. </View>
  73. </ScrollView>
  74. {/* <Order left={ this.state.lefts }></Order> */}
  75. </View>
  76. );
  77. }
  78. back(){
  79. this.props.navigation.goBack()
  80. }
  81. full(isFull){
  82. if(isFull) {
  83. // 全屏时隐藏多余的view
  84. this.setState({
  85. fullStyle: {},
  86. lefts: 0
  87. })
  88. }else {
  89. // 全屏时隐藏多余的view
  90. this.setState({
  91. fullStyle: {
  92. display: 'none'
  93. },
  94. lefts: '-100%'
  95. })
  96. }
  97. }
  98. changeUri(uri) {
  99. console.log(uri)
  100. this.setState({
  101. uri
  102. })
  103. // 开始播放
  104. this.video.start();
  105. }
  106. }
  107. const styles = StyleSheet.create({
  108. });