2025-05-21 16:59:39 +08:00

117 lines
2.7 KiB
Plaintext

import { ItemComp } from './ItemComp'
import { MeetingItemModel,MeetingModel,MeetingModels,ItemModel } from '../model/ItemModel'
import { HdList, HdListController,BasicConstant,hdHttp, HdResponse ,logger} from '@itcast/basic/Index'
import { promptAction, router } from '@kit.ArkUI'
import { BusinessError } from '@kit.BasicServicesKit';
import { HdLoadingDialog } from '@itcast/basic'
import HashMap from '@ohos.util.HashMap';
@Component
export struct ListComp {
@State
list: ItemModel[] = []
controller = new HdListController()
@State
page: number = 1
@State
keyword: string = ''
@Prop
@Watch('onUpdate')
sort: number = 30
timer: number = -1
hashMap: HashMap<string, string> = new HashMap();
dialog: CustomDialogController = new CustomDialogController({
builder: HdLoadingDialog({ message: '加载中...' }),
customStyle: true,
alignment: DialogAlignment.Center
})
onUpdate() {
if (this.timer) clearTimeout(this.timer)
this.timer = setTimeout(() => {
this.controller.reload()
this.onRefresh()
}, 500)
}
onRefresh() {
this.page = 1
this.initData(0)
}
initData(type:number)
{
this.dialog.open()
this.hashMap.clear();
this.hashMap.set('page', this.page+"")
hdHttp.httpReq<string>(BasicConstant.meetingListV2,this.hashMap).then(async (res: HdResponse<string>) => {
logger.info('Response meetingListV2'+res);
let json:MeetingModels = JSON.parse(res+'') as MeetingModels;
this.dialog.close();
if(type==0)
{
this.controller.refreshed()
}
else
{
this.controller.loaded()
}
if(this.page==1&&json.data.list!=null&&json.data.list.length>0)
{
this.list = json.data.list
}
else if(this.page>1)
{
this.list.push(...json.data.list)
}
this.getPosition()
if (this.page >= json.data.pages) {
this.controller.finished()
} else {
this.page++
}
}).catch((err: BusinessError) => {
this.dialog.close();
})
}
getPosition() {
let DatasList:string[] = [];
let count = 0;
for (let i = 0; i <this.list.length; i++) {
if (!DatasList.includes(this.list[i].begin_date
.substring(0, 7))) {
DatasList.push(this.list[i].begin_date.substring(0, 7));
count = 0;
this.list[i].count=count;
} else {
count++;
this.list[i].count=count;
}
}
}
build() {
HdList({
lw: 1,
controller: this.controller,
onRefresh: () => {
this.onRefresh()
},
onLoad: () => {
this.initData(1)
}
}) {
ForEach(this.list, (item: MeetingItemModel) => {
ListItem() {
ItemComp({ item })
}
})
}
}
}