index.js 6.66 KB
Newer Older
1
import React, { Component } from 'react'
2
import { CallApp } from '../../common'
xuzhenghua committed
3
import './index.scss'
4
import { WithTab } from '@/HOCs'
FE committed
5 6
// import Swiper from 'react-mobile-swiper'
// import createStyle from './createStyle'
7
import HomeCourseList from './course-list'
8
import { http } from '@/utils'
xuzhenghua committed
9
import LiveRoom from './liveRoom'
10 11 12
import { Link } from "react-router-dom"
import { Toast } from 'antd-mobile'
import { connect } from "react-redux";
FE committed
13
import TopSwiper from './TopSwiper'
xuzhenghua committed
14
import ExpandActiveToast from './expandActiveToast'
15
import AllCourseNavigation from "./all-course"
xuzhenghua committed
16

FE committed
17
// const animateTypes = Swiper.animateTypes
baiguangyao committed
18

19
@connect(state => ({
zhanghaozhe committed
20
  user: state.user
21
}))
baiguangyao committed
22
class Index extends Component {
zhanghaozhe committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
  constructor(props) {
    super(props)
    this.state = {
      banner: [],   // 首页banner
      lives: [],  //近期直播
      modules: [],  //首页课程模块儿
      isShow: false,
      islive: false,
      roomMess: '',
      tabdata: [
        {
          'src': require('./image/freeclass_icon.png'),
          'name': '公开课',
          'href': '/study/free-course'
        },
        {
          'src': require('./image/jingpin_icon.png'),
          'name': '精品特惠',
          'href': '/preferential'
        },
        {
          'src': require('./image/zjxj_icon.png'),
          'name': '赚奖学金',
          'href': '/scholarship'
        },
        {
          'src': require('./image/mryt_icon.png'),
          'name': '每日一题',
          'href': '/examination'
        },
        {
          'src': require('./image/shequ_icon.png'),
          'name': '社区',
          'href': 'https://ask.julyedu.com'
xuzhenghua committed
57
        }
zhanghaozhe committed
58
      ],
xuzhenghua committed
59
    }
zhanghaozhe committed
60 61 62 63 64 65 66 67 68 69 70
  }

  componentDidMount() {
    this.getIndexData()
  }

  // 首页课程
  getIndexData = () => {
    http.get(`${API.home}/m/home`).then((res) => {
      if (res.data.code === 200) {
        const {data} = res.data || {}
zhanghaozhe committed
71
        const modules = Array.isArray(data.modules) ? data.modules : []
zhanghaozhe committed
72 73 74
        this.setState({
          banner: data.banner,
          lives: data.lives,
zhanghaozhe committed
75
          modules
zhanghaozhe committed
76 77 78 79
        })
      } else {
        Toast.info(res.data.msg, 2)
      }
xuzhenghua committed
80

zhanghaozhe committed
81 82
    })
  }
xuzhenghua committed
83

xuzhenghua committed
84

zhanghaozhe committed
85 86 87 88 89 90 91 92 93 94 95 96
  // 点击近期直播课程弹出预约提示框
  liveCourse = (item) => {
    const {user} = this.props
    const uid = user && user.data && user.data.uid
    if (!uid) {
      this.props.history.push('/passport/login')
    } else {
      if (item.live_status === 0) {
        this.setState({
          isShow: true,
          islive: true,
          roomMess: item
xuzhenghua committed
97
        })
zhanghaozhe committed
98 99 100
      } else {
        window.location.href = `${window.location.href.includes('pre') ? 'http://www-pre.julyedu.com' : 'http://www.julyedu.com'}/live/m_room/${item.room_id}`
      }
xuzhenghua committed
101
    }
zhanghaozhe committed
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
  }
  // 自组件传给父组件的isshow
  colseBox = (val) => {
    this.setState({isShow: val})
  }

  // 点击头部搜索跳转到搜索页面
  toSearch() {
    this.props.history.push('/search')
  }

  render() {
    return (
      <div className='index-box'>
        <div className='header'>
          <img
            className="logo"
            src="http://julyedu-img-public.oss-cn-beijing.aliyuncs.com/Public/img/index/logo.png"
            alt=""
          />
          <CallApp
            className='to-app'
            text='在APP打开'
          />
          <i
            className='iconfont iconiconfront- search'
            onClick={this.toSearch.bind(this)}
          />
        </div>
xuzhenghua committed
131

zhanghaozhe committed
132
        <div className='zw_height'></div>
xuzhenghua committed
133

zhanghaozhe committed
134
        <ExpandActiveToast/>
xuzhenghua committed
135

zhanghaozhe committed
136 137 138 139 140 141
        <div className='index-swiper'>
          {
            this.state.banner && this.state.banner.length > 0 &&
            <TopSwiper bannerList={this.state.banner}/>
          }
        </div>
142

zhanghaozhe committed
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
        <div className="tabbox">
          <ul>
            {
              this.state.tabdata.map((item, index) => {
                return (
                  <li key={index}>
                    <a href={item.href}>
                      <img src={item.src} alt=""/>
                      <span>{item.name}</span>
                    </a>
                  </li>
                )
              })
            }
          </ul>
        </div>
xuzhenghua committed
159

zhanghaozhe committed
160
        <p className="borderTop"/>
xuzhenghua committed
161

zhanghaozhe committed
162
        {
xuzhenghua committed
163

zhanghaozhe committed
164 165 166 167 168 169 170 171 172
          (this.state.lives && this.state.lives.length > 0) ?
            <div className='lives'>
              <h2 className="title">近期直播</h2>
              <ScrollBox
                livesList={this.state.lives}
                liveCourse={this.liveCourse}
              />
            </div> : null
        }
xuzhenghua committed
173

174 175 176
        <HomeCourseList
          modules={this.state.modules}
        />
xuzhenghua committed
177

178
        <AllCourseNavigation/>
xuzhenghua committed
179

zhanghaozhe committed
180 181 182 183 184 185 186 187 188 189 190 191 192
        {/* 直播间预约 */}
        {
          this.state.islive &&
          <LiveRoom
            isShow={this.state.isShow}
            colseBox={this.colseBox}
            roomMess={this.state.roomMess}
            getIndexData={this.getIndexData}
          />
        }
      </div>
    )
  }
baiguangyao committed
193 194 195

}

zhanghaozhe committed
196

zhanghaozhe committed
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
//近期直播
function ScrollBox(props) {
  return (
    <div className='scroll-box'>
      <ul className='scroll-list'>
        {
          props.livesList && props.livesList.length > 0 && props.livesList.map((item, index) => {
            return (
              <li key={index} className='scroll-item'
                  onClick={e => props.liveCourse(item)}>
                <div className='item-box'>
                  {
                    item.live_status === 0 &&
                    <span className='no-start'>即将开始</span>
                  }
                  {
                    (item.live_status === 1 || item.live_status === 10) &&
                    <span className='start'>正在直播</span>
                  }
                  <img className="item-img" src={item.live_img} alt=""/>
                  <div className="item-content">
                    <h2 className="item-title">{item.live_title}</h2>
                    <p className="item-teacher">讲师:{item.live_teacher_name}</p>

                    {/*公开课需预约、付费课不需要预约*/}
xuzhenghua committed
222
                    {
zhanghaozhe committed
223 224
                      (item.is_prepare || item.is_free === 0) && item.live_status === 0 &&
                      <p className="item-time">时间:{item.live_start_time}</p>
xuzhenghua committed
225 226
                    }
                    {
zhanghaozhe committed
227 228
                      !item.is_prepare && item.live_status === 0 && item.is_free === 1 &&
                      <button className='item-btn'>预约</button>
xuzhenghua committed
229
                    }
zhanghaozhe committed
230 231 232 233 234 235 236 237 238 239 240 241 242
                    {
                      (item.live_status === 1 || item.live_status === 10) &&
                      <button className='item-btn'>正在直播</button>
                    }
                  </div>
                </div>
              </li>
            )
          })
        }
      </ul>
    </div>
  )
xuzhenghua committed
243
}
xuzhenghua committed
244

245
export default WithTab(Index);