courseList.js 2.43 KB
Newer Older
zhanghaozhe committed
1 2 3 4 5 6 7
import React, { Component } from "react"
import { http } from "src/utils"
import { HeaderBar } from "src/common"
import CollegeBanner from "./banner"
import CollegeHeader from "./header"
import "./courseList.scss"
import { Toast } from "antd-mobile"
xuzhenghua committed
8 9 10

class CollegeCourse extends Component {
  constructor(props) {
zhanghaozhe committed
11
    super(props)
xuzhenghua committed
12
    this.state = {
zhanghaozhe committed
13 14 15
      header: "",
      courseList: [],
    }
xuzhenghua committed
16 17 18
  }

  componentDidMount() {
zhanghaozhe committed
19
    this.fetchCourseList()
xuzhenghua committed
20 21 22
  }

  fetchCourseList = () => {
zhanghaozhe committed
23 24 25 26 27
    const { match } = this.props
    const id = match.params.id || 0
    http.get(`${API["home"]}/sys/school/${id}`).then((res) => {
      const { code, data } = res.data
      if (code === 200) {
xuzhenghua committed
28 29
        this.setState({
          header: data.name,
zhanghaozhe committed
30 31
          courseList: data.data,
        })
FE committed
32
        document.title = `助力高校在线教学计划之${data.name}专区 - 七月在线`
xuzhenghua committed
33
      }
zhanghaozhe committed
34
    })
xuzhenghua committed
35 36 37
  }

  toCourseDetail = (id) => {
zhanghaozhe committed
38
    const { history, match } = this.props
xuzhenghua committed
39
    const school_id = match.params.id || 0
zhanghaozhe committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
    http
      .post(`${API["home"]}/sys/school/verify`, {
        school_id,
        course_id: id,
      })
      .then((res) => {
        const { code, msg } = res.data
        if (code === 200) {
          history.push(`/detail?id=${id}`)
        } else if (code === 4030 || code === 4013) {
          history.push("/passport/login")
        } else {
          Toast.info(`${msg}~`)
        }
      })
xuzhenghua committed
55 56 57
  }

  render() {
zhanghaozhe committed
58
    const { courseList = [], header } = this.state
xuzhenghua committed
59 60
    return (
      <>
zhanghaozhe committed
61
        <HeaderBar title={"助学计划"} arrow={true} />
xuzhenghua committed
62
        <CollegeBanner />
xuzhenghua committed
63
        <CollegeHeader
xuzhenghua committed
64
          headerStyle={{
zhanghaozhe committed
65
            marginTop: "20px",
xuzhenghua committed
66 67 68
          }}
          title={header}
        />
zhanghaozhe committed
69 70 71
        <p className="college-course__desc">
          点击需要学习的课程封面,在课程详情页进入购买流程凭免单券免费兑换课程。
        </p>
xuzhenghua committed
72
        <div className="college-course__body">
zhanghaozhe committed
73 74 75 76 77 78 79 80 81 82 83 84 85
          {courseList.map((item) => (
            <div
              className="college-course__item"
              onClick={() => this.toCourseDetail(item.course_id)}
              key={item.course_id}
            >
              <i
                className="college-course__cover"
                style={{ backgroundImage: `url(${item.image_name})` }}
              ></i>
              <p className="college-course__title">{item.course_title}</p>
            </div>
          ))}
xuzhenghua committed
86 87 88 89 90 91
        </div>
      </>
    )
  }
}

zhanghaozhe committed
92
export default CollegeCourse