index.js 2.75 KB
Newer Older
xuzhenghua committed
1 2
import React, {Component} from 'react';
import './index.scss';
zhanghaozhe committed
3 4
import {HeaderBar, VList} from 'src/common';
import {http, getParam, SendMessageToApp} from 'src/utils';
xuzhenghua committed
5
import {Toast} from 'antd-mobile';
xuzhenghua committed
6

xuzhenghua committed
7 8 9 10 11

class ShareCourse extends Component {

    constructor(props) {
        super(props);
xuzhenghua committed
12 13 14 15
        this.state = {
            list: [],
            fromApp: !getParam('from') ? false : true
        };
xuzhenghua committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29
    }

    componentDidMount() {
        http.get(`${API.home}/sys/red_packet/share_course`).then((res) => {
            if (res.data.code === 200) {
                this.setState({
                    list: res.data.data
                })
            } else {
                Toast.info(res.data.msg, 2)
            }
        })
    }

xuzhenghua committed
30
    toCourseDetail = (id) => {
xuzhenghua committed
31 32 33 34
        const _this = this
        if (_this.state.fromApp) {
            SendMessageToApp("toCourse", id)
        } else {
xuzhenghua committed
35 36 37 38 39
            const {history} = this.props;
            history.push(`/detail?id=${id}`)
        }
    }

xuzhenghua committed
40 41 42 43
    render() {
        const {list} = this.state;
        return (
            <div className={'share-course'}>
xuzhenghua committed
44 45 46 47 48
                {
                    !this.state.fromApp &&
                    <HeaderBar title='分享领红包' arrow={true}/>
                }

xuzhenghua committed
49 50 51 52 53 54 55 56 57 58 59 60
                {
                    list && list.length > 0 ? <div>
                            {
                                list.map((item, index) => {
                                    const Info = (
                                        <div className="info">
                                            <p className={'title text-overflow-1'}>{item.course_title}</p>
                                            <p className={'contact text-overflow-1'}>{item.simpledescription}</p>
                                            <button>分享领红包</button>
                                        </div>
                                    )
                                    return (
xuzhenghua committed
61
                                        <div key={index}>
xuzhenghua committed
62 63 64
                                            <VList
                                                img={item.image_name}
                                                info={Info}
xuzhenghua committed
65 66
                                                id={item.course_id}
                                                toDetail={this.toCourseDetail}
xuzhenghua committed
67
                                            />
xuzhenghua committed
68 69
                                        </div>

xuzhenghua committed
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
                                    )
                                })
                            }
                        </div> :
                        <div>
                            <p className='not-data'>暂时没有可分享的课程哦〜</p>
                        </div>
                }

            </div>
        )
    }
}

export default ShareCourse;