213 lines
6.0 KiB
Plaintext
213 lines
6.0 KiB
Plaintext
import { BasicConstant, EmptyViewComp, hdHttp, HdLoadingDialog, HdNav, HdResponse, HdSearchNav } from '@itcast/basic'
|
|
import { HMRouter, HMRouterMgr, HMRouterPathCallback, HMRouterPathInfo } from '@hadss/hmrouter'
|
|
import { PullToRefreshLayout, RefreshController } from 'refreshlib'
|
|
import { HashMap } from '@kit.ArkTS';
|
|
import { BusinessError } from '@kit.BasicServicesKit';
|
|
import { PatientTBean, TeachModel } from '@itcast/basic/src/main/ets/models/TeachModel';
|
|
import { promptAction } from '@kit.ArkUI';
|
|
import { ItemCompTeach } from '../components/ItemCompTeach';
|
|
import { StringIsEmpty } from '@nimkit/common';
|
|
|
|
@HMRouter({ pageUrl: 'TuwenCompPage' })
|
|
@Component
|
|
export struct TuwenComp {
|
|
dialog: CustomDialogController = new CustomDialogController({
|
|
builder: HdLoadingDialog({ message: '加载中...' }),
|
|
customStyle: true,
|
|
alignment: DialogAlignment.Center
|
|
})
|
|
@State pageNumber:number = 1;
|
|
@State totalPageNumer:number = 1;
|
|
@State data:PatientTBean[]=[];
|
|
@State isEmptyViewVisible: boolean = false; // 控制显隐的状态变量
|
|
aboutToAppear() {
|
|
this.getApplyList();
|
|
}
|
|
getApplyList() {
|
|
const hashMap: HashMap<string, string> = new HashMap();
|
|
hashMap.set('page',this.pageNumber.toString());
|
|
hashMap.set("type", this.sort);
|
|
hashMap.set("keywords", this.inputText);
|
|
this.dialog.open()
|
|
hdHttp.httpReq<string>(BasicConstant.polularScienceArticleListByKeywordsNew,hashMap).then(async (res: HdResponse<string>) => {
|
|
this.dialog.close();
|
|
let json:TeachModel = JSON.parse(res+'') as TeachModel;
|
|
if(json.code == '1') {
|
|
if(this.pageNumber==1)
|
|
{
|
|
this.data=[]
|
|
if(json.data!=null)
|
|
{
|
|
this.data = json.data;
|
|
}
|
|
|
|
}
|
|
else if(this.pageNumber>1)
|
|
{
|
|
this.data.push(...json.data)
|
|
}
|
|
|
|
this.totalPageNumer =json.totalPage;
|
|
if (this.data.length > 0) {
|
|
this.isEmptyViewVisible = false;
|
|
} else {
|
|
this.isEmptyViewVisible = true;
|
|
}
|
|
} else {
|
|
|
|
promptAction.showToast({ message: json.message, duration: 1000 })
|
|
}
|
|
}).catch((err: BusinessError) => {
|
|
this.dialog.close();
|
|
this.controller.refreshError();
|
|
console.info(`Response fails: ${err}`);
|
|
})
|
|
}
|
|
public controller:RefreshController = new RefreshController();
|
|
scroller = new Scroller();
|
|
@State Sorts:string='最新'
|
|
@State Imgs:ResourceStr=$r('app.media.cb_new')
|
|
@State inputText:string=''
|
|
@State
|
|
@Watch('onRefresh')
|
|
sort:string='1'
|
|
|
|
onRefresh()
|
|
{
|
|
this.pageNumber = 1;
|
|
this.getApplyList();
|
|
}
|
|
build() {
|
|
Column(){
|
|
HdNav({ title: '患教学堂', showRightIcon: false, showLeftIcon: true , isLeftAction:true,leftItemAction:()=>{
|
|
HMRouterMgr.pop()
|
|
}})
|
|
|
|
Row() {
|
|
Row() {
|
|
Image($r('app.media.search_no')).width(15).height(15).margin({ right:5 })
|
|
Text('搜索').fontSize(14).fontColor($r('app.color.common_gray_03')).textAlign(TextAlign.Start)
|
|
|
|
|
|
}
|
|
.layoutWeight(1)
|
|
.justifyContent(FlexAlign.Center)
|
|
.onClick(()=>{
|
|
const pathInfo1: HMRouterPathInfo = {
|
|
pageUrl: 'SearchComp',
|
|
param:{type:'tuwen'}
|
|
|
|
};
|
|
const callback: HMRouterPathCallback = {
|
|
onResult: (popInfo: PopInfo) => {
|
|
const result = popInfo.result as string;
|
|
if(!StringIsEmpty(result))
|
|
{
|
|
HMRouterMgr.pop({param:result})
|
|
}
|
|
|
|
// this.sendHelloMessage(result,BasicConstant.Teach);
|
|
}
|
|
};
|
|
HMRouterMgr.push(pathInfo1,callback)
|
|
// HMRouterMgr.push({ pageUrl: 'SearchComp' })
|
|
})
|
|
|
|
Text('|').fontColor($r('app.color.tab_text_nor'))
|
|
.fontSize(13)
|
|
|
|
Row() {
|
|
Text(this.Sorts).fontSize(14).fontColor($r('app.color.common_gray_03')).textAlign(TextAlign.Start)
|
|
.margin({ left:5 })
|
|
Image(this.Imgs).width(15).height(15)
|
|
}
|
|
.layoutWeight(1)
|
|
.justifyContent(FlexAlign.Center)
|
|
.onClick(()=>{
|
|
if(this.Sorts=='最新')
|
|
{
|
|
this.sort='2'
|
|
this.Sorts='最热'
|
|
this.Imgs=$r('app.media.cb_hot')
|
|
}
|
|
else
|
|
{
|
|
this.sort='1'
|
|
this.Sorts='最新'
|
|
this.Imgs=$r('app.media.cb_new')
|
|
}
|
|
})
|
|
|
|
}.width('100%').height(45)
|
|
Text().height(5).width('100%').backgroundColor($r('app.color.home_gray'))
|
|
if (this.isEmptyViewVisible){
|
|
EmptyViewComp({promptText:'暂无数据',isVisibility:this.isEmptyViewVisible}).layoutWeight(1)
|
|
|
|
}
|
|
else
|
|
{
|
|
PullToRefreshLayout({
|
|
scroller:this.scroller,
|
|
viewKey:"ListPage",
|
|
controller:this.controller,
|
|
contentView:()=>{
|
|
this.contentView()
|
|
},
|
|
|
|
onRefresh:()=>{
|
|
this.pageNumber = 1;
|
|
this.getApplyList();
|
|
setTimeout(() => {
|
|
this.controller.refreshSuccess()
|
|
}, 1000)
|
|
},
|
|
onCanPullRefresh:()=>{
|
|
if (!this.scroller.currentOffset()) {
|
|
/*处理无数据,为空的情况*/
|
|
return true
|
|
}
|
|
//如果列表到顶,返回true,表示可以下拉,返回false,表示无法下拉
|
|
return this.scroller.currentOffset().yOffset <= 0
|
|
},
|
|
onLoad:()=>{
|
|
this.pageNumber++;
|
|
this.getApplyList();
|
|
setTimeout(() => {
|
|
this.controller.loadSuccess()
|
|
}, 1000)
|
|
|
|
},
|
|
onCanPullLoad: () => {
|
|
if (this.pageNumber >= this.totalPageNumer) {
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
}
|
|
}).width('100%').layoutWeight(1).clip(true)
|
|
}
|
|
|
|
}
|
|
.width('100%')
|
|
.height('100%')
|
|
}
|
|
|
|
@Builder
|
|
contentView(){
|
|
List({ scroller: this.scroller }) {
|
|
ForEach(this.data, (item: PatientTBean, index) => {
|
|
ListItem() {
|
|
ItemCompTeach({item:item})
|
|
}
|
|
})
|
|
}
|
|
.width('100%')
|
|
.height('100%')
|
|
.edgeEffect(EdgeEffect.None)
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|