index.js 8.74 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 10
import LiveRoom from './liveRoom'

xuzhenghua committed
11 12

const animateTypes = Swiper.animateTypes
baiguangyao committed
13 14

class Index extends Component {
xuzhenghua committed
15
    constructor(props) {
xuzhenghua committed
16
        super(props)
xuzhenghua committed
17 18 19 20 21 22 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
        this.state = {
            banner: [],
            lives: [],
            modules: [],
            isShow: false,
            islive: false,
            roomId: '',
            tabdata: [
                {
                    'src': require('./image/freeclass_icon.png'),
                    'name': '公开课',
                    'href':''
                },
                {
                    'src': require('./image/jingpin_icon.png'),
                    'name': '精品特惠',
                    'href':'/preferential'
                },
                {
                    'src': require('./image/zjxj_icon.png'),
                    'name': '赚奖学金',
                    'href':''
                },
                {
                    'src': require('./image/mryt_icon.png'),
                    'name': '每日一题',
                    'href':''
                },
                {
                    'src': require('./image/qynx_icon.png'),
                    'name': '企业内训',
                    'href':''
                }
            ]
        }
xuzhenghua committed
52
    }
xuzhenghua committed
53

xuzhenghua committed
54 55
    componentDidMount() {
        // 首页课程
xuzhenghua committed
56
        http.get(`${api.home}/m/home`).then((res) => {
xuzhenghua committed
57 58 59 60 61 62 63 64
            if (res.data.code === 200) {
                this.setState({
                    banner: res.data.data.banner,
                    lives: res.data.data.lives,
                    modules: res.data.data.modules
                })
            }
        })
xuzhenghua committed
65
    }
xuzhenghua committed
66 67


xuzhenghua committed
68 69
    // 点击近期直播课程弹出预约提示框
    liveCourse = (roomId) => {
xuzhenghua committed
70
        this.setState(status => ({
xuzhenghua committed
71 72 73
            isShow: true,
            islive: true,
            roomId
xuzhenghua committed
74
        }))
xuzhenghua committed
75
    }
xuzhenghua committed
76 77
    // 自组件传给父组件的isshow
    colseBox = (val) => {
xuzhenghua committed
78
        this.setState({isShow: val})
6  
xuzhenghua committed
79
    }
xuzhenghua committed
80

xuzhenghua committed
81
    toSearch() {
xuzhenghua committed
82
        window.location.href = '/search'
xuzhenghua committed
83
    }
xuzhenghua committed
84

baiguangyao committed
85 86
    render() {
        return (
xuzhenghua committed
87
            <div className='index-box'>
xuzhenghua committed
88
                <div className='header'>
xuzhenghua committed
89 90
                    <img className="logo"
                         src="http://julyedu-img-public.oss-cn-beijing.aliyuncs.com/Public/img/index/logo.png" alt=""/>
xuzhenghua committed
91 92 93 94
                    <button className='to-app'>APP打开</button>
                    <i className='iconfont iconiconfront- search' onClick={this.toSearch.bind(this)}></i>
                </div>

xuzhenghua committed
95
                <div className='index-swiper'>
xuzhenghua committed
96 97 98 99
                    {
                        this.state.banner && this.state.banner.length > 0 &&
                        <TopSwiper bannerList={this.state.banner}/>
                    }
xuzhenghua committed
100
                </div>
xuzhenghua committed
101

6  
xuzhenghua committed
102 103
                <div className="tabbox">
                    <ul>
xuzhenghua committed
104
                        {
xuzhenghua committed
105
                            this.state.tabdata.map((item, index) => {
xuzhenghua committed
106 107
                                return (
                                    <li key={index}>
xuzhenghua committed
108 109 110 111
                                        <a href={item.href}>
                                            <img src={item.src} alt=""/>
                                            <span>{item.name}</span>
                                        </a>
xuzhenghua committed
112 113 114 115
                                    </li>
                                )
                            })
                        }
6  
xuzhenghua committed
116 117
                    </ul>
                </div>
xuzhenghua committed
118 119 120

                <p className="borderTop"></p>
                <div className='lives'>
xuzhenghua committed
121
                    <h2 className="title">近期直播</h2>
xuzhenghua committed
122
                    <ScrollBox livesList={this.state.lives} liveCourse={this.liveCourse}/>
xuzhenghua committed
123
                </div>
xuzhenghua committed
124

xuzhenghua committed
125 126 127 128 129 130 131 132 133 134
                {
                    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
135

xuzhenghua committed
136 137 138 139
                <div className="category all-course">
                    <p>查看全部课程</p>
                    <span>数学基础、数学结构、大数据实战、Python...</span>
                </div>
xuzhenghua committed
140

xuzhenghua committed
141
                {/* 直播间预约 */}
xuzhenghua committed
142
                {
xuzhenghua committed
143 144
                    this.state.islive &&
                    <LiveRoom isShow={this.state.isShow} colseBox={this.colseBox} roomId={this.state.roomId}></LiveRoom>
xuzhenghua committed
145 146
                }

baiguangyao committed
147
            </div>
xuzhenghua committed
148
        )
baiguangyao committed
149 150 151 152
    }

}

xuzhenghua committed
153

xuzhenghua committed
154 155
function TopSwiper({bannerList}) {
    return (
xuzhenghua committed
156
        <Swiper type={animateTypes.CARD} loop={true} height={168} autoPlay={true} typePro createStyle={createStyle}>
xuzhenghua committed
157
            {bannerList && bannerList.length > 0 && bannerList.map((item, index) => {
xuzhenghua committed
158
                return (
xuzhenghua committed
159 160 161
                    <a href={item.jump_url} key={index}>
                        <img className="item" src={item.name} alt=""/>
                    </a>
xuzhenghua committed
162 163 164 165 166 167
                )
            })
            }
        </Swiper>
    )
}
xuzhenghua committed
168
function CourseList({modules}) {
xuzhenghua committed
169 170
    let isOdd = modules.list.length % 2 === 0
    let filterList = isOdd ? modules.list : modules.list.slice(1)
xuzhenghua committed
171
    return (
xuzhenghua committed
172
        <div className='category'>
xuzhenghua committed
173 174 175 176
            <h2 className="title">{modules.name}</h2>
            {
                modules.show_more === 1 &&
                <a className="more" href="/#">更多 ></a>
xuzhenghua committed
177 178
            }
            {
xuzhenghua committed
179 180
                modules.show_more === 2 &&
                <a className="more" href="/#">更多 ></a>
xuzhenghua committed
181
            }
xuzhenghua committed
182
            <LazyLoad offset={50}>
xuzhenghua committed
183
                <ul className='course-detail'>
xuzhenghua committed
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
                    {
                        !isOdd &&
                        <div className="category-vip">
                            <a href="/#">
                                <img src={modules.list[0].course_img_small} alt=""/>
                            </a>
                        </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
215
                                <Course key={index} top={top} data={item} bottom={bottom} img={item.course_img_small} title={item.course_title}></Course>
xuzhenghua committed
216 217 218
                            )
                        })
                    }
xuzhenghua committed
219 220 221 222 223
                </ul>
            </LazyLoad>
        </div>
    )
}
xuzhenghua committed
224 225 226

function ScrollBox(props) {
    return (
xuzhenghua committed
227 228 229
        <div className='scroll-box'>
            <ul className='scroll-list'>
                {
xuzhenghua committed
230
                    props.livesList && props.livesList.length > 0 && props.livesList.map((item, index) => {
xuzhenghua committed
231
                        return (
xuzhenghua committed
232 233 234
                            <li key={index} className='scroll-item' onClick={e => props.liveCourse(item.room_id)}>
                                <div className='item-box'>
                                    <img className="item-img" src={item.live_img} alt=""/>
xuzhenghua committed
235
                                    <div className="item-content">
xuzhenghua committed
236 237 238
                                        <h2 className="item-title">{item.live_title}</h2>
                                        <p className="item-teacher">讲师:{item.live_teacher_name}</p>
                                        <p className="item-time">时间:{item.live_start_time}</p>
xuzhenghua committed
239
                                    </div>
xuzhenghua committed
240
                                </div>
xuzhenghua committed
241 242 243 244 245 246 247 248 249
                            </li>
                        )
                    })
                }
            </ul>
        </div>
    )
}

xuzhenghua committed
250
export default WithTab(Index)