index.js 1.62 KB
Newer Older
zhanghaozhe committed
1 2
import React, { Component } from "react"
import QRCode from "qrcode"
zhanghaozhe committed
3
import { http } from "src/utils"
zhanghaozhe committed
4
import "./index.scss"
FE committed
5 6 7

class FollowBarcode extends Component {
  constructor(props) {
zhanghaozhe committed
8
    super(props)
FE committed
9
    this.state = {
zhanghaozhe committed
10 11
      url: "",
      codeUrl: "",
FE committed
12 13 14 15
    }
  }

  componentDidMount() {
zhanghaozhe committed
16 17 18 19 20 21 22 23 24 25
    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)
zhanghaozhe committed
26
          if (errno === 0) {
zhanghaozhe committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40
            this.setState({
              url: data.url,
            })
            const _this = this
            return new Promise((resolve) => {
              QRCode.toDataURL(data.url, {}, function (err, url) {
                _this.setState({
                  codeUrl: url,
                })
              })
              resolve()
            })
          }
        })
FE committed
41 42 43 44
    }
  }

  render() {
zhanghaozhe committed
45 46 47 48 49 50
    const { codeUrl } = this.state
    const {
      firendBaigainPrice,
      userInfo: { avatar },
      money,
    } = this.props
FE committed
51
    return (
zhanghaozhe committed
52 53 54 55 56 57 58 59 60
      <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
61
        <img className="bargain-popup__imgage" src={codeUrl} alt="" />
FE committed
62
      </div>
zhanghaozhe committed
63
    )
FE committed
64 65 66
  }
}

zhanghaozhe committed
67
export default FollowBarcode