|
@@ -1,13 +1,89 @@
|
1
|
|
-import React, { useState } from 'react'
|
|
1
|
+import React, { useState, useEffect } from 'react'
|
|
2
|
+import Taro from '@tarojs/taro'
|
2
|
3
|
import Page from '@/layouts'
|
3
|
4
|
import { useModel } from '@/store'
|
|
5
|
+import { Input, Picker } from '@tarojs/components'
|
|
6
|
+import request, { apis } from '@/utils/request'
|
4
|
7
|
import '@/assets/css/reset.less'
|
5
|
8
|
import '@/assets/css/iconfont.less'
|
6
|
9
|
import './index.less'
|
7
|
10
|
|
8
|
11
|
export default function GeRenXinXi (props) {
|
9
|
12
|
|
10
|
|
- const { user } = useModel('user')
|
|
13
|
+ const { user, setUser } = useModel('user')
|
|
14
|
+ const [Name, setName] = useState(null)
|
|
15
|
+ const [Phone, setPhone] = useState(null)
|
|
16
|
+ const [Birthday, setBirthday] = useState(null)
|
|
17
|
+ const [ShowNameEdit, setShowNameEdit] = useState(false)
|
|
18
|
+ const [ShowPhoneEdit, setShowPhoneEdit] = useState(false)
|
|
19
|
+ const [ShowBirthdayEdit, setShowBirthdayEdit] = useState(false)
|
|
20
|
+ const [Sex, setSex] = useState(null)
|
|
21
|
+ const [SexList] = useState([{ id: 1, name: '男' }, { id: 2, name: '女' }])
|
|
22
|
+
|
|
23
|
+ useEffect(() => {
|
|
24
|
+ if (user !== null) {
|
|
25
|
+ setName(user.name || user.nickname)
|
|
26
|
+ setPhone(user.tel || user.phone)
|
|
27
|
+ setBirthday(user.birthday)
|
|
28
|
+ SexList.map((item, index) => {
|
|
29
|
+ if (user.sex - 0 === item.id - 0 ||user.gender - 0 === item.id - 0) {
|
|
30
|
+ setSex(index)
|
|
31
|
+ }
|
|
32
|
+ })
|
|
33
|
+ }
|
|
34
|
+ }, [user])
|
|
35
|
+
|
|
36
|
+ const NameChange = (e) => {
|
|
37
|
+ setName(e.detail.value)
|
|
38
|
+ }
|
|
39
|
+
|
|
40
|
+ const PhoneChange = (e) => {
|
|
41
|
+ setPhone(e.detail.value)
|
|
42
|
+ }
|
|
43
|
+
|
|
44
|
+ const BirthdayChange = (e) => {
|
|
45
|
+ setBirthday(e.detail.value)
|
|
46
|
+ }
|
|
47
|
+
|
|
48
|
+ const SexChange = (e) => {
|
|
49
|
+ request({ ...apis.EditUserInfo, data: { sex: SexList[e.detail.value - 0].id - 0 } }).then(() => {
|
|
50
|
+ Taro.showToast({ title: '修改成功', icon: 'none' })
|
|
51
|
+ setSex(e.detail.value - 0)
|
|
52
|
+ setUser({ ...user, sex: SexList[e.detail.value - 0].id - 0 })
|
|
53
|
+ }).catch((res) => {
|
|
54
|
+ Taro.showToast({ title: res, icon: 'none' })
|
|
55
|
+ })
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+ const EditName = () => {
|
|
59
|
+ request({ ...apis.EditUserInfo, data: { name: Name } }).then(() => {
|
|
60
|
+ setShowNameEdit(false)
|
|
61
|
+ Taro.showToast({ title: '修改成功', icon: 'none' })
|
|
62
|
+ setUser({ ...user, name: Name })
|
|
63
|
+ }).catch((res) => {
|
|
64
|
+ Taro.showToast({ title: res, icon: 'none' })
|
|
65
|
+ })
|
|
66
|
+ }
|
|
67
|
+
|
|
68
|
+ const EditPhone = () => {
|
|
69
|
+ request({ ...apis.EditUserInfo, data: { phone: Phone } }).then(() => {
|
|
70
|
+ setShowPhoneEdit(false)
|
|
71
|
+ Taro.showToast({ title: '修改成功', icon: 'none' })
|
|
72
|
+ setUser({ ...user, tel: Phone })
|
|
73
|
+ }).catch((res) => {
|
|
74
|
+ Taro.showToast({ title: res, icon: 'none' })
|
|
75
|
+ })
|
|
76
|
+ }
|
|
77
|
+
|
|
78
|
+ const EditBirthday = () => {
|
|
79
|
+ request({ ...apis.EditUserInfo, data: { birthday: Birthday } }).then(() => {
|
|
80
|
+ setShowBirthdayEdit(false)
|
|
81
|
+ Taro.showToast({ title: '修改成功', icon: 'none' })
|
|
82
|
+ setUser({ ...user, birthday: Birthday })
|
|
83
|
+ }).catch((res) => {
|
|
84
|
+ Taro.showToast({ title: res, icon: 'none' })
|
|
85
|
+ })
|
|
86
|
+ }
|
11
|
87
|
|
12
|
88
|
return (
|
13
|
89
|
<Page>
|
|
@@ -19,19 +95,93 @@ export default function GeRenXinXi (props) {
|
19
|
95
|
<image mode='aspectFill' src={user !== null ? user.avatarurl : null}></image>
|
20
|
96
|
</view>
|
21
|
97
|
</view>
|
22
|
|
- <view className='flex-h'>
|
|
98
|
+ <view className='flex-h' onClick={() => { setShowNameEdit(true) }}>
|
23
|
99
|
<text className='flex-item'>姓名</text>
|
24
|
|
- <text>{user !== null ? user.nickname : null}</text>
|
|
100
|
+ <text>{Name}</text>
|
25
|
101
|
</view>
|
26
|
102
|
<view className='flex-h'>
|
27
|
103
|
<text className='flex-item'>性别</text>
|
28
|
|
- <text>{user !== null ? user.gender - 0 === 1 ? '男' : user.sex - 0 === 2 ? '女' : null : null}</text>
|
|
104
|
+ {/* <text>{user !== null ? user.gender - 0 === 1 ? '男' : user.gender - 0 === 2 ? '女' : null : null}</text> */}
|
|
105
|
+ <Picker value={Sex} range-key='name' range={SexList} onChange={SexChange}>
|
|
106
|
+ <view className='PickerText'>{Sex === null ? '请选择性别' : SexList[Sex].id - 0 === 1 ? '男' : '女'}</view>
|
|
107
|
+ </Picker>
|
29
|
108
|
</view>
|
30
|
|
- <view className='flex-h'>
|
|
109
|
+ <view className='flex-h' onClick={() => { setShowPhoneEdit(true) }}>
|
31
|
110
|
<text className='flex-item'>联系电话</text>
|
32
|
|
- <text>{user !== null ? user.phone : null}</text>
|
|
111
|
+ <text>{Phone}</text>
|
|
112
|
+ </view>
|
|
113
|
+ <view className='flex-h' onClick={() => { setShowBirthdayEdit(true) }}>
|
|
114
|
+ <text className='flex-item'>生日</text>
|
|
115
|
+ <text>{Birthday}</text>
|
33
|
116
|
</view>
|
34
|
117
|
</view>
|
|
118
|
+
|
|
119
|
+ {
|
|
120
|
+ ShowNameEdit &&
|
|
121
|
+ <view className='Popup'>
|
|
122
|
+ <view className='centerLabel'>
|
|
123
|
+ <view className='Title'>
|
|
124
|
+ <text>修改姓名</text>
|
|
125
|
+ </view>
|
|
126
|
+ <view className='Content'>
|
|
127
|
+ <Input value={Name} onInput={NameChange}></Input>
|
|
128
|
+ </view>
|
|
129
|
+ <view className='Bottom flex-h'>
|
|
130
|
+ <view className='flex-item'>
|
|
131
|
+ <text onClick={() => { setShowNameEdit(false); setName(user.nickname) }}>取消</text>
|
|
132
|
+ </view>
|
|
133
|
+ <view className='flex-item'>
|
|
134
|
+ <text onClick={EditName}>确定</text>
|
|
135
|
+ </view>
|
|
136
|
+ </view>
|
|
137
|
+ </view>
|
|
138
|
+ </view>
|
|
139
|
+ }
|
|
140
|
+
|
|
141
|
+ {
|
|
142
|
+ ShowPhoneEdit &&
|
|
143
|
+ <view className='Popup'>
|
|
144
|
+ <view className='centerLabel'>
|
|
145
|
+ <view className='Title'>
|
|
146
|
+ <text>修改手机号</text>
|
|
147
|
+ </view>
|
|
148
|
+ <view className='Content'>
|
|
149
|
+ <Input type='tel' value={Phone} onInput={PhoneChange}></Input>
|
|
150
|
+ </view>
|
|
151
|
+ <view className='Bottom flex-h'>
|
|
152
|
+ <view className='flex-item'>
|
|
153
|
+ <text onClick={() => { setShowPhoneEdit(false); setPhone(user.phone) }}>取消</text>
|
|
154
|
+ </view>
|
|
155
|
+ <view className='flex-item'>
|
|
156
|
+ <text onClick={EditPhone}>确定</text>
|
|
157
|
+ </view>
|
|
158
|
+ </view>
|
|
159
|
+ </view>
|
|
160
|
+ </view>
|
|
161
|
+ }
|
|
162
|
+
|
|
163
|
+ {
|
|
164
|
+ ShowBirthdayEdit &&
|
|
165
|
+ <view className='Popup'>
|
|
166
|
+ <view className='centerLabel'>
|
|
167
|
+ <view className='Title'>
|
|
168
|
+ <text>修改生日</text>
|
|
169
|
+ </view>
|
|
170
|
+ <view className='Content'>
|
|
171
|
+ <Input placeholder='例如:2012-02-02' value={Birthday} onInput={BirthdayChange}></Input>
|
|
172
|
+ </view>
|
|
173
|
+ <view className='Bottom flex-h'>
|
|
174
|
+ <view className='flex-item'>
|
|
175
|
+ <text onClick={() => { setShowBirthdayEdit(false); setBirthday(user.birthday) }}>取消</text>
|
|
176
|
+ </view>
|
|
177
|
+ <view className='flex-item'>
|
|
178
|
+ <text onClick={EditBirthday}>确定</text>
|
|
179
|
+ </view>
|
|
180
|
+ </view>
|
|
181
|
+ </view>
|
|
182
|
+ </view>
|
|
183
|
+ }
|
|
184
|
+
|
35
|
185
|
{/* <view className='Form'>
|
36
|
186
|
<view className='flex-h'>
|
37
|
187
|
<text className='flex-item'>身份</text>
|