import { ApplyViews } from '../views/ApplyViews' import { authStore, HdNav } from '@itcast/basic'; import { applyListCallBacl,applyListModel,applyHistoryCallBacl,historyModel } from '../models/ApplyModel' import HashMap from '@ohos.util.HashMap'; import { HdLoadingDialog } from '@itcast/basic' import { BasicConstant,hdHttp, HdResponse ,logger} from '@itcast/basic/Index' import { BusinessError } from '@kit.BasicServicesKit'; import { promptAction, router } from '@kit.ArkUI' import { patientDbManager, PatientData } from '@itcast/basic'; import { PullToRefreshLayout, RefreshController } from 'refreshlib' import { HMRouter, HMRouterMgr } from '@hadss/hmrouter'; interface extraData { expertUuid: string, page: number, uuid: string, status: string } @HMRouter({ pageUrl: 'PatientApplyPage' }) @Component export struct PatientApplyPage { public controller:RefreshController = new RefreshController(); private params: ESObject = HMRouterMgr.getCurrentParam() scroller = new Scroller(); @State applyArray:applyListModel[] = []; @State historyArray:historyModel[] = []; @State pageNumber:number = 1; @State totalPageNumer:number = 1; dialog: CustomDialogController = new CustomDialogController({ builder: HdLoadingDialog({ message: '加载中...' }), customStyle: true, alignment: DialogAlignment.Center }) aboutToAppear(): void { this.getApplyList(); this.getHistoryApplyList(); } getHistoryApplyList() { const hashMap: HashMap = new HashMap(); hashMap.set('page',this.pageNumber.toString()); this.dialog.open() hdHttp.httpReq(BasicConstant.relationRecordLately,hashMap).then(async (res: HdResponse) => { this.dialog.close(); this.controller.refreshSuccess(); this.controller.loadSuccess(); logger.info('Response relationRecordLately'+res); let json:applyHistoryCallBacl = JSON.parse(res+'') as applyHistoryCallBacl; if(json.code == 200) { this.historyArray = json.data.list; this.totalPageNumer = Number(json.data.pages); } else { console.error('患者申请记录列表失败:'+json.message) promptAction.showToast({ message: json.message, duration: 1000 }) } }).catch((err: BusinessError) => { this.dialog.close(); this.controller.refreshError(); console.info(`Response fails: ${err}`); }) } getApplyList() { this.dialog.open() hdHttp.post(BasicConstant.applyList, { expertUuid: authStore.getUser().uuid, } as extraData).then(async (res: HdResponse) => { this.dialog.close(); this.controller.refreshSuccess(); this.controller.loadSuccess(); logger.info('Response applyList'+res); let json:applyListCallBacl = JSON.parse(res+'') as applyListCallBacl; if(json.code == 1) { this.applyArray = json.data; } else { console.error('新的患者列表失败:'+json.message) promptAction.showToast({ message: json.message, duration: 1000 }) } }).catch((err: BusinessError) => { this.dialog.close(); this.controller.refreshError(); console.info(`Response fails: ${err}`); }) } getApplyListOperate(status: string,model:applyListModel) { this.dialog.open() hdHttp.post(BasicConstant.applyListOperate, { uuid: model.uuid, status: status } as extraData).then(async (res: HdResponse) => { this.dialog.close(); logger.info('Response applyListOperate'+res); let json:applyListCallBacl = JSON.parse(res+'') as applyListCallBacl; if(json.code == 1) { if (status == '2') { this.getApplyList(); // 添加单个患者 const singlePatient: PatientData = { uuid:model.patientUuid as string, nickname: '', mobile: model.mobile as string, realName: model.realName as string, nation: '', sex: model.sex as number, type: 1, photo: model.photo as string, expertUuid: authStore.getUser().uuid }; const success1 = await patientDbManager.addPatient(singlePatient); if (success1) { console.info('添加成功'); const patients = await patientDbManager.getAllPatients(); promptAction.showToast({message:`现在一共是 ${patients.length} 个患者`}) } else { console.info('添加失败'); } promptAction.showToast({ message: '消息已处理', duration: 1000 }) router.pushUrl({ url:'pages/PatientsPage/PatientMsgSetPage', params:{ 'model':model } }) } else if (status == '3') { this.pageNumber = 1; this.getApplyList(); this.getHistoryApplyList(); } } else { console.error('患者列表申请处理失败:'+json.message) promptAction.showToast({ message: json.message, duration: 1000 }) } }).catch((err: BusinessError) => { this.dialog.close(); console.info(`Response fails: ${err}`); }) } build() { Column(){ HdNav({ title: '新的患者', showRightIcon: false, hasBorder: true, isLeftAction:this.params?true:false, leftItemAction:()=>{ HMRouterMgr.pop() }, }) PullToRefreshLayout({ scroller:this.scroller, viewKey:"ListPage", controller:this.controller, contentView:()=>{ this.contentView() }, onRefresh:()=>{ this.pageNumber = 1; this.getApplyList(); this.getHistoryApplyList(); }, onCanPullRefresh:()=>{ if (!this.scroller.currentOffset()) { /*处理无数据,为空的情况*/ return true } //如果列表到顶,返回true,表示可以下拉,返回false,表示无法下拉 return this.scroller.currentOffset().yOffset <= 0 }, onLoad:()=>{ this.pageNumber++; this.getApplyList(); this.getHistoryApplyList(); }, onCanPullLoad: () => { if (this.pageNumber >= this.totalPageNumer) { return false; } else { return true; } } }).width('100%').height('calc(100% - 156vp)').clip(true) Row(){ Text('加患者') .fontSize(16) .fontColor(Color.White) .backgroundColor('rgb(63,199,193)') .width('100%').height(50).textAlign(TextAlign.Center) .onClick(()=>{ router.pushUrl({ url: 'pages/WebView/WebPage', // 目标url params: {url:BasicConstant.wxUrl+'expert/expertcodeimg?expert_uuid='+authStore.getUser().uuid,title:'随访二维码'} }) }) }.width('100%').height(56).backgroundColor(Color.White).alignItems(VerticalAlign.Top) }.width('100%').height('100%') } @Builder contentView(){ Column(){ Row({space:5}){ Image($r('app.media.addPatientApply_reminder_icon')) .width(18).height(21) Text('提醒: 为了避免不必要的纠纷,请您务必选择线下就诊过的患者') .fontSize(16).fontColor('#666666') }.width('100%').padding({left:10,top:10,right:20,bottom:10}).backgroundColor(Color.White) if (this.applyArray.length > 0) { Column(){ Text('随访申请') .fontSize(15).fontColor('#333333').margin({left:10}).height(42) ForEach(this.applyArray,(item:applyListModel)=>{ ApplyViews({applyItme:item,isApply:true,applyItemAction:((status: string,model:applyListModel)=>{ this.getApplyListOperate(status,model) })}) }) }.width('100%').alignItems(HorizontalAlign.Start) } if (this.historyArray.length > 0) { Column(){ Text('申请记录(近一月)') .fontSize(15).fontColor('#333333').margin({left:10}).height(42) ForEach(this.historyArray,(item:historyModel)=>{ ApplyViews({historyItem:item,isApply:false}) }) }.width('100%').alignItems(HorizontalAlign.Start) } }.width('100%').height('100%').backgroundColor('#f4f4f4') } }