index.js 4.5 KB
Newer Older
xuzhenghua committed
1 2 3 4 5 6 7 8
import React, { Component } from 'react';
import './index.scss';
import ListHeader from './../blessingPreheat/listHeader/index'
import { http, getParam } from '@/utils';
import { Toast } from 'antd-mobile';
import AddressPopup from './../blessingPreheat/addressPopup/index'
import { Popup } from '@/common'
import { connect } from 'react-redux'
wangshuo committed
9
import jsCookie from 'js-cookie'
xuzhenghua committed
10 11 12 13 14 15 16 17 18 19 20 21 22
@connect(({user}) => (
  {
    uid: user.data.uid || ''
  }
))
class BlessingGetPrize extends Component {
  popupInstance = null
  constructor(props) {
    super(props);
    this.state = {
      date: '',
      next_date: '',
      name: '',
wangshuo committed
23
      is_winning: "", //是否中奖
xuzhenghua committed
24 25 26 27 28 29 30
      is_virtual: 1, // 实物奖品 虚拟奖品
      prize_data: [],
      address: false,
    }
  }

  componentDidMount () {
wangshuo committed
31 32 33
    const _this = this;
    setTimeout(function(){
      const {history, uid} = _this.props;
wangshuo committed
34
      if(!uid) {
wangshuo committed
35
        history.push('/passport');
wangshuo committed
36 37 38 39 40 41 42 43 44 45 46 47
      }else{
        http.get(`${API.home}/sys/lottery_result?id=${getParam('id')}`).then(res => {
          const {code, msg, data} = res.data;
          if(code === 200) {
            _this.setState({
              ...data.info,
              prize_data: data.prize_data.slice(0, 6),
            })
          } else {
            Toast.info(msg);
          }
        });
xuzhenghua committed
48
      }
wangshuo committed
49
    }, 300);
xuzhenghua committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
  }

  showAddress = (bool) => {
    const {history, uid} = this.props;
    const {name} = this.state;
    if (bool && !uid) {
      history.push('/passport')
    } else {
      if (bool && !this.popupInstance) {
        this.popupInstance = Popup({
          title: '恭喜您',
          content: <AddressPopup tip='填写您的联系方式' prize={name} handleToHide={() => this.showAddress(false)}/>
        })
      } else {
        this.popupInstance.close()
        this.popupInstance = null
      }
    }
  }

  render() {
    const {date, next_date, name, is_winning, is_virtual, prize_data, address} = this.state;
    return (
      <div className="blessing_get_prize">
        <div className='is__get_prize'>
          <div className="get_piriz__info">
            <div className='result'>{date}中奖结果</div>
            {
              is_winning === 0 && (
                <div className='no_prize'>很遗憾,你未中奖~</div>
              )
            }
            {
              is_winning === 1 && is_virtual === 0 && (
                <div className='real__prize'>
                  <div>恭喜你,已抽中{name}奖品</div>
                  <span onClick={()=> this.showAddress(true)} className='address'>填写收货地址</span>
                </div>
              )
            }
            {
              is_winning === 1 && is_virtual === 1 && (
                <div className='virtual '>
                  <div>恭喜你抽中{name}</div>
                  <div>奖品已存放到你的账户</div>
                </div>
              )
            }
          </div>
        </div>
wangshuo committed
100 101 102 103 104 105 106
        
        { 
          prize_data && prize_data.length > 0 && <>
          <div className='current_stage'>
            {next_date}
          </div>
          <ListHeader text="抽奖已开启" styles={{margin: '16px 0 18px'}}/>
xuzhenghua committed
107

wangshuo committed
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
          <div className='prize_list_container'>
              {
                prize_data.length > 0 && prize_data.map((item, index) => {
                  return (<div className='prize__item' key={index}>
                    <img className='prize__image' src={item.img}></img>
                    <div className='name__num'>
                      <span>{item.name}</span>
                      <span>{`*${item.num}`}</span>
                    </div>
                  </div>)
                })
              }
          </div>
  
          <a href='/blessingPreheat' className='join__button'>
            立即参与抽奖
          </a>
  
          <div className='prize__tip'>
            <div className='line'></div>
            <span>中奖小tips</span>
            <div className='line'></div>
          </div>
          <div className='blessing__des'>积攒的福气值越高,中奖概率越大哦</div>
          <a className='to__preheat' href='/invite'>积攒更多福气值</a>
          </>
        }
        {
          (!prize_data || prize_data.length === 0) && (
            <div className="active_over_container">
FE committed
138 139 140
              <p>AI充电节返场已开启</p>
              <p>狂欢不能停~</p>
              <a href='/blessingPreheat' className='to_active'>立即查看</a>
wangshuo committed
141 142 143
            </div>
          )
        }
xuzhenghua committed
144 145 146 147 148
      </div>
    )
  }
}
export default BlessingGetPrize