index.js 34.4 KB
Newer Older
FE committed
1
import React, { PureComponent } from 'react';
FE committed
2
import {CopyToClipboard} from 'react-copy-to-clipboard';
FE committed
3 4 5 6
import classnames from 'classnames';
import { isEmpty } from 'lodash';
import { browser } from '@/utils';
import { http, getParam, validateTel } from "@/utils";
FE committed
7
import { Formik, Form, Field } from 'formik';
FE committed
8 9
import { Toast } from 'antd-mobile';
import Captcha from '@/common/Captcha';
FE committed
10
import FollowQRcode from './../followQRcode';
FE committed
11
import './index.scss';
zhanghaozhe committed
12
import cookie from 'js-cookie'
zhanghaozhe committed
13 14
import { Link } from "react-router-dom";

FE committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33

class RedPacket extends PureComponent {

  constructor(props) {
    super(props),
    this.state = {

      // 弹窗类型:0: 无弹出,1:非微信,2:微信
      type: 0,
      isCopy: false,
      validate: '',
      captchaInstance: null,
      seconds: 60,
      isFirst: true,
      timer: null,
      isTimer: false, // 是否开始倒计时
      shareInfo: {
        url: '',
        share_code: '',
34
        command: '【七月在线送你一个红包】https://www.julyedu.com/'
FE committed
35 36 37 38
      },
      doneInfo: { //领取后的状态,1:领取成功,2:领取超时
        status: 2,
        txt: '手机号绑定超时,红包已失效!',
39
        desc: ''
FE committed
40 41 42 43 44
      },
      money: '', // 红包金额,
      endTime: 10, // 手机绑定时限
      countdownTimer: null,
      countdown: '00分00秒', // 绑定时间
xuzhenghua committed
45
      accountInfo: {},
46 47 48 49
      bindInfo: {},
      country: {
        num: '86'
      }
FE committed
50 51 52 53
    }
  }

  componentDidMount() {
54
    // console.log(this.props);
55 56 57 58
    this.judgePopupTypeFromCountry();

    // 分享链接进入
    this.judgePopupType();
zhanghaozhe committed
59 60

    window.addEventListener('beforeunload', this.removeStatisticsCookie)
zhanghaozhe committed
61

zhanghaozhe committed
62

zhanghaozhe committed
63

64 65
    // 微信进入
    const isWechat = getParam('wechat');
66
    const { userInfo } = this.props;
zhanghaozhe committed
67 68 69
    if(!userInfo || !userInfo.uid) {
      this.setRelativeCookie()
    }
70
    if(isWechat === '1' && !browser.isWeixin) {
71
      if(userInfo && userInfo.uid) {
72 73 74 75 76
        const type = window.localStorage.getItem('redpacket-click');
        if(type === 'split') {
          http.get(`${API.home}/sys/redPacket/shareUrl/${getParam('id')}`).then(res => {
            const { code, data } = res.data;
            if(code === 200) {
zhanghaozhe committed
77

78 79 80 81 82 83
              // 检查收否领取过
              http.post(
                `${API.home}/sys/redPacket/split`,
                {
                  action: 'check',
                  share_code: data.share_code
84
                }
85 86 87 88
              ).then(res => {
                const { code, data } = res.data;
                if(code === 200) {
                  window.localStorage.removeItem('redpacket-click');
zhanghaozhe committed
89
                  // is_receive	是否领取过 0-否 1-是
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
                  if(data.is_receive) {
                    this.judgeReceiveStatus(data, 8);
                  }else {
                    this.setState({
                      type: 3
                    });
                  }
                }
              })
            }
          });
        }else {
          this.setState({
            type: 1
          });
          window.localStorage.removeItem('redpacket-click');
        }
107
      }else {
zhanghaozhe committed
108
        this.setRelativeCookie()
109 110 111 112
        this.setState({
          type: 1
        });
      }
113
    }
FE committed
114 115 116
    this.fetchShareInfo();
  }

zhanghaozhe committed
117 118 119 120 121 122 123 124 125
  removeStatisticsCookie = () => {
    cookie.remove('share_code', {path: '/', domain: '.julyedu.com'})
  }

  componentWillUnmount() {
    window.removeEventListener('beforeunload', this.removeStatisticsCookie)
  }


FE committed
126 127
  // 获取分享信息
  fetchShareInfo = () => {
FE committed
128
    const share_code = getParam('share_code');
FE committed
129 130 131 132
    http.get(`${API.home}/sys/redPacket/shareUrl/${getParam('id')}`).then(res => {
      const { code, data } = res.data;
      if(code === 200) {
        this.setState({
FE committed
133
          shareInfo: share_code? Object.assign({}, data, {share_code}) : data
FE committed
134 135 136
        });
      }
    });
137 138 139 140 141 142 143
  }

  // 分享后进入,链接中带 share_code 字段
  judgePopupType = () => {
    const share_code = getParam('share_code');
    const { shareInfo } = this.state;
    if(share_code && share_code !== 'null') {
FE committed
144
      this.setState({
145
        shareInfo: Object.assign({}, shareInfo, {
FE committed
146
          share_code
147
        })
FE committed
148
      });
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167

      // 检查收否领取过
      http.post(
        `${API.home}/sys/redPacket/split`,
        {
          action: 'check',
          share_code
        }
      ).then(res => {
        const {code, data} = res.data;
        if(code === 200) {

          // is_overdue	红包是否过期 0-否 1-是
          if(data.is_overdue) {
            this.setState({
              type: 7
            });
          }else {

xuzhenghua committed
168
            // is_receive	是否领取过 0-否 1-是
169 170 171 172
            if(data.is_receive) {
              this.judgeReceiveStatus(data);
            }else {
              this.setState({
173
                type: browser.isWeixin? 2 : 3
174 175 176 177 178 179 180 181 182 183 184 185 186
              });
            }
          }
        }
        if(code === 4030 || code === 4040) {
          this.setState({
            type: browser.isWeixin? 2 : 3
          });
        }
      });
    }
  }

187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
  // 选择区号后进入
  judgePopupTypeFromCountry = () => {
    const { country } = this.props;
    const { shareInfo } = this.state;
    if(country.code) {
      this.setState({
        country,
        shareInfo: Object.assign({}, shareInfo, {
          share_code: country.code
        })
      });

      // 检查收否领取过
      http.post(
        `${API.home}/sys/redPacket/split`,
        {
          action: 'check',
          share_code: country.code
        }
      ).then(res => {
        console.log(res);
        const { code, data } = res.data;
        if(code === 200) {

xuzhenghua committed
211
          // is_receive	是否领取过 0-否 1-是
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
          if(data.is_receive) {
            this.judgeReceiveStatus(data, 8);
          }else {
            this.setState({
              type: 3
            });
          }

          // 清除
          this.props.delCountryNum();
        }
      })
    }
  }


228
  // 判断领取状态--领取后
229 230 231 232 233 234 235 236 237 238 239
  judgeReceiveStatus = (data, bindType=4) => {
    let txt = '';
    let desc = '';

    // receive_type 领取类型 1自己 2别人
    if(data.receive_type === 1) {
      desc = '越多好友领取,你所得越多!';
    }
    if(data.receive_type === 2) {
      desc = '每天只能帮好友领取一次哦~';
    }
240

FE committed
241 242 243 244 245 246 247
    // is_overdue	红包是否过期 0-否 1-是
    if(data.is_overdue) {
      txt = data.red_packet_type === 1? `您已经领过该红包 ${data.amount}元现金!`: `您已经领过该红包 ${data.amount}元代金券碎片!`;
    }else {
      txt = data.red_packet_type === 1? `今日已领取${data.amount}元现金!`: `今日已领取${data.amount}元代金券碎片!`;
    }

248 249 250 251 252 253 254 255 256 257 258 259
    // receive_status 领取状态 1-已领取 2-已领取未绑定 3-已失效
    if(data.receive_status === 1) {
      this.setState({
        type: 9,
        doneInfo: {
          status: 1,
          txt,
          desc
        }
      });
    }else if(data.receive_status === 2) {
      this.setState({
260
        type: bindType,
261 262 263 264 265 266 267 268 269 270 271 272 273
        money: data.amount,
        endTime: data.end_time
      });
      this.startCountDown();
    }else if(data.receive_status === 3) {
      this.setState({
        type: 9,
        doneInfo: {
          status: 2,
          txt: '手机号绑定超时,红包已失效!',
          desc
        }
      });
FE committed
274 275 276 277 278
    }
  }

  // 绑定时间
  startCountDown = () => {
FE committed
279 280 281
    if(this.countdownTimer) {
      window.clearInterval(this.countdownTimer);
    }
FE committed
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
    const { endTime } = this.state;
    let time = endTime;
    let minutes = 0;
    let seconds = 0;
    this.countdownTimer = window.setInterval(() => {
      if (time <= 0) {
        window.clearInterval(this.countdownTimer);
        this.setState({
          endTime: 0
        });
      }
      time -= 1;
      minutes = `${Math.floor(time / 60)}`.padStart(2, 0);
      seconds = `${(time % 60)}`.padStart(2, 0);
      this.setState({
        countdown: `${minutes}${seconds}秒`
      });
    }, 1000)
  }

FE committed
302
  // 获取分享信息
FE committed
303
  handleToShare = () => {
FE committed
304 305 306 307 308 309 310 311
    const { history, userInfo } = this.props;
    if(browser.isWeixin) {
      this.setState({
        type: 2
      });
      history.push(`/detail?id=${getParam('id')}&wechat=1`);
    }else {
      if(userInfo && userInfo.uid) {
312 313 314 315 316 317 318 319 320
        // 领取好友的后,再领取自己的 share_code 未更新
        http.get(`${API.home}/sys/redPacket/shareUrl/${getParam('id')}`).then(res => {
          const { code, data } = res.data;
          if(code === 200) {
            this.setState({
              shareInfo: data,
              type: 1
            });
          }
FE committed
321 322 323
        });
      }else {
        history.push('/passport/login');
FE committed
324
      }
FE committed
325
    }
FE committed
326 327
  }

FE committed
328 329 330 331 332 333 334 335 336 337 338 339
  // 提示关注公众号
  openTip = () => {
    const { shareInfo } = this.state;

    // is_follow 是否关注公众号,0否,1是
    if(!shareInfo.is_follow) {
      this.setState({
        type: 11
      });
    }
  }

FE committed
340
  // 拆红包
FE committed
341 342 343 344 345 346 347 348 349 350 351 352 353
  handleToOpen = () => {
    const { history } = this.props;
    const { shareInfo: { share_code='' } } = this.state;
    http.post(
      `${API.home}/sys/redPacket/split`,
      {
        action: 'receive',
        share_code
      }
    ).then(res => {
      const { code, data } = res.data;
      if(code === 200) {

354 355 356
        // is_receive	是否领取过 0-否 1-是
        if(data.is_receive) {
          this.judgeReceiveStatus(data);
FE committed
357 358
        }else {

359 360 361 362 363 364 365
          // red_packet_type 红包类型 1-现金 2-代金券
          if(data.red_packet_type === 2) {
            this.setState({
              type: 6,
              money: data.amount
            });
          }else if(data.red_packet_type === 1) {
FE committed
366 367 368

            // receive_status 领取状态 1-已领取 2-已领取未绑定 3-已失效
            if(data.receive_status === 1) {
369 370 371 372 373 374 375 376 377 378
              if(data.red_packet_type === 1) {
                this.setState({
                  type: 5,
                  money: data.amount
                });
              }else if(data.red_packet_type === 2 ) {
                this.setState({
                  type: 6,
                  money: data.amount
                });
FE committed
379 380 381 382 383 384 385 386 387 388 389 390 391
              }
            }else if(data.receive_status === 2) {
              this.setState({
                type: 4,
                money: data.amount,
                endTime: data.end_time
              });
              this.startCountDown();
            }else if(data.receive_status === 3) {
              this.setState({
                type: 9,
                doneInfo: {
                  status: 2,
392 393
                  txt: '手机号绑定超时,红包已失效!',
                  desc:  data.receive_type === 1? '越多好友领取,你所得越多!' : data.receive_type === 2? '每天只能帮好友领取一次哦~' : ''
FE committed
394 395 396 397
                }
              });
            }
          }
398
        }
FE committed
399
      }else if(code === 4030 || code === 4040) {
FE committed
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
        history.push('/passport/login');
      }
    })
  }

  // 关闭弹出
  handleToClose = (isOpen, isShare = false) => {
    if(isOpen) {
      const { shareInfo: { share_code='' } } = this.state;

      // 检查收否领取过
      http.post(
        `${API.home}/sys/redPacket/split`,
        {
          action: 'check',
          share_code
        }
      ).then(res => {
        const { code, data } = res.data;
        if(code === 200) {

          // is_receive	是否领取过 0-否 1-是
          if(data.is_receive) {
423
            this.judgeReceiveStatus(data);
FE committed
424
          }else {
425 426 427
            this.setState({
              type: 3
            });
FE committed
428 429 430 431 432 433 434 435 436 437 438 439 440 441
          }
        }
      });
    }else {
      if(isShare) {
        const { history } = this.props;
        history.push(`/detail?id=${getParam('id')}`);
      }
      this.setState({
        type: 0
      });
    }
  }

442 443 444 445 446 447 448 449 450 451
  // 微信内点击蒙层
  clickMask = () => {
    const { type } = this.state;
    if(type === 2) {
      this.setState({
        type: 0
      });
    }
  }

FE committed
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468
  getCaptchaInstance = instance => {
    this.setState({
      captchaInstance: instance
    });
  }

  onVerify = (err, data) => {
    if (err) {
      console.log(err);
    } else {
      this.setState({
        validate: data.validate
      });
    }
  }

  handleToSend = ({tel, code}) => {
FE committed
469
    let { validate, seconds, isFirst, isTimer, captchaInstance, country: {num = '86'} } = this.state;
FE committed
470 471 472 473 474 475 476 477 478 479 480 481
    if(validate) {
      if (!isFirst) {
        Toast.info('请重新进行滑块验证', 2, null, false);
        captchaInstance.refresh();
        this.setState({
            isFirst: true
        });
        return
      }
      if(!isTimer) {
        if (!tel) {
          Toast.info('手机号码不能为空', 2, null, false);
482 483
        }else if(!/^\d+$/.test(tel)) {
        // }else if (!validateTel(tel)) {
FE committed
484 485 486 487 488 489 490
          Toast.info('请输入正确格式的手机号码', 2, null, false);
        }else {

          // 获取验证码
          http.post(
            `${API['passport-api']}/m/personal/bindPhoneSendCode`,
            {
FE committed
491
              area_code: `00${num}`,
FE committed
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558
              phone_num: tel
            }
          ).then(res => {
            const { errno, msg } = res.data;
            if(errno === 200) {
              Toast.info('验证码发送成功', 2, null, false);

              // 倒计时
              this.timer = window.setInterval(() => {
                if (seconds <= 0) {
                  window.clearInterval(this.timer);
                  this.setState({
                    isTimer: false,
                    seconds: 60
                  });
                }else {
                  this.setState({
                    isTimer: true,
                    seconds: --seconds
                  });
                }
              }, 1000);

              // 滑块
              this.setState({
                isFirst: false
              })
            }else {
              Toast.info(msg, 2, null, false);
            }
          })
        }
      }
    }
    return false;
  }

  // 绑定后领取
  receviceAfterBind = () => {
    http.get(`${API.home}/sys/red_packet/receive`).then(res => {
      const { code, data, msg } = res.data;
      if(code === 200) {
        // receive_status 领取状态 1-已领取 2-已领取未绑定 3-已失效
        if(data.receive_status === 1) {
          if(data.red_packet_type === 1) {
            this.setState({
              type: 5,
              money: data.amount
            });
          }else if(data.red_packet_type === 2 ) {
            this.setState({
              type: 6,
              money: data.amount
            });
          }
        }else if(data.receive_status === 2) {
          this.setState({
            type: 4,
            money: data.amount,
            endTime: data.end_time
          });
          this.startCountDown();
        }else if(data.receive_status === 3) {
          this.setState({
            type: 9,
            doneInfo: {
              status: 2,
559 560
              txt: '手机号绑定超时,红包已失效!',
              desc:  data.receive_type === 1? '越多好友领取,你所得越多!' : data.receive_type === 2? '每天只能帮好友领取一次哦~' : ''
FE committed
561 562 563 564 565 566 567 568 569 570 571
            }
          });
        }
      }else {
        Toast.info(msg, 2, null, false);
      }
    })
  }

  // 绑定手机
  toContinueBind = (isValid = 1) => {
FE committed
572
    const { accountInfo: { tel, code}, country: {num = '86'}  } = this.state;
FE committed
573 574
    // is_valid	是否验证 1:验证(默认),0不验证
    http.post(
xuzhenghua committed
575
      `${API['passport-api']}/m/personal/bindPhone`,
FE committed
576
      {
FE committed
577
        area_code: `00${num}`,
FE committed
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603
        phone_num: tel,
        code: code,
        type: 1,
        is_valid: isValid
      }
    ).then(res => {
      const { errno, data, msg } = res.data;
      if(errno === 200 ) {
        if(isValid) {
          if(data.tip_info) {
            this.setState({
              type: 10,
              bindInfo: data.tip_info
            })
          }else {
            this.receviceAfterBind();
          }
        }else {
          this.receviceAfterBind();
        }
      }else {
        Toast.info(msg, 2, null, false);
      }
    });
  }

zhanghaozhe committed
604 605 606 607

  //设置统计信息
  setRelativeCookie = () => {
    const config = {path: '/', domain: '.julyedu.com'}
zhanghaozhe committed
608
    cookie.set('share_code', getParam('share_code') ? getParam('share_code') : 'share_code', config)
zhanghaozhe committed
609 610
  }

FE committed
611 612
  render() {
    // console.log(this.props);
FE committed
613
    const { history, userInfo } = this.props;
xuzhenghua committed
614 615 616 617 618 619
    const {
      type,
      isCopy,
      validate,
      isTimer,
      seconds,
FE committed
620
      shareInfo: {
621 622
        command = '',
        share_code = ''
xuzhenghua committed
623 624
      },
      money,
FE committed
625 626 627
      doneInfo,
      countdown,
      endTime,
628 629
      bindInfo,
      country
FE committed
630 631
    } = this.state;
    const cls = classnames('popup-mask',{
632
      'popup-mask--no': type !== 2
FE committed
633 634 635 636 637 638 639 640 641 642 643
    });
    return (
      <>
        <div className="red-packet">
          <p className="red-packet__title">分享课程给好友,你和好友都可以领红包哦〜</p>
          <button className="red-packet__button" onClick={this.handleToShare}>分享领红包</button>
        </div>

        {/* popup */}
        {
          type !== 0 &&
644
          <div className={cls} onClick={this.clickMask}>
FE committed
645 646 647

            {/* wechat */}
            {
xuzhenghua committed
648
              type == 2 &&
FE committed
649 650
              <div className="pupup-wechat">
                <h4 className="popup-wechat__title">当前环境不支持领红包活动</h4>
FE committed
651
                <p className="popup-wechat__desc">请点击右上角“ ··· ”,选择在浏览器中打开 然后参与活动!</p>
FE committed
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666
                <i className="popup-wechat__icon"></i>
              </div>
            }

            {/* wechat--no */}
            {
              type === 1 &&
              <div className="popup-password">
                <div className="popup-password__content">
                  <h4 className="popup-password__header">复制口令发送给好友</h4>
                  <div className="popup-password__body">
                    <p id="password" className="popup-passowrd__info">
                      {command.length > 16? `${command.substr(0, 16)}...` : command}
                    </p>
                    {!isCopy
FE committed
667
                      ? userInfo && userInfo.uid
FE committed
668
                      ? (
xuzhenghua committed
669
                        <CopyToClipboard
FE committed
670 671 672 673
                          text={command}
                          onCopy={() => this.setState({
                            isCopy: true
                          })}
674
                        >
FE committed
675 676
                          <button className="popup-password__button--copy">复制口令</button>
                        </CopyToClipboard>
677
                      )
FE committed
678
                      : (
xuzhenghua committed
679 680
                          <button
                            className="popup-password__button--copy"
FE committed
681
                            onClick={() => {
682
                              window.localStorage.setItem('redpacket-click', 'copy');
FE committed
683 684 685 686
                              history.push('/passport/login');
                            }}
                          >复制口令</button>
                        )
FE committed
687 688 689 690 691 692 693 694
                      : <p className="popup-password__success">复制成功,快发送给好友吧~</p>
                    }
                  </div>
                  <p className="popup-password__footer">
                    好友领取红包后,你将获得同样奖励。<br />
                    自己也可以领取哦~
                  </p>
                </div>
xuzhenghua committed
695 696
                <i
                  className="popup-password__button--close iconfont iconiconfront-2"
697 698
                  onClick={() => {
                    if(getParam('wechat') === '1') {
699 700 701 702 703 704 705
                      if(userInfo && userInfo.uid) {
                        this.handleToClose(true);
                        history.push(`/detail?id=${getParam('id')}`);
                      }else {
                        this.setState({
                          type: 3
                        });
706
                        window.localStorage.setItem('redpacket-click', 'split');
707
                      }
708 709 710
                    }else {
                      this.handleToClose(true);
                    }
FE committed
711 712 713
                    this.setState({
                      isCopy: false
                    });
714
                  }}
FE committed
715 716 717 718
                />
              </div>
            }

xuzhenghua committed
719
            {/* red-packet--close */}
FE committed
720 721
            {
              type === 3 &&
xuzhenghua committed
722
              <Packet
FE committed
723 724 725
                type={3}
                packetInfo={{
                  title: '七月在线给你发了个红包~'
xuzhenghua committed
726

FE committed
727 728 729 730 731 732 733 734 735
                }}
                handleToClose={() => this.handleToClose(false)}
                handleToOpen={this.handleToOpen}
              />
            }

            {/* red-packet--open */}
            {
              type === 4 &&
xuzhenghua committed
736
              <Packet
FE committed
737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
                type={4}
                packetInfo={{
                  money,
                  tip: ['为了您的资金安全,请于5分钟之内绑定手机号,超时红包将失效'],
                  btn: {
                    txt: `立即绑定(${countdown})`,
                    onClick: () => {
                      this.setState({
                        type: 8
                      });
                    }
                  }
                }}
                handleToClose={() => this.handleToClose(false)}
              />
            }

            {/* red-packet--money success */}
            {
              type === 5 &&
xuzhenghua committed
757
              <Packet
FE committed
758 759 760 761 762 763 764 765 766 767 768 769 770 771
                type={5}
                packetInfo={{
                  money,
                  tip: ['可前往【七月在线】APP','- 账户资金中提现'],
                  btn: {
                    txt: '获取更多奖励',
                    onClick: () => {
                      history.push('/ShareCourse');
                    }
                  }
                }}
                handleToClose={() => {
                  const isShare = getParam('share_code')? true : false;
                  this.handleToClose(false, isShare);
FE committed
772
                  this.openTip();
FE committed
773 774 775 776 777 778 779
                }}
              />
            }

            {/* red-packet--fragment success */}
            {
              type === 6 &&
xuzhenghua committed
780
              <Packet
FE committed
781 782 783 784 785 786 787 788 789 790 791 792 793 794
                type={6}
                packetInfo={{
                  money,
                  tip: ['可前往【七月在线】APP','- 我的优惠券中合成代金券'],
                  btn: {
                    txt: '获取更多奖励',
                    onClick: () => {
                      history.push('/ShareCourse');
                    }
                  }
                }}
                handleToClose={() => {
                  const isShare = getParam('share_code')? true : false;
                  this.handleToClose(false, isShare);
FE committed
795
                  this.openTip();
FE committed
796 797 798 799 800 801 802
                }}
              />
            }

            {/* red-packet--late 来完了 */}
            {
              type === 7 &&
xuzhenghua committed
803
              <Packet
FE committed
804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830
                type={7}
                packetInfo={{
                  btn: {
                    txt: '获取更多奖励',
                    onClick: () => {
                      history.push('/ShareCourse')
                    }
                  }
                }}
                handleToClose={() => {
                  const isShare = getParam('share_code')? true : false;
                  this.handleToClose(false, isShare);
                }}
              />
            }

            {/* form */}
            {
              type === 8 &&
              <div className="popup-form">
                <Formik
                  initialValues={{
                    tel: '',
                    code: ''
                  }}
                  validate={({tel, code}) => {
                    const errors = {};
xuzhenghua committed
831

832 833
                    // if (!validateTel(tel)) {
                    if(!/^\d+$/.test(tel)) {
FE committed
834 835 836 837 838
                      errors.tel = '请填写正确格式的手机号';
                    }
                    if (!/[0-9]{6}/.test(code)) {
                      errors.code = '请输入验证码';
                    }
xuzhenghua committed
839

FE committed
840 841 842 843 844 845 846 847 848 849 850 851 852 853
                    return errors;
                  }}
                  onSubmit={(values, { setStatus, setSubmitting }) => {
                    this.setState({
                      accountInfo: {
                        ...values
                      }
                    });
                    this.toContinueBind();
                  }}
                  render={({values: {tel, code}, errors}) => (
                    <Form className="popup-form__content">
                      <h4 className="popup-form__title">绑定手机号</h4>
                      <div className="popup-form__item">
xuzhenghua committed
854
                        <Link
xuzhenghua committed
855
                          className="popup-form__button--num"
xuzhenghua committed
856
                          to={`/country?id=${getParam('id')}&share_code=${share_code}`}>
857
                          +{country.num}
xuzhenghua committed
858 859
                          <i className="iconfont iconiconfront-69"/>
                        </Link>
FE committed
860 861 862 863
                        <Field
                          name="tel"
                          render={({field}) => {
                            return (
xuzhenghua committed
864
                              <input
FE committed
865
                                {...field}
xuzhenghua committed
866
                                className="popup-form__ipt"
FE committed
867 868 869 870 871 872 873 874 875
                                data-bdrs="0 6px 6px 0"
                                data-type="tel"
                                type="text"
                                placeholder="请填写手机号"
                              />
                            );
                          }}
                        />
                      </div>
xuzhenghua committed
876
                      <Captcha
FE committed
877 878 879 880 881 882 883 884 885 886 887 888 889
                        mrBtm={15}
                        getInstance={this.getCaptchaInstance}
                        onVerify={this.onVerify}
                      />
                      {
                        endTime === 0? (
                          <>
                            <div className="popup-form__item">
                              <p className="popup-form__tip">
                                <i className="iconfont icondanseshixintubiao-8"></i>
                                绑定超时,红包已失效!
                              </p>
                            </div>
xuzhenghua committed
890 891
                            <button
                              className="popup-packet__button--bundle"
FE committed
892 893 894 895 896 897 898 899 900 901 902 903 904 905
                              data-status="do"
                              type="button"
                              onClick={() => {
                                history.push('/ShareCourse');
                              }}
                            >获取更多奖励</button>
                          </>
                        ) : (
                          <>
                            <div className="popup-form__item">
                              <Field
                                name="code"
                                render={({field}) => {
                                  return (
xuzhenghua committed
906
                                    <input
FE committed
907
                                      {...field}
908
                                      className="popup-form__ipt popup-form__ipt--left"
FE committed
909 910 911 912 913 914
                                      type="text"
                                      placeholder="输入验证码"
                                    />
                                  );
                                }}
                              />
xuzhenghua committed
915
                              <button
FE committed
916 917 918 919 920 921 922 923 924 925
                                className="popup-form__button--code"
                                data-status={(validate && !isTimer)? 'do': ''}
                                type="button"
                                onClick={() => this.handleToSend({tel, code})}
                              >
                                {
                                  isTimer? `重新发送${seconds}s` : '发送验证码'
                                }
                              </button>
                            </div>
xuzhenghua committed
926 927
                            <button
                              className="popup-packet__button--bundle"
FE committed
928 929 930 931 932 933 934 935 936 937 938
                              data-status={(tel && code && isEmpty(errors))? 'do': 'done'}
                              type="submit"
                            >
                              {`完成绑定(${countdown})`}
                            </button>
                          </>
                        )
                      }
                    </Form>
                  )}
                />
xuzhenghua committed
939 940
                <i
                  className="popup-password__button--close iconfont iconiconfront-2"
FE committed
941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957
                  onClick={() => this.handleToClose(false)}
                />
              </div>
            }

            {/* 领取后的状态 */}
            {
              type === 9 &&
              <div className="popup-done">
                <div className="popup-done__content">
                  <h4 className={classnames("popup-done__title", {'popup-done__title--overtime': doneInfo.status === 2})}>
                    {
                      doneInfo.status === 2 &&
                      <i className="iconfont icondanseshixintubiao-8"></i>
                    }
                    {doneInfo.txt}
                  </h4>
958
                  <p className="popup-done__desc">{doneInfo.desc}</p>
xuzhenghua committed
959 960
                  <button
                    className="popup-packet__button--bundle"
FE committed
961 962 963 964 965 966 967
                    data-status="do"
                    type="submit"
                    onClick={() => {
                      history.push('/ShareCourse');
                    }}
                  >获取更多奖励</button>
                </div>
xuzhenghua committed
968 969
                <i
                  className="popup-password__button--close iconfont iconiconfront-2"
FE committed
970 971 972 973 974 975 976 977 978 979
                  onClick={() => {
                    const isShare = getParam('share_code')? true : false;
                    this.handleToClose(false, isShare);
                  }}
                />
              </div>
            }

            {/* 手机号绑定提示  */}
            {
xuzhenghua committed
980
              type === 10 &&
FE committed
981 982 983 984 985 986 987 988
              <div className="popup-bind">
                <div className="popup-bind__content">
                  <h4 className="popup-bind__title">绑定确认</h4>
                  <p className="popup-bind__desc">该手机号已绑定到以下账号,继续绑定将解除以下绑定状态</p>
                  <ul className="popup-bind__list">
                    {
                      bindInfo['email'] &&
                      <li className="popup-bind__account">
xuzhenghua committed
989

FE committed
990 991 992 993 994 995 996 997 998 999
                        {/* 邮箱 */}
                        <i className="iconfont iconduanxin"></i>
                        <p className="popup-bind__account--name">{bindInfo['email']}</p>
                      </li>
                    }
                    {
                      bindInfo['wechat_nickname'] &&
                      <li className="popup-bind__account">

                        {/* wechat */}
FE committed
1000
                        <i className="icon-wachat"></i>
FE committed
1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023
                        <p className="popup-bind__account--name">{bindInfo['wechat_nickname']}</p>
                      </li>
                    }
                    {
                      bindInfo['qq_nickname'] &&
                      <li className="popup-bind__account">

                      {/* qq */}
                      <i className="icon-qq"></i>
                      <p className="popup-bind__account--name">{bindInfo['qq_nickname']}</p>
                    </li>
                    }
                    {
                      bindInfo['sina_nickname'] &&
                      <li className="popup-bind__account">

                        {/* 微博 */}
                        <i className="icon-sina"></i>
                        <p className="popup-bind__account--name">{bindInfo['sina_nickname']}</p>
                      </li>
                    }
                  </ul>
                  <div className="popup-bind__button">
xuzhenghua committed
1024 1025
                    <button
                    className="popup-bind__button--cancle"
FE committed
1026
                    onClick={() => this.handleToClose(false)}>取消</button>
xuzhenghua committed
1027 1028
                    <button
                    className="popup-bind__button--confirm"
FE committed
1029 1030 1031
                    onClick={() => this.toContinueBind(0)}>继续绑定</button>
                  </div>
                </div>
xuzhenghua committed
1032 1033
                <i
                  className="popup-password__button--close iconfont iconiconfront-2"
FE committed
1034 1035 1036 1037
                  onClick={() => this.handleToClose(false)}
                />
              </div>
            }
FE committed
1038 1039 1040 1041 1042 1043

            {/* 关注公众号 */}
            {
              type === 11 &&
              <FollowQRcode toClose={() => this.handleToClose(false)} />
            }
FE committed
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094
          </div>
        }
      </>
    )
  }
}

const Packet = ({type, packetInfo, handleToClose, handleToOpen }) => {
  const cls_content = classnames(
    'popup-packet__content',
    {
      'popup-packet__content--open': type === 4,
      'popup-packet__content--money': type === 5,
      'popup-packet__content--fragment': type === 6,
      'popup-packet__content--late': type === 7,
    }
  );
  const {money, tip=[], btn} = packetInfo;
  return (
    <div className={classnames('popup-packet')}>
      <div className={cls_content}>
        {
          type === 3 &&
          <>
            <p className="popup-packet__title">七月在线给你发了个红包~</p>
            <button className="popup-packet__button--split" onClick={handleToOpen} />
          </>
        }
        {
          (type === 4 || type === 5 || type === 6)&&
          <>
            <h4 className="popup-packet__label">恭喜您获得</h4>
            <p className="popup-packet__value">
              {money}
              <span className="popup-packet__value--unit"></span>
            </p>
            <p className="popup-packet__tip">
              {
                tip.map((item, index) => {
                  if(index !== (tip.lenght - 1)) {
                    return (
                      <>
                        {item}
                        <br />
                      </>
                    )
                  }
                  return item;
                })
              }
            </p>
xuzhenghua committed
1095
            <button
FE committed
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110
              className="popup-packet__button--bundle"
              onClick={btn.onClick}
            >
              {btn.txt}
            </button>
          </>
        }
        {
          type === 7 &&
          <>
            <h4 className="popup-packet__label">您来晚了!</h4>
            <p className="popup-packet__value">
              红包仅能当日领取,下次<br />
              早点来哦~
            </p>
xuzhenghua committed
1111
            <button
FE committed
1112 1113 1114 1115 1116 1117 1118 1119
              className="popup-packet__button--bundle"
              onClick={btn.onClick}
            >
              {btn.txt}
            </button>
          </>
        }
      </div>
xuzhenghua committed
1120 1121
      <i
        className="popup-password__button--close iconfont iconiconfront-2"
FE committed
1122 1123 1124 1125 1126 1127 1128
        onClick={handleToClose}
      />
    </div>
  );
}

export default RedPacket;