wangliang_wd

feat:增加地区选择

import router from '@ohos.router';
import { CustomTitleUI } from '../reusable/CustomTitleUI';
import { EditInfoModel, EditListInfo, editModel } from '../../model/EditInfoModel';
import { EditListInfo } from '../../model/EditInfoModel';
import EditInfoViewModel from '../../viewmodel/EditInfoViewModel';
import { WDRouterPage, WDRouterRule } from 'wdRouter';
import {AreaPickerDialog} from '../view/areaPickerDialog/AreaPickerDialog'
import { AreaListModel } from '../../model/AreaListModel';
@Entry
@Component
struct EditUserInfoPage {
private listData: EditListInfo[] = []
// editM: editModel
@State listData: EditListInfo[] = []
@State headerImg: string = ''
@State dataSource: AreaListModel[] = []
dialogController: CustomDialogController = new CustomDialogController({
builder: AreaPickerDialog({dataSource:this.dataSource}),
alignment: DialogAlignment.Bottom,
offset:{dx:0,dy:-20}
})
aboutToAppear() {
// this.listData = EditInfoViewModel.getEditListInfo(this.editM)
// this.listData = EditInfoViewModel.getEditListInfo()
this.getAccountOwnerInfo()
this.getAreaList()
}
build() {
Row() {
Column() {
CustomTitleUI({titleName:'资料编辑'})
Image('')
Image(this.headerImg)
.alt($r('app.media.default_head'))
.backgroundColor(Color.Gray)
.width(100)
.height(100)
... ... @@ -87,6 +98,8 @@ struct EditUserInfoPage {
// url:'pages/EditUserInstoductionPage',
// params:{pageNum:i}
// })
}else if (i === 3){
this.dialogController.open()
} else if (i === 4) {
DatePickerDialog.show({
start:new Date('1900-1-1'),
... ... @@ -110,9 +123,15 @@ struct EditUserInfoPage {
}
getAccountOwnerInfo(){
EditInfoViewModel.queryAccountOwnerInfo(1,getContext(this)).then((result) => {
// this.editM = result
EditInfoViewModel.queryAccountOwnerInfo(1,getContext(this)).then((editModel) => {
this.headerImg = editModel.userExtend.headPhotoUrl
this.listData.push(...EditInfoViewModel.getEditListInfo(editModel))
});
}
getAreaList(){
EditInfoViewModel.getAreaList(getContext(this)).then((value) =>{
this.dataSource.push(...value)
})
}
}
... ...
import { AreaListManageModel, AreaListModel } from '../../../model/AreaListModel';
import EditInfoViewModel from '../../../viewmodel/EditInfoViewModel';
import { FirstLevelComponent } from './FirstLevelComponent';
import { SecondLevelComponent } from './SecondLevelComponent';
import { ThirdLevelComponent } from './ThirdLevelComponent';
@CustomDialog
export struct AreaPickerDialog {
@Provide currentFirst: AreaListManageModel = new AreaListManageModel('','','',[])
@Provide currentSecondBean: AreaListManageModel = new AreaListManageModel('','','',[])
@Provide currentThirdBean: AreaListManageModel = new AreaListManageModel('','','',[])
controller: CustomDialogController
title: string = '地区选择'
@Provide dataSource: AreaListModel[] = []
result: JSON[] = [];
aboutToAppear(){
this.currentFirst = EditInfoViewModel.getAreaListManageModel(this.dataSource[0])
this.currentSecondBean = EditInfoViewModel.getAreaListManageModel(this.dataSource[0].children[0])
this.currentThirdBean = EditInfoViewModel.getAreaListManageModel(this.dataSource[0].children[0].children[0])
}
build() {
Column(){
Row(){
Button('取消',{type:ButtonType.Normal})
.onClick(()=> {
this.controller.close()
})
.backgroundColor(0xffffff)
.fontColor(Color.Black)
.layoutWeight(1)
Blank()
Text(this.title)
.fontSize(18).textAlign(TextAlign.Center).margin({top:10,bottom:10})
Blank()
Button('确定',{type:ButtonType.Normal})
.onClick(()=> {
})
.backgroundColor(0xffffff)
.fontColor(Color.Blue)
.layoutWeight(1)
}
.margin({top:0,bottom:10})
Row(){
FirstLevelComponent().width('30%')
SecondLevelComponent().width('30%')
ThirdLevelComponent().width('30%')
}
}
.height('40%')
}
}
\ No newline at end of file
... ...
import { AreaListManageModel, AreaListModel } from '../../../model/AreaListModel';
import EditInfoViewModel from '../../../viewmodel/EditInfoViewModel';
@Component
export struct FirstLevelComponent {
@State labelList :string[] = [];
@State select: number = 0;
@Consume currentFirst: AreaListManageModel
@Consume dataSource: AreaListModel[]
aboutToAppear(){
for (let index = 0; index < this.dataSource.length; index++) {
const element = this.dataSource[index];
this.labelList.push(element.label)
}
}
build() {
Column(){
Column(){
if (this.labelList.length === 0){
Text('暂无数据').fontSize(20)
}else {
TextPicker({range:this.labelList,selected:this.select})
// .onChange((value:string,index:number) => {
// this.select = index
// this.currentFirst = EditInfoViewModel.getAreaListManageModel(this.dataSource[index])
// })
.backgroundColor(Color.White)
.border({color:'#e2e2e2',width:{right:0.5}})
.width('100%')
.layoutWeight(1)
}
}
.justifyContent(FlexAlign.Center)
}
.height('100%')
}
}
\ No newline at end of file
... ...
import { AreaListManageModel, AreaListModel } from '../../../model/AreaListModel';
@Component
export struct SecondLevelComponent {
@State mTip: string = '暂无数据'
@State labelList: string[] = [];
@State select: number = 0;
@Consume @Watch('onFirstChange') currentFirst: AreaListManageModel;
@Consume currentSecondBean: AreaListManageModel
aboutToAppear(){
for (let index = 0; index < this.currentFirst.children.length; index++) {
const element = this.currentFirst.children[index];
this.labelList.push(element.label)
}
}
build() {
Column(){
Column(){
if (this.labelList.length === 0){
Text(this.mTip).fontSize(20)
}else {
TextPicker({range:this.labelList,selected:this.select})
// .onChange((value:string,index:number) => {
// this.select = index
// this.currentSecondBean = this.currentFirst.children[index]
// })
.backgroundColor(Color.White)
.border({color:'#e2e2e2',width:{right:0.5}})
.width('100%')
.layoutWeight(1)
}
}
.justifyContent(FlexAlign.Center)
}
.height('100%')
}
onFirstChange(){
if (!this.currentFirst) {
this.mTip = '暂无数据';
} else {
this.labelList = []
for (let index = 0; index < this.currentFirst.children.length; index++) {
const element = this.currentFirst.children[index];
this.labelList.push(element.label)
}
// this.currentSecondBean = this.currentFirst.children[this.select]
}
}
}
\ No newline at end of file
... ...
import { AreaListManageModel, AreaListModel } from '../../../model/AreaListModel';
@Component
export struct ThirdLevelComponent {
@State mTip: string = '暂无数据'
@State labelList: string[] = [];
@State select: number = 0;
@Consume @Watch('onFirstChange') currentFirst: AreaListManageModel;
@Consume @Watch('onSecondChange') currentSecondBean: AreaListManageModel;
@Consume currentThirdBean: AreaListManageModel
aboutToAppear(){
for (let index = 0; index < this.currentSecondBean.children.length; index++) {
const element = this.currentSecondBean.children[index];
this.labelList.push(element.label)
}
}
build() {
Column(){
Column(){
if (this.labelList.length === 0){
Text(this.mTip).fontSize(20)
}else {
TextPicker({range:this.labelList,selected:this.select})
// .onChange((value:string,index:number) => {
// this.select = index
// this.currentThirdBean = this.currentSecondBean.children[index]
// })
.backgroundColor(Color.White)
.border({color:'#e2e2e2',width:{right:0.5}})
.width('100%')
.layoutWeight(1)
}
}
.justifyContent(FlexAlign.Center)
}
.height('100%')
}
onFirstChange(){
}
onSecondChange(){
if (!this.currentSecondBean) {
this.mTip = '暂无数据';
} else {
this.labelList = []
for (let index = 0; index < this.currentSecondBean.children.length; index++) {
const element = this.currentSecondBean.children[index];
this.labelList.push(element.label)
}
// this.currentThirdBean = this.currentSecondBean.children[this.select]
}
}
}
\ No newline at end of file
... ...
export interface AreaListModel{
code: string
id: string
label: string
children: AreaListModel[]
}
export class AreaListManageModel{
code: string = ''
id: string = ''
label: string = ''
children: AreaListModel[] = []
constructor(code:string , id:string,label:string, children:AreaListModel[]) {
this.code = code;
this.id = id
this.label = label;
this.children = children
}
}
\ No newline at end of file
... ...
... ... @@ -23,7 +23,7 @@ export interface EditInfoModel{
//生日
birthday:string
//性别
sex:string
sex:number
}
export interface editModel{
... ...
... ... @@ -3,6 +3,7 @@ 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"
... ... @@ -27,13 +28,13 @@ class EditInfoViewModel {
}
getEditListInfo(item:editModel):EditListInfo[]{
getEditListInfo(item?:editModel):EditListInfo[]{
this.editListData = [
// new EditListInfo('昵称',item&&item.userName?item.userName:'待完善'),
// new EditListInfo('简介',item&&item.userExtend.introduction?item.userExtend.introduction:'待完善'),
// new EditListInfo('地区',item&&item.userExtend.city?item.userExtend.city:'待完善'),
// new EditListInfo('生日',item&&item.userExtend.birthday?item.userExtend.birthday:'待完善'),
// new EditListInfo('性别',item&&item.userExtend.sex?item.userExtend.sex:'待完善'),
new EditListInfo('昵称',item&&item.userName?item.userName:'待完善'),
new EditListInfo('简介',item&&item.userExtend.introduction?item.userExtend.introduction:'待完善'),
new EditListInfo('地区',item&&item.userExtend.city?item.userExtend.city:'待完善'),
new EditListInfo('生日',item&&item.userExtend.birthday?item.userExtend.birthday:'待完善'),
new EditListInfo('性别',item&&item.userExtend.sex?item.userExtend.sex===1?'男':'女':'待完善'),
]
return this.editListData
}
... ... @@ -46,10 +47,10 @@ class EditInfoViewModel {
// let editM = navResDTO.data as EditInfoModel
// success(JSON.parse(navResDTO.data)
}
return this.GetqueryAccountOwnerLocal(context)
success(this.GetqueryAccountOwnerLocal(context))
}).catch((error: Error) => {
Logger.info('EditInfoViewModel','EditInfoViewModel','EditInfoViewModel')
return this.GetqueryAccountOwnerLocal(context)
success(this.GetqueryAccountOwnerLocal(context))
})
}))
... ... @@ -66,6 +67,38 @@ class EditInfoViewModel {
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(){
}
... ...
This diff could not be displayed because it is too large.