index.js 14.8 KB
Newer Older
zhanghaozhe committed
1 2
import React, { Component } from 'react'
import { Course, CallApp } from '../../common'
xuzhenghua committed
3
import './index.scss'
zhanghaozhe committed
4
import { WithTab } from '@/HOCs'
FE committed
5 6
// import Swiper from 'react-mobile-swiper'
// import createStyle from './createStyle'
xuzhenghua committed
7
import LazyLoad from 'react-lazy-load'
zhanghaozhe committed
8
import { http } from '@/utils'
xuzhenghua committed
9
import LiveRoom from './liveRoom'
zhanghaozhe committed
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

xuzhenghua committed
15

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

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

xuzhenghua committed
61
    componentDidMount() {
xuzhenghua committed
62 63 64 65 66
        this.getIndexData()
    }

    // 首页课程
    getIndexData = () => {
zhanghaozhe committed
67
        http.get(`${API.home}/m/home`).then((res) => {
xuzhenghua committed
68
            if (res.data.code === 200) {
zhanghaozhe committed
69
                const {data} = res.data || {}
xuzhenghua committed
70
                this.setState({
xuzhenghua committed
71 72
                    banner: data.banner,
                    lives: data.lives,
zhanghaozhe committed
73
                    modules: typeof data.modules === 'object' && data.modules.length > 0 ? data.modules : []
xuzhenghua committed
74
                })
xuzhenghua committed
75 76
            } else {
                Toast.info(res.data.msg, 2)
xuzhenghua committed
77
            }
xuzhenghua committed
78

xuzhenghua committed
79
        })
xuzhenghua committed
80
    }
xuzhenghua committed
81 82


xuzhenghua committed
83
    // 点击近期直播课程弹出预约提示框
xuzhenghua committed
84
    liveCourse = (item) => {
xuzhenghua committed
85 86 87 88
        const {user} = this.props
        const uid = user && user.data && user.data.uid
        if (!uid) {
            this.props.history.push('/passport/login')
xuzhenghua committed
89
        } else {
xuzhenghua committed
90 91 92 93 94 95 96
            if (item.live_status === 0) {
                this.setState({
                    isShow: true,
                    islive: true,
                    roomMess: item
                })
            } else {
FE committed
97
                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
98
            }
xuzhenghua committed
99
        }
xuzhenghua committed
100
    }
xuzhenghua committed
101 102
    // 自组件传给父组件的isshow
    colseBox = (val) => {
xuzhenghua committed
103
        this.setState({isShow: val})
6  
xuzhenghua committed
104
    }
xuzhenghua committed
105

xuzhenghua committed
106
    // 点击头部搜索跳转到搜索页面
xuzhenghua committed
107
    toSearch() {
xuzhenghua committed
108
        this.props.history.push('/search')
xuzhenghua committed
109
    }
xuzhenghua committed
110

111
    toCourseDetail = (id) => {
zhanghaozhe committed
112
        const {dispatch, history} = this.props;
113
        // dispatch(getCourses(id, () => {
zhanghaozhe committed
114 115
        history.push(`/detail?id=${id}`);
        return false;
116
        // }));
117 118
    }

baiguangyao committed
119 120
    render() {
        return (
xuzhenghua committed
121
            <div className='index-box'>
xuzhenghua committed
122
                <div className='header'>
FE committed
123
                    <img
FE committed
124
                        className="logo"
FE committed
125
                        src="http://julyedu-img-public.oss-cn-beijing.aliyuncs.com/Public/img/index/logo.png"
FE committed
126 127
                        alt=""
                    />
FE committed
128 129 130
                    <CallApp
                        className='to-app'
                        text='在APP打开'
FE committed
131
                    />
FE committed
132 133 134
                    <i
                        className='iconfont iconiconfront- search'
                        onClick={this.toSearch.bind(this)}
FE committed
135
                    />
xuzhenghua committed
136 137
                </div>

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

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

zhanghaozhe committed
162
                <p className="borderTop"/>
xuzhenghua committed
163 164 165

                {

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

xuzhenghua committed
176
                {
xuzhenghua committed
177
                    (this.state.modules && this.state.modules.length > 0) ? this.state.modules.map((item, index) => {
xuzhenghua committed
178 179
                        return (
                            <div key={index}>
FE committed
180 181
                                <CourseList
                                    modules={item}
FE committed
182 183
                                    toDetail={this.toCourseDetail}
                                />
zhanghaozhe committed
184
                                <p className="borderTop"/>
xuzhenghua committed
185 186
                            </div>
                        )
xuzhenghua committed
187
                    }) : null
xuzhenghua committed
188
                }
xuzhenghua committed
189

xuzhenghua committed
190
                <div className="category all-course">
xuzhenghua committed
191 192 193 194
                    <Link to='/classify'>
                        <p>查看全部课程</p>
                        <span>数学基础、数学结构、大数据实战、Python...</span>
                    </Link>
xuzhenghua committed
195
                </div>
xuzhenghua committed
196

xuzhenghua committed
197
                {/* 直播间预约 */}
xuzhenghua committed
198
                {
xuzhenghua committed
199
                    this.state.islive &&
FE committed
200 201
                    <LiveRoom
                        isShow={this.state.isShow}
FE committed
202
                        colseBox={this.colseBox}
FE committed
203
                        roomMess={this.state.roomMess}
FE committed
204 205
                        getIndexData={this.getIndexData}
                    />
xuzhenghua committed
206
                }
baiguangyao committed
207
            </div>
xuzhenghua committed
208
        )
baiguangyao committed
209 210 211 212
    }

}

xuzhenghua committed
213

FE committed
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
// function TopSwiper({bannerList}) {
//     return (
//         <Swiper
//             type={animateTypes.CARD}
//             loop={true}
//             height={168}
//             autoPlay={true}
//             typePro
//             createStyle={createStyle}
//         >
//             {bannerList && bannerList.length > 0 && bannerList.map((item, index) => {
//                 return (
//                     Number.isNaN(parseInt(item.jump_url)) ?
//                         <a href={item.jump_url} key={index}>
//                             {/* <Link to={item.jump_url} key={index}> */}
//                             <img className="item" src={item.name} alt="" />
//                             {/* </Link> */}
//                         </a> :
//                         <Link
//                             to={{
//                                 pathname: '/detail',
//                                 search: `?id=${item.jump_url}`
//                             }}
//                             key={index}
//                         >
//                             <img
//                                 className="item"
//                                 src={item.name}
//                                 alt=""
//                             />
//                         </Link>
//                 )
//             })
//             }
//         </Swiper>
//     )
// }
xuzhenghua committed
251

xuzhenghua committed
252 253
// 课程模块儿公共组件
// 课程数量是奇数第一个课程需要横着展示沾满一行,课程数量是偶数一行显示两个
254
function CourseList({modules, toDetail}) {
xuzhenghua committed
255
    let isOdd = modules.list.length % 2 === 0
xuzhenghua committed
256 257
    // 数量为奇数时,第一个课程显示大图(如后台未上传,前台显示小图),课程数量为偶数时,均显示小图
    let filterList = ''
xuzhenghua committed
258

zhanghaozhe committed
259
    if (isOdd) {
xuzhenghua committed
260 261
        filterList = modules.list
    } else {
xuzhenghua committed
262
        filterList = modules.list[0].course_img === modules.list[0].course_img_small ? modules.list : modules.list.slice(1)
xuzhenghua committed
263
    }
xuzhenghua committed
264
    return (
xuzhenghua committed
265
        <div className='category'>
xuzhenghua committed
266 267 268
            <h2 className="title">{modules.name}</h2>
            {
                modules.show_more === 1 &&
xuzhenghua committed
269
                <Link className="more" to='/classify'>更多 ></Link>
xuzhenghua committed
270 271
            }
            {
xuzhenghua committed
272
                modules.show_more === 2 &&
xuzhenghua committed
273
                <Link className="more" to={modules.more_page}>更多 ></Link>
xuzhenghua committed
274
            }
xuzhenghua committed
275
            <LazyLoad offset={50}>
xuzhenghua committed
276
                <ul className='index-course-detail'>
xuzhenghua committed
277
                    {
zhanghaozhe committed
278
                        !isOdd && modules.list[0].course_img !== modules.list[0].course_img_small &&
279 280
                        <div className="category-vip" onClick={() => toDetail(modules.list[0].course_id)}>
                            {/* <Link to={`/detail?id=${modules.list[0].course_id}`}> */}
zhanghaozhe committed
281
                            <img src={modules.list[0].course_img} alt=""/>
282
                            {/* </Link> */}
xuzhenghua committed
283 284 285 286 287 288 289 290 291
                        </div>
                    }
                    {
                        filterList.map((item, index) => {
                            const top = (
                                <div>
                                    {item.is_audition === true &&
                                    <span className='audition'><i className={'iconfont iconerji'}></i>试听</span>
                                    }
xuzhenghua committed
292 293 294
                                    {item.is_aist &&
                                    <span className='return_bash'></span>
                                    }
xuzhenghua committed
295
                                </div>
xuzhenghua committed
296
                            );
xuzhenghua committed
297 298 299 300

                            const bottom = (
                                <div>
                                    {!item.isbuy && <p className="course-price">
FE committed
301 302
                                        <span className="new">¥{item.discounts_price}</span>
                                        <span className="old">¥{item.price}</span>
xuzhenghua committed
303 304 305
                                    </p>
                                    }
                                    {item.isbuy &&
xuzhenghua committed
306
                                    <a className="isbuy">已购买</a>
xuzhenghua committed
307 308 309
                                    }
                                </div>
                            )
xuzhenghua committed
310 311 312 313 314 315 316 317 318 319 320

                            const status = (
                                <div>
                                    {item.is_bargain &&
                                    <p className='course-status'>砍价减{item.bargain_price}</p>
                                    }
                                    {item.is_groupon &&
                                    <p className='course-status'>拼团价{item.groupon_price}</p>
                                    }
                                </div>
                            )
xuzhenghua committed
321
                            return (
322
                                <Course
xuzhenghua committed
323 324 325 326 327
                                    key={index}
                                    top={top}
                                    data={item}
                                    bottom={bottom}
                                    status={status}
328
                                    img={item.course_img_small}
xuzhenghua committed
329
                                    title={item.course_title}
330 331 332 333
                                    id={item.course_id}
                                    toDetail={toDetail}
                                    className='text-overflow-2'
                                />
xuzhenghua committed
334 335 336
                            )
                        })
                    }
xuzhenghua committed
337 338 339 340 341
                </ul>
            </LazyLoad>
        </div>
    )
}
xuzhenghua committed
342

xuzhenghua committed
343
//近期直播
xuzhenghua committed
344 345
function ScrollBox(props) {
    return (
xuzhenghua committed
346 347 348
        <div className='scroll-box'>
            <ul className='scroll-list'>
                {
xuzhenghua committed
349
                    props.livesList && props.livesList.length > 0 && props.livesList.map((item, index) => {
xuzhenghua committed
350
                        return (
xuzhenghua committed
351 352
                            <li key={index} className='scroll-item'
                                onClick={e => props.liveCourse(item)}>
xuzhenghua committed
353
                                <div className='item-box'>
xuzhenghua committed
354 355 356 357 358
                                    {
                                        item.live_status === 0 &&
                                        <span className='no-start'>即将开始</span>
                                    }
                                    {
xuzhenghua committed
359
                                        (item.live_status === 1 || item.live_status === 10) &&
xuzhenghua committed
360 361
                                        <span className='start'>正在直播</span>
                                    }
xuzhenghua committed
362
                                    <img className="item-img" src={item.live_img} alt=""/>
xuzhenghua committed
363
                                    <div className="item-content">
xuzhenghua committed
364 365
                                        <h2 className="item-title">{item.live_title}</h2>
                                        <p className="item-teacher">讲师:{item.live_teacher_name}</p>
xuzhenghua committed
366 367

                                        {/*公开课需预约、付费课不需要预约*/}
xuzhenghua committed
368
                                        {
zhanghaozhe committed
369
                                            (item.is_prepare || item.is_free === 0) && item.live_status === 0 &&
xuzhenghua committed
370 371 372
                                            <p className="item-time">时间:{item.live_start_time}</p>
                                        }
                                        {
xuzhenghua committed
373
                                            !item.is_prepare && item.live_status === 0 && item.is_free === 1 &&
xuzhenghua committed
374
                                            <button className='item-btn'>预约</button>
xuzhenghua committed
375
                                        }
xuzhenghua committed
376 377
                                        {
                                            (item.live_status === 1 || item.live_status === 10) &&
xuzhenghua committed
378
                                            <button className='item-btn'>正在直播</button>
xuzhenghua committed
379
                                        }
xuzhenghua committed
380
                                    </div>
xuzhenghua committed
381
                                </div>
xuzhenghua committed
382 383 384 385 386 387 388 389 390
                            </li>
                        )
                    })
                }
            </ul>
        </div>
    )
}

xuzhenghua committed
391

392
export default WithTab(Index);