index.js 11.6 KB
Newer Older
FE committed
1
import React, { Component } from 'react';
FE committed
2
import { connect } from 'react-redux';
FE committed
3
import { Link } from 'react-router-dom';
FE committed
4
import { http, getParam, SendMessageToApp } from '@/utils';
FE committed
5
import { Toast } from "antd-mobile";
FE committed
6 7 8 9
import ListFrame from './../listFrame/index';
import ListHeader from './../listHeader';
import './index.scss';

FE committed
10
@connect(({user})=> ({
xuzhenghua committed
11
  uid: user && user.data && user.data.uid ? user.data.uid :''
FE committed
12
}))
FE committed
13 14 15 16 17 18
class CollectBlessing extends Component {

  constructor(props) {
    super(props);
    this.state = {
      rules: [
FE committed
19
        'app/h5/pc端活动页签到+5点福气值(每天一次)',
FE committed
20
        '关注七月在线微信服务号+30点福气值(仅限一次)',
xuzhenghua committed
21
        '分享活动页到朋友圈、qq、微博,分别+2点福气值(每个平台每天一次)',
FE committed
22 23 24
        '浏览指定课程详情页,一门课程+2点福气值(每天一次)',
        '邀请好友注册,+10点福气值/人(无上限)',
        '活动期间每购买一门课程+20点福气值',
wangshuo committed
25 26 27 28 29 30
      ],
      welfareRuleList: [
        {
          range: '50~100',
          rules: [
            {id: 1, text: '1.每天一次抽奖机会;'},
wangshuo committed
31
            {id: 2, text: '2.中奖概率翻2倍', des: '(福气值越高,中奖概率越大);'},
wangshuo committed
32 33 34 35 36 37 38
            {id: 3, text: '3.满111减11、满1111减111。'},
          ]
        },
        {
          range: '101~190',
          rules: [
            {id: 1, text: '1.每天两次抽奖机会;'},
wangshuo committed
39
            {id: 2, text: '2.中奖概率翻3倍', des: '(福气值越高,中奖概率越大);'},
wangshuo committed
40 41 42 43 44 45 46 47
            {id: 3, text: '3.满111减31、满1111减211;'},
            {id: 4, text: '4.AI水平测试增加1次。'},
          ]
        },
        {
          range: '>190',
          rules: [
            {id: 1, text: '1.每天三次抽奖机会;'},
wangshuo committed
48
            {id: 2, text: '2.中奖概率翻4倍', des: '(福气值越高,中奖概率越大);'},
wangshuo committed
49
            {id: 3, text: '3.满111减51、满1111减411;'},
FE committed
50
            {id: 4, text: '4.AI水平测试增加2次。'},
wangshuo committed
51 52 53
          ]
        }
      ],
xuzhenghua committed
54
      seconds: 5,
FE committed
55 56
    };
  }
FE committed
57

xuzhenghua committed
58
  qqToShare = () => {
FE committed
59
    const { uid, history } = this.props;
FE committed
60 61 62 63
    if(getParam('version')) {
      if(!uid) {
        SendMessageToApp("toLogin");
      }else {
xuzhenghua committed
64
        SendMessageToApp("QQshare", {
FE committed
65 66 67 68
          title: 'AI充电节,积福气享1折秒课,超10万元奖品来就送!!',
          desc: '把这门超5万人报名的【Python基础入门 升级版】课程送给你,附200元红包,请笑纳!--七月在线',
          link: 'https://m.julyedu.com/blessingPreheat',
          imgUrl: 'https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/active19_1111/m/index-share-img.png',
xuzhenghua committed
69
        });
FE committed
70
      }
FE committed
71
    }else {
FE committed
72 73 74 75 76 77 78 79
      if(!uid) {
        history.push('/passport');
      }else {
        history.push('/blessingPreheat?utm_source=qq&utm_medium=11&utm_campaign=QQ11&utm_content=11&utm_term=11')
        this.fetchUserBlessing(3, () => {
          this.handleToAddBlessing(3);
        });
      }
FE committed
80 81 82 83 84
    }
  }

  wechatToShare = () => {
    const { uid, history } = this.props;
FE committed
85 86 87 88
    if(getParam('version')) {
      if(!uid) {
        SendMessageToApp("toLogin");
      }else {
xuzhenghua committed
89
        SendMessageToApp("WXshare", {
FE committed
90 91 92 93
          title: 'AI充电节,积福气享1折秒课,超10万元奖品来就送!!',
          desc: '把这门超5万人报名的【Python基础入门 升级版】课程送给你,附200元红包,请笑纳!--七月在线',
          link: 'https://m.julyedu.com/blessingPreheat',
          imgUrl: 'https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/active19_1111/m/index-share-img.png',
xuzhenghua committed
94
        });
FE committed
95
      }
FE committed
96
    }else {
FE committed
97 98 99 100 101 102 103 104
      if(!uid) {
        history.push('/passport');
      }else {
        history.push('/blessingPreheat?utm_source=1&utm_medium=1&utm_campaign=11&utm_content=1&utm_term=1');
        this.fetchUserBlessing(1, () => {
          this.handleToAddBlessing(1);
        });
      }
FE committed
105 106 107
    }
  }

FE committed
108 109
  weiboToShare = () => {
    const { uid, history } = this.props;
FE committed
110 111 112 113
    if(getParam('version')) {
      if(!uid) {
        SendMessageToApp("toLogin");
      }else {
xuzhenghua committed
114
        SendMessageToApp("WBshare",  {
FE committed
115 116 117 118
          title: 'AI充电节,积福气享1折秒课,超10万元奖品来就送!!',
          desc: '把这门超5万人报名的【Python基础入门 升级版】课程送给你,附200元红包,请笑纳!--七月在线',
          link: 'https://m.julyedu.com/blessingPreheat',
          imgUrl: 'https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/active19_1111/m/index-share-img.png',
xuzhenghua committed
119
        });
FE committed
120
      }
FE committed
121
    }else {
FE committed
122 123 124 125 126 127 128 129
      if(!uid) {
        history.push('/passport');
      }else {
        history.push('/blessingPreheat?utm_source=sina&utm_medium=11&utm_campaign=sina11&utm_content=1&utm_term=11');
        this.fetchUserBlessing(2, () => {
          this.handleToAddBlessing(2);
        });
      }
FE committed
130 131
    }
  }
xuzhenghua committed
132

FE committed
133
  fetchUserBlessing(key, cb) {
xuzhenghua committed
134
    const { handleToShowShare } = this.props;
FE committed
135 136 137 138 139
    let { seconds } = this.state;
    http.get(`${API.home}/sys/user/blessing`).then(res => {
      const { code, data } = res.data;
      if(code === 200) {
        if(data.today_shared_platforms.some(item => item === key)) {
xuzhenghua committed
140
          handleToShowShare();
FE committed
141
          Toast.info('今日已+2点福气值”~', 2, null, false);
FE committed
142 143
        }else {
          handleToShowShare();
xuzhenghua committed
144
          this.shareTimer && clearInterval(this.shareTimer);
FE committed
145 146
          this.shareTimer = setInterval(() => {
            this.setState(
xuzhenghua committed
147
              {
FE committed
148
                seconds: (--seconds)
xuzhenghua committed
149
              },
FE committed
150 151
              () => {
                if (seconds === 0) {
xuzhenghua committed
152 153 154
                  this.setState({
                    seconds: 5
                  });
FE committed
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
                  typeof cb === 'function' && cb();
                  clearInterval(this.shareTimer);
                }
              }
            );
          }, 1000);
        }
      }
    });
  }

  handleToAddBlessing = (key) => {
    http.post(`${API.home}/sys/add/blessing`, {
      share_platform: key, // 1 朋友圈 2 微博 3 qq
      type: 3 // 1:签到;3:分享;4:浏览课程;
    }).then(res => {
      const {code } = res.data;
      if (code === 200) {
        Toast.info('+2点福气值~', 2, null, false);
      }
    });
  }
xuzhenghua committed
177

FE committed
178 179 180 181 182 183 184 185 186
  handleToInvite = () => {
    const { uid, history } = this.props;
    if(!uid) {
      if(getParam('version')) {
        SendMessageToApp("toLogin");
      }else {
        history.push('/passport')
      }
    }else {
xuzhenghua committed
187
      if(getParam('version')) {
xuzhenghua committed
188
        history.push('/invite?version=' + getParam('version') + '&plat_form='+ getParam('plat_form'))
xuzhenghua committed
189 190 191
      } else {
        history.push('/invite')
      }
FE committed
192 193 194
    }
  }

FE committed
195
  render() {
xuzhenghua committed
196
    const {
FE committed
197
      isSign,
FE committed
198
      userInfo: {blessingVal = 0, buyBlessing = 0, inviteBlessing = 0, isFollow = 0 },
xuzhenghua committed
199
      isLogin,
xuzhenghua committed
200 201
      handleToShowNotice,
      handleToShowList,
wangshuo committed
202
      toLogin,
FE committed
203
      toSection
FE committed
204
    } = this.props;
FE committed
205
    const { rules, welfareRuleList, seconds } = this.state;
FE committed
206
    return (
wangshuo committed
207 208
      <div className="collect-blessing">
        {
xuzhenghua committed
209
          isLogin
FE committed
210 211
          ? (
            <ListHeader text={`我的福气值: ${blessingVal}分`} size="middle" styles={{margin: '20px 0 0 0'}} />
xuzhenghua committed
212
          )
FE committed
213
          : (
wangshuo committed
214
            <ListHeader size="middle" styles={{margin: '20px 0 0 0'}} >
xuzhenghua committed
215
              <span className="text_nologin">我的福气值:</span>
wangshuo committed
216
              <span onClick={toLogin} className="login__btn">登录</span>
FE committed
217
            </ListHeader>
wangshuo committed
218 219
          )
        }
FE committed
220
        <p className='activity__over'>活动结束前福气榜前50名可获奖品一份</p>
FE committed
221 222 223 224 225 226 227
        {
          welfareRuleList.map((item, index) => (
            <div className="rules__item" key={index}>
              <div className="item__left">
                <div className='tip__bubble'>
                  <div className="tip__text">福气值</div>
                  <div className='tip__style'></div>
wangshuo committed
228
                </div>
FE committed
229
                <div className='range__number'>{item.range}</div>
wangshuo committed
230
              </div>
FE committed
231 232 233 234
              <div className="item__right">
                {
                  item.rules.map(item => {
                    return (
FE committed
235
                      <p key={item.id}>
xuzhenghua committed
236
                        {item.text}
FE committed
237 238 239 240 241 242 243 244 245 246
                        <span>{item.des}</span>
                      </p>
                    )
                  })
                }
              </div>
            </div>
          ))
        }
        <ListHeader text="福气值积攒规则" size="middle" styles={{margin: '30px 0 0'}} />
FE committed
247 248 249 250 251
        {
          rules.map((item, index) => (
            <div className="collect-blessing__item" key={index}>
              <i className="collect-blessing__num">{index+1}</i>
              <p className="collect-blessing__title">{item}</p>
FE committed
252
              {
xuzhenghua committed
253
                index === 0 &&
FE committed
254 255 256 257
                <>
                  {
                    (isLogin && isSign)
                    ? (
xuzhenghua committed
258
                      <button className="collect-blessing__content" data-status="done">
xuzhenghua committed
259
                        已加5
xuzhenghua committed
260
                      </button>
FE committed
261 262
                    )
                    : (
xuzhenghua committed
263
                      <button onClick={toLogin} className="collect-blessing__content">
FE committed
264
                        点击<br/>签到
xuzhenghua committed
265
                      </button>
FE committed
266 267 268
                    )
                  }
                </>
FE committed
269 270
              }
              {
xuzhenghua committed
271
                index === 1 &&
FE committed
272 273 274 275
                <>
                  {
                    isFollow === 1
                    ? (
xuzhenghua committed
276
                      <button className="collect-blessing__content" data-status="done" onClick={handleToShowNotice}>
FE committed
277
                        已加30
xuzhenghua committed
278
                      </button>
FE committed
279 280
                    )
                    : (
xuzhenghua committed
281
                      <button className="collect-blessing__content" onClick={handleToShowNotice}>
FE committed
282
                        关注<br/>二维码
xuzhenghua committed
283
                      </button>
FE committed
284 285 286
                    )
                  }
                </>
FE committed
287 288 289
              }
              {
                index === 2 &&
FE committed
290
                <div className="collect-blessing__content" data-layout="column">
FE committed
291 292
                  <p className="collect-blessing__label">去分享</p>
                  <div className="collect-blessing__share">
xuzhenghua committed
293
                    <button
xuzhenghua committed
294
                    className="collect-blessing__share-button"
FE committed
295
                    data-type="qq"
xuzhenghua committed
296 297 298
                    onClick={this.qqToShare}
                    ></button>
                    <button
xuzhenghua committed
299
                      className="collect-blessing__share-button"
FE committed
300 301
                      data-type="wechat"
                      onClick={this.wechatToShare}
xuzhenghua committed
302 303
                    ></button>
                    <button
xuzhenghua committed
304
                      className="collect-blessing__share-button"
FE committed
305 306
                      data-type="weibo"
                      onClick={this.weiboToShare}
xuzhenghua committed
307
                    ></button>
FE committed
308 309 310 311 312
                  </div>
                </div>
              }
              {
                index === 3 &&
xuzhenghua committed
313
                <button className="collect-blessing__content" onClick={handleToShowList}>
FE committed
314
                  浏览课程<br/>详情页
xuzhenghua committed
315
                </button>
FE committed
316 317 318
              }
              {
                index === 4 &&
xuzhenghua committed
319
                <button className="collect-blessing__content" onClick={this.handleToInvite}>
FE committed
320
                  <span>邀请链接</span>
wangshuo committed
321 322 323
                  {
                    inviteBlessing > 0 && <i>已加{inviteBlessing}</i>
                  }
xuzhenghua committed
324
                </button>
FE committed
325 326 327
              }
              {
                index === 5 &&
xuzhenghua committed
328
                <button className="collect-blessing__content" onClick={toSection}>
FE committed
329
                  <span>去选课</span>
wangshuo committed
330 331 332
                  {
                    buyBlessing > 0 && <i>已加{buyBlessing}</i>
                  }
xuzhenghua committed
333
                </button>
FE committed
334
              }
FE committed
335 336 337 338 339 340 341 342 343
            </div>
          ))
        }
      </div>
    )
  }
}

export default ListFrame(CollectBlessing);