import 'package:flutter/material.dart'; import 'package:get_it/get_it.dart'; import 'package:ustest/Services/NotificationReceivedArgs.dart'; import 'package:ustest/Services/UserService.dart'; import 'package:ustest/tool.dart'; import 'Services/ConsultationService.dart'; class ConsultationList extends StatefulWidget { ConsultationList({Key? key, required this.token, required this.consultations}) : super(); final String token; final List consultations; @override _ConsultationListState createState() => _ConsultationListState(); } class _ConsultationListState extends State { @override void initState() { var service = GetIt.instance.get(); service.NotificationReceived.subscribe((args) { if (args == null) { return; } NotificationTypeEnum type = args.type; switch (type) { case NotificationTypeEnum.InviteLiveConsultationNotification: var code = args.jsonMessage['ConsultationCode']; showConfirmDialog(context, "xxx请求会诊,要接吗?", () { OnAcceptLiveConsultation(code); }, () { OnRejectLiveConsultation(code); }); break; default: //TDOO } }); super.initState(); } @override void dispose() { var service = GetIt.instance.get(); service.NotificationReceived.unsubscribe((args) {}); super.dispose(); } void showConfirmDialog(BuildContext context, String content, Function confirmCallback, Function rejectCallback) { showDialog( context: context, builder: (context) { return new AlertDialog( title: new Text("提示"), content: new Text(content), actions: [ new TextButton( onPressed: () { confirmCallback(); Navigator.of(context).pop(); }, child: new Text("接受"), ), new TextButton( onPressed: () { Navigator.of(context).pop(); }, child: new Text("拒絕"), ), ], ); }); } @override Widget build(BuildContext context) { return Scaffold( body: Container( height: 600, child: Row( children: [ Container( height: 500, width: 400, child: ListView( restorationId: 'list_demo_list_view', padding: const EdgeInsets.symmetric(vertical: 0), children: [ for (int index = 0; index < widget.consultations.length; index++) Row( children: [ Expanded( child: Container( child: ListTile( leading: ExcludeSemantics( child: Icon(Icons.person), ), title: Text(widget.consultations[index].id + " - " + widget.consultations[index].expertUserCode), subtitle: Text( widget.consultations[index].patientName + getStatusDesc(widget.consultations[index] .consultationStatus)), onTap: (() => onTabPatient(widget.consultations[index].id)), ), )), Row( children: [ Offstage( offstage: widget.consultations[index] .consultationStatus != 1, child: TextButton.icon( onPressed: () => onApprovalConsultation( context, widget.consultations[index]), icon: Icon(Icons.update), label: Text("批准"))) ], ), Container( alignment: Alignment.topRight, child: Container( child: Column( children: [ ClipRRect( borderRadius: BorderRadius.circular(2), child: Container( color: Colors.amber[50], child: Row(children: [ Icon( Icons.star, color: Colors.amber[500], size: 12, ), Text( "5.0", style: TextStyle( color: Colors.amber[900], fontSize: 9), ), ]))), Container( child: Row( children: [ TextButton( child: Text("Start"), onPressed: (() => OnStartLiveConsultation(widget .consultations[index].id))), TextButton( child: Text("Cancel"), onPressed: (() => OnCancelLiveConsultation(widget .consultations[index].id))) ], )) ], ), )), ], ), ], ), ), ], ), )); } void onTabPatient(String id) async {} void OnStartLiveConsultation(id) async { try { var service = GetIt.instance.get(); Navigator.of(context).pushNamed('/meeting'); } catch (ex) { print('OnStartLiveConsultation.to ex:$ex'); MeetingTool.toast(ex.toString(), context); } } void OnCancelLiveConsultation(String id) async { try { var service = GetIt.instance.get(); var result = await service.CancelLiveConsultationAsync(id); } catch (ex) { print('OnCancelLiveConsultation.to ex:$ex'); MeetingTool.toast(ex.toString(), context); } } void OnAcceptLiveConsultation(id) async { try { var service = GetIt.instance.get(); Navigator.of(context).pushNamed('/meeting'); } catch (ex) { print('OnAcceptLiveConsultation.to ex' + ex.toString()); } } void OnRejectLiveConsultation(id) async { try { var service = GetIt.instance.get(); var result = await service.RejectLiveConsultationAsync(id); print("RejectLiveConsultationAsync"); } catch (ex) { print('OnRejectLiveConsultation.to ex' + ex.toString()); } } String getStatusDesc(status) { if (status == 1) { return "已申请"; } else if (status == 2) { return "已撤回"; } else if (status == 3) { return "已拒绝"; } else if (status == 4) { return "待开始(即申请已同意)"; } else if (status == 5) { return "进行中"; } else if (status == 6) { return "待报告"; } else if (status == 7) { return "已结束(即会诊报告已提交)"; } return ""; } void onApprovalConsultation(context, Consultation model) { print("onApprovalConsultation click"); //Navigator.of(context).pushNamed('/approvalconsultation',arguments: model); //Navigator.push( //context, //MaterialPageRoute( //builder: (context) => ApprovalConsultationScreen(model: model))); } } class Consultation { final String id; final String patientName; final int consultationStatus; final String expertUserCode; final String applyUserCode; Consultation( {required this.id, required this.patientName, required this.consultationStatus, required this.expertUserCode, required this.applyUserCode}); factory Consultation.fromJson(Map json) { var item = Consultation( id: json['ConsultationCode'] as String, //expertUserCode: json['ExpertUserCode'] as String, //applyUserCode: json['ApplyUserCode'] as String, //patientName: json['PatientName'] as String, //consultationStatus: json['ConsultationStatus'] as int); expertUserCode: '', applyUserCode: '', patientName: '', consultationStatus: json['ConsultationStatus']); return item; } Map toMap() { return { 'ConsultationCode': id, 'PatientName': patientName, 'ExpertUserCode': expertUserCode, }; } @override String toString() { return 'Patient{id: $id}'; } }