ConsultationList.dart 11 KB

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