index.js 14.9 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
import ExpandActiveToast from './expandActiveToast'
xuzhenghua committed
15

xuzhenghua committed
16

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

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

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

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

xuzhenghua committed
80
        })
xuzhenghua committed
81
    }
xuzhenghua committed
82 83


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

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

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

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

xuzhenghua committed
139 140 141 142
                <div className='zw_height'></div>

                <ExpandActiveToast/>

xuzhenghua committed
143
                <div className='index-swiper'>
xuzhenghua committed
144 145
                    {
                        this.state.banner && this.state.banner.length > 0 &&
zhanghaozhe committed
146
                        <TopSwiper bannerList={this.state.banner}/>
xuzhenghua committed
147
                    }
xuzhenghua committed
148
                </div>
xuzhenghua committed
149

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

zhanghaozhe committed
167
                <p className="borderTop"/>
xuzhenghua committed
168 169 170

                {

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

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

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

xuzhenghua committed
202
                {/* 直播间预约 */}
xuzhenghua committed
203
                {
xuzhenghua committed
204
                    this.state.islive &&
FE committed
205 206
                    <LiveRoom
                        isShow={this.state.isShow}
FE committed
207
                        colseBox={this.colseBox}
FE committed
208
                        roomMess={this.state.roomMess}
FE committed
209 210
                        getIndexData={this.getIndexData}
                    />
xuzhenghua committed
211
                }
baiguangyao committed
212
            </div>
xuzhenghua committed
213
        )
baiguangyao committed
214 215 216 217
    }

}

xuzhenghua committed
218

FE committed
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 251 252 253 254 255
// 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
256

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

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

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

                            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
326
                            return (
327
                                <Course
xuzhenghua committed
328 329 330 331 332
                                    key={index}
                                    top={top}
                                    data={item}
                                    bottom={bottom}
                                    status={status}
333
                                    img={item.course_img_small}
xuzhenghua committed
334
                                    title={item.course_title}
335 336 337 338
                                    id={item.course_id}
                                    toDetail={toDetail}
                                    className='text-overflow-2'
                                />
xuzhenghua committed
339 340 341
                            )
                        })
                    }
xuzhenghua committed
342 343 344 345 346
                </ul>
            </LazyLoad>
        </div>
    )
}
xuzhenghua committed
347

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

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

xuzhenghua committed
396

397
export default WithTab(Index);