select_patient.dart 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. import 'dart:convert';
  2. import 'dart:io';
  3. import 'package:eitc_erm_app/registration.dart';
  4. import 'package:eitc_erm_app/utils/Component.dart';
  5. import 'package:eitc_erm_app/utils/Constants.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:http/http.dart' as http;
  8. import 'add_patient.dart';
  9. import 'bean/user_list.dart';
  10. import 'chat/chat_home.dart';
  11. import 'online_consultation.dart';
  12. String mFrom = "";
  13. // void main() {
  14. // WidgetsFlutterBinding.ensureInitialized();
  15. // runApp(SelectPatient());
  16. // }
  17. class SelectPatient extends StatefulWidget {
  18. SelectPatient(String from) {
  19. mFrom = from;
  20. }
  21. @override
  22. State<StatefulWidget> createState() => SelectPatientState();
  23. }
  24. class SelectPatientState extends State<SelectPatient> {
  25. ValueNotifier<dynamic> result = ValueNotifier(null);
  26. late Future<UserListEntity?> _future;
  27. late BuildContext cxt;
  28. @override
  29. void initState() {
  30. super.initState();
  31. _future = fetchData();
  32. }
  33. Future<UserListEntity?> fetchData() async {
  34. Map<String, String> headers = {
  35. 'token': '${Global.token}',
  36. };
  37. final response = await http
  38. .get(Uri.parse('${Global.BaseUrl}user/list'), headers: {
  39. HttpHeaders.contentTypeHeader: "application/json; charset=utf-8",
  40. 'token': '${Global.token}',
  41. });
  42. if (response.statusCode == 200) {
  43. final jsonString = utf8.decode(response.bodyBytes);
  44. final jsonResponse = jsonDecode(jsonString);
  45. print(jsonResponse);
  46. UserListEntity mUserListEntity =
  47. new UserListEntity.fromJson(jsonResponse);
  48. if (mUserListEntity.code == Global.responseSuccessCode) {
  49. } else {
  50. Component.toast("服务器错误提示:" + mUserListEntity.msg.toString(), 0);
  51. return null;
  52. }
  53. return mUserListEntity;
  54. } else {
  55. Component.toast("出错了,请稍后再试!", 0);
  56. return null;
  57. }
  58. }
  59. @override
  60. Widget build(BuildContext context) {
  61. cxt = context;
  62. return MaterialApp(
  63. home: Scaffold(
  64. appBar: new AppBar(
  65. title: new Text('选择就诊人',
  66. style: TextStyle(
  67. color: Colors.white,
  68. )),
  69. centerTitle: true,
  70. elevation: 0.5,
  71. backgroundColor: Global.StatusBarColor,
  72. leading: new IconButton(
  73. tooltip: '返回上一页',
  74. icon: const Icon(
  75. Icons.arrow_back_ios,
  76. color: Colors.white,
  77. ),
  78. onPressed: () {
  79. Navigator.of(context).pop();
  80. //_nextPage(-1);
  81. },
  82. ),
  83. ),
  84. body: Column(children: [
  85. /*Text(
  86. '选择就诊人',
  87. style: const TextStyle(fontSize: 15),
  88. textAlign: TextAlign.start,
  89. overflow: TextOverflow.ellipsis,
  90. ),*/
  91. FutureBuilder<UserListEntity?>(
  92. future: _future,
  93. builder: (context, snapshot) {
  94. if (snapshot.hasData) {
  95. UserListEntity? data = snapshot.data;
  96. return Expanded(
  97. // wrap in Expanded
  98. child: ListView.builder(
  99. shrinkWrap: true,
  100. itemCount: data?.data?.length,
  101. itemBuilder: (context, index) {
  102. return ListTile(
  103. title: Row(
  104. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  105. children: [
  106. Row(
  107. children: [
  108. Text(
  109. data!.data == null ? "" : data!.data![index].patientName as String,
  110. style: const TextStyle(fontSize: 18),
  111. ),
  112. SizedBox(width: 15),
  113. // if (index == 0)
  114. ElevatedButton(
  115. child: Text(" ${data!.data == null ? "" : data!.data![index].userRelationship } ",
  116. style: TextStyle(
  117. color: Colors.indigo, fontSize: 13)),
  118. style: ButtonStyle(
  119. backgroundColor:
  120. MaterialStateProperty.resolveWith<Color>(
  121. (states) {
  122. return Colors
  123. .lightBlueAccent; // Regular color
  124. }),
  125. // fixedSize: MaterialStateProperty.all<Size>(
  126. // Size(70, 15),
  127. // ),
  128. padding: MaterialStateProperty.all(
  129. EdgeInsets.zero),
  130. minimumSize:
  131. MaterialStateProperty.all(Size.zero),
  132. ),
  133. onPressed: () {},
  134. ),]),
  135. if (data!.data == null ? false : data!.data![index].isDefault == 1)
  136. Text(
  137. '默认就诊人',
  138. style: const TextStyle(
  139. fontSize: 13, color: Colors.grey),
  140. ),
  141. ]),
  142. subtitle: Text('身份证-${data!.data == null ? "" : data!.data![index].identificationCard}'),
  143. onTap: () {
  144. Global.appointmentPersonId = data!.data![index].patientId!;
  145. Global.patient = data;
  146. Global.selectPatient = index;
  147. if(mFrom == "fromDoctorDetail") {
  148. Navigator.of(cxt).pop();
  149. } else if(mFrom == "fromRecordRegistration") {
  150. Navigator.pop(cxt, "success");
  151. } else if(mFrom == "fromSelectDoctor") {
  152. Navigator.push(
  153. context,
  154. MaterialPageRoute(
  155. builder: (context) => OnlineConsultation()),
  156. );
  157. } else {
  158. Navigator.push(
  159. context,
  160. MaterialPageRoute(
  161. builder: (context) => Registration(userListEntity : data, whichPatient : index, key : new Key(""))),
  162. );
  163. }
  164. },
  165. );
  166. },
  167. ));
  168. } else if (snapshot.hasError) {
  169. return Text('Error: ${snapshot.error}');
  170. }
  171. return CircularProgressIndicator();
  172. },
  173. ),
  174. ElevatedButton(
  175. child: Text("添加就诊人",
  176. style: TextStyle(color: Colors.white, fontSize: 15)),
  177. style: ButtonStyle(
  178. backgroundColor:
  179. MaterialStateProperty.resolveWith<Color>((states) {
  180. return Colors.blue; // Regular color
  181. }),
  182. fixedSize: MaterialStateProperty.all<Size>(
  183. Size(MediaQuery.of(context).size.width - 32, 30), // 设置宽度和高度
  184. ),
  185. ),
  186. onPressed: () async {
  187. final result = await Navigator.push(
  188. context,
  189. MaterialPageRoute(builder: (context) => AddPatient(userListEntity : new UserListEntity(), whichPatient : -1, key: new Key(""),)),
  190. );
  191. setState(() {
  192. _future = fetchData();
  193. });
  194. },
  195. ),
  196. ]),
  197. ),
  198. );
  199. }
  200. }