patient_list.dart 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. import 'dart:io';
  2. import 'package:eitc_erm_app/utils/Component.dart';
  3. import 'package:eitc_erm_app/utils/Constants.dart';
  4. import 'package:eitc_erm_app/utils/logger.dart';
  5. import 'package:eitc_erm_app/widget/loading.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:http/http.dart' as http;
  8. import 'package:left_scroll_actions/cupertinoLeftScroll.dart';
  9. import 'package:left_scroll_actions/global/actionListener.dart';
  10. import 'package:left_scroll_actions/leftScroll.dart';
  11. import 'add_patient.dart';
  12. import 'bean/normal_response.dart';
  13. import 'bean/user_list.dart';
  14. void main() {
  15. WidgetsFlutterBinding.ensureInitialized();
  16. runApp(PatientList());
  17. }
  18. class PatientList extends StatefulWidget {
  19. @override
  20. State<StatefulWidget> createState() => PatientListState();
  21. }
  22. class PatientListState extends State<PatientList> {
  23. ValueNotifier<dynamic> result = ValueNotifier(null);
  24. late Future<UserListEntity?> _future;
  25. @override
  26. void initState() {
  27. super.initState();
  28. _future = fetchData();
  29. }
  30. Future<UserListEntity?> fetchData() async {
  31. final response =
  32. await http.get(Uri.parse('${Global.BaseUrl}user/list'), headers: jsonHeaders(withToken: true));
  33. if (response.statusCode == 200) {
  34. final json = decodeBodyToJson(response.bodyBytes);
  35. logd("就诊人列表=$json");
  36. UserListEntity mUserListEntity = UserListEntity.fromJson(json);
  37. return mUserListEntity;
  38. } else {
  39. Component.toast("出错了,请稍后再试!", 0);
  40. }
  41. }
  42. @override
  43. Widget build(BuildContext context) {
  44. return Scaffold(
  45. appBar: AppBar(
  46. title: const Text('就诊人管理',
  47. style: TextStyle(
  48. color: Colors.white,
  49. )),
  50. centerTitle: true,
  51. elevation: 0.5,
  52. backgroundColor: Global.StatusBarColor,
  53. leading: IconButton(
  54. tooltip: '返回上一页',
  55. icon: const Icon(
  56. Icons.arrow_back_ios,
  57. color: Colors.white,
  58. ),
  59. onPressed: () {
  60. Navigator.of(context).pop();
  61. //_nextPage(-1);
  62. },
  63. ),
  64. ),
  65. body: Column(children: [
  66. /*Text(
  67. '选择就诊人',
  68. style: const TextStyle(fontSize: 15),
  69. textAlign: TextAlign.start,
  70. overflow: TextOverflow.ellipsis,
  71. ),*/
  72. FutureBuilder<UserListEntity?>(
  73. future: _future,
  74. builder: (context, snapshot) {
  75. if (snapshot.hasData) {
  76. UserListEntity? data = snapshot.data;
  77. return Expanded(
  78. child: ListView.builder(
  79. itemCount: data?.data?.length,
  80. itemBuilder: (context, index) {
  81. return ListTile(
  82. contentPadding: const EdgeInsets.all(0),
  83. title: CupertinoLeftScroll(
  84. key: Key('$index'),
  85. // left scroll widget will auto close while the other widget is opened and has same closeTag.
  86. // 当另一个有相同closeTag的组件打开时,其他有着相同closeTag的组件会自动关闭.
  87. closeTag: const LeftScrollCloseTag('tag'),
  88. buttonWidth: 70,
  89. buttons: <Widget>[
  90. Row(
  91. children: <Widget>[
  92. const SizedBox(width: 20.0),
  93. LeftScrollItem(
  94. text: ' 解绑 ',
  95. color: Colors.red,
  96. onTap: () {
  97. showDialog(
  98. context: context,
  99. builder: (context) {
  100. return AlertDialog(
  101. title: const Text('提示',
  102. style: TextStyle(
  103. color: Colors.blueAccent)),
  104. content: const Text('确定解绑该就诊人?'),
  105. actions: <Widget>[
  106. TextButton(
  107. onPressed: () {
  108. Navigator.of(context).pop();
  109. },
  110. child: const Text('取消'),
  111. ),
  112. TextButton(
  113. onPressed: () {
  114. Navigator.of(context).pop();
  115. remove(
  116. patientId:
  117. '${data!.data![index].patientId}');
  118. },
  119. child: const Text('确定'),
  120. ),
  121. ]);
  122. });
  123. },
  124. ),
  125. ],
  126. ),
  127. ],
  128. onTap: () async {
  129. final result = await Navigator.push(
  130. context,
  131. MaterialPageRoute(
  132. builder: (context) => AddPatient(
  133. userListEntity: data,
  134. whichPatient: index,
  135. key: const Key(""),
  136. )),
  137. );
  138. setState(() {
  139. _future = fetchData();
  140. });
  141. },
  142. child: Container(
  143. padding: const EdgeInsets.only(left: 10),
  144. height: 60,
  145. color: Colors.white,
  146. alignment: Alignment.centerLeft,
  147. child: Row(
  148. children: [
  149. Expanded(
  150. child: Text(
  151. data!.data![index].patientName as String,
  152. style: const TextStyle(fontSize: 18),
  153. )),
  154. Visibility(
  155. visible: data.data?[index].isDefault == 1,
  156. child: Container(
  157. margin: const EdgeInsets.only(right: 10),
  158. padding: const EdgeInsets.symmetric(
  159. horizontal: 8, vertical: 3),
  160. decoration: BoxDecoration(
  161. borderRadius: BorderRadius.circular(30),
  162. color: Colors.lightBlueAccent),
  163. child: const Text(
  164. "默认",
  165. style: TextStyle(
  166. fontSize: 12, color: Colors.white),
  167. ),
  168. ))
  169. ],
  170. ),
  171. ),
  172. ),
  173. subtitle: Container(
  174. padding: const EdgeInsets.only(left: 10),
  175. child:
  176. Text('身份证-${data.data![index].identificationCard}'),
  177. ),
  178. onTap: () async {
  179. final result = await Navigator.push(
  180. context,
  181. MaterialPageRoute(
  182. builder: (context) => AddPatient(
  183. userListEntity: data,
  184. whichPatient: index,
  185. key: const Key(""),
  186. )),
  187. );
  188. setState(() {
  189. _future = fetchData();
  190. });
  191. },
  192. );
  193. },
  194. ));
  195. } else if (snapshot.hasError) {
  196. return Text('Error: ${snapshot.error}');
  197. }
  198. return const Expanded(child: ColorLoader());
  199. },
  200. ),
  201. Padding(
  202. padding: const EdgeInsets.symmetric(horizontal: 20),
  203. child: SizedBox(
  204. width: double.infinity,
  205. child: ElevatedButton(
  206. style: const ButtonStyle(
  207. backgroundColor: WidgetStatePropertyAll(Colors.blue),
  208. ),
  209. onPressed: () async {
  210. await Navigator.push(
  211. context,
  212. MaterialPageRoute(
  213. builder: (context) => AddPatient(
  214. userListEntity: new UserListEntity(),
  215. whichPatient: -1,
  216. key: const Key(""),
  217. )),
  218. );
  219. setState(() {
  220. _future = fetchData();
  221. });
  222. },
  223. child: const Text("添加就诊人",
  224. style: TextStyle(color: Colors.white, fontSize: 15)),
  225. ),
  226. )),
  227. const SizedBox(
  228. height: 10,
  229. )
  230. ]),
  231. );
  232. }
  233. onGoBack() {
  234. setState(() {
  235. _future = fetchData();
  236. });
  237. }
  238. Future<void> remove({required String patientId}) async {
  239. logd("要解绑的就诊人ID=$patientId");
  240. final response = await http.delete(
  241. Uri.parse('${Global.BaseUrl}user/remove?patientId=$patientId'),
  242. headers: {
  243. 'token': Global.token,
  244. },
  245. );
  246. try {
  247. final json = decodeBodyToJson(response.bodyBytes);
  248. logd("删除就诊人结果=$json");
  249. NormalResponse mNormalResponse = NormalResponse.fromJson(json);
  250. if (mNormalResponse.code == Global.responseSuccessCode) {
  251. Component.toast("解绑成功!", 2);
  252. setState(() {
  253. _future = fetchData();
  254. });
  255. } else {
  256. Component.toast(mNormalResponse.msg.toString(), 0);
  257. }
  258. } catch (e) {
  259. Component.toast("异常: $e", 0);
  260. } finally {}
  261. }
  262. }