index.js 8.91 KB
Newer Older
zhanghaozhe committed
1
/* eslint-disable eqeqeq */
zhanghaozhe committed
2 3 4
import React, { Component } from "react"
import "./index.scss"
import { WithTab } from "src/HOCs"
FE committed
5 6
// import Swiper from 'react-mobile-swiper'
// import createStyle from './createStyle'
zhanghaozhe committed
7 8 9
import HomeCourseList from "./course-list"
import { http, isValidUrl } from "src/utils"
import LiveRoom from "./liveRoom"
zhanghaozhe committed
10
import { Link } from "react-router-dom"
zhanghaozhe committed
11
import { Toast } from "antd-mobile"
zhanghaozhe committed
12
import { connect } from "react-redux"
zhanghaozhe committed
13
import TopSwiper from "./TopSwiper"
xuzhenghua committed
14
// import ExpandActiveToast from './expandActiveToast'
wangshuo committed
15 16 17
import TeacherList from "./tercher"
import Teaching from "./teaching"

wangshuo committed
18
//tan框
dazhou committed
19
import UserGift from "src/common/UserGift"
xuzhenghua committed
20

FE committed
21
// const animateTypes = Swiper.animateTypes
baiguangyao committed
22

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

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

zhanghaozhe committed
67
  componentWillMount() {
dazhou committed
68
    this.showUserGiftFun()
zhanghaozhe committed
69 70 71
  }

  userStatus = () => {
zhanghaozhe committed
72 73
    http.get(`${API["base-api"]}/sys/user/new_user_status`).then((res) => {
      const { errno, data } = res.data
zhanghaozhe committed
74 75 76 77 78 79
      if (errno === 0) {
        if (data.status == 1) {
          // 新用户登录之后判断是否是新用户
          this.setState({
            isShowUserGift: false,
          })
dazhou committed
80
          Toast.info("新人大礼包已领取成功!", 2)
xuzhenghua committed
81
        } else {
zhanghaozhe committed
82 83 84
          this.setState({
            isShowUserGift: false,
          })
xuzhenghua committed
85
        }
zhanghaozhe committed
86 87 88
      }
    })
  }
xuzhenghua committed
89

dazhou committed
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
  showUserGiftFun = () => {
    let newer_last_time = localStorage.getItem("newer_last_time") // 获取用户关闭大礼包的时间
    let now_time = new Date().valueOf()
    if (!newer_last_time || now_time - newer_last_time > 86400000) {
      this.setState({
        isShowUserGift: true,
      })
    } else {
      this.setState({
        isShowUserGift: false,
      })
    }
  }
  close = () => {
    this.setState({
      isShowUserGift: false,
    })
    let now_time = new Date().valueOf() // 获取当前时间
    localStorage.setItem("newer_last_time", now_time) // 存储关闭时间
  }
xuzhenghua committed
110

dazhou committed
111 112 113 114
  get_newerModal = () => {
    this.close()
    this.props.history.push("/passport/login")
  }
xuzhenghua committed
115

zhanghaozhe committed
116 117 118 119
  // 首页课程
  getIndexData = () => {
    http.get(`${API.home}/m/home`).then((res) => {
      if (res.data.code === 200) {
zhanghaozhe committed
120
        const { data } = res.data || {}
zhanghaozhe committed
121 122
        const modules = Array.isArray(data.modules) ? data.modules : []
        this.setState({
zhanghaozhe committed
123
          banner: data.banner,
zhanghaozhe committed
124 125
          lives: data.lives,
          modules,
xuzhenghua committed
126
        })
zhanghaozhe committed
127 128 129 130 131
      } else {
        Toast.info(res.data.msg, 2)
      }
    })
  }
zhanghaozhe committed
132

zhanghaozhe committed
133 134
  // 点击近期直播课程弹出预约提示框
  liveCourse = (item) => {
zhanghaozhe committed
135
    const { user } = this.props
zhanghaozhe committed
136 137
    const uid = user && user.data && user.data.uid
    if (!uid) {
zhanghaozhe committed
138
      this.props.history.push("/passport/login")
zhanghaozhe committed
139 140 141 142 143 144 145 146
    } else {
      if (item.live_status === 0) {
        this.setState({
          isShow: true,
          islive: true,
          roomMess: item,
        })
      } else {
zhanghaozhe committed
147 148 149 150 151
        window.location.href = `${
          window.location.href.includes("pre")
            ? "http://www-pre.julyedu.com"
            : "http://www.julyedu.com"
        }/live/m_room/${item.room_id}`
zhanghaozhe committed
152
      }
xuzhenghua committed
153
    }
zhanghaozhe committed
154
  }
dazhou committed
155
  govip = () => {}
zhanghaozhe committed
156 157
  // 自组件传给父组件的isshow
  colseBox = (val) => {
zhanghaozhe committed
158
    this.setState({ isShow: val })
zhanghaozhe committed
159
  }
xuzhenghua committed
160

zhanghaozhe committed
161 162
  // 点击头部搜索跳转到搜索页面
  toSearch() {
zhanghaozhe committed
163
    this.props.history.push("/search")
zhanghaozhe committed
164 165 166 167
  }

  render() {
    return (
zhanghaozhe committed
168 169
      <div className="index-box">
        <div className="header">
zhanghaozhe committed
170 171
          <img
            className="logo"
172
            src="http://img-public.julyedu.com/Public/img/index/logo.png"
zhanghaozhe committed
173 174 175
            alt=""
          />
          {/* <CallApp
zhanghaozhe committed
176 177
            className='to-app'
            text='在APP打开'
zhanghaozhe committed
178
          />*/}
zhanghaozhe committed
179
          <div className="right">
wangshuo committed
180
            {/* <Link to={"/intelligent-recommend"}>
zhanghaozhe committed
181 182
              <span className={"intelligent-recommend-entry"}>
                <i className={"mind-icon"}></i>
zhanghaozhe committed
183
                智能选课
zhanghaozhe committed
184
              </span>
wangshuo committed
185
            </Link> */}
zhanghaozhe committed
186
            <i
zhanghaozhe committed
187
              className="iconfont iconiconfront- search"
zhanghaozhe committed
188 189 190 191
              onClick={this.toSearch.bind(this)}
            />
          </div>
        </div>
xuzhenghua committed
192

zhanghaozhe committed
193
        <div className="zw_height"></div>
xuzhenghua committed
194

zhanghaozhe committed
195 196 197
        {/*支付尾款提示*/}
        {/*<ExpandActiveToast/>*/}

zhanghaozhe committed
198 199 200 201
        <div className="index-swiper">
          {this.state.banner && this.state.banner.length > 0 && (
            <TopSwiper bannerList={this.state.banner} />
          )}
zhanghaozhe committed
202
        </div>
xuzhenghua committed
203

zhanghaozhe committed
204 205
        <div className="tabbox">
          <ul>
zhanghaozhe committed
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
            {this.state.tabdata.map((item, index) => {
              return (
                <li key={index}>
                  {isValidUrl(item.href) ? (
                    <a href={item.href}>
                      <img src={item.src} alt="" />
                      <span>{item.name}</span>
                    </a>
                  ) : (
                    <Link to={item.href}>
                      <img src={item.src} alt="" />
                      <span>{item.name}</span>
                    </Link>
                  )}
                </li>
              )
            })}
zhanghaozhe committed
223 224
          </ul>
        </div>
xuzhenghua committed
225

zhanghaozhe committed
226
        <p className="borderTop" />
xuzhenghua committed
227

zhanghaozhe committed
228 229 230 231 232 233 234 235 236
        {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
237

zhanghaozhe committed
238
        <HomeCourseList modules={this.state.modules} />
dazhou committed
239 240
        <TeacherList />
        <p className="borderTop" />
dazhou committed
241
        {/* <botton className="fix"><a href="https://live.easyliao.com/live/chat.do?c=27526&g=53481&config=81372"><span>点击</span><span>咨询</span></a></botton> */}
dazhou committed
242
        <Teaching />
xuzhenghua committed
243

wangshuo committed
244
        {/* <AllCourseNavigation /> */}
xuzhenghua committed
245

zhanghaozhe committed
246
        {/* 直播间预约 */}
zhanghaozhe committed
247
        {this.state.islive && (
zhanghaozhe committed
248 249 250 251 252 253
          <LiveRoom
            isShow={this.state.isShow}
            colseBox={this.colseBox}
            roomMess={this.state.roomMess}
            getIndexData={this.getIndexData}
          />
zhanghaozhe committed
254
        )}
xuzhenghua committed
255

dazhou committed
256
        {this.state.isShowUserGift && (
zhanghaozhe committed
257
          <UserGift close={this.close} get_newerModal={this.get_newerModal} />
dazhou committed
258
        )}
zhanghaozhe committed
259 260 261
      </div>
    )
  }
baiguangyao committed
262 263
}

zhanghaozhe committed
264 265
//近期直播
function ScrollBox(props) {
zhanghaozhe committed
266
  return (
zhanghaozhe committed
267 268 269 270 271
    <div className="scroll-box">
      <ul className="scroll-list">
        {props.livesList &&
          props.livesList.length > 0 &&
          props.livesList.map((item, index) => {
zhanghaozhe committed
272
            return (
zhanghaozhe committed
273 274 275 276 277 278 279 280 281 282 283 284 285
              <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="" />
zhanghaozhe committed
286 287
                  <div className="item-content">
                    <h2 className="item-title">{item.live_title}</h2>
zhanghaozhe committed
288 289 290
                    <p className="item-teacher">
                      讲师:{item.live_teacher_name}
                    </p>
zhanghaozhe committed
291

zhanghaozhe committed
292
                    {/*公开课需预约、付费课不需要预约*/}
zhanghaozhe committed
293 294 295 296 297 298 299 300 301 302 303 304 305 306
                    {(item.is_prepare || item.is_free === 0) &&
                      item.live_status === 0 && (
                        <p className="item-time">
                          时间:{item.live_start_time}
                        </p>
                      )}
                    {!item.is_prepare &&
                      item.live_status === 0 &&
                      item.is_free === 1 && (
                        <button className="item-btn">预约</button>
                      )}
                    {(item.live_status === 1 || item.live_status === 10) && (
                      <button className="item-btn">正在直播</button>
                    )}
zhanghaozhe committed
307 308 309 310
                  </div>
                </div>
              </li>
            )
zhanghaozhe committed
311
          })}
zhanghaozhe committed
312 313 314
      </ul>
    </div>
  )
xuzhenghua committed
315
}
xuzhenghua committed
316

xuzhenghua committed
317
export default WithTab(Index)