1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { useState, useEffect } from 'react'
  2. import { Image } from '@tarojs/components'
  3. import withLayout from '@/layout'
  4. import { fetch } from '@/utils/request'
  5. import { API_QRCODE } from '@/constants/api'
  6. import { getImgURL, save2Album } from '@/utils/image'
  7. import Taro from '@tarojs/taro'
  8. import '@/assets/css/iconfont.css'
  9. import './index.scss'
  10. export default withLayout((props) => {
  11. const { person, page } = props
  12. const [QrCodeUrl, setQrCodeUrl] = useState(null)
  13. useEffect(() => {
  14. const payload = {
  15. scene: `id=${person?.personId}&from=${page.type}_share&recommender=${person?.personId}`,
  16. page: `pages/consultant/myHomepage/index`
  17. }
  18. fetch({ url: API_QRCODE, payload, method: 'post' }).then((res) => {
  19. setQrCodeUrl(res)
  20. })
  21. }, [])
  22. const Save = () => {
  23. Taro.downloadFile({
  24. url: QrCodeUrl,
  25. success: function(res) {
  26. save2Album(res.tempFilePath).then(() => {
  27. Taro.showToast({ title: '保存成功', icon: 'none' })
  28. })
  29. },
  30. fail: function(err) {
  31. console.error(err)
  32. Taro.showToast({
  33. title: '操作失败, 您可以试试预览保存',
  34. icon: 'none'
  35. })
  36. }
  37. })
  38. }
  39. const PreviewImage = () => {
  40. Taro.previewImage({
  41. current: QrCodeUrl,
  42. urls: [QrCodeUrl],
  43. showmenu: true,
  44. })
  45. }
  46. return (
  47. <view className='Page myRecommendCode'>
  48. <view className='CodeContent'>
  49. <view>
  50. <view className='flex-h'>
  51. <view className='Icon'>
  52. <Image mode='scaleToFill' src={getImgURL(person?.userPhoto || person?.avatarurl)}></Image>
  53. </view>
  54. <text>{person?.name}</text>
  55. </view>
  56. <Image mode='widthFix' src={QrCodeUrl} onClick={PreviewImage}></Image>
  57. <text>扫一扫上面的二维码图案,成为我的客户</text>
  58. </view>
  59. </view>
  60. <view className='Btn'>
  61. <text onClick={Save}>保存到手机</text>
  62. </view>
  63. </view>
  64. )
  65. })