AuthPhone.jsx 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import React, { useState } from 'react'
  2. import Taro from '@tarojs/taro'
  3. import { View } from '@tarojs/components'
  4. import AuthBox from './AuthBox'
  5. import useAuth from './useAuth'
  6. import './style.scss'
  7. export default (props) => {
  8. const {
  9. consultant,
  10. router,
  11. page,
  12. onCancel = (x => x),
  13. onSuccess = () => {},
  14. onError = () => {},
  15. } = props;
  16. const [loading, setLoading] = useState(false)
  17. const { updatePhoneNumber } = useAuth(consultant, router, page)
  18. const handlePhoneNumber = (detail) => {
  19. const { errMsg, ...data } = detail || {}
  20. if (errMsg === 'getPhoneNumber:ok') {
  21. setLoading(true)
  22. updatePhoneNumber(data).then(() => {
  23. setLoading(false)
  24. onSuccess()
  25. }).catch((err) => {
  26. console.error(err)
  27. setLoading(false)
  28. onError()
  29. })
  30. } else {
  31. console.error(errMsg);
  32. Taro.showToast({
  33. title: '授权手机失败',
  34. icon: 'none',
  35. duration: 2000
  36. })
  37. onCancel()
  38. }
  39. }
  40. return (
  41. <AuthBox
  42. title='授权手机'
  43. openType='getPhoneNumber'
  44. loading={loading}
  45. onGetPhoneNumber={handlePhoneNumber}
  46. onCancel={onCancel}
  47. >
  48. <View>请确认授权手机号,以便为您提供更优质的服务内容。</View>
  49. </AuthBox>
  50. )
  51. }