123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import { useState, useEffect } from 'react'
  2. import { useSelector } from 'react-redux'
  3. import withLayout from '@/layout'
  4. import { ScrollView, Image } from '@tarojs/components'
  5. import Taro from '@tarojs/taro'
  6. import '@/assets/css/iconfont.css'
  7. import { fetch } from '@/utils/request'
  8. import { API_PUT_REGISTERCONSULTANT } from '@/constants/api'
  9. import { getImgURL } from '@/utils/image'
  10. import { UPDATE_USER_INFO, ROLE_CODE } from '@/constants/user'
  11. import store from '@/store'
  12. import './index.scss'
  13. import MineMenuList from './tabData'
  14. const defaultRuleImage = 'https://yz-websit.oss-cn-hangzhou.aliyuncs.com/xlk/index-icon18.jpg'
  15. const version = `版本: ${Version}`
  16. const copyRight = `云致科技 @ ${(new Date()).getFullYear()}`
  17. export default withLayout(() => {
  18. const user = useSelector(state => state.user)
  19. const [UserRole, setUserRole] = useState(null) // 1-普通用户 2-经纪人 3-置业顾问 4-驻场管理
  20. const [MenuList, setMenuList] = useState([])
  21. const { dispatch } = store
  22. useEffect(() => {
  23. if (user?.userInfo?.person?.personId) {
  24. const person = user.userInfo.person
  25. setUserRole(person.personType === ROLE_CODE.CUSTOMER || person.personType === ROLE_CODE.DRIFT ? 1 : person.personType === ROLE_CODE.CHANNEL_AGENT ? 2 : person.personType === ROLE_CODE.CONSULTANT ? 3 : 4)
  26. }
  27. }, [user])
  28. useEffect(() => {
  29. if (UserRole !== null) {
  30. setMenuList(UserRole === 1 ? MineMenuList.User : UserRole === 2 ? MineMenuList.Broker : UserRole === 3 ? MineMenuList.Adviser : MineMenuList.Resident)
  31. }
  32. }, [UserRole])
  33. const MenuClick = (router) => {
  34. return () => {
  35. if (router === 'propertyConsultant') {
  36. fetch({ url: API_PUT_REGISTERCONSULTANT, method: 'put' }).then(() => {
  37. Taro.showToast({
  38. title: '匹配成功',
  39. icon: 'none',
  40. duration: 2000
  41. })
  42. dispatch({ type: UPDATE_USER_INFO, payload: { personType: 'Realty Consultant' } })
  43. setTimeout(() => {
  44. Taro.navigateBack({ delta: 1 })
  45. }, 2000)
  46. }).catch(() => {
  47. Taro.showToast({
  48. title: '匹配失败,请联系相关管理人员',
  49. icon: 'none'
  50. })
  51. })
  52. } else if (router) {
  53. Taro.navigateTo({ url: router })
  54. }
  55. }
  56. }
  57. return (
  58. <view className='Page Mine'>
  59. <ScrollView scroll-y>
  60. <view className='PageContent'>
  61. <view className='Content'>
  62. {/* 用户信息 */}
  63. <view className='UserInfo'>
  64. <view className='UserIcon'>
  65. <Image mode='aspectFill' className='centerLabel' src={getImgURL(user?.userInfo?.person?.userPhoto || user?.userInfo?.person?.avatarurl) || defaultRuleImage} />
  66. </view>
  67. <view className='OtherInfo'>
  68. <view className='Name'>
  69. <view>
  70. <text>{user?.userInfo?.person?.nickname}</text>
  71. <view>
  72. <text className='iconfont icon-bianji' onClick={() => { Taro.navigateTo({ url: `/pages/mine/userInfo/index` }) }}></text>
  73. <text onClick={() => { Taro.navigateTo({ url: `/pages/mine/userInfo/index` }) }}>个人信息资料修改</text>
  74. </view>
  75. </view>
  76. <text className='Role'>{UserRole === 1 ? '客户' : UserRole === 2 ? '经纪人' : UserRole === 3 ? '置业顾问' : '驻场管理'}</text>
  77. <text className='New'>NEW</text>
  78. <text className='iconfont icon-diqiu'></text>
  79. </view>
  80. </view>
  81. </view>
  82. {/* 用户菜单 */}
  83. <view className='MenuList'>
  84. {
  85. MenuList.map((item, index) => (
  86. <view>
  87. {
  88. item.map((subItem, subIndex) => (
  89. <view key={`MenuItem-${index}-${subIndex}`} className='flex-h' onClick={MenuClick(subItem.router)}>
  90. <view className='Icon'>
  91. <Image mode='aspectFit' className='centerLabel' src={subItem.icon} />
  92. </view>
  93. <view className='flex-item flex-h'>
  94. <text className='flex-item'>{subItem.name}</text>
  95. <text className='iconfont icon-jiantouright'></text>
  96. </view>
  97. </view>
  98. ))
  99. }
  100. </view>
  101. ))
  102. }
  103. </view>
  104. </view>
  105. </view>
  106. <view className='copyright'>
  107. <view>{version}</view>
  108. <view>{copyRight}</view>
  109. </view>
  110. </ScrollView>
  111. </view>
  112. )
  113. })