190 lines
5.4 KiB
Plaintext
190 lines
5.4 KiB
Plaintext
import {
|
||
BaseBean,
|
||
BasicConstant, EmptyViewComp, hdHttp, HdLoadingDialog, HdNav, HdResponse, HdSearchNav } from '@itcast/basic'
|
||
import { HMLifecycleState, HMRouter, HMRouterMgr, HMRouterPathCallback, HMRouterPathInfo } from '@hadss/hmrouter'
|
||
import { PullToRefreshLayout, RefreshController } from 'refreshlib'
|
||
import { HashMap } from '@kit.ArkTS';
|
||
import { BusinessError } from '@kit.BasicServicesKit';
|
||
import { promptAction } from '@kit.ArkUI';
|
||
import { StringIsEmpty } from '@nimkit/common';
|
||
import { ListOut, ListOutPatientModel } from '../model/ListOutPatientModel';
|
||
import { ItemCompArrange } from '../components/ItemCompArrange';
|
||
|
||
@HMRouter({ pageUrl: 'ArrangementsComp' })
|
||
@Component
|
||
export struct ArrangementsComp {
|
||
dialog: CustomDialogController = new CustomDialogController({
|
||
builder: HdLoadingDialog({ message: '加载中...' }),
|
||
customStyle: true,
|
||
alignment: DialogAlignment.Center
|
||
})
|
||
@State pageNumber:number = 1;
|
||
@State totalPageNumer:number = 1;
|
||
@State data:ListOut[]=[];
|
||
@State isEmptyViewVisible: boolean = false; // 控制显隐的状态变量
|
||
@State
|
||
@Watch('deleteOutPatient')
|
||
delete: boolean=false
|
||
@State deleteUuid:string=''
|
||
private lifecycleOwner = HMRouterMgr.getCurrentLifecycleOwner()
|
||
private handleCallback = () => {
|
||
this.getList();
|
||
}
|
||
aboutToAppear() {
|
||
this.getList();
|
||
this.lifecycleOwner?.addObserver(HMLifecycleState.onShown,this.handleCallback)
|
||
}
|
||
aboutToDisappear(): void {
|
||
this.lifecycleOwner?.removeObserver(HMLifecycleState.onShown,this.handleCallback)
|
||
}
|
||
getList() {
|
||
const hashMap: HashMap<string, string> = new HashMap();
|
||
hashMap.set('page',this.pageNumber.toString());
|
||
this.dialog.open()
|
||
hdHttp.httpReq<string>(BasicConstant.listOutPatient,hashMap).then(async (res: HdResponse<string>) => {
|
||
this.dialog.close();
|
||
let json:ListOutPatientModel = JSON.parse(res+'') as ListOutPatientModel;
|
||
if(json.code == '200') {
|
||
if(this.pageNumber==1)
|
||
{
|
||
this.data=[]
|
||
if(json.data!=null)
|
||
{
|
||
this.data = json.data.list;
|
||
}
|
||
|
||
}
|
||
else if(this.pageNumber>1)
|
||
{
|
||
this.data.push(...json.data.list)
|
||
}
|
||
|
||
this.totalPageNumer =json.data.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.getList();
|
||
}
|
||
build() {
|
||
Column(){
|
||
|
||
Text().height(20).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.getList();
|
||
setTimeout(() => {
|
||
this.controller.refreshSuccess()
|
||
}, 1000)
|
||
},
|
||
onCanPullRefresh:()=>{
|
||
if (!this.scroller.currentOffset()) {
|
||
/*处理无数据,为空的情况*/
|
||
return true
|
||
}
|
||
//如果列表到顶,返回true,表示可以下拉,返回false,表示无法下拉
|
||
return this.scroller.currentOffset().yOffset <= 0
|
||
},
|
||
onLoad:()=>{
|
||
this.pageNumber++;
|
||
this.getList();
|
||
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%')
|
||
.backgroundColor($r('app.color.home_gray'))
|
||
}
|
||
|
||
@Builder
|
||
contentView(){
|
||
List({ scroller: this.scroller }) {
|
||
ForEach(this.data, (item: ListOut, index) => {
|
||
ListItem() {
|
||
ItemCompArrange({item:item,deleteUuid:this.deleteUuid,delete:this.delete})
|
||
}
|
||
})
|
||
}
|
||
.divider({
|
||
strokeWidth: 5,
|
||
})
|
||
.width('100%')
|
||
.height('100%')
|
||
.edgeEffect(EdgeEffect.None)
|
||
|
||
}
|
||
deleteOutPatient() {
|
||
this.dialog.open()
|
||
|
||
const hashMap: HashMap<string, string> = new HashMap();
|
||
hashMap.set('uuid',this.deleteUuid)
|
||
hdHttp.httpReq<string>(BasicConstant.deleteOutPatient,hashMap).then(async (res: HdResponse<string>) => {
|
||
this.dialog.close();
|
||
let json:BaseBean = JSON.parse(res+'') as BaseBean;
|
||
if(json.code == '200') {
|
||
this.getList();
|
||
} else {
|
||
|
||
promptAction.showToast({ message: json.message, duration: 1000 })
|
||
}
|
||
}).catch((err: BusinessError) => {
|
||
this.dialog.close();
|
||
console.info(`Response fails: ${err}`);
|
||
})
|
||
|
||
|
||
}
|
||
|
||
}
|
||
|