index.js 4.99 KB
Newer Older
xuzhenghua committed
1 2 3 4 5
import React, {PureComponent} from 'react'
import {Flex, WhiteSpace, List} from 'antd-mobile'
import './index.scss'
import Avatar from './image/avatar.png'
import Vip from './image/vip.png'
xuzhenghua committed
6
import {WithTab} from '@/HOCs'
xuzhenghua committed
7 8 9
import {Link} from "react-router-dom"
import {connect} from "react-redux"
import {HeaderBar} from "@/common"
10
import {getCourses} from './../detail/actions';
.  
baiguangyao committed
11 12 13

const Item = List.Item;
const Brief = Item.Brief;
baiguangyao committed
14

15 16 17
@connect(state => ({
    user: state.user
}))
18
class My extends PureComponent {
xuzhenghua committed
19 20 21 22 23 24
    constructor(props) {
        super(props)
        this.state = {
            data: []
        }
    }
xuzhenghua committed
25 26 27 28 29 30

    // 去登录
    toLogin = () => {
        this.props.history.push('/passport')
    }

31 32
    toCourseDetail = (id) => {
        const { dispatch, history } = this.props;
33
        // dispatch(getCourses(id, () => {
34 35
            history.push(`/detail?id=${id}`);
            return false;
36
        // }));
37 38
    }

baiguangyao committed
39
    render() {
xuzhenghua committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
        const {user} = this.props
        const uid = user && user.data && user.data.uid
        const username = user && user.data && user.data.username
        const avatar = user && user.data && user.data.avatar
        const isVIP = user && user.data && user.data.isVIP
        let list
        if (!uid) {
            list = <List className="my-list">
                <Item
                    className="avatar-wrap"
                    arrow="horizontal"
                    multipleLine
                    thumb={Avatar}
                    onClick={this.toLogin}>
                    <Brief>点击登录</Brief>
                </Item>
            </List>
        } else {
            list = <List className="my-list">
xuzhenghua committed
59 60 61 62 63 64 65 66 67 68 69 70 71
                <Link to='/myedit'>
                    <Item
                        className="avatar-wrap"
                        arrow="horizontal"
                        multipleLine
                        thumb={avatar}
                    >
                        <Brief>
                            {username}
                            {
                                isVIP === 1 &&
                                <img src={Vip} className='vip' alt=""/>
                            }
xuzhenghua committed
72

xuzhenghua committed
73 74 75 76
                        </Brief>
                        <Brief style={{fontSize: "12px"}}>学号: {uid}</Brief>
                    </Item>
                </Link>
xuzhenghua committed
77
                {
xuzhenghua committed
78
                    !isVIP &&
xuzhenghua committed
79
                    <a href="javascript:;" className="my-isvip" onClick={() => this.toCourseDetail(139)}></a>
xuzhenghua committed
80 81 82
                }
            </List>
        }
baiguangyao committed
83
        return (
baiguangyao committed
84 85 86
            <div className="flex-container">
                <Flex>
                    <Flex.Item>
xuzhenghua committed
87 88
                        <HeaderBar title='我的' arrow={false} cart={false}></HeaderBar>

xuzhenghua committed
89 90
                        {list}

xuzhenghua committed
91 92 93 94 95
                        {
                            !uid &&
                            <div className="am-list-header"></div>

                        }
xuzhenghua committed
96 97 98 99 100 101 102 103

                        <List className="my-list-content">
                            <Link to='/purchased'>
                                <Item arrow="horizontal">
                                    <i className="iconfont iconiconfront-27"></i>
                                    已购课程
                                </Item>
                            </Link>
xuzhenghua committed
104
                            <Link to='/shopcart'>
xuzhenghua committed
105 106
                                <Item arrow="horizontal">
                                    <i className="iconfont icongouwuche-xianxing"></i>
xuzhenghua committed
107 108 109 110
                                    购物车
                                </Item>
                            </Link>
                            <Link to='/myorders'>
xuzhenghua committed
111
                                <Item arrow="horizontal">
xuzhenghua committed
112 113 114 115
                                    <i className="iconfont iconiconfront-24"></i>
                                    课程订单
                                </Item>
                            </Link>
zhanghaozhe committed
116 117 118 119 120 121
                            <Link to={{
                                pathname: '/coupons',
                                state: {
                                    from: this.props.location.pathname
                                }
                            }}>
xuzhenghua committed
122
                                <Item arrow="horizontal" className="no-border">
123 124
                                    <i className="iconfont iconiconfront-52"></i>
                                    优惠券
zhanghaozhe committed
125 126
                                </Item>
                            </Link>
xuzhenghua committed
127
                            <div className="am-list-header"></div>
128

xuzhenghua committed
129 130
                            <Link to='/scholarship'>
                                <Item arrow="horizontal" className='btm-scholarship'>
xuzhenghua committed
131 132 133
                                    <i className="iconfont iconiconfront-51"></i>
                                    赚奖学金
                                </Item>
xuzhenghua committed
134 135
                            </Link>
                        </List>
xuzhenghua committed
136

baiguangyao committed
137 138
                    </Flex.Item>
                </Flex>
139
                <WhiteSpace size="lg"/>
baiguangyao committed
140 141 142 143 144 145
            </div>
        )
    }

}

146
export default WithTab(My);