index.js 3.62 KB
Newer Older
zhanghaozhe committed
1
import React, { Component } from 'react';
xuzhenghua committed
2
import './index.scss';
zhanghaozhe committed
3 4 5 6 7
import { HeaderBar, VList } from '../../common'
import { http, dateCountDown } from "@/utils";
import { Link } from 'react-router-dom'
import { Toast } from 'antd-mobile'
import { connect } from "react-redux"
xuzhenghua committed
8
import Loading from '@/common/Loading'
xuzhenghua committed
9 10

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

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

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

zhanghaozhe committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
  toCourseDetail = (id) => {
    const {dispatch, history} = this.props;
    // dispatch(getCourses(id, () => {
    history.push(`/detail?id=${id}`)
    // }));
  }
  render() {
    const {user} = this.props
    const uid = user && user.data && user.data.uid
    return (
      <div className='purchased-box'>
        <HeaderBar arrow={true} title='已购课程' cart={false} toHref='/my'/>
        <Loading isLoading={this.state.isLoading}>
          {
            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' onClick={() => this.toCourseDetail(item.course_id)}>
                          {item.course_title}
                        </p>
                        <p className='contact text-overflow-2'>{item.simpledescription}</p>
xuzhenghua committed
62

zhanghaozhe committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
                        {
                          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 = (
zhanghaozhe committed
78
                      item.is_aist && <span className='status'>返现</span>
zhanghaozhe committed
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
                    )
                    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>
          }
        </Loading>
xuzhenghua committed
104

zhanghaozhe committed
105 106 107
      </div>
    )
  }
xuzhenghua committed
108 109 110
}

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