import { useState, useEffect } from 'react'
import { Image } from '@tarojs/components'
import withLayout from '@/layout'
import '@/assets/css/iconfont.css'
import { fetch } from '@/utils/request'
import { API_QRCODE } from '@/constants/api'
import './index.scss'

export default withLayout((props) => {

  const { person, page } = props
  const [QrCodeUrl, setQrCodeUrl] = useState(null)

  useEffect(() => {
    const payload = {
      scene: `id=${person?.personId}&from=${page.type}_share&recommender=${person?.personId}`,
      page: `pages/mine/myRecommendCode/index`
    }
    fetch({ url: API_QRCODE, payload, method: 'post' }).then((res) => {
      setQrCodeUrl(res)
    })
  }, [])

  return (
    <view className='Page myRecommendCode'>
      <Image mode='widthFix' src={QrCodeUrl}></Image>
      <text>扫一扫上面的二维码图案,成为我的客户</text>
    </view>
  )
})
