index.js 3.54 KB
Newer Older
zhanghaozhe committed
1
/* eslint-disable eqeqeq */
zhanghaozhe committed
2 3 4 5 6 7
import React, { Component } from "react"
import "./index.scss"
import { HeaderBar, VList } from "../../common"
import { http } from "src/utils"
import { Link } from "react-router-dom"
import { Toast } from "antd-mobile"
zhanghaozhe committed
8
import { connect } from "react-redux"
zhanghaozhe committed
9
import Loading from "src/common/Loading"
xuzhenghua committed
10 11

class Purchased extends Component {
zhanghaozhe committed
12 13 14 15
  constructor(props) {
    super(props)
    this.state = {
      data: [],
zhanghaozhe committed
16
      isLoading: true,
xuzhenghua committed
17
    }
zhanghaozhe committed
18
  }
xuzhenghua committed
19

zhanghaozhe committed
20 21 22
  componentDidMount() {
    this.getList()
  }
xuzhenghua committed
23

zhanghaozhe committed
24 25
  // 获取订单
  getList = () => {
zhanghaozhe committed
26
    http.get(`${API.home}/m/my/courses`).then((res) => {
zhanghaozhe committed
27 28 29
      if (res.data.code === 200) {
        this.setState({
          data: res.data.data,
zhanghaozhe committed
30
          isLoading: false,
xuzhenghua committed
31
        })
zhanghaozhe committed
32
      } else {
zhanghaozhe committed
33
        Toast.info(res.data.msg, 2)
zhanghaozhe committed
34 35 36
      }
    })
  }
xuzhenghua committed
37

zhanghaozhe committed
38
  toCourseDetail = (id) => {
zhanghaozhe committed
39
    const { history } = this.props
zhanghaozhe committed
40 41 42
    history.push(`/detail?id=${id}`)
  }
  render() {
zhanghaozhe committed
43
    const { user } = this.props
zhanghaozhe committed
44 45
    const uid = user && user.data && user.data.uid
    return (
zhanghaozhe committed
46 47
      <div className="purchased-box">
        <HeaderBar arrow={true} title="已购课程" cart={false} toHref="/my" />
zhanghaozhe committed
48
        <Loading isLoading={this.state.isLoading}>
zhanghaozhe committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
          {this.state.data && this.state.data.length > 0 ? (
            <div className="purchased-body">
              <div className="tip">加群请备注您的学号:{uid}</div>
              {this.state.data.map((item, index) => {
                const Info = (
                  <div className="info">
                    <p
                      className="title text-overflow-2"
                      onClick={() => this.toCourseDetail(item.course_id)}
                    >
                      {item.course_title}
                    </p>
                    <p className="contact text-overflow-1">
                      {item.simpledescription}
                    </p>
xuzhenghua committed
64

zhanghaozhe committed
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
                    {item.is_aist && (
                      <div className="des">助教微信:{item.assist_weixin}</div>
                    )}
                    {!item.is_aist &&
                      item.contact_type == 1 &&
                      item.course_qq && (
                        <div className="des">QQ群:{item.course_qq}</div>
                      )}
                    {!item.is_aist &&
                      item.contact_type == 2 &&
                      item.course_qq && (
                        <div className="des">班主任微信:{item.course_qq}</div>
                      )}
                  </div>
                )
                const status = item.is_aist && (
                  <span className="status">返现</span>
                )
                const courseExpire = item.course_expire &&
                  item.course_expire != "" && (
                    <span className="course-expire">{item.course_expire}</span>
                  )
                return (
                  <VList
                    key={index}
                    img={item.image_name}
                    id={item.course_id}
                    info={Info}
                    status={status}
                    courseExpire={courseExpire}
                    toDetail={this.toCourseDetail}
                  />
                )
              })}
            </div>
          ) : (
            <div className="cart-tip">
              <p className="cart-mess">您还没有课程哦,快去逛逛吧~</p>
              <Link to="/classify">去逛逛</Link>
            </div>
          )}
zhanghaozhe committed
106 107 108 109
        </Loading>
      </div>
    )
  }
xuzhenghua committed
110 111
}

zhanghaozhe committed
112
export default connect((state) => ({ user: state.user }), null)(Purchased)