select_patient.dart 7.5 KB

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