index.js 1.53 KB
Newer Older
FE committed
1 2 3 4 5 6 7 8 9 10
import React, { Component } from 'react';
import QRCode from 'qrcode';
import { http } from "@/utils"
import './index.scss';

class FollowBarcode extends Component {

  constructor(props) {
    super(props);
    this.state = {
11 12
      url: '',
      codeUrl: ''
FE committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26
    }
  }

  componentDidMount() {
    console.log(this.props);
    const { userInfo: { uid = '' } } = this.props;
    if(uid) {
      http.get(`${API['base-api']}/wx/user_temporary_qrcode/${uid}`).then((res) => {
        const { errno, data } = res.data;
        console.log(res);
        if (errno == 0) {
          this.setState({
            url: data.url
          });
FE committed
27
          const _this = this;
FE committed
28 29
          return new Promise(resolve => {
            QRCode.toDataURL(data.url, {}, function (err, url) {
FE committed
30
              _this.setState({
FE committed
31
                codeUrl: url
FE committed
32
              });
FE committed
33 34 35 36 37 38 39 40 41
            });
            resolve();
          });
        }
      });
    }
  }

  render() {
42
    const { codeUrl } = this.state;
FE committed
43 44 45 46 47 48 49 50 51
    const { firendBaigainPrice, userInfo: { avatar }, money } = this.props;
    return (
      <div className='bargain-popup__barcode'>
        <i className='bargain-popup__avatar' style={{backgroundImage: `url(${avatar})`}} />
        {
          firendBaigainPrice &&
          <p className='bargain-popup__title'>谢谢你帮我砍了{money}元!</p>
        }
        <p className='bargain-popup__desc'>关注公众号,可以再砍一刀哦~</p>
FE committed
52
        <img className="bargain-popup__imgage" src={codeUrl} alt="" />
FE committed
53 54 55 56 57 58
      </div>
    );
  }
}

export default FollowBarcode;