index.js 2.95 KB
Newer Older
xuzhenghua committed
1 2 3 4 5 6 7
import React, {Component} from 'react';
import './index.scss';
import {HeaderBar} from '../../common'
import {VList} from '../../common'
import {http, api} from "@/utils";
import {Link} from 'react-router-dom'
import {Toast} from 'antd-mobile'
xuzhenghua committed
8
import {connect} from "react-redux"
xuzhenghua committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

class Purchased extends Component {
    constructor(props) {
        super(props)
        this.state = {
            data: []
        }
    }

    componentDidMount() {
        this.getList()
    }

    // 获取订单
    getList = () => {
        http.get(`${api.home}/m/my/courses`,).then((res) => {
            if (res.data.code === 200) {
                this.setState({
                    data: res.data.data
                })
            } 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'>
xuzhenghua committed
41
                <HeaderBar title='已购课程' arrow={true} cart={false}></HeaderBar>
xuzhenghua committed
42 43 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 76 77 78 79 80 81 82 83
                {
                    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>
                                            <div className='des'>
                                                QQ群:{item.course_qq}
                                            </div>
                                        </div>
                                    )
                                    return (
                                        <VList key={index} img={item.image_name}
                                               id={item.course_id}
                                               info={Info}></VList>
                                    )
                                })
                            }
                        </div>
                        : <div className="cart-tip">
                            <p className='cart-mess'>您还没有课程哦,快去逛逛吧~</p>
                            <Link to='/classify'>去逛逛</Link>
                        </div>
                }

            </div>
        )
    }
}

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