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

class Purchased extends Component {
    constructor(props) {
        super(props)
        this.state = {
xuzhenghua committed
14 15
            data: [],
            isLoading: true
xuzhenghua committed
16 17 18 19 20 21 22 23 24
        }
    }

    componentDidMount() {
        this.getList()
    }

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


    render() {
        const {user} = this.props
        const uid = user && user.data && user.data.uid
        return (
            <div className='purchased-box'>
FE committed
43
                <HeaderBar title='已购课程' cart={false} href='/my'></HeaderBar>
xuzhenghua committed
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
                <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'>
                                                    <Link to={`/detail?id=${item.course_id}`}>
                                                        {item.course_title}
                                                    </Link>
                                                </p>
                                                <p className='contact text-overflow-2'>{item.simpledescription}</p>
zhanghaozhe committed
59 60 61 62 63
                                                {
                                                    item.is_aist
                                                        ? <div className='des'>助教微信:{item.assist_weixin}</div>
                                                        : <div className='des'>QQ群:{item.course_qq}</div>
                                                }
xuzhenghua committed
64
                                            </div>
xuzhenghua committed
65
                                        )
zhanghaozhe committed
66 67 68
                                        const status = (
                                            item.is_aist && <span className='status'>返现</span>
                                        )
xuzhenghua committed
69
                                        return (
zhanghaozhe committed
70 71
                                            <VList key={index}
                                                   img={item.image_name}
xuzhenghua committed
72
                                                   id={item.course_id}
zhanghaozhe committed
73 74 75
                                                   info={Info}
                                                   status={status}
                                            />
xuzhenghua committed
76 77 78 79 80 81 82 83 84 85
                                        )
                                    })
                                }
                            </div>
                            : <div className="cart-tip">
                                <p className='cart-mess'>您还没有课程哦,快去逛逛吧~</p>
                                <Link to='/classify'>去逛逛</Link>
                            </div>
                    }
                </Loading>
xuzhenghua committed
86 87 88 89 90 91 92 93 94 95

            </div>
        )
    }
}

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