index.dart 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. // ignore_for_file: must_be_immutable
  2. import 'package:date_format/date_format.dart';
  3. import 'package:fis_jsonrpc/rpc.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:get/get.dart';
  6. import 'package:vitalapp/components/button.dart';
  7. import 'package:vitalapp/components/dialog_date.dart';
  8. import 'package:vitalapp/components/dialog_input.dart';
  9. import 'package:vitalapp/components/dialog_select.dart';
  10. import 'package:vitalapp/components/input.dart';
  11. import 'package:vitalapp/pages/medical_checkup_station/registration/controller.dart';
  12. import 'package:vitalapp/pages/medical_checkup_station/registration/state/list.dart';
  13. class RegistrationFormDialog extends StatefulWidget {
  14. final PatientDTO? patient;
  15. final bool? isEdit;
  16. RegistrationFormDialog({Key? key, this.patient, this.isEdit = false})
  17. : super(key: key);
  18. @override
  19. _RegistrationFormDialogState createState() => _RegistrationFormDialogState();
  20. }
  21. class _RegistrationFormDialogState extends State<RegistrationFormDialog> {
  22. var controller = Get.find<RegistrationController>();
  23. @override
  24. Widget build(BuildContext context) {
  25. return GetBuilder<RegistrationController>(
  26. id: "registration_Form",
  27. builder: (_) {
  28. return Dialog(
  29. child: Container(
  30. width: 900,
  31. height: 580,
  32. child: _buildView(),
  33. ),
  34. );
  35. },
  36. );
  37. }
  38. Widget _buildView() {
  39. return Column(
  40. children: [
  41. _buildHead(),
  42. _buildInputItem(
  43. "身份证号",
  44. value: widget.patient?.cardNo ?? '',
  45. onTap: () async {
  46. var result = await VDialogInput(
  47. initialValue: widget.patient?.cardNo ?? '',
  48. title: "身份证号",
  49. ).show();
  50. if (result != null) {
  51. widget.patient?.cardNo = result;
  52. widget.patient?.birthday = _getBirthDayofIdNumber(result);
  53. controller.update(["registration_Form"]);
  54. }
  55. },
  56. ),
  57. _buildInputItem(
  58. "姓名",
  59. value: widget.patient?.patientName ?? '',
  60. onTap: () async {
  61. var result = await VDialogInput(
  62. initialValue: widget.patient?.patientName ?? '',
  63. title: "姓名",
  64. ).show();
  65. if (result != null) {
  66. widget.patient?.patientName = result;
  67. controller.update(["registration_Form"]);
  68. }
  69. },
  70. ),
  71. _buildInputItem(
  72. "性别",
  73. value: controller.formController.selectGenderList
  74. .firstWhereOrNull(
  75. (element) => element.code == widget.patient?.patientGender)
  76. ?.name,
  77. onTap: () async {
  78. String? result =
  79. await VDialogSelect<VSelectGenderEnumModel, String>(
  80. source: controller.formController.selectGenderList,
  81. labelGetter: (data) => data.name,
  82. valueGetter: (data) => data.code.index.toString(),
  83. initialValue: widget.patient?.patientGender.index.toString(),
  84. title: "性别",
  85. ).show();
  86. if (result != null) {
  87. widget.patient?.patientGender =
  88. GenderEnum.values[int.parse(result)];
  89. controller.update(["registration_Form"]);
  90. }
  91. },
  92. suffixIcon: Icon(
  93. Icons.chevron_right_rounded,
  94. size: 30,
  95. ),
  96. ),
  97. _buildInputItem(
  98. "生日",
  99. value: getBirthDay(widget.patient?.birthday),
  100. onTap: () async {
  101. var result = await VDialogDate(
  102. initialValue: widget.patient?.birthday,
  103. title: "生日",
  104. // maxValue: appointment?.appointmentEndTime,
  105. ).show();
  106. if (result != null) {
  107. widget.patient?.birthday = result;
  108. controller.update(["registration_Form"]);
  109. }
  110. },
  111. suffixIcon: Icon(
  112. Icons.chevron_right_rounded,
  113. size: 30,
  114. ),
  115. ),
  116. _buildInputItem(
  117. "手机号",
  118. value: widget.patient?.phone,
  119. onTap: () async {
  120. var result = await VDialogInput(
  121. initialValue: widget.patient?.phone ?? '',
  122. title: "手机号",
  123. ).show();
  124. if (result != null) {
  125. widget.patient?.phone = result;
  126. controller.update(["registration_Form"]);
  127. }
  128. },
  129. ),
  130. _buildInputItem(
  131. "家庭住址",
  132. value: widget.patient?.patientAddress ?? '',
  133. onTap: () async {
  134. var result = await VDialogInput(
  135. initialValue: widget.patient?.patientAddress ?? '',
  136. title: "家庭住址",
  137. ).show();
  138. if (result != null) {
  139. widget.patient?.patientAddress = result;
  140. controller.update(["registration_Form"]);
  141. }
  142. },
  143. ),
  144. _buildIdentityVerifyButton(),
  145. ],
  146. );
  147. }
  148. Widget _buildHead() {
  149. return SizedBox(
  150. height: 60,
  151. child: Row(
  152. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  153. children: [
  154. Container(
  155. padding: const EdgeInsets.only(left: 16),
  156. child: Text(
  157. widget.isEdit! ? "编辑登记信息" : "身份信息录入",
  158. style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
  159. ),
  160. ),
  161. IconButton(
  162. onPressed: () => Get.back(),
  163. icon: const Icon(
  164. Icons.close,
  165. size: 30,
  166. ),
  167. ),
  168. ],
  169. ),
  170. );
  171. }
  172. Widget _buildInputItem(String title,
  173. {String? value, Function()? onTap, Widget? suffixIcon, int? maxLines}) {
  174. return Container(
  175. padding: const EdgeInsets.only(
  176. left: 80,
  177. right: 110,
  178. ),
  179. child: Row(
  180. children: [
  181. Container(
  182. width: 150,
  183. padding: const EdgeInsets.symmetric(vertical: 16),
  184. child: Text(
  185. title,
  186. style: const TextStyle(fontSize: 22),
  187. ),
  188. ),
  189. Expanded(
  190. child: VInput(
  191. initialValue: value,
  192. radius: 4,
  193. readOnly: true,
  194. suffixIcon: suffixIcon,
  195. maxLines: maxLines,
  196. onTap: () {
  197. onTap?.call();
  198. },
  199. ),
  200. )
  201. ],
  202. ),
  203. );
  204. }
  205. Widget _buildIdentityVerifyButton() {
  206. return Container(
  207. padding: const EdgeInsets.symmetric(
  208. vertical: 12,
  209. ),
  210. child: VButton(
  211. label: "确定",
  212. onTap: () {
  213. Get.back(result: widget.patient);
  214. },
  215. ),
  216. );
  217. }
  218. DateTime? _getBirthDayofIdNumber(String idCardNumber) {
  219. if (idCardNumber.isEmpty) return DateTime(1970, 1, 1);
  220. final idCardRegex = RegExp(r'^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})(\d|X)$');
  221. final match = idCardRegex.firstMatch(idCardNumber);
  222. if (match != null) {
  223. final year = int.parse(match.group(2)!);
  224. final month = int.parse(match.group(3)!);
  225. final day = int.parse(match.group(4)!);
  226. final birthDate = DateTime(year, month, day);
  227. return birthDate;
  228. }
  229. return null; // 返回一个默认值,表示无法提取出生日期
  230. }
  231. String getBirthDay(DateTime? birthDay) {
  232. if (birthDay == null) {
  233. return "";
  234. }
  235. return formatDate(birthDay, [yyyy, "-", mm, "-", dd]);
  236. }
  237. }