CourseDetails.js 2.6 KB

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