view.dart 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. import 'package:date_format/date_format.dart';
  2. import 'package:fis_jsonrpc/rpc.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:get/get.dart';
  5. import 'package:vnoteapp/architecture/utils/datetime.dart';
  6. import 'package:vnoteapp/components/button.dart';
  7. import 'package:vnoteapp/components/panel.dart';
  8. import 'package:vnoteapp/components/search_input.dart';
  9. import 'package:vnoteapp/consts/rpc_enum_labels.dart';
  10. import 'controller.dart';
  11. class PatientListPage extends GetView<PatientListController> {
  12. const PatientListPage({super.key});
  13. @override
  14. Widget build(BuildContext context) {
  15. return Container(
  16. padding: const EdgeInsets.all(8),
  17. color: Colors.grey.shade200,
  18. child: Column(
  19. mainAxisSize: MainAxisSize.max,
  20. children: [
  21. _HeaderWidget(),
  22. const SizedBox(height: 20),
  23. Expanded(child: _buildListView()),
  24. // Obx(
  25. // () {
  26. // if (controller.state.hasNextPage == false) {
  27. // return Container(
  28. // alignment: Alignment.center,
  29. // padding: const EdgeInsets.symmetric(vertical: 8),
  30. // child: const Text(
  31. // "没有更多数据了~",
  32. // style: TextStyle(color: Colors.grey, fontSize: 14),
  33. // ),
  34. // );
  35. // } else {
  36. // return const SizedBox();
  37. // }
  38. // },
  39. // ),
  40. ],
  41. ),
  42. );
  43. }
  44. Widget _buildListView() {
  45. final scrollController = ScrollController();
  46. scrollController.addListener(
  47. () {
  48. // 如果滑动到底部
  49. try {
  50. if (scrollController.position.atEdge) {
  51. if (scrollController.position.pixels != 0) {
  52. if (controller.state.hasNextPage) {
  53. controller.loadNextPageList();
  54. }
  55. }
  56. }
  57. } catch (e) {
  58. // logger.e("listViewScrollController exception:", e);
  59. }
  60. },
  61. );
  62. return RefreshIndicator(
  63. onRefresh: () async {
  64. controller.reloadList();
  65. },
  66. child: Obx(
  67. () {
  68. final list = controller.state.dataList;
  69. final children = <Widget>[];
  70. for (var i = 0; i < list.length; i++) {
  71. children.add(_PatientCard(dto: list[i]));
  72. }
  73. return Scrollbar(
  74. trackVisibility: true,
  75. controller: scrollController,
  76. child: GridView(
  77. shrinkWrap: true,
  78. controller: scrollController,
  79. gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
  80. crossAxisCount: 3,
  81. mainAxisSpacing: 16,
  82. crossAxisSpacing: 20,
  83. childAspectRatio: 360 / 180,
  84. ),
  85. children: children,
  86. ),
  87. );
  88. },
  89. ),
  90. );
  91. }
  92. }
  93. class _HeaderWidget extends GetView<PatientListController> {
  94. @override
  95. Widget build(BuildContext context) {
  96. return SizedBox(
  97. height: 76,
  98. child: Row(
  99. children: [
  100. Expanded(
  101. child: SizedBox(
  102. height: 70,
  103. child: VSearchInput(
  104. placeholder: "身份证号码/姓名/手机号",
  105. onSearch: (value) {
  106. controller.state.searchString = value;
  107. controller.reloadList();
  108. },
  109. ),
  110. ),
  111. ),
  112. const SizedBox(width: 8),
  113. SizedBox(
  114. width: 180,
  115. height: 70,
  116. child: VButton(
  117. child: const Row(
  118. mainAxisAlignment: MainAxisAlignment.center,
  119. children: [
  120. Icon(Icons.note_add_outlined, size: 24),
  121. Text("新建档案", style: TextStyle(fontSize: 20)),
  122. ],
  123. ),
  124. onTap: () {
  125. controller.onCreateClicked();
  126. },
  127. ),
  128. ),
  129. const SizedBox(width: 8),
  130. SizedBox(
  131. width: 150,
  132. height: 70,
  133. child: VButton(
  134. child: const Row(
  135. mainAxisAlignment: MainAxisAlignment.center,
  136. children: [
  137. Icon(Icons.filter_alt, size: 24),
  138. Text("筛选", style: TextStyle(fontSize: 20)),
  139. ],
  140. ),
  141. onTap: () {
  142. controller.onFilterClicked();
  143. },
  144. ),
  145. ),
  146. ],
  147. ),
  148. );
  149. }
  150. }
  151. class _PatientCard extends StatelessWidget {
  152. final PatientDTO dto;
  153. const _PatientCard({super.key, required this.dto});
  154. @override
  155. Widget build(BuildContext context) {
  156. final body = Stack(
  157. children: [
  158. Container(
  159. padding: const EdgeInsets.symmetric(
  160. horizontal: 16,
  161. vertical: 12,
  162. ),
  163. child: Column(
  164. crossAxisAlignment: CrossAxisAlignment.start,
  165. children: [
  166. const SizedBox(height: 8),
  167. LayoutBuilder(
  168. builder: (context, c) {
  169. final width = c.maxWidth - 80 - 20;
  170. // 不和状态标签重叠,并保持一定距离
  171. return SizedBox(width: width, child: _buildBaseInfoRow());
  172. },
  173. ),
  174. const SizedBox(height: 12),
  175. _buildClassTags(),
  176. ],
  177. ),
  178. ),
  179. Positioned(
  180. top: 0,
  181. right: 0,
  182. child: _PatientSignStatusTag(),
  183. ),
  184. ],
  185. );
  186. return Material(
  187. borderRadius: BorderRadius.circular(8),
  188. child: Ink(
  189. decoration: BoxDecoration(
  190. color: Colors.white,
  191. borderRadius: BorderRadius.circular(8),
  192. ),
  193. child: InkWell(
  194. borderRadius: BorderRadius.circular(8),
  195. onTap: () {
  196. Get.find<PatientListController>().gotoDetail(dto.code!);
  197. },
  198. child: body,
  199. ),
  200. ),
  201. );
  202. }
  203. Widget _buildBaseInfoRow() {
  204. final birthday = dto.birthday!.toLocal();
  205. final age = DataTimeUtils.calculateAge(birthday);
  206. return Row(
  207. mainAxisSize: MainAxisSize.max,
  208. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  209. children: [
  210. SizedBox(
  211. width: 100,
  212. child: Text(
  213. dto.patientName!,
  214. style: const TextStyle(
  215. color: Colors.black,
  216. fontSize: 20,
  217. fontWeight: FontWeight.bold,
  218. ),
  219. ),
  220. ),
  221. Expanded(
  222. child: Row(
  223. mainAxisSize: MainAxisSize.max,
  224. mainAxisAlignment: MainAxisAlignment.start,
  225. children: [
  226. Expanded(
  227. child: Text(
  228. RpcEnumLabels.gender[dto.patientGender] ?? "未知",
  229. style: const TextStyle(
  230. color: Colors.grey,
  231. fontSize: 20,
  232. fontWeight: FontWeight.bold,
  233. ),
  234. ),
  235. ),
  236. Expanded(
  237. child: Text(
  238. "$age岁",
  239. style: const TextStyle(
  240. color: Colors.grey,
  241. fontSize: 20,
  242. ),
  243. ),
  244. ),
  245. ],
  246. ),
  247. ),
  248. ],
  249. );
  250. }
  251. Widget _buildClassTags() {
  252. fn(String x) => Text(
  253. x,
  254. style: const TextStyle(color: Colors.grey, fontSize: 18),
  255. );
  256. return ConstrainedBox(
  257. constraints: const BoxConstraints(minWidth: double.infinity),
  258. child: Wrap(
  259. alignment: WrapAlignment.start,
  260. spacing: 20,
  261. runSpacing: 8,
  262. children: [
  263. fn("一般人群"),
  264. fn("高血压"),
  265. fn("冠心病"),
  266. fn("冠心病"),
  267. fn("精神病"),
  268. ],
  269. ),
  270. );
  271. }
  272. }
  273. class _PatientSignStatusTag extends StatelessWidget {
  274. @override
  275. Widget build(BuildContext context) {
  276. const radius = Radius.circular(8);
  277. return Container(
  278. width: 80,
  279. height: 36,
  280. alignment: Alignment.center,
  281. decoration: BoxDecoration(
  282. color: Theme.of(context).primaryColor,
  283. borderRadius: BorderRadius.only(
  284. topRight: radius,
  285. bottomLeft: radius,
  286. ),
  287. ),
  288. child: Text(
  289. "已签约",
  290. style: TextStyle(color: Colors.white, fontSize: 14),
  291. ),
  292. );
  293. }
  294. }