index.js 3.23 KB
Newer Older
xuzhenghua committed
1 2
import React, {Component} from 'react';
import './index.scss';
xuzhenghua committed
3
import {HeaderBar, VList} from '../../common'
xuzhenghua committed
4 5 6
import {http, api} from "@/utils";
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 25 26 27
        }
    }

    componentDidMount() {
        this.getList()
    }

    // 获取订单
    getList = () => {
        http.get(`${api.home}/m/my/courses`,).then((res) => {
            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'>
xuzhenghua committed
43
                <HeaderBar title='已购课程' arrow={true} cart={false}></HeaderBar>
xuzhenghua committed
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
                <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>
                                                <div className='des'>
                                                    QQ群:{item.course_qq}
                                                </div>
xuzhenghua committed
62
                                            </div>
xuzhenghua committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
                                        )
                                        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>
                    }
                </Loading>
xuzhenghua committed
78 79 80 81 82 83 84 85 86 87

            </div>
        )
    }
}

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