EditInfoViewModel.ets
4.25 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
import { EditInfoModel, EditListInfo, editModel } from '../model/EditInfoModel';
import HashMap from '@ohos.util.HashMap';
import { HttpUrlUtils, ResponseDTO, WDHttp } from 'wdNetwork';
import { Logger, ResourcesUtils } from 'wdKit';
import { AreaListManageModel, AreaListModel } from '../model/AreaListModel';
const TAG = "EditInfoViewModel"
class EditInfoViewModel {
private static instance: EditInfoViewModel;
editListData:EditListInfo[] = []
/**
* 单例模式
* @returns
*/
public static getInstance(): EditInfoViewModel {
if (!EditInfoViewModel.instance) {
EditInfoViewModel.instance = new EditInfoViewModel();
}
return EditInfoViewModel.instance;
}
BaseGetRequest(requestUrl:string){
let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders()
requestUrl = HttpUrlUtils.HOST_SIT + requestUrl
return WDHttp.get<ResponseDTO>(requestUrl,headers)
}
getEditListInfo(item?:editModel):EditListInfo[]{
this.editListData = [
new EditListInfo('昵称',item&&item.userName.length > 0?item.userName:'待完善'),
new EditListInfo('简介',item&&item.userExtend.introduction.length > 0?item.userExtend.introduction:'待完善'),
new EditListInfo('地区',item&&item.userExtend.city.length > 0?item.userExtend.city:'待完善'),
new EditListInfo('生日',item&&item.userExtend.birthday.length > 0?item.userExtend.birthday:'待完善'),
new EditListInfo('性别',item&&item.userExtend.sex.length > 0?(item.userExtend.sex=== '1'?'男':'女'):'待完善'),
]
return this.editListData
}
///1普通用户
queryAccountOwnerInfo(userType:number, context: Context):PromiseLike<editModel>{
return new Promise(((success, error) => {
this.BaseGetRequest(userType == 1?HttpUrlUtils.APPOINTMENT_QueryUserDetail_PATH:HttpUrlUtils.APPOINTMENT_AccountOwner_PATH).then((navResDTO:ResponseDTO) =>{
if (navResDTO.code == 200) {
// let editM = navResDTO.data as EditInfoModel
// success(JSON.parse(navResDTO.data)
}
success(this.GetqueryAccountOwnerLocal(context))
}).catch((error: Error) => {
Logger.info('EditInfoViewModel','EditInfoViewModel','EditInfoViewModel')
success(this.GetqueryAccountOwnerLocal(context))
})
}))
}
async GetqueryAccountOwnerLocal(context: Context): Promise<editModel> {
Logger.info(TAG, `getBottomNavDataMock start`);
let compRes: ResponseDTO<editModel> | null = await ResourcesUtils.getResourcesJson<ResponseDTO<editModel>>(context,'userInfo.json');
if (!compRes || !compRes.data) {
Logger.info(TAG, `getAppointmentListDataLocal compRes is empty`);
return new editModel()
}
Logger.info(TAG, `getAppointmentListDataLocal getResourcesJsonSync compRes : ${JSON.stringify(compRes)}`);
return compRes.data
}
getAreaList(context: Context):PromiseLike<AreaListModel[]>{
return new Promise(((success, error) => {
success(this.getAreaListLocal(context))
// this.BaseGetRequest(HttpUrlUtils.APPOINTMENT_AccountOwner_PATH).then((navResDTO:ResponseDTO) =>{
// if (navResDTO.code == 200) {
// // let editM = navResDTO.data as EditInfoModel
// // success(JSON.parse(navResDTO.data)
// }
//
// }).catch((error: Error) => {
// Logger.info('EditInfoViewModel','EditInfoViewModel','EditInfoViewModel')
// success(this.GetqueryAccountOwnerLocal(context))
//
// })
}))
}
async getAreaListLocal(context: Context): Promise<AreaListModel[]> {
Logger.info(TAG, `getBottomNavDataMock start`);
let compRes: ResponseDTO<AreaListModel[]> | null = await ResourcesUtils.getResourcesJson<ResponseDTO<AreaListModel[]>>(context,'areaList_data.json');
if (!compRes || !compRes.data) {
Logger.info(TAG, `getAppointmentListDataLocal compRes is empty`);
return [] as AreaListModel[]
}
Logger.info(TAG, `getAppointmentListDataLocal getResourcesJsonSync compRes : ${JSON.stringify(compRes)}`);
return compRes.data
}
getAreaListManageModel(item:AreaListModel):AreaListManageModel{
return new AreaListManageModel(item.code,item.id,item.label,item.children)
}
updateUserInfo(){
}
}
const editInfoViewModel = EditInfoViewModel.getInstance();
export default editInfoViewModel as EditInfoViewModel