123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- // ignore_for_file: must_be_immutable
- import 'package:date_format/date_format.dart';
- import 'package:fis_jsonrpc/rpc.dart';
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- import 'package:vitalapp/components/button.dart';
- import 'package:vitalapp/components/dialog_date.dart';
- import 'package:vitalapp/components/dialog_input.dart';
- import 'package:vitalapp/components/dialog_select.dart';
- import 'package:vitalapp/components/input.dart';
- import 'package:vitalapp/pages/medical_checkup_station/registration/controller.dart';
- import 'package:vitalapp/pages/medical_checkup_station/registration/state/list.dart';
- class RegistrationFormDialog extends StatefulWidget {
- final PatientDTO? patient;
- final bool? isEdit;
- RegistrationFormDialog({Key? key, this.patient, this.isEdit = false})
- : super(key: key);
- @override
- _RegistrationFormDialogState createState() => _RegistrationFormDialogState();
- }
- class _RegistrationFormDialogState extends State<RegistrationFormDialog> {
- var controller = Get.find<RegistrationController>();
- @override
- Widget build(BuildContext context) {
- return GetBuilder<RegistrationController>(
- id: "registration_Form",
- builder: (_) {
- return Dialog(
- child: Container(
- width: 900,
- height: 580,
- child: _buildView(),
- ),
- );
- },
- );
- }
- Widget _buildView() {
- return Column(
- children: [
- _buildHead(),
- _buildInputItem(
- "身份证号",
- value: widget.patient?.cardNo ?? '',
- onTap: () async {
- var result = await VDialogInput(
- initialValue: widget.patient?.cardNo ?? '',
- title: "身份证号",
- ).show();
- if (result != null) {
- widget.patient?.cardNo = result;
- widget.patient?.birthday = _getBirthDayofIdNumber(result);
- controller.update(["registration_Form"]);
- }
- },
- ),
- _buildInputItem(
- "姓名",
- value: widget.patient?.patientName ?? '',
- onTap: () async {
- var result = await VDialogInput(
- initialValue: widget.patient?.patientName ?? '',
- title: "姓名",
- ).show();
- if (result != null) {
- widget.patient?.patientName = result;
- controller.update(["registration_Form"]);
- }
- },
- ),
- _buildInputItem(
- "性别",
- value: controller.formController.selectGenderList
- .firstWhereOrNull(
- (element) => element.code == widget.patient?.patientGender)
- ?.name,
- onTap: () async {
- String? result =
- await VDialogSelect<VSelectGenderEnumModel, String>(
- source: controller.formController.selectGenderList,
- labelGetter: (data) => data.name,
- valueGetter: (data) => data.code.index.toString(),
- initialValue: widget.patient?.patientGender.index.toString(),
- title: "性别",
- ).show();
- if (result != null) {
- widget.patient?.patientGender =
- GenderEnum.values[int.parse(result)];
- controller.update(["registration_Form"]);
- }
- },
- suffixIcon: Icon(
- Icons.chevron_right_rounded,
- size: 30,
- ),
- ),
- _buildInputItem(
- "生日",
- value: getBirthDay(widget.patient?.birthday),
- onTap: () async {
- var result = await VDialogDate(
- initialValue: widget.patient?.birthday,
- title: "生日",
- // maxValue: appointment?.appointmentEndTime,
- ).show();
- if (result != null) {
- widget.patient?.birthday = result;
- controller.update(["registration_Form"]);
- }
- },
- suffixIcon: Icon(
- Icons.chevron_right_rounded,
- size: 30,
- ),
- ),
- _buildInputItem(
- "手机号",
- value: widget.patient?.phone,
- onTap: () async {
- var result = await VDialogInput(
- initialValue: widget.patient?.phone ?? '',
- title: "手机号",
- ).show();
- if (result != null) {
- widget.patient?.phone = result;
- controller.update(["registration_Form"]);
- }
- },
- ),
- _buildInputItem(
- "家庭住址",
- value: widget.patient?.patientAddress ?? '',
- onTap: () async {
- var result = await VDialogInput(
- initialValue: widget.patient?.patientAddress ?? '',
- title: "家庭住址",
- ).show();
- if (result != null) {
- widget.patient?.patientAddress = result;
- controller.update(["registration_Form"]);
- }
- },
- ),
- _buildIdentityVerifyButton(),
- ],
- );
- }
- Widget _buildHead() {
- return SizedBox(
- height: 60,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Container(
- padding: const EdgeInsets.only(left: 16),
- child: Text(
- widget.isEdit! ? "编辑登记信息" : "身份信息录入",
- style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
- ),
- ),
- IconButton(
- onPressed: () => Get.back(),
- icon: const Icon(
- Icons.close,
- size: 30,
- ),
- ),
- ],
- ),
- );
- }
- Widget _buildInputItem(String title,
- {String? value, Function()? onTap, Widget? suffixIcon, int? maxLines}) {
- return Container(
- padding: const EdgeInsets.only(
- left: 80,
- right: 110,
- ),
- child: Row(
- children: [
- Container(
- width: 150,
- padding: const EdgeInsets.symmetric(vertical: 16),
- child: Text(
- title,
- style: const TextStyle(fontSize: 22),
- ),
- ),
- Expanded(
- child: VInput(
- initialValue: value,
- radius: 4,
- readOnly: true,
- suffixIcon: suffixIcon,
- maxLines: maxLines,
- onTap: () {
- onTap?.call();
- },
- ),
- )
- ],
- ),
- );
- }
- Widget _buildIdentityVerifyButton() {
- return Container(
- padding: const EdgeInsets.symmetric(
- vertical: 12,
- ),
- child: VButton(
- label: "确定",
- onTap: () {
- Get.back(result: widget.patient);
- },
- ),
- );
- }
- DateTime? _getBirthDayofIdNumber(String idCardNumber) {
- if (idCardNumber.isEmpty) return DateTime(1970, 1, 1);
- final idCardRegex = RegExp(r'^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})(\d|X)$');
- final match = idCardRegex.firstMatch(idCardNumber);
- if (match != null) {
- final year = int.parse(match.group(2)!);
- final month = int.parse(match.group(3)!);
- final day = int.parse(match.group(4)!);
- final birthDate = DateTime(year, month, day);
- return birthDate;
- }
- return null; // 返回一个默认值,表示无法提取出生日期
- }
- String getBirthDay(DateTime? birthDay) {
- if (birthDay == null) {
- return "";
- }
- return formatDate(birthDay, [yyyy, "-", mm, "-", dd]);
- }
- }
|