|
@@ -4,24 +4,36 @@ import { useSelector } from 'react-redux'
|
4
|
4
|
import withLayout from '@/layout'
|
5
|
5
|
import { ScrollView, Input, Image } from '@tarojs/components'
|
6
|
6
|
import { getImgURL } from '@/utils/image'
|
7
|
|
-import { fetch } from '@/utils/request'
|
8
|
|
-import login from '@/utils/login'
|
9
|
|
-import { API_EDIT_AGENT } from '@/constants/api'
|
|
7
|
+import { fetch, uploadFiles } from '@/utils/request'
|
|
8
|
+import { UPDATE_USER_INFO, ROLE_CODE } from '@/constants/user'
|
|
9
|
+import { API_EDIT_AGENT, API_UPDATE_PHOTO } from '@/constants/api'
|
|
10
|
+import store from '@/store'
|
10
|
11
|
import '@/assets/css/iconfont.css'
|
11
|
12
|
import './index.scss'
|
12
|
13
|
|
13
|
14
|
export default withLayout(() => {
|
14
|
15
|
|
|
16
|
+ const { dispatch } = store
|
|
17
|
+
|
15
|
18
|
const user = useSelector(state => state.user)
|
16
|
19
|
const [UserInfo, setUserInfo] = useState({})
|
|
20
|
+ const [UserRole, setUserRole] = useState(null) // 1-普通用户 2-经纪人 3-置业顾问 4-驻场管理
|
17
|
21
|
const [FormData, setFormData] = useState({
|
18
|
22
|
name: '',
|
19
|
23
|
phone: ''
|
20
|
24
|
})
|
21
|
25
|
|
|
26
|
+ useEffect(() => {
|
|
27
|
+ if (user?.userInfo?.person?.personId) {
|
|
28
|
+ const person = user.userInfo.person
|
|
29
|
+ 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)
|
|
30
|
+ }
|
|
31
|
+ }, [user])
|
|
32
|
+
|
22
|
33
|
useEffect(() => {
|
23
|
34
|
setUserInfo(user?.userInfo?.person)
|
24
|
|
- setFormData({name: user?.userInfo?.person.name, phone: user?.userInfo?.person.phone})
|
|
35
|
+ console.log(user)
|
|
36
|
+ setFormData({ name: user?.userInfo?.person.name, phone: user?.userInfo?.person.phone })
|
25
|
37
|
}, [user])
|
26
|
38
|
|
27
|
39
|
const Save = () => {
|
|
@@ -30,16 +42,37 @@ export default withLayout(() => {
|
30
|
42
|
title: '修改成功',
|
31
|
43
|
icon: 'none'
|
32
|
44
|
})
|
33
|
|
- login({path: '', scene: ''})
|
|
45
|
+ dispatch({ type: UPDATE_USER_INFO, payload: { name: FormData.name, phone: FormData.phone } })
|
|
46
|
+ // login({ path: '', scene: '' })
|
34
|
47
|
})
|
35
|
48
|
}
|
36
|
49
|
|
37
|
50
|
const FormChange = (key, e) => {
|
38
|
|
- let Data = {...FormData}
|
|
51
|
+ let Data = { ...FormData }
|
39
|
52
|
Data[key] = e.detail.value
|
40
|
53
|
setFormData(Data)
|
41
|
54
|
}
|
42
|
55
|
|
|
56
|
+ const ToUploadImg = () => {
|
|
57
|
+ if(UserRole - 0 === 3) {
|
|
58
|
+ Taro.chooseImage({
|
|
59
|
+ count: 1,
|
|
60
|
+ success: function (res) {
|
|
61
|
+ if (res.errMsg === 'chooseImage:ok') {
|
|
62
|
+ Taro.showToast({ title: '正在上传...', icon: 'loading', mask: true, duration: 10000 })
|
|
63
|
+ uploadFiles(res.tempFilePaths).then((subRes) => {
|
|
64
|
+ fetch({ url: API_UPDATE_PHOTO, payload: { photoUrl: subRes[0] }, method: 'put' }).then(() => {
|
|
65
|
+ Taro.hideToast()
|
|
66
|
+ Taro.showToast({ title: '修改成功', icon: 'none', duration: 2000 })
|
|
67
|
+ dispatch({ type: UPDATE_USER_INFO, payload: { userPhoto: subRes[0] } })
|
|
68
|
+ })
|
|
69
|
+ })
|
|
70
|
+ }
|
|
71
|
+ }
|
|
72
|
+ })
|
|
73
|
+ }
|
|
74
|
+ }
|
|
75
|
+
|
43
|
76
|
return (
|
44
|
77
|
<view className='Page UserInfo'>
|
45
|
78
|
|
|
@@ -47,10 +80,10 @@ export default withLayout(() => {
|
47
|
80
|
<view className='PageContent'>
|
48
|
81
|
|
49
|
82
|
<text>头像</text>
|
50
|
|
- <view className='FormLine flex-h'>
|
|
83
|
+ <view className='FormLine flex-h' onClick={ToUploadImg}>
|
51
|
84
|
<view className='flex-item'>
|
52
|
85
|
<view className='Icon'>
|
53
|
|
- <Image mode='aspectFill' src={getImgURL(UserInfo.avatarurl)}></Image>
|
|
86
|
+ <Image mode='aspectFill' src={getImgURL(UserInfo.userPhoto || UserInfo.avatarurl)}></Image>
|
54
|
87
|
</view>
|
55
|
88
|
</view>
|
56
|
89
|
{/* <text className='iconfont icon-jiantouright'></text> */}
|