index.js 3.83 KB
Newer Older
zhanghaozhe committed
1 2 3 4 5 6
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { http } from "@/utils"
import { Popup } from '@/common'
import AddressPopup from './../blessingPreheat/addressPopup/index'
import './index.scss'
FE committed
7

zhanghaozhe committed
8
@connect(({user}) => (
FE committed
9 10 11 12
  {
    uid: user.data.uid || ''
  }
))
FE committed
13
class BlessingRank extends Component {
zhanghaozhe committed
14
  popupInstance = null
FE committed
15
  constructor(props) {
zhanghaozhe committed
16
    super(props)
FE committed
17
    this.state = {
FE committed
18 19 20 21 22 23 24
      rankList: [],
      rules: [
        '1、排行榜名次以2019年11月13日24点七月在线公布的排行榜为准,榜单确认后,得奖小伙伴请及时填写邮寄信息,7个自然日内不填写,视为主动放弃奖品;',
        '2、福气值只在本活动期间享受抽奖、提高中奖概率、购课优化、增加AI水平测试等福利;',
        '3、如有发现恶意刷榜,刷虚假数据等行为将取消其领奖资格;',
        '4、本活动解释权归北京七月在线科技有限公司所有。',
      ],
FE committed
25 26 27 28
    }
  }

  componentDidMount() {
zhanghaozhe committed
29
    this.fetchRankData()
FE committed
30 31 32 33
  }

  fetchRankData = () => {
    http.get(`${API.home}/sys/blessing/ranking`).then(res => {
zhanghaozhe committed
34 35
      const {code, data} = res.data
      if (code === 200) {
FE committed
36 37
        this.setState({
          rankList: data,
zhanghaozhe committed
38
        })
FE committed
39
      }
zhanghaozhe committed
40
    })
FE committed
41 42
  }

FE committed
43
  handleToSwitch = (bool) => {
zhanghaozhe committed
44 45 46 47
    const {history, uid} = this.props
    if (bool && !uid) {
      history.push('/passport')
    } else {
zhanghaozhe committed
48 49 50 51 52 53 54 55 56
      if (bool && !this.popupInstance) {
        this.popupInstance = Popup({
          title: '收货信息',
          content: <AddressPopup handleToHide={() => this.handleToSwitch(false)}/>
        })
      } else {
        this.popupInstance.close()
        this.popupInstance = null
      }
FE committed
57 58 59
    }
  }

FE committed
60
  formatString = (str, len) => {
zhanghaozhe committed
61
    return str.length > len ? `${str.substr(0, len)}...` : str
FE committed
62 63 64
  }

  render() {
zhanghaozhe committed
65
    const {rankList, rules} = this.state
FE committed
66 67
    return (
      <>
FE committed
68
        <div className="rank__banner"></div>
FE committed
69
        <div className="rank__body">
FE committed
70
          <button className="rank__address" onClick={() => this.handleToSwitch(true)}>填写收货地址></button>
FE committed
71 72 73 74
          <div className="rank__table">
            <dl className="rank__table-header">
              <dd className="rank__table-column">排名</dd>
              <dd className="rank__table-column">用户</dd>
FE committed
75
              <dd className="rank__table-column">分数</dd>
FE committed
76 77 78 79 80 81 82 83 84
              <dd className="rank__table-column">奖品</dd>
            </dl>
            {
              rankList.map((item, index) => {
                return (
                  <dl className="rank__table-body" key={index}>
                    <dd className="rank__table-column">
                      {
                        index < 3
zhanghaozhe committed
85 86 87 88
                          ? (
                            <i className="rank__table-num" data-num={index + 1}></i>
                          )
                          : index + 1
FE committed
89 90 91 92 93 94 95 96 97 98 99
                      }
                    </dd>
                    <dd className="rank__table-column">
                      <div className="rank__table-user">
                        <i className="rank__table-portrait" style={{backgroundImage: `url(${item.head_image})`}}></i>
                        <span>{this.formatString(item.user_name, 5)}</span>
                      </div>
                    </dd>
                    <dd className="rank__table-column">{item.blessing_value}</dd>
                    <dd className="rank__table-column">{this.formatString(item.prize_name, 7)}</dd>
                  </dl>
zhanghaozhe committed
100
                )
FE committed
101 102
              })
            }
zhanghaozhe committed
103

FE committed
104 105 106
          </div>
          <div className="rank__rule">
            <h2 className="rank__rule-title">活动规则</h2>
FE committed
107 108 109 110 111
            {
              rules.map((item, index) => (
                <p className="rank__rule-desc" key={index}>{item}</p>
              ))
            }
FE committed
112 113 114
          </div>
        </div>
      </>
zhanghaozhe committed
115
    )
FE committed
116 117 118
  }
}

zhanghaozhe committed
119
export default BlessingRank