ConsultationList.dart 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. import 'package:flutter/material.dart';
  2. import 'package:get_it/get_it.dart';
  3. import 'package:ustest/Services/NotificationReceivedArgs.dart';
  4. import 'package:ustest/Services/UserService.dart';
  5. import 'package:ustest/tool.dart';
  6. import 'Services/ConsultationService.dart';
  7. class ConsultationList extends StatefulWidget {
  8. ConsultationList({Key? key, required this.token, required this.consultations})
  9. : super();
  10. final String token;
  11. final List<Consultation> consultations;
  12. @override
  13. _ConsultationListState createState() => _ConsultationListState();
  14. }
  15. class _ConsultationListState extends State<ConsultationList> {
  16. @override
  17. void initState() {
  18. var service = GetIt.instance.get<UserService>();
  19. service.NotificationReceived.subscribe((args) {
  20. if (args == null) {
  21. return;
  22. }
  23. NotificationTypeEnum type = args.type;
  24. switch (type) {
  25. case NotificationTypeEnum.InviteLiveConsultationNotification:
  26. var code = args.jsonMessage['ConsultationCode'];
  27. showConfirmDialog(context, "xxx请求会诊,要接吗?", () {
  28. OnAcceptLiveConsultation(code);
  29. }, () {
  30. OnRejectLiveConsultation(code);
  31. });
  32. break;
  33. default:
  34. //TDOO
  35. }
  36. });
  37. super.initState();
  38. }
  39. @override
  40. void dispose() {
  41. var service = GetIt.instance.get<UserService>();
  42. service.NotificationReceived.unsubscribe((args) {});
  43. super.dispose();
  44. }
  45. void showConfirmDialog(BuildContext context, String content,
  46. Function confirmCallback, Function rejectCallback) {
  47. showDialog(
  48. context: context,
  49. builder: (context) {
  50. return new AlertDialog(
  51. title: new Text("提示"),
  52. content: new Text(content),
  53. actions: <Widget>[
  54. new TextButton(
  55. onPressed: () {
  56. confirmCallback();
  57. Navigator.of(context).pop();
  58. },
  59. child: new Text("接受"),
  60. ),
  61. new TextButton(
  62. onPressed: () {
  63. Navigator.of(context).pop();
  64. },
  65. child: new Text("拒絕"),
  66. ),
  67. ],
  68. );
  69. });
  70. }
  71. @override
  72. Widget build(BuildContext context) {
  73. return Scaffold(
  74. body: Container(
  75. height: 600,
  76. child: Row(
  77. children: [
  78. Container(
  79. height: 500,
  80. width: 400,
  81. child: ListView(
  82. restorationId: 'list_demo_list_view',
  83. padding: const EdgeInsets.symmetric(vertical: 0),
  84. children: [
  85. for (int index = 0;
  86. index < widget.consultations.length;
  87. index++)
  88. Row(
  89. children: [
  90. Expanded(
  91. child: Container(
  92. child: ListTile(
  93. leading: ExcludeSemantics(
  94. child: Icon(Icons.person),
  95. ),
  96. title: Text(widget.consultations[index].id +
  97. " - " +
  98. widget.consultations[index].expertUserCode),
  99. subtitle: Text(
  100. widget.consultations[index].patientName +
  101. getStatusDesc(widget.consultations[index]
  102. .consultationStatus)),
  103. onTap: (() =>
  104. onTabPatient(widget.consultations[index].id)),
  105. ),
  106. )),
  107. Row(
  108. children: [
  109. Offstage(
  110. offstage: widget.consultations[index]
  111. .consultationStatus !=
  112. 1,
  113. child: TextButton.icon(
  114. onPressed: () => onApprovalConsultation(
  115. context, widget.consultations[index]),
  116. icon: Icon(Icons.update),
  117. label: Text("批准")))
  118. ],
  119. ),
  120. Container(
  121. alignment: Alignment.topRight,
  122. child: Container(
  123. child: Column(
  124. children: [
  125. ClipRRect(
  126. borderRadius: BorderRadius.circular(2),
  127. child: Container(
  128. color: Colors.amber[50],
  129. child: Row(children: [
  130. Icon(
  131. Icons.star,
  132. color: Colors.amber[500],
  133. size: 12,
  134. ),
  135. Text(
  136. "5.0",
  137. style: TextStyle(
  138. color: Colors.amber[900],
  139. fontSize: 9),
  140. ),
  141. ]))),
  142. Container(
  143. child: Row(
  144. children: [
  145. TextButton(
  146. child: Text("Start"),
  147. onPressed: (() =>
  148. OnStartLiveConsultation(widget
  149. .consultations[index].id))),
  150. TextButton(
  151. child: Text("Cancel"),
  152. onPressed: (() =>
  153. OnCancelLiveConsultation(widget
  154. .consultations[index].id)))
  155. ],
  156. ))
  157. ],
  158. ),
  159. )),
  160. ],
  161. ),
  162. ],
  163. ),
  164. ),
  165. ],
  166. ),
  167. ));
  168. }
  169. void onTabPatient(String id) async {}
  170. void OnStartLiveConsultation(id) async {
  171. try {
  172. var service = GetIt.instance.get<ConsultationService>();
  173. Navigator.of(context).pushNamed('/meeting');
  174. } catch (ex) {
  175. print('OnStartLiveConsultation.to ex:$ex');
  176. MeetingTool.toast(ex.toString(), context);
  177. }
  178. }
  179. void OnCancelLiveConsultation(String id) async {
  180. try {
  181. var service = GetIt.instance.get<ConsultationService>();
  182. var result = await service.CancelLiveConsultationAsync(id);
  183. } catch (ex) {
  184. print('OnCancelLiveConsultation.to ex:$ex');
  185. MeetingTool.toast(ex.toString(), context);
  186. }
  187. }
  188. void OnAcceptLiveConsultation(id) async {
  189. try {
  190. var service = GetIt.instance.get<ConsultationService>();
  191. Navigator.of(context).pushNamed('/meeting');
  192. } catch (ex) {
  193. print('OnAcceptLiveConsultation.to ex' + ex.toString());
  194. }
  195. }
  196. void OnRejectLiveConsultation(id) async {
  197. try {
  198. var service = GetIt.instance.get<ConsultationService>();
  199. var result = await service.RejectLiveConsultationAsync(id);
  200. print("RejectLiveConsultationAsync");
  201. } catch (ex) {
  202. print('OnRejectLiveConsultation.to ex' + ex.toString());
  203. }
  204. }
  205. String getStatusDesc(status) {
  206. if (status == 1) {
  207. return "已申请";
  208. } else if (status == 2) {
  209. return "已撤回";
  210. } else if (status == 3) {
  211. return "已拒绝";
  212. } else if (status == 4) {
  213. return "待开始(即申请已同意)";
  214. } else if (status == 5) {
  215. return "进行中";
  216. } else if (status == 6) {
  217. return "待报告";
  218. } else if (status == 7) {
  219. return "已结束(即会诊报告已提交)";
  220. }
  221. return "";
  222. }
  223. void onApprovalConsultation(context, Consultation model) {
  224. print("onApprovalConsultation click");
  225. //Navigator.of(context).pushNamed('/approvalconsultation',arguments: model);
  226. //Navigator.push(
  227. //context,
  228. //MaterialPageRoute(
  229. //builder: (context) => ApprovalConsultationScreen(model: model)));
  230. }
  231. }
  232. class Consultation {
  233. final String id;
  234. final String patientName;
  235. final int consultationStatus;
  236. final String expertUserCode;
  237. final String applyUserCode;
  238. Consultation(
  239. {required this.id,
  240. required this.patientName,
  241. required this.consultationStatus,
  242. required this.expertUserCode,
  243. required this.applyUserCode});
  244. factory Consultation.fromJson(Map<String, dynamic> json) {
  245. var item = Consultation(
  246. id: json['ConsultationCode'] as String,
  247. //expertUserCode: json['ExpertUserCode'] as String,
  248. //applyUserCode: json['ApplyUserCode'] as String,
  249. //patientName: json['PatientName'] as String,
  250. //consultationStatus: json['ConsultationStatus'] as int);
  251. expertUserCode: '',
  252. applyUserCode: '',
  253. patientName: '',
  254. consultationStatus: json['ConsultationStatus']);
  255. return item;
  256. }
  257. Map<String, dynamic> toMap() {
  258. return {
  259. 'ConsultationCode': id,
  260. 'PatientName': patientName,
  261. 'ExpertUserCode': expertUserCode,
  262. };
  263. }
  264. @override
  265. String toString() {
  266. return 'Patient{id: $id}';
  267. }
  268. }