import React, { Component } from 'react'
import {connect} from "react-redux";
import { http, getParam } from '@/utils';
import './index.scss';
import {Toast} from "antd-mobile";
import jsCookie from 'js-cookie';

class Activity extends Component {
  constructor(props) {
    super(props);
  }

  componentWillMount() {
    jsCookie.set('blessing_invite_uid', getParam('shareuid'));
    jsCookie.set('blessing_invite_code', getParam('code'));
  }

  getGift = () => {
    if(this.props.user.hasError) {
      this.props.history.push('/passport');
    } else {
      http.get(`${API.home}/sys/receive/reg/gift`).then(res => {
        let {code, msg} = res.data;
        if(code === 200) {
          Toast.info('领取成功，你可前往七月在线官网/APP进行查看', 2);
        }else{
          Toast.info(msg, 2);
        }
      })
    }
  }

  render() {
    return (
      <div className="activity__con">
        <div className='banner__con'></div>
        <div className='content__con'>
          <div className="button__get" onClick={this.getGift}>立即领取</div>
        </div>
      </div>
    )
  }
}

export default connect(
  state => ({user: state.user}),
  null
)(Activity);
