index.js 5.83 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 70
        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 uid = info.uid
            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
71 72
    }

xuzhenghua committed
73 74 75 76 77 78 79 80

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

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

xuzhenghua committed
88
    render() {
89 90 91 92 93
        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
94 95
        return (
            <div className='share-ranking'>
96
                <Flex className='share-container' justify='between'>
xuzhenghua committed
97 98 99 100 101 102 103
                    <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
104 105 106
                                    <img src={item.head_imgurl} alt=""/>
                                    <i>{item.amount}</i>
                                </span>
xuzhenghua committed
107 108 109
                                    )
                                })
                            }
xuzhenghua committed
110

xuzhenghua committed
111 112 113 114 115 116 117 118 119

                        </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>
120
                </Flex>
xuzhenghua committed
121

xuzhenghua committed
122 123

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

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

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