harmony/features/patient/src/main/ets/components/BuildOrEditGroupPage.ets
2025-08-01 10:34:52 +08:00

291 lines
9.9 KiB
Plaintext

import { authStore, ChangeUtil, HdNav } from '@itcast/basic';
import { promptAction } from '@kit.ArkUI'
import { HdLoadingDialog,DefaultHintProWindows } from '@itcast/basic'
import { BasicConstant,hdHttp, HdResponse ,logger} from '@itcast/basic/Index'
import { BusinessError } from '@kit.BasicServicesKit';
import { patientListModel } from '../models/PatientsGroupModel'
import { HMRouter, HMRouterMgr,HMRouterPathInfo,HMRouterPathCallback } from "@hadss/hmrouter"
@HMRouter({ pageUrl: 'BuildOrEditGroupPage' })
@Component
export struct BuildOrEditGroupPage {
private params: ESObject = HMRouterMgr.getCurrentParam();
// @State params:Record<string, string> = router.getParams() as Record<string, string>
scrollerCon:Scroller = new Scroller()
@State groupPatientList:patientListModel[] = []
@State groupName:string = ''
private hintWindowDialog!: CustomDialogController
dialog: CustomDialogController = new CustomDialogController({
builder: HdLoadingDialog({ message: '加载中...' }),
customStyle: true,
alignment: DialogAlignment.Center
})
private hintPopWindowDialog() {
this.hintWindowDialog = new CustomDialogController({
builder:DefaultHintProWindows({
controller:this.hintWindowDialog,
message:'确定删除该分组',
cancleTitleColor: '#333333',
confirmTitleColor: '#333333',
selectedButton: (index:number)=>{
if (index === 1) {
this.deleGroupAction()
}
this.hintWindowDialog.close();
}
}),
alignment: DialogAlignment.Center,
cornerRadius:24,
backgroundColor: ('rgba(0,0,0,0.5)'),
})
}
aboutToAppear(): void {
if (this.params.title != '新建分组') {
this.getGroupPatientsData()
}
this.hintPopWindowDialog()
}
getGroupPatientsData() {
this.dialog.open()
hdHttp.post<string>(BasicConstant.patientListByGroup, {
"expert_uuid": authStore.getUser().uuid,
"group_uuid":this.params.group_uuid
} as Record<string,string>).then(async (res: HdResponse<string>) => {
this.dialog.close();
logger.info('Response patientListByGroup'+res);
let json:Record<string,string | patientListModel[]> = JSON.parse(res+'') as Record<string,string | patientListModel[]>;
if(json.code == '1') {
this.groupPatientList = json.data as patientListModel[];
} else {
console.error('获取患者分组列表失败:'+json.message)
promptAction.showToast({ message: String(json.message), duration: 1000 })
}
}).catch((err: BusinessError) => {
this.dialog.close();
console.error(`Response fails: ${err}`);
})
}
deleGroupAction() {
this.dialog.open()
hdHttp.post<string>(BasicConstant.deleteGroup, {
"expert_uuid": authStore.getUser().uuid,
"group_uuid":this.params.group_uuid
} as Record<string,string>).then(async (res: HdResponse<string>) => {
this.dialog.close();
logger.info('Response patientListByGroup'+res);
let json:Record<string,string> = JSON.parse(res+'') as Record<string,string>;
if(json.code == '1') {
promptAction.showToast({ message: '删除分组成功', duration: 1000 })
// router.back();
HMRouterMgr.pop({param:{"nameString":true}})
} else {
console.error('删除患者分组列表失败:'+json.message)
promptAction.showToast({ message: json.message, duration: 1000 })
}
}).catch((err: BusinessError) => {
this.dialog.close();
console.error(`Response fails: ${err}`);
})
}
setCreatOrEditGroup(index:number) {
if (this.groupName.length <= 0) {
promptAction.showToast({ message: '请输入分组名称', duration: 1000 })
return
}
const uuidString:string = this.groupPatientList.map(item => item.uuid).join(",");
this.dialog.open()
hdHttp.post<string>(index == 0 ? BasicConstant.addGroup:BasicConstant.updateGroup, index == 0 ? {
"expert_uuid": authStore.getUser().uuid,
"name":this.groupName,
"patient_uuid":uuidString
} as Record<string,string> : {
"uuid": this.params.group_uuid,
"name":this.groupName,
"patient_uuid":uuidString
} as Record<string,string>).then(async (res: HdResponse<string>) => {
this.dialog.close();
logger.info('Response patientListByGroup'+res);
let json:Record<string,string> = JSON.parse(res+'') as Record<string,string>;
if(json.code == '1') {
promptAction.showToast({ message:'分组成功', duration: 1000 })
HMRouterMgr.pop({param:{"nameString":true}})
} else if (json.code == '2') {
promptAction.showToast({ message:'该分组已存在', duration: 1000 })
} else {
console.error('删除患者分组列表失败:'+json.message)
promptAction.showToast({ message: json.message, duration: 1000 })
}
}).catch((err: BusinessError) => {
this.dialog.close();
console.error(`Response fails: ${err}`);
})
}
build() {
Row() {
Column() {
HdNav({
title: this.params.title,
showRightIcon: false,
hasBorder: true,
rightText: '保存',
showRightText: true,
isLeftAction:true,
leftItemAction:()=>{
HMRouterMgr.pop({param:{"nameString":false}})
},
rightItemAction: () => {
if (this.params.title == '新建分组') {
this.setCreatOrEditGroup(0);
} else {
this.setCreatOrEditGroup(1);
}
}
})
Scroll(this.scrollerCon){
Column() {
Text('分组名称')
.fontSize(15)
.fontColor('#333333')
.margin({ left: 15 })
.height(50)
.textAlign(TextAlign.Start)
TextInput({placeholder:'设置分组名称',text:this.params.group_name})
.padding({left:15})
.width('100%')
.height(50)
.backgroundColor(Color.White)
.onChange((input:string)=>{
this.groupName = input;
})
Text('分组成员')
.fontSize(15)
.fontColor('#333333')
.margin({ left: 15 })
.height(50)
.textAlign(TextAlign.Start)
Row(){
Image($r('app.media.add_patients_to_roup'))
.width(50).height(50)
.margin({left:15})
Text('添加组患者')
.fontSize(16)
.fontColor('#333333')
.margin({left:15})
}
.width('100%')
.height(80)
.backgroundColor(Color.White)
.onClick(()=>{
const pathInfo1: HMRouterPathInfo = {
pageUrl: 'PatientsListComp',
param:{group_uuid:this.params.group_uuid,selectedPatients:this.groupPatientList}
};
const callback: HMRouterPathCallback = {
onResult: (popInfo: PopInfo) => {
const result = popInfo.result as Record<string,string | patientListModel[]>
const patients = result?.selectedPatients as patientListModel[] | undefined;
if (patients?.length) {
for (const model of result.selectedPatients as patientListModel[]) {
if (model.isSelected) {
this.groupPatientList.push(model)
}
}
}
}
};
HMRouterMgr.push(pathInfo1,callback)
// router.pushUrl({
// url:'pages/PatientsPage/PatientsListPage',
// params:{group_uuid:this.params.group_uuid,selectedPatients:this.groupPatientList}
// })
})
List(){
ListItemGroup({footer:this.footerView()}) {
ForEach(this.groupPatientList,(item:patientListModel,index:number)=>{
ListItem(){
this.patientsListItem(item,index)
}
})
}
}
}.width('100%').alignItems(HorizontalAlign.Start).justifyContent(FlexAlign.Start)
}
.width('100%').height('calc(100% - 56vp - 55vp)')
.scrollBar(BarState.Off)
.backgroundColor('#f4f4f4')
.align(Alignment.TopStart)
}
.width('100%').height('100%')
}
.height('100%')
}
@Builder
footerView (){
Column() {
Text('删除分组')
.fontSize(16)
.fontColor(Color.White)
.backgroundColor($r('app.color.main_color'))
.borderRadius(5)
.height(50)
.textAlign(TextAlign.Center)
.width('90%')
.onClick(()=>{
this.hintWindowDialog.open();
})
.visibility(this.params.title == '新建分组'?Visibility.None:Visibility.Visible)
}.width('100%')
.height(120)
.justifyContent(FlexAlign.End)
}
@Builder
patientsListItem(item:patientListModel,index:number) {
Column() {
Row() {
Image(BasicConstant.urlImage + item.photo)
.alt($r('app.media.userPhoto_default'))
.borderRadius(6)
.width(50)
.height(50)
.margin({ left: 15 })
Text(item.nickname ? item.nickname : ChangeUtil.stringIsUndefinedAndNull(item.realname)?item.realName:item.realname)
.fontSize(16)
.fontColor('#333333')
.margin({ left: 15 })
Blank()
Image($r('app.media.dele_patient_inThe_group'))
.width(22).height(22)
.objectFit(ImageFit.Fill)
.margin({ right: 15 })
.onClick(()=>{
this.groupPatientList.splice(index,1);
this.groupPatientList = [...this.groupPatientList];
})
}
.width('100%')
.height(80)
.backgroundColor(Color.White)
Blank()
.width('80%')
.height(1)
.backgroundColor(Color.Gray)
.margin({left:60})
}
}
}