EditUserInfoPage.ets
13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
import { CustomTitleUI } from '../reusable/CustomTitleUI';
import { EditListInfo, editModel, editModelParams, WDEditDataModelType } from '../../model/EditInfoModel';
import EditInfoViewModel from '../../viewmodel/EditInfoViewModel';
import { WDRouterPage, WDRouterRule } from 'wdRouter';
import {AreaPickerDialog} from '../view/areaPickerDialog/AreaPickerDialog'
import {EditUserInfoCustomDialog} from '../view/areaPickerDialog/EditUserInfoCustomDialog'
import {EditUserSexCustomDialog} from '../view/areaPickerDialog/EditUserSexCustomDialog'
import {CustomDialogUI} from '../view/areaPickerDialog/CustomDialogUI'
import { AreaListManageModel, AreaListModel } from '../../model/AreaListModel';
import router from '@ohos.router';
import TrackingPageBrowseUtils from '../../utils/TrackingPageBrowseUtils'
import { TrackConstants } from 'wdTracking/Index';
import { SPHelper } from 'wdKit/Index';
import { SpConstants } from 'wdConstant/Index';
import { photoPickerUtils} from '../../utils/PhotoPickerUtils';
import { cameraPickerUtils } from '../../utils/CameraPickerUtils';
@Entry
@Component
struct EditUserInfoPage {
@State listData: EditListInfo[] = []
@State headerImg: string = ''
@State dataSource: AreaListModel[] = []
@State currentUserInfo: editModel = {} as editModel
@State topSafeHeight: number = AppStorage.get<number>('topSafeHeight') || 0
@State bottomSafeHeight: number = AppStorage.get<number>('bottomSafeHeight') || 0
userType:string = "1"
@State firstSelect:number = 0
@State secondSelect:number = 0
@State thirdSelect:number = 0
dialogController: CustomDialogController = new CustomDialogController({
builder: AreaPickerDialog({dataSource:this.dataSource,firstSelect:this.firstSelect,secondSelect:this.secondSelect,thirdSelect:this.thirdSelect,
confirmCallback:(province:AreaListManageModel,city:AreaListManageModel,county:AreaListManageModel,address:string)=>{
this.currentUserInfo.userExtend.province = province.label;
this.currentUserInfo.userExtend.city = city.label;
this.currentUserInfo.userExtend.county = county.label;
this.currentUserInfo.userExtend.address = address;
this.currentUserInfo.userExtend.provinceCode = province.code;
this.currentUserInfo.userExtend.cityCode = city.code;
this.currentUserInfo.userExtend.districtCode = county.code;
this.currentUserInfo.editDataType = WDEditDataModelType.WDEditDataModelType_region
this.updateEditModel()
// this.getAreaIndex()
}
}),
alignment: DialogAlignment.Bottom,
customStyle: true,
closeAnimation:{duration:0}
})
dateDialogController: CustomDialogController = new CustomDialogController({
builder: EditUserInfoCustomDialog({
confirmCallback:(selectDate:Date)=>{
let mon = selectDate.getUTCMonth() as number + 1
let monStr = mon.toString().padStart(2,'0')
let dayStr = selectDate.getUTCDate().toString().padStart(2,'0')
this.currentUserInfo.userExtend.birthday = selectDate.getUTCFullYear()+'-'+monStr+'-'+dayStr;
this.currentUserInfo.editDataType = WDEditDataModelType.WDEditDataModelType_birthday
this.updateEditModel()
}
}),
alignment: DialogAlignment.Bottom,
customStyle: true,
closeAnimation:{duration:0}
})
sexDialogController: CustomDialogController = new CustomDialogController({
builder: EditUserSexCustomDialog({
confirmCallback:(index)=>{
///1男 2女
this.currentUserInfo.userExtend.sex = index == 0?2:1;
this.currentUserInfo.editDataType = WDEditDataModelType.WDEditDataModelType_sex
this.updateEditModel()
}
}),
alignment: DialogAlignment.Bottom,
customStyle: true,
closeAnimation:{duration:0}
})
photoDialogController: CustomDialogController = new CustomDialogController({
builder: CustomDialogUI({
itemData:['相册','拍照'],
confirmCallback:(index)=>{
this.pickerSelect(index)
}
}),
alignment: DialogAlignment.Bottom,
customStyle: true,
closeAnimation:{duration:0}
})
pickerSelect(index:number){
if (index === 0) {
photoPickerUtils.getPhotoPicker(1).then(value => {
if (value['photoUris'].length > 0) {
this.headerImg = value['photoUris'][0]
}
})
}else {
cameraPickerUtils.getCamera().then(value => {
if (value.length > 0) {
this.headerImg = value
}
})
}
}
aboutToAppear() {
let userType = SPHelper.default.getSync(SpConstants.USER_Type,"") as string
if (userType && userType.length > 0) {
this.userType = userType
}
this.getAccountOwnerInfo()
}
onPageShow(){
this.updateUserNameAndIntroduction()
TrackingPageBrowseUtils.TrackingPageBrowseExposureStart()
}
onPageHide(): void {
TrackingPageBrowseUtils.TrackingPageBrowseExposureEnd(TrackConstants.PageName.Edit_Information,TrackConstants.PageName.Edit_Information)
}
build() {
Row() {
Column() {
CustomTitleUI({titleName:'编辑资料'})
Stack(){
Image(this.headerImg)
.alt($r('app.media.default_head'))
.backgroundColor(Color.Gray)
.width(84)
.height(84)
.borderRadius(42)
// if (this.headerImg.length === 0){
// Image('')
// .width('84')
// .height('84')
// .backgroundColor(Color.Gray)
// .opacity(0.7)
// .borderRadius(5)
// .borderRadius(42)
//
// Image($r('app.media.seletct_photo'))
// .width('30')
// .height('30')
// }
}.margin({top:20})
.onClick(()=>{
// this.photoDialogController.open()
})
///目前不支持头像上传,暂时屏蔽
// Button('点击更换头像')
// .fontColor(Color.Gray)
// .fontSize(15)
// .backgroundColor(Color.White)
// .margin({top:10,bottom:20})
List({}){
ForEach(this.listData,(item:EditListInfo,index:number) =>{
ListItem(){
this.RouterItem(item,index+1)
}
}
)
}
.layoutWeight(1)
.alignListItem(ListItemAlign.Center)
.width('100%')
}
}
.width('100%')
.height('100%')
.padding({top:px2vp(this.topSafeHeight),bottom:px2vp(this.bottomSafeHeight)})
}
@Builder
RouterItem(r:EditListInfo,i:Number){
Column(){
Row(){
Text(r.title)
.fontSize(15)
.fontColor('#666666')
Blank()
Text(r.subTitle)
.textOverflow({overflow:TextOverflow.Ellipsis})
.maxLines(1)
.fontSize(14)
.fontColor(r.subTitle === '待完善'?'#cccccc':'#666666')
.padding({right:10})
.width('70%')
.textAlign(TextAlign.End)
Image($r('app.media.mine_user_edit'))
.width('12')
.height('12')
}
.alignItems(VerticalAlign.Center)
.width('100%')
.padding(16)
Divider()
.width('90%')
}
.height(60)
.width('100%')
.onClick(()=>{
if (i === 1){
// TODO 缺失特殊用户判断
let params: editModelParams = {
editContent: this.currentUserInfo.userName
}
WDRouterRule.jumpWithPage(WDRouterPage.editUserNikeNamePage,params)
}else if (i === 2){
let params: editModelParams = {
editContent: this.currentUserInfo.userExtend.introduction
}
WDRouterRule.jumpWithPage(WDRouterPage.editUserIntroductionPage,params)
}else if (i === 3){
if (this.dataSource.length > 0) {
this.dialogController.open()
}
} else if (i === 4) {
this.dateDialogController.open()
}else if(i === 5){
this.sexDialogController.open()
}
})
}
updateUserNameAndIntroduction(){
let backParams:editModelParams = router.getParams() as editModelParams;
if (backParams) {
let userName = backParams.userName as string ///昵称
let introduction = backParams.introduction as string ///简介
this.listData = []
if (userName) {
if (userName != this.currentUserInfo.userName) {
this.currentUserInfo.userName = userName;
this.currentUserInfo.editDataType = WDEditDataModelType.WDEditDataModelType_nickname
this.listData.push(...EditInfoViewModel.getEditListInfo(this.currentUserInfo))
// this.updateEditModel()
// this.getAccountOwnerInfo()
}
} else if (introduction){
if (introduction != this.currentUserInfo.userExtend.introduction ) {
this.currentUserInfo.userExtend.introduction = introduction;
this.currentUserInfo.editDataType = WDEditDataModelType.WDEditDataModelType_intro
this.listData.push(...EditInfoViewModel.getEditListInfo(this.currentUserInfo))
// this.updateEditModel()
// this.getAccountOwnerInfo()
}
}
}
}
updateEditModel(){
// this.listData.push(...EditInfoViewModel.getEditListInfo(this.currentUserInfo))
EditInfoViewModel.updateUserInfo(this.currentUserInfo).then(()=>{
this.getAccountOwnerInfo()
})
}
async getAccountOwnerInfo(){
if (this.userType === '1') {
EditInfoViewModel.queryAccountOwnerInfo(getContext(this)).then((editModel) => {
this.listData = []
if (editModel.userExtend?.headPhotoUrl) {
this.headerImg = editModel.userExtend.headPhotoUrl
}
this.currentUserInfo = editModel as editModel;
this.listData.push(...EditInfoViewModel.getEditListInfo(editModel))
});
this.getAreaList()
}else {
EditInfoViewModel.queryPeopleAccountOwnerInfo(getContext(this)).then((peopleItem) => {
this.currentUserInfo = new editModel()
this.currentUserInfo.userExtend.introduction = peopleItem.introduction
this.currentUserInfo.userExtend.creatorId = peopleItem.creatorId
this.currentUserInfo.userName = peopleItem.userName
this.headerImg = peopleItem.headPhotoUrl
this.currentUserInfo.userType = Number(this.userType)
this.currentUserInfo.userExtend.districtCode = peopleItem.district
this.currentUserInfo.userExtend.cityCode = peopleItem.city
this.currentUserInfo.userExtend.provinceCode = peopleItem.province
// this.listData.push(...EditInfoViewModel.getEditListInfo(this.currentUserInfo))
this.getAreaList()
});
}
}
getAreaList(){
EditInfoViewModel.getAreaList(getContext(this)).then((value) =>{
this.dataSource.push(...value)
this.getAreaIndex()
})
}
getAreaIndex(){
if (this.userType === '1'){
///地区选择器当前位置
if (this.currentUserInfo.userExtend.province.length > 0) {
this.dataSource.forEach((element,index) => {
if (element.label === this.currentUserInfo.userExtend.province) {
this.firstSelect = index
let currentFirst = EditInfoViewModel.getAreaListManageModel(element)
currentFirst.children.forEach((element,index) => {
if (element.label === this.currentUserInfo.userExtend.city) {
this.secondSelect = index
let currentSecondBean = EditInfoViewModel.getAreaListManageModel(element)
currentSecondBean.children.forEach((element,index) => {
if (element.label === this.currentUserInfo.userExtend.county) {
this.thirdSelect = index
}
});
}
});
}
});
}
}else {
///地区选择器当前位置
if (this.currentUserInfo.userExtend.provinceCode.length > 0) {
this.dataSource.forEach((element,index) => {
if (element.code === this.currentUserInfo.userExtend.provinceCode) {
this.firstSelect = index
this.currentUserInfo.userExtend.province = element.label
let currentFirst = EditInfoViewModel.getAreaListManageModel(element)
currentFirst.children.forEach((element,index) => {
if (element.code === this.currentUserInfo.userExtend.cityCode) {
this.secondSelect = index
this.currentUserInfo.userExtend.city = element.label
let currentSecondBean = EditInfoViewModel.getAreaListManageModel(element)
currentSecondBean.children.forEach((element,index) => {
if (element.code === this.currentUserInfo.userExtend.districtCode) {
this.currentUserInfo.userExtend.county = element.label
this.thirdSelect = index
}
});
}
});
}
});
this.listData = []
this.currentUserInfo.userExtend.address = this.currentUserInfo.userExtend.province + this.currentUserInfo.userExtend.city + this.currentUserInfo.userExtend.county
this.listData.push(...EditInfoViewModel.getEditListInfo(this.currentUserInfo))
}
}
}
}