index.js 1.99 KB
Newer Older
zhanghaozhe committed
1 2 3 4 5
import React, { Component } from "react"
import "./index.scss"
import { HeaderBar, VList } from "src/common"
import { http, getParam, SendMessageToApp } from "src/utils"
import { Toast } from "antd-mobile"
xuzhenghua committed
6 7

class ShareCourse extends Component {
zhanghaozhe committed
8 9 10 11 12
  constructor(props) {
    super(props)
    this.state = {
      list: [],
      fromApp: !getParam("from") ? false : true,
xuzhenghua committed
13
    }
zhanghaozhe committed
14
  }
xuzhenghua committed
15

zhanghaozhe committed
16 17 18 19 20
  componentDidMount() {
    http.get(`${API.home}/sys/red_packet/share_course`).then((res) => {
      if (res.data.code === 200) {
        this.setState({
          list: res.data.data,
xuzhenghua committed
21
        })
zhanghaozhe committed
22 23 24 25 26
      } else {
        Toast.info(res.data.msg, 2)
      }
    })
  }
xuzhenghua committed
27

zhanghaozhe committed
28 29 30 31 32 33 34
  toCourseDetail = (id) => {
    const _this = this
    if (_this.state.fromApp) {
      SendMessageToApp("toCourse", id)
    } else {
      const { history } = this.props
      history.push(`/detail?id=${id}`)
xuzhenghua committed
35
    }
zhanghaozhe committed
36
  }
xuzhenghua committed
37

zhanghaozhe committed
38 39 40 41 42
  render() {
    const { list } = this.state
    return (
      <div className={"share-course"}>
        {!this.state.fromApp && <HeaderBar title="分享领红包" arrow={true} />}
xuzhenghua committed
43

zhanghaozhe committed
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
        {list && list.length > 0 ? (
          <div>
            {list.map((item, index) => {
              const Info = (
                <div className="info">
                  <p className={"title text-overflow-1"}>{item.course_title}</p>
                  <p className={"contact text-overflow-1"}>
                    {item.simpledescription}
                  </p>
                  <button>分享领红包</button>
                </div>
              )
              return (
                <div key={index}>
                  <VList
                    img={item.image_name}
                    info={Info}
                    id={item.course_id}
                    toDetail={this.toCourseDetail}
                  />
                </div>
              )
            })}
          </div>
        ) : (
          <div>
            <p className="not-data">暂时没有可分享的课程哦〜</p>
          </div>
        )}
      </div>
    )
  }
xuzhenghua committed
76 77
}

zhanghaozhe committed
78
export default ShareCourse