index.js 10.3 KB
Newer Older
xuzhenghua committed
1
import React, {Component} from 'react'
xuzhenghua committed
2
import {Course} from '../../common'
xuzhenghua committed
3
import './index.scss'
zhanghaozhe committed
4
import {WithTab} from '@/HOCs'
xuzhenghua committed
5 6
import Swiper from 'react-mobile-swiper'
import createStyle from './createStyle'
xuzhenghua committed
7
import LazyLoad from 'react-lazy-load'
xuzhenghua committed
8
import {http, api} from '@/utils'
xuzhenghua committed
9
import LiveRoom from './liveRoom'
xuzhenghua committed
10
import {Link} from "react-router-dom"
xuzhenghua committed
11
import {Toast} from 'antd-mobile'
xuzhenghua committed
12 13
import {CallApp} from '../../common'

xuzhenghua committed
14

xuzhenghua committed
15 16

const animateTypes = Swiper.animateTypes
baiguangyao committed
17 18

class Index extends Component {
xuzhenghua committed
19
    constructor(props) {
xuzhenghua committed
20
        super(props)
xuzhenghua committed
21 22 23 24 25 26
        this.state = {
            banner: [],
            lives: [],
            modules: [],
            isShow: false,
            islive: false,
xuzhenghua committed
27
            roomMess: '',
xuzhenghua committed
28 29 30 31
            tabdata: [
                {
                    'src': require('./image/freeclass_icon.png'),
                    'name': '公开课',
xuzhenghua committed
32
                    'href': '/study/free-course'
xuzhenghua committed
33 34 35 36
                },
                {
                    'src': require('./image/jingpin_icon.png'),
                    'name': '精品特惠',
xuzhenghua committed
37
                    'href': '/preferential'
xuzhenghua committed
38 39 40 41
                },
                {
                    'src': require('./image/zjxj_icon.png'),
                    'name': '赚奖学金',
xuzhenghua committed
42
                    'href': '/scholarship'
xuzhenghua committed
43 44 45 46
                },
                {
                    'src': require('./image/mryt_icon.png'),
                    'name': '每日一题',
xuzhenghua committed
47
                    'href': '/examination'
xuzhenghua committed
48 49 50 51
                },
                {
                    'src': require('./image/qynx_icon.png'),
                    'name': '企业内训',
xuzhenghua committed
52
                    'href': 'http://m-active.julyedu.com'
xuzhenghua committed
53 54 55
                }
            ]
        }
xuzhenghua committed
56
    }
xuzhenghua committed
57

xuzhenghua committed
58 59
    componentDidMount() {
        // 首页课程
xuzhenghua committed
60
        http.get(`${api.home}/m/home`).then((res) => {
xuzhenghua committed
61 62 63 64 65 66
            if (res.data.code === 200) {
                this.setState({
                    banner: res.data.data.banner,
                    lives: res.data.data.lives,
                    modules: res.data.data.modules
                })
xuzhenghua committed
67 68
            } else {
                Toast.info(res.data.msg, 2)
xuzhenghua committed
69
            }
xuzhenghua committed
70

xuzhenghua committed
71
        })
xuzhenghua committed
72
    }
xuzhenghua committed
73 74


xuzhenghua committed
75
    // 点击近期直播课程弹出预约提示框
xuzhenghua committed
76 77 78 79 80 81 82 83 84 85 86
    liveCourse = (item) => {
        if (item.live_status === 0) {
            this.setState({
                isShow: true,
                islive: true,
                roomMess: item
            })
        } else {
            window.location.href = `http://www-test.julyedu.com/live/m_room/${item.room_id}`
        }

xuzhenghua committed
87
    }
xuzhenghua committed
88 89
    // 自组件传给父组件的isshow
    colseBox = (val) => {
xuzhenghua committed
90
        this.setState({isShow: val})
6  
xuzhenghua committed
91
    }
xuzhenghua committed
92

xuzhenghua committed
93
    toSearch() {
xuzhenghua committed
94
        window.location.href = '/search'
xuzhenghua committed
95
    }
xuzhenghua committed
96

baiguangyao committed
97 98
    render() {
        return (
xuzhenghua committed
99
            <div className='index-box'>
xuzhenghua committed
100
                <div className='header'>
xuzhenghua committed
101 102
                    <img className="logo"
                         src="http://julyedu-img-public.oss-cn-beijing.aliyuncs.com/Public/img/index/logo.png" alt=""/>
xuzhenghua committed
103 104 105
                    {/*<button className='to-app'>在APP打开</button>*/}
                    <CallApp className='to-app'></CallApp>

xuzhenghua committed
106 107 108
                    <i className='iconfont iconiconfront- search' onClick={this.toSearch.bind(this)}></i>
                </div>

xuzhenghua committed
109
                <div className='index-swiper'>
xuzhenghua committed
110 111 112 113
                    {
                        this.state.banner && this.state.banner.length > 0 &&
                        <TopSwiper bannerList={this.state.banner}/>
                    }
xuzhenghua committed
114
                </div>
xuzhenghua committed
115

6  
xuzhenghua committed
116 117
                <div className="tabbox">
                    <ul>
xuzhenghua committed
118
                        {
xuzhenghua committed
119
                            this.state.tabdata.map((item, index) => {
xuzhenghua committed
120 121
                                return (
                                    <li key={index}>
xuzhenghua committed
122 123 124 125
                                        <a href={item.href}>
                                            <img src={item.src} alt=""/>
                                            <span>{item.name}</span>
                                        </a>
xuzhenghua committed
126 127 128 129
                                    </li>
                                )
                            })
                        }
6  
xuzhenghua committed
130 131
                    </ul>
                </div>
xuzhenghua committed
132 133 134

                <p className="borderTop"></p>
                <div className='lives'>
xuzhenghua committed
135
                    <h2 className="title">近期直播</h2>
xuzhenghua committed
136
                    <ScrollBox livesList={this.state.lives} liveCourse={this.liveCourse}/>
xuzhenghua committed
137
                </div>
xuzhenghua committed
138

xuzhenghua committed
139 140 141 142 143 144 145 146 147 148
                {
                    this.state.modules && this.state.modules.length > 0 && this.state.modules.map((item, index) => {
                        return (
                            <div key={index}>
                                <CourseList modules={item}/>
                                <p className="borderTop"></p>
                            </div>
                        )
                    })
                }
xuzhenghua committed
149

xuzhenghua committed
150
                <div className="category all-course">
xuzhenghua committed
151 152 153 154
                    <Link to='/classify'>
                        <p>查看全部课程</p>
                        <span>数学基础、数学结构、大数据实战、Python...</span>
                    </Link>
xuzhenghua committed
155
                </div>
xuzhenghua committed
156

xuzhenghua committed
157
                {/* 直播间预约 */}
xuzhenghua committed
158
                {
xuzhenghua committed
159
                    this.state.islive &&
xuzhenghua committed
160 161
                    <LiveRoom isShow={this.state.isShow} colseBox={this.colseBox}
                              roomMess={this.state.roomMess}></LiveRoom>
xuzhenghua committed
162 163
                }

baiguangyao committed
164
            </div>
xuzhenghua committed
165
        )
baiguangyao committed
166 167 168 169
    }

}

xuzhenghua committed
170

xuzhenghua committed
171 172
function TopSwiper({bannerList}) {
    return (
xuzhenghua committed
173
        <Swiper type={animateTypes.CARD} loop={true} height={168} autoPlay={true} typePro createStyle={createStyle}>
xuzhenghua committed
174
            {bannerList && bannerList.length > 0 && bannerList.map((item, index) => {
xuzhenghua committed
175
                return (
xuzhenghua committed
176
                    <Link to={item.jump_url} key={index}>
xuzhenghua committed
177
                        <img className="item" src={item.name} alt=""/>
xuzhenghua committed
178
                    </Link>
xuzhenghua committed
179 180 181 182 183 184
                )
            })
            }
        </Swiper>
    )
}
xuzhenghua committed
185

xuzhenghua committed
186
function CourseList({modules}) {
xuzhenghua committed
187 188
    let isOdd = modules.list.length % 2 === 0
    let filterList = isOdd ? modules.list : modules.list.slice(1)
xuzhenghua committed
189
    return (
xuzhenghua committed
190
        <div className='category'>
xuzhenghua committed
191 192 193
            <h2 className="title">{modules.name}</h2>
            {
                modules.show_more === 1 &&
xuzhenghua committed
194
                <a className="more" href='/classify'>更多 ></a>
xuzhenghua committed
195 196
            }
            {
xuzhenghua committed
197
                modules.show_more === 2 &&
xuzhenghua committed
198
                <a className="more" href={modules.more_page}>更多 ></a>
xuzhenghua committed
199
            }
xuzhenghua committed
200
            <LazyLoad offset={50}>
xuzhenghua committed
201
                <ul className='course-detail'>
xuzhenghua committed
202 203 204
                    {
                        !isOdd &&
                        <div className="category-vip">
xuzhenghua committed
205
                            <Link to={`/detail?id=${modules.list[0].course_id}`}>
xuzhenghua committed
206
                                <img src={modules.list[0].course_img_small} alt=""/>
xuzhenghua committed
207
                            </Link>
xuzhenghua committed
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
                        </div>
                    }
                    {
                        filterList.map((item, index) => {
                            const top = (
                                <div>
                                    {item.is_audition === true &&
                                    <span className='audition'><i className={'iconfont iconerji'}></i>试听</span>
                                    }
                                </div>
                            )

                            const bottom = (
                                <div>
                                    {!item.isbuy && <p className="course-price">
                                        <span className="new">¥{item.price}</span>
                                        <span className="old">¥{item.discounts_price}</span>
                                    </p>
                                    }
                                    {item.isbuy &&
                                    <a href="/#" className="isbuy">已购买</a>
                                    }
                                </div>
                            )
                            return (
xuzhenghua committed
233 234
                                <Course key={index} top={top} data={item} bottom={bottom} img={item.course_img_small}
                                        title={item.course_title} id={item.course_id}></Course>
xuzhenghua committed
235 236 237
                            )
                        })
                    }
xuzhenghua committed
238 239 240 241 242
                </ul>
            </LazyLoad>
        </div>
    )
}
xuzhenghua committed
243 244 245

function ScrollBox(props) {
    return (
xuzhenghua committed
246 247 248
        <div className='scroll-box'>
            <ul className='scroll-list'>
                {
xuzhenghua committed
249
                    props.livesList && props.livesList.length > 0 && props.livesList.map((item, index) => {
xuzhenghua committed
250
                        return (
xuzhenghua committed
251 252
                            <li key={index} className='scroll-item'
                                onClick={e => props.liveCourse(item)}>
xuzhenghua committed
253
                                <div className='item-box'>
xuzhenghua committed
254 255 256 257 258
                                    {
                                        item.live_status === 0 &&
                                        <span className='no-start'>即将开始</span>
                                    }
                                    {
xuzhenghua committed
259
                                        (item.live_status === 1 || item.live_status === 10) &&
xuzhenghua committed
260 261
                                        <span className='start'>正在直播</span>
                                    }
xuzhenghua committed
262
                                    <img className="item-img" src={item.live_img} alt=""/>
xuzhenghua committed
263
                                    <div className="item-content">
xuzhenghua committed
264 265
                                        <h2 className="item-title">{item.live_title}</h2>
                                        <p className="item-teacher">讲师:{item.live_teacher_name}</p>
xuzhenghua committed
266
                                        {
xuzhenghua committed
267 268 269 270 271 272
                                            item.is_prepare &&
                                            <p className="item-time">时间:{item.live_start_time}</p>
                                        }
                                        {
                                            !item.is_prepare &&
                                            <p className='item-btn'>预约</p>
xuzhenghua committed
273
                                        }
xuzhenghua committed
274
                                    </div>
xuzhenghua committed
275
                                </div>
xuzhenghua committed
276 277 278 279 280 281 282 283 284
                            </li>
                        )
                    })
                }
            </ul>
        </div>
    )
}

xuzhenghua committed
285
export default WithTab(Index)