patient_info.dart 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. // ignore_for_file: must_be_immutable
  2. import 'package:fis_jsonrpc/rpc.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:get/get.dart';
  5. import 'package:vitalapp/architecture/utils/datetime.dart';
  6. import 'package:vitalapp/components/cell.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/consts/nations.dart';
  11. import 'package:vitalapp/consts/rpc_enum_labels.dart';
  12. import 'package:vitalapp/pages/patient/create/controller.dart';
  13. class PatientInfo extends GetView<CreatePatientController> {
  14. PatientInfo({super.key, this.isNotScanCode = true});
  15. bool? isNotScanCode;
  16. @override
  17. Widget build(BuildContext context) {
  18. return Container(
  19. padding: const EdgeInsets.only(bottom: 80),
  20. child: _buildContent(),
  21. );
  22. }
  23. Widget _buildContent() {
  24. return SingleChildScrollView(
  25. child: Column(
  26. children: [_buildVListFormCellGroup()],
  27. ),
  28. );
  29. }
  30. Widget _buildVListFormCellGroup() {
  31. final state = controller.state;
  32. return Obx(
  33. () => VListFormCellGroup(
  34. children: [
  35. VListFormCell(
  36. labelWidget: RichText(
  37. text: const TextSpan(
  38. text: '* ',
  39. style: TextStyle(color: Colors.red, fontSize: 20),
  40. children: [
  41. TextSpan(
  42. text: '证件号',
  43. style: TextStyle(color: Colors.black, fontSize: 20),
  44. ),
  45. ],
  46. ),
  47. ),
  48. content: controller.state.cardNo,
  49. onTap: () async {
  50. final result = await VDialogInput(
  51. title: "证件号",
  52. initialValue: controller.state.cardNo,
  53. placeholder: "请填写证件号",
  54. ).show();
  55. if (result != null) {
  56. controller.state.cardNo = result;
  57. if (!result.isEmpty && result.length > 17) {
  58. var sexNum = result.substring(16, 17);
  59. if (!sexNum.isEmpty && RegExp(r'^\d+$').hasMatch(sexNum)) {
  60. if (int.parse(sexNum) % 2 == 1) {
  61. controller.state.gender = GenderEnum.Male;
  62. } else {
  63. controller.state.gender = GenderEnum.Female;
  64. }
  65. } else {
  66. controller.state.gender = GenderEnum.Unknown;
  67. }
  68. }
  69. }
  70. },
  71. ),
  72. VListFormCell(
  73. labelWidget: RichText(
  74. text: const TextSpan(
  75. text: '* ',
  76. style: TextStyle(color: Colors.red, fontSize: 20),
  77. children: [
  78. TextSpan(
  79. text: '姓名',
  80. style: TextStyle(color: Colors.black, fontSize: 20),
  81. ),
  82. ],
  83. ),
  84. ),
  85. content: controller.state.name,
  86. onTap: () async {
  87. final result = await VDialogInput(
  88. title: "姓名",
  89. initialValue: controller.state.name,
  90. placeholder: "请填写姓名",
  91. ).show();
  92. if (result != null) {
  93. controller.state.name = result.toString().trim();
  94. }
  95. },
  96. ),
  97. VListFormCell(
  98. label: "性别",
  99. content: RpcEnumLabels.gender[state.gender],
  100. onTap: () async {
  101. final result = await VDialogSelect<GenderEnum, GenderEnum>(
  102. title: "选择性别",
  103. source: const [
  104. GenderEnum.Male,
  105. GenderEnum.Female,
  106. GenderEnum.Unknown,
  107. GenderEnum.Unspecified
  108. ],
  109. valueGetter: (data) => data,
  110. labelGetter: (data) => RpcEnumLabels.gender[data] ?? "",
  111. initialValue: state.gender,
  112. ).show();
  113. if (result != null) {
  114. controller.state.gender = result;
  115. }
  116. },
  117. ),
  118. VListFormCell(
  119. label: "民族",
  120. content: state.nation,
  121. onTap: () async {
  122. final result = await VDialogSelect<String, String>(
  123. title: "选择民族",
  124. source: Nations.china,
  125. valueGetter: (data) => data,
  126. labelGetter: (data) => data,
  127. initialValue: state.nation,
  128. ).show();
  129. if (result != null) {
  130. controller.state.nation = result;
  131. }
  132. },
  133. ),
  134. VListFormCell(
  135. label: "出生日期",
  136. content: controller.state.birthday != null
  137. ? DataTimeUtils.formatDateString(controller.state.birthday!)
  138. : "",
  139. onTap: () async {
  140. final result = await VDialogDate(
  141. title: "设置出生日期",
  142. initialValue: controller.state.birthday,
  143. maxValue: DateTime.now(),
  144. ).show();
  145. if (result != null) {
  146. controller.state.birthday = result;
  147. }
  148. },
  149. ),
  150. VListFormCell(
  151. label: "年龄",
  152. content: controller.state.age.toString(),
  153. ),
  154. VListFormCell(
  155. label: "手机号码",
  156. content: controller.state.phoneNo,
  157. onTap: () async {
  158. final result = await VDialogInput(
  159. title: "手机号码",
  160. initialValue: controller.state.phoneNo,
  161. placeholder: "请填写手机号码",
  162. ).show();
  163. if (result != null) {
  164. controller.state.phoneNo = result;
  165. }
  166. },
  167. ),
  168. VListFormCell(
  169. label: "同步户籍地址到现住地址",
  170. labelWidth: 250,
  171. contentWidget: Container(
  172. child: Switch(
  173. onChanged: (value) {
  174. controller.onSyncAddressCheckChanged(value);
  175. },
  176. value: controller.state.isSyncAddresses,
  177. ),
  178. ),
  179. ),
  180. VListFormCell(
  181. label: "户籍地址",
  182. content: controller.state.censusRegister,
  183. onTap: () async {
  184. final result = await VDialogInput(
  185. title: "户籍地址",
  186. initialValue: controller.state.censusRegister,
  187. placeholder: "请填写户籍地址",
  188. ).show();
  189. if (result != null) {
  190. controller.onCensusRegisterChanged(result);
  191. }
  192. },
  193. ),
  194. VListFormCell(
  195. label: "现住地址",
  196. content: controller.state.address,
  197. onTap: () async {
  198. final result = await VDialogInput(
  199. title: "现住地址",
  200. initialValue: controller.state.address,
  201. placeholder: "请填写现住地址",
  202. ).show();
  203. if (result != null) {
  204. controller.state.address = result;
  205. }
  206. },
  207. ),
  208. ],
  209. ),
  210. );
  211. }
  212. }