index.js 5.8 KB
Newer Older
xuzhenghua committed
1 2
import React, {Component} from 'react'
import './index.scss'
FE committed
3
import {getParam, http} from "@/utils"
4
import {Toast, Flex} from 'antd-mobile'
xuzhenghua committed
5 6 7
import {connect} from "react-redux"
import {withRouter} from 'react-router-dom'
import {compose} from "redux"
xuzhenghua committed
8

xuzhenghua committed
9
class ShareRank extends Component {
xuzhenghua committed
10 11
    constructor(props) {
        super(props)
xuzhenghua committed
12
        this.state = {
xuzhenghua committed
13 14 15
            list: [],  // 分销排行榜
            rankingslice: [],  // 分销排行榜前两名
            code: '', // 分销code
xuzhenghua committed
16
            shareRank: false
xuzhenghua committed
17
        }
xuzhenghua committed
18 19 20
    }

    componentDidMount() {
xuzhenghua committed
21 22 23 24 25 26
        this.getRankList()
        this.getCode()
    }

    // 获取排行榜
    getRankList = () => {
zhanghaozhe committed
27
        http.get(`${API.home}/dist/rankList/${getParam('id')}`).then((res) => {
xuzhenghua committed
28 29 30
            if (res.data.code === 200) {
                this.setState({
                    list: res.data.data,
xuzhenghua committed
31
                    rankingslice: res.data.data.slice(0, 2)
xuzhenghua committed
32
                })
xuzhenghua committed
33 34
            } else {
                Toast.info(res.data.msg, 2)
xuzhenghua committed
35 36
            }
        })
xuzhenghua committed
37 38 39 40
    }

    // 获取分销码
    getCode = () => {
xuzhenghua committed
41 42 43
        const {user} = this.props
        const uid = user && user.data && user.data.uid
        if (!uid) return
xuzhenghua committed
44 45 46
        let data = {
            course_id: getParam('id')
        }
zhanghaozhe committed
47
        http.post(`${API.home}/dist/createCode`, data).then((res) => {
xuzhenghua committed
48 49 50
            if (res.data.code === 200) {
                this.setState({
                    code: res.data.data.code
xuzhenghua committed
51
                })
xuzhenghua committed
52 53
            } else {
                Toast.info(res.data.msg, 2)
xuzhenghua committed
54 55
            }
        })
xuzhenghua committed
56 57
    }

xuzhenghua committed
58
    // 点击分销跳转到海报页
xuzhenghua committed
59
    share = (info) => {
xuzhenghua committed
60 61 62 63 64 65 66 67 68 69
        const {user} = this.props
        const uid = user && user.data && user.data.uid
        if (!uid) {
            this.props.history.push('/passport/login')
        } else {
            const courseId = getParam('id')
            const dist_first = info.dist_first_level_ti
            const dist_code = this.state.code
            this.props.history.push(`/shareposter?courseId=${courseId}&dist_first=${dist_first}&uid=${uid}&dist_code=${dist_code}`)
        }
xuzhenghua committed
70 71
    }

xuzhenghua committed
72 73 74 75 76 77 78 79

    // 打开分销排行榜弹窗
    openRanking = () => {
        this.setState({
            shareRank: true
        })
    }

xuzhenghua committed
80 81
    // 关闭弹窗
    colse = () => {
xuzhenghua committed
82 83 84
        this.setState({
            shareRank: false
        })
xuzhenghua committed
85 86
    }

xuzhenghua committed
87
    render() {
88 89 90 91 92
        const { courseInfo: info = '' } = this.props;
        // let info = ''
        // if (this.props.courseInfo && this.props.courseInfo.courseInfo && this.props.courseInfo.courseInfo.course_info) {
        //     info = this.props.courseInfo.courseInfo.course_info
        // }
xuzhenghua committed
93 94
        return (
            <div className='share-ranking'>
95
                <Flex className='share-container' justify='between'>
xuzhenghua committed
96 97 98 99 100 101 102
                    <Flex className='share-list'>
                        <span className="title">排行榜:</span>
                        <div className='ranking-box' onClick={this.openRanking}>
                            {
                                this.state.rankingslice && this.state.rankingslice.length > 0 && this.state.rankingslice.map((item, index) => {
                                    return (
                                        <span key={index} className="ranking-mess">
xuzhenghua committed
103 104 105
                                    <img src={item.head_imgurl} alt=""/>
                                    <i>{item.amount}</i>
                                </span>
xuzhenghua committed
106 107 108
                                    )
                                })
                            }
xuzhenghua committed
109

xuzhenghua committed
110 111 112 113 114 115 116 117 118

                        </div>
                    </Flex>
                    <Flex className='share-money' justify='between' align='center'>
                        <img onClick={this.openRanking} className="ranking-ellipsis"
                             src="https://julyedu-img.oss-cn-beijing.aliyuncs.com/Image/train/ellipsis.png" alt=""/>
                        <button className="share" onClick={this.share.bind(this, info)}>分享赚{info.dist_first_level_ti}
                        </button>
                    </Flex>
119
                </Flex>
xuzhenghua committed
120

xuzhenghua committed
121 122

                {
xuzhenghua committed
123
                    this.state.shareRank &&
xuzhenghua committed
124 125 126 127 128 129 130
                    <div className="shareMbc">
                        <div className="content">
                            <div className="title-box">
                                <span className="lable">赚钱排行榜</span>
                                <span className="tips">只展示前9名用户</span>
                            </div>
                            <ul>
xuzhenghua committed
131
                                {
xuzhenghua committed
132 133
                                    this.state.list && this.state.list.length > 0 && this.state.list.map((item, index) => {
                                        return (
xuzhenghua committed
134 135 136 137 138 139 140 141
                                            <li key={index}>
                                                <img src={item.head_imgurl} alt=""/>
                                                <span className='course-title'>{item.user_name}</span>
                                                <span className='course-price'>{item.amount}</span>
                                            </li>
                                        )
                                    })
                                }
xuzhenghua committed
142
                            </ul>
xuzhenghua committed
143
                            <div className='shareBtn'>
xuzhenghua committed
144
                                <button onClick={this.share.bind(this, info)}>分享赚{info.dist_first_level_ti}</button>
xuzhenghua committed
145
                            </div>
146
                            <i onClick={this.colse} className={'iconfont iconiconfront-2 close'}></i>
xuzhenghua committed
147
                        </div>
xuzhenghua committed
148

xuzhenghua committed
149 150
                    </div>
                }
xuzhenghua committed
151 152 153 154 155
            </div>
        );
    }
}

xuzhenghua committed
156 157
export default compose(
    connect(
xuzhenghua committed
158
        state => ({
159
            // courseInfo: state,
xuzhenghua committed
160 161
            user: state.user
        }),
xuzhenghua committed
162 163 164 165
        null
    ),
    withRouter
)(ShareRank)