From 67c2c35841431b34685dfdf7c39b9f069f0c198b Mon Sep 17 00:00:00 2001 From: xiaoxiao Date: Fri, 25 Jul 2025 13:44:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=82=A3=E8=80=85=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/components/MassSendingComp.ets | 379 ++++++++++++++++++ 1 file changed, 379 insertions(+) create mode 100644 features/patient/src/main/ets/components/MassSendingComp.ets diff --git a/features/patient/src/main/ets/components/MassSendingComp.ets b/features/patient/src/main/ets/components/MassSendingComp.ets new file mode 100644 index 0000000..5686843 --- /dev/null +++ b/features/patient/src/main/ets/components/MassSendingComp.ets @@ -0,0 +1,379 @@ +import { BasicConstant, ChangeUtil, + EmptyViewComp, + hdHttp, HdLoadingDialog, HdNav, HdResponse, logger,TripleOptionDialog, + ViewImageInfo } from "@itcast/basic"; +import { HashMap,JSON } from "@kit.ArkTS"; +import { BusinessError } from "@kit.BasicServicesKit"; +import { promptAction, router } from "@kit.ArkUI"; +import { PullToRefreshLayout, RefreshController } from "refreshlib"; +import { HMPopInfo, HMRouterMgr } from "@hadss/hmrouter"; + +@Component +export struct MassSendingComp { + @State pageNumber: number = 1 + @State totalPage: number = 1 + scroller = new Scroller() + @State messageList: ApiItem[] = [] + public controller: RefreshController = new RefreshController() + + aboutToAppear(): void { + this.initGetGroupListAction() + } + + initGetGroupListAction() { + this.pageNumber = 1 + this.messageList = [] + this.getGroupListAction() + } + + dialogController: CustomDialogController = new CustomDialogController({ + builder: TripleOptionDialog({ title: '温馨提示',subTitle:'',oneButtonTitle:'单独选择',twoButtonTitle:'分组选择',buttonSelected:(actionType:string)=>{ + if (actionType == '单独选择') { + HMRouterMgr.push({pageUrl:'PatientsListComp', + param:{group_uuid:"",selectedPatients:[],pageName:"群发消息"} + },{ + onResult:(popInfo:HMPopInfo)=>{ + if (popInfo && popInfo.result && popInfo.result["isRefresh"] !== undefined) { + this.initGetGroupListAction() + } + } + }) + } else { + HMRouterMgr.push({pageUrl:'SelectedPatientGroupComp' + },{ + onResult:(popInfo:HMPopInfo)=>{ + if (popInfo && popInfo.result && popInfo.result["isRefresh"] !== undefined) { + this.initGetGroupListAction() + } + } + }) + } + }}), + alignment: DialogAlignment.Center, + offset: { dx: 0, dy: 0 }, + autoCancel: true + }); + + dialog: CustomDialogController = new CustomDialogController({ + builder: HdLoadingDialog({ message: '加载中...' }), + customStyle: true, + alignment: DialogAlignment.Center + }) + + getGroupListAction() { + const hashMap: HashMap = new HashMap(); + hashMap.set('page', String(this.pageNumber)); + this.dialog.open() + hdHttp.httpReq(BasicConstant.listGroupSendMsg, hashMap).then(async (res: HdResponse) => { + this.dialog.close(); + logger.info('Response listGroupSendMsg' + res); + let json: Record = JSON.parse(res + '') as Record; + if (json.code == '200') { + this.controller.refreshSuccess(); + this.controller.loadSuccess(); + this.totalPage = json.data["pages"] + if (Array.isArray(json.data["list"])) { + this.messageList = [...this.messageList, ...json.data["list"]]; + } + } else { + console.error('群发消息列表失败:' + json.message) + promptAction.showToast({ message: String(json.message), duration: 1000 }) + } + }).catch((err: BusinessError) => { + this.dialog.close(); + this.controller.refreshError(); + console.info(`Response fails: ${err}`); + }) + } + + deleteGroupMessage(uuid: string) { + const hashMap: HashMap = new HashMap(); + hashMap.set('uuid', uuid); + this.dialog.open() + hdHttp.httpReq(BasicConstant.delGroupSendMsg, hashMap).then(async (res: HdResponse) => { + this.dialog.close(); + logger.info('Response listGroupSendMsg' + res); + let json: Record = JSON.parse(res + '') as Record; + if (json.code == '200') { + promptAction.showToast({ message: '删除成功', duration: 1000 }) + this.messageList = this.messageList.filter(item => item.uuid !== uuid); + } else { + console.error('删除群发消息失败:' + json.message) + promptAction.showToast({ message: String(json.message), duration: 1000 }) + } + }).catch((err: BusinessError) => { + this.dialog.close(); + this.controller.refreshError(); + console.info(`Response fails: ${err}`); + }) + } + + build() { + Column() { + HdNav({ + showLeftIcon: true, + title: '群发消息', + showRightText: false, + showRightIcon: false, + isLeftAction: true, + leftItemAction: () => { + router.back() + } + }) + + PullToRefreshLayout({ + scroller: this.scroller, + viewKey: "MessageGroupList", + controller: this.controller, + contentView: () => { + this.contentView() + }, + onRefresh: () => { + this.pageNumber = 1 + this.messageList = [] + this.getGroupListAction() + }, + onCanPullRefresh: () => { + if (!this.scroller.currentOffset()) { + return true + } + return this.scroller.currentOffset().yOffset <= 0 + }, + onCanPullLoad: () => { + if (this.pageNumber >= this.totalPage) { + return false; + } else { + return true; + } + }, + onLoad: () => { + this.pageNumber++; + this.getGroupListAction() + } + }).width('100%').height('calc(100% - 176vp)').clip(true) + + Text('群发消息') + .width('100%') + .height(50) + .fontSize(16) + .fontColor(Color.White) + .textAlign(TextAlign.Center) + .backgroundColor('rgba(63,199,193,1)') + .margin({ bottom: 20 }) + .onClick(() => this.dialogController.open()) + } + .width('100%') + } + + @Builder + contentView() { + List({ scroller: this.scroller }) { + ForEach(this.messageList, (item: ApiItem) => { + ListItem() { + Column() { + Text(String(item.msg_send_date)) + .height(45) + .fontSize(18) + .fontColor('#333333') + Column() { + Blank() + .width('100%') + .height(3) + .backgroundColor($r('app.color.main_color')) + Row() { + Column() { + Text(this.safeGetNameCount(item.realname).toString() + '位患者') + .fontSize(16) + .fontColor('rgba(51,51,51,1)') + .margin({ left: 10,top:10, right: 50 }) + .height(30) + Text(String(item.realname)) + .fontSize(14) + .fontColor('rgba(102,102,102,1)') + .width('100%') + .margin({ left: 10, right: 50 }) + }.width('100%').alignItems(HorizontalAlign.Start).justifyContent(FlexAlign.Start).layoutWeight(1) + + Image($r('app.media.message_sendgroup_delete')) + .width(35) + .height(35) + .onClick(() => this.deleteGroupMessage(item.uuid)) + }.width('100%').alignItems(VerticalAlign.Top).justifyContent(FlexAlign.Start) + + this.lineView() + Column() { + if (item.msg_type == 1) { + Text(String(item.msg_content)) + .fontSize(16) + .fontColor('#333333') + .width('100%') + .padding(10) + } else if (item.msg_type == 2) { + Image(BasicConstant.urlImage + String(item.msg_content)) + .width(100) + .height(100) + .alt($r('app.media.home_scroll_default1')) + .objectFit(ImageFit.Cover) + .padding(10) + .onClick(()=>{ + router.pushUrl({ + url: 'pages/Netease/PreviewPhotoPage', + params: { previewIndex:0 ,imgList:[{url:String(item.msg_content)}] as ViewImageInfo[],downLoad:false} + }) + }) + } else { + this.customMessage(item) + } + } + .width('100%') + .margin({ left: 10, right: 10 }) + } + .margin({ left: 10, right: 10 }) + .backgroundColor(Color.White) + .borderRadius(5) + + Row() { + Blank() + .layoutWeight(1) + Text('再发一条') + .fontSize(12) + .fontColor($r('app.color.main_color')) + .borderRadius(10) + .borderWidth(1) + .borderColor($r('app.color.main_color')) + .width(65) + .height(20) + .textAlign(TextAlign.Center) + .margin({ right: 20, top: 10, bottom: 10 }) + .onClick(()=>{ + HMRouterMgr.push({pageUrl:'SendGroupMessageComp',param:{'realname':item.realname,'patient_uuid':item.patient_uuid}},{ + onResult:(popInfo:HMPopInfo)=>{ + if (popInfo && popInfo.result && popInfo.result["isPop"] !== undefined) { + this.initGetGroupListAction() + } + } + }) + }) + } + .width('100%') + } + .width('100%') + } + }) + } + .backgroundColor('#f4f4f4') + .width('100%') + .scrollBar(BarState.Off) + .layoutWeight(1) + + EmptyViewComp({promptText:'暂无随访计划',isVisibility:true}) + .width('100%') + .height('100%') + .visibility(this.messageList.length>0?Visibility.None:Visibility.Visible) + } + + @Builder + lineView() { + Row() { + Blank() + .width(10) + .height(10) + .borderRadius(5) + .backgroundColor('rgba(228,228,228,1)') + .margin({ left: -1 }) + Blank() + .width('95%') + .height(1) + .backgroundColor('rgba(228,228,228,1)') + Blank() + .width(10) + .height(10) + .borderRadius(5) + .backgroundColor('rgba(228,228,228,1)') + } + .width('100%') + .height(10) + .margin({ top: 10 }) + } + + @Builder + customMessage(item: ApiItem) { + Column() { + Text(String(item.msg_type) == '4' ? this.parseMsgContent(item.msg_content).name : + this.parseMsgContent(item.msg_content).topic) + .fontSize(14) + .maxLines(2) + .margin({ left: 10, top: 10, right: 10 }) + + Row() { + Text(String(item.msg_type) == '5' || String(item.msg_type) == '6' || String(item.msg_type) == '7' || + String(item.msg_type) == '8' ? this.parseMsgContent(item.msg_content).path : + BasicConstant.urlImage + this.parseMsgContent(item.msg_content).path) + .fontSize(12) + .width('60%') + .maxLines(3) + .fontColor('rgba(127,127,127,1)') + .margin({ left: 10, top: 10, bottom: 10 }) + .layoutWeight(1) + Image(String(item.msg_type) == '7' || String(item.msg_type) == '8' ? + this.parseMsgContent(item.msg_content).imgPath : + BasicConstant.urlImage + this.parseMsgContent(item.msg_content).imgPath) + .alt($r('app.media.userPhoto_default')) + .objectFit(ImageFit.Fill) + .width(50) + .height(50) + .margin({ right: 10, bottom: 10 }) + } + } + .width('70%') + .borderWidth(0.5) + .borderRadius(5) + .borderColor('#999999') + .margin({ top: 15, bottom: 15 }) + .alignItems(HorizontalAlign.Start) + .justifyContent(FlexAlign.Start) + .onClick(()=>{ + router.pushUrl({ + url: 'pages/WebView/WebPage', + params: {'title':String(item.msg_type) == '4' || String(item.msg_type) == '3'?'患教详情':String(item.msg_type) == '5'?'出/停诊公告':'消息详情','url':String(item.msg_type) == '5' || String(item.msg_type) == '6' || String(item.msg_type) == '7' || + String(item.msg_type) == '8' ? this.parseMsgContent(item.msg_content).path : + BasicConstant.urlImage + this.parseMsgContent(item.msg_content).path} + }) + }) + } + + safeGetNameCount(realname: string | string[]): number { + if (Array.isArray(realname)) { + return realname.length; + } else if (typeof realname === 'string') { + return realname.split(',').filter(name => name.trim() !== '').length; + } + return 0; + } + + parseMsgContent(content: string): CardMsg { + // try { + return JSON.parse(content) as CardMsg + // } catch (e) { + // console.error("JSON 解析失败", e); + // return null; + // } + } +} + +interface ApiItem { + uuid: string + realname: string | string[] + msg_content: string + msg_type: number + patient_uuid:string + msg_send_date:string +} + +interface CardMsg { + path: string + imgPath: string + topic: string + uuid: string + name:string +} \ No newline at end of file