123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841 |
- import 'package:eitc_erm_app/utils/Component.dart';
- import 'package:eitc_erm_app/utils/Constants.dart';
- import 'package:eitc_erm_app/utils/Utils.dart';
- import 'package:eitc_erm_app/utils/logger.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:http/http.dart' as http;
- import 'bean/dropdown_list.dart';
- import 'bean/normal_response3.dart';
- import 'bean/user_list.dart';
- /*void main() {
- WidgetsFlutterBinding.ensureInitialized();
- runApp(AddPatient());
- }*/
- UserListEntity mUserListEntity = new UserListEntity();
- int mWhichPatient = 0;
- bool isEdit = false;
- class AddPatient extends StatefulWidget {
- AddPatient({required Key key, required userListEntity, required whichPatient})
- : super(key: key) {
- mUserListEntity = userListEntity;
- mWhichPatient = whichPatient;
- mWhichPatient == -1 ? isEdit = false : isEdit = true;
- logd(isEdit.toString() + ' =================');
- }
- @override
- State<StatefulWidget> createState() => AddPatientState();
- }
- class AddPatientState extends State<AddPatient> {
- int selectedRadioValue = 0;
- bool switchSelected = true;
- String relationship = "请选择与本人的关系";
- String passport = "请选择证件类型";
- String previous = "请选择既往病史";
- String family = "请选择家族病史";
- TextEditingController nameController = TextEditingController();
- TextEditingController passportController = TextEditingController();
- TextEditingController mobileController = TextEditingController();
- TextEditingController allergyController = TextEditingController();
- TextEditingController homeAddressController = TextEditingController();
- bool mobileCanEdit = true;
- List selectItem0 = [];
- List selectItem1 = [];
- List selectItem2 = [];
- List selectItem3 = [];
- void getDropdownList() {
- for (int i = 0; i < 4; i++) {
- dropdownList(i);
- }
- }
- Future<DropdownList?> dropdownList(int i) async {
- String url =
- '${Global.BaseUrl}system/dropdownList?dictType=erm_personal_relationship';
- logd(url);
- switch (i) {
- case 1:
- url = '${Global.BaseUrl}system/type/erm_document_type';
- break;
- case 2:
- url = '${Global.BaseUrl}system/dropdownList?dictType=erm_past_history';
- break;
- case 3:
- url =
- '${Global.BaseUrl}system/dropdownList?dictType=erm_family_history';
- break;
- }
- final response =
- await http.get(Uri.parse(url), headers: jsonHeaders(withToken: true));
- if (response.statusCode == 200) {
- final json = decodeBodyToJson(response.bodyBytes);
- logd("下拉列表$json");
- DropdownList mDropdownList = DropdownList.fromJson(json);
- if (mDropdownList.code == Global.responseSuccessCode) {
- switch (i) {
- case 0:
- mDropdownList.data?.forEach((item) {
- selectItem0.add(item.dictValue);
- });
- break;
- case 1:
- mDropdownList.data?.forEach((item) {
- selectItem1.add(item.dictValue);
- });
- break;
- case 2:
- mDropdownList.data?.forEach((item) {
- selectItem2.add(item.dictValue);
- });
- break;
- case 3:
- mDropdownList.data?.forEach((item) {
- selectItem3.add(item.dictValue);
- });
- break;
- }
- if (mounted) {
- setState(() {});
- }
- } else {
- Component.toast(mDropdownList.msg.toString(), 0);
- return null;
- }
- return mDropdownList;
- } else {
- Component.toast("出错了,请稍后再试!", 0);
- return null;
- }
- }
- @override
- void initState() {
- super.initState();
- getDropdownList();
- if (isEdit) {
- relationship =
- mUserListEntity.data![mWhichPatient].userRelationship.toString();
- nameController.text =
- mUserListEntity.data![mWhichPatient].patientName.toString();
- int? passportInt = mUserListEntity.data![mWhichPatient].documentType;
- switch (passportInt) {
- case 0:
- passport = "身份证";
- break;
- case 1:
- passport = "护照";
- break;
- case 2:
- passport = "港澳通行证";
- break;
- }
- if (relationship == "本人") {
- mobileCanEdit = false;
- } else {
- mobileCanEdit = true;
- }
- passportController.text =
- mUserListEntity.data![mWhichPatient].identificationCard.toString();
- previous = mUserListEntity.data![mWhichPatient].pastHistory.toString();
- logd("------------------------ " +
- mUserListEntity.data![mWhichPatient].pastHistory.toString());
- family = mUserListEntity.data![mWhichPatient].familyHistory.toString();
- if (!mUserListEntity.data![mWhichPatient].allergyHistory
- .toString()
- .isEmpty) {
- selectedRadioValue = 1;
- allergyController.text =
- mUserListEntity.data![mWhichPatient].allergyHistory.toString();
- }
- mobileController.text =
- mUserListEntity.data![mWhichPatient].patientPhone.toString();
- homeAddressController.text =
- mUserListEntity.data![mWhichPatient].homeAddress.toString();
- if (mUserListEntity.data![mWhichPatient].isDefault == 1) {
- switchSelected = true;
- } else {
- switchSelected = false;
- }
- }
- }
- final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
- String _errorText = '';
- Future<void> _validateInputs() async {
- final FormState? form = _formKey.currentState;
- /*if (form!.validate()) {
- _errorText = '';
- } else {
- _errorText = '输入不能为空';
- }
- form.save();*/
- setState(() {
- if (relationship == "请选择与本人的关系") {
- _errorText = "请选择与本人的关系";
- return;
- } else if (passport == "请选择证件类型") {
- _errorText = "请选择证件类型";
- return;
- } else if (previous == "请选择既往病史") {
- _errorText = "请选择既往病史";
- return;
- } else if (family == "请选择家族病史") {
- _errorText = "请选择家族病史";
- return;
- } else if (nameController.text == '') {
- _errorText = "请填写姓名";
- return;
- } else if (passportController.text == '') {
- _errorText = "请填写证件号码";
- return;
- } else if (mobileController.text == '') {
- _errorText = "请填写手机号码";
- return;
- } else if (selectedRadioValue == 1 && allergyController.text == '') {
- _errorText = "请填写过敏史";
- return;
- } else if (!Utils.validateIDCard(passportController.text)) {
- _errorText = "请输入正确的身份证号码";
- return;
- } else if (!Utils.isChinaPhoneLegal(mobileController.text)) {
- _errorText = "请输入正确的手机号码";
- return;
- } else {
- _errorText = "";
- }
- });
- if (_errorText.isNotEmpty) {
- return;
- }
- logd("${previous} ${family} ${allergyController.text} ");
- int passportType = 0;
- if (passport == "身份证") {
- passportType = 0;
- } else if (passport == "护照") {
- passportType = 1;
- } else if (passport == "港澳通行证") {
- passportType = 2;
- }
- int isDefault = 1;
- if (switchSelected) {
- isDefault = 1;
- } else {
- isDefault = 0;
- }
- String patientId =
- isEdit ? mUserListEntity.data![mWhichPatient].patientId.toString() : "";
- var params = {
- 'patientId': patientId,
- 'userRelationship': relationship,
- 'documentType': passportType,
- 'pastHistory': previous,
- 'familyHistory': family,
- 'patientName': nameController.text,
- 'identificationCard': passportController.text,
- 'patientPhone': mobileController.text,
- 'allergyHistory': allergyController.text,
- 'homeAddress': homeAddressController.text,
- 'isDefault': isDefault,
- };
- logd(params);
- Map<String, String> headers = jsonHeaders(withToken: true);
- var response = await http.post(Uri.parse('${Global.BaseUrl}user'),
- body: encodeBody(params), headers: headers);
- if (isEdit) {
- response = await http.put(Uri.parse('${Global.BaseUrl}user'),
- body: encodeBody(params), headers: headers);
- }
- logd(response.body.toString());
- if (response.statusCode == 200) {
- final json = decodeBodyToJson(response.bodyBytes);
- logd("新增/编辑就诊人结果=$json");
- NormalResponse3 mNormalResponse = NormalResponse3.fromJson(json);
- if (mNormalResponse.code == Global.responseSuccessCode) {
- Component.toast(isEdit ? "保存成功!" : "添加成功!", 2);
- Navigator.pop(context, "success");
- } else {
- Component.toast(mNormalResponse.msg.toString(), 0);
- }
- } else {
- Component.toast("出错了,请稍后再试!", 0);
- return;
- }
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text(isEdit ? '编辑就诊人' : '添加就诊人',
- style: const TextStyle(
- color: Colors.white,
- )),
- centerTitle: true,
- elevation: 0.5,
- backgroundColor: Global.StatusBarColor,
- leading: IconButton(
- tooltip: '返回上一页',
- icon: const Icon(
- Icons.arrow_back_ios,
- color: Colors.white,
- ),
- onPressed: () {
- Navigator.of(context).pop();
- //_nextPage(-1);
- },
- ),
- ),
- body: SingleChildScrollView(
- child: Form(
- key: _formKey,
- child: Column(children: [
- const Padding(
- padding: EdgeInsets.all(10),
- child: Text(
- "请认真填写就诊人信息",
- style: TextStyle(
- color: Colors.orange,
- ),
- )),
- if (_errorText.isNotEmpty)
- Container(
- color: Colors.red,
- padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 3),
- child: Text(
- _errorText,
- style: const TextStyle(color: Colors.white),
- ),
- ),
- Padding(
- padding: const EdgeInsets.all(10),
- child: GestureDetector(
- onTap: () {
- selectItem(selectItem0, 0);
- },
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- const Text(
- "关系",
- style: TextStyle(
- color: Colors.grey,
- ),
- ),
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- Text(
- relationship,
- style: const TextStyle(
- color: Colors.black,
- ),
- ),
- const Icon(
- Icons.chevron_right,
- color: Colors.grey,
- ),
- ])
- ]),
- ),
- ),
- const Divider(
- color: Colors.grey,
- thickness: 1,
- indent: 10,
- endIndent: 10,
- ),
- // new Line(),
- Padding(
- padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
- child: Container(
- alignment: Alignment.center,
- height: 45,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- const Text(
- "姓名 ",
- style: TextStyle(
- color: Colors.grey,
- ),
- ),
- Expanded(
- child: TextFormField(
- maxLines: 1,
- onSaved: (value) {},
- textAlign: TextAlign.right,
- controller: nameController,
- inputFormatters: [
- FilteringTextInputFormatter.singleLineFormatter,
- LengthLimitingTextInputFormatter(4)
- ],
- decoration: const InputDecoration(
- hintText: ('请填写姓名'),
- hintStyle: TextStyle(
- color: Color(0xff999999),
- fontSize: 13,
- ),
- alignLabelWithHint: true,
- border:
- OutlineInputBorder(borderSide: BorderSide.none),
- ),
- ),
- ),
- ]),
- ),
- ),
- const Divider(
- color: Colors.grey,
- thickness: 1,
- indent: 10,
- endIndent: 10,
- ),
- Padding(
- padding: const EdgeInsets.all(10),
- child: GestureDetector(
- onTap: () {
- // selectItem(['身份证', '护照', '港澳通行证'], 1);
- selectItem(selectItem1, 1);
- },
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- const Text(
- "证件类型",
- style: TextStyle(
- color: Colors.grey,
- ),
- ),
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- Text(
- passport,
- style: const TextStyle(
- color: Colors.black,
- ),
- ),
- const Icon(
- Icons.chevron_right,
- color: Colors.grey,
- ),
- ])
- ]),
- ),
- ),
- const Divider(
- color: Colors.grey,
- thickness: 1,
- indent: 10,
- endIndent: 10,
- ),
- Padding(
- padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
- child: Container(
- alignment: Alignment.center,
- height: 50,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- const Text(
- "证件号码",
- style: TextStyle(
- color: Colors.grey,
- ),
- ),
- Expanded(
- child: TextFormField(
- controller: passportController,
- maxLines: 1,
- onSaved: (value) {},
- textAlign: TextAlign.right,
- inputFormatters: [
- FilteringTextInputFormatter.singleLineFormatter,
- LengthLimitingTextInputFormatter(18)
- ],
- decoration: const InputDecoration(
- hintText: ('请输入证件号码'),
- hintStyle: TextStyle(
- color: Color(0xff999999),
- fontSize: 13,
- ),
- alignLabelWithHint: true,
- border:
- OutlineInputBorder(borderSide: BorderSide.none),
- ),
- ),
- ),
- ]),
- ),
- ),
- const Divider(
- color: Colors.grey,
- thickness: 1,
- indent: 10,
- endIndent: 10,
- ),
- Padding(
- padding: const EdgeInsets.all(10),
- child: GestureDetector(
- onTap: () {
- selectItem(selectItem2, 2);
- },
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- const Text(
- "既往病史",
- style: TextStyle(
- color: Colors.grey,
- ),
- ),
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- Text(
- previous,
- style: const TextStyle(
- color: Colors.black,
- ),
- ),
- const Icon(
- Icons.chevron_right,
- color: Colors.grey,
- ),
- ])
- ]),
- ),
- ),
- const Divider(
- color: Colors.grey,
- thickness: 1,
- indent: 10,
- endIndent: 10,
- ),
- Padding(
- padding: const EdgeInsets.all(10),
- child: GestureDetector(
- onTap: () {
- selectItem(selectItem3, 3);
- },
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- const Text(
- "家族病史",
- style: TextStyle(
- color: Colors.grey,
- ),
- ),
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- Text(
- family,
- style: const TextStyle(
- color: Colors.black,
- ),
- ),
- const Icon(
- Icons.chevron_right,
- color: Colors.grey,
- ),
- ])
- ]),
- ),
- ),
- const Divider(
- color: Colors.grey,
- thickness: 1,
- indent: 10,
- endIndent: 10,
- ),
- Padding(
- padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- const Text(
- "过敏史",
- style: TextStyle(
- color: Colors.grey,
- ),
- ),
- Row(
- children: <Widget>[
- const Text("无"),
- Radio(
- value: 0,
- onChanged: (value) {
- setState(() {
- allergyController.text = "";
- selectedRadioValue = value!;
- });
- },
- groupValue: selectedRadioValue,
- ),
- const SizedBox(
- width: 20,
- ),
- const Text("有"),
- Radio(
- value: 1,
- onChanged: (value) {
- setState(() {
- this.selectedRadioValue = value!;
- });
- },
- groupValue: selectedRadioValue,
- ),
- ],
- ),
- ]),
- ),
- Visibility(
- visible: selectedRadioValue == 1,
- child: Padding(
- padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- const Text(
- "",
- style: TextStyle(
- color: Colors.grey,
- ),
- ),
- Expanded(
- child: TextFormField(
- controller: allergyController,
- maxLines: 1,
- onSaved: (value) {},
- textAlign: TextAlign.right,
- inputFormatters: [
- FilteringTextInputFormatter.singleLineFormatter,
- LengthLimitingTextInputFormatter(18)
- ],
- decoration: const InputDecoration(
- hintText: ('请填写过敏史'),
- hintStyle: TextStyle(
- color: Color(0xff999999),
- fontSize: 13,
- ),
- alignLabelWithHint: true,
- border:
- OutlineInputBorder(borderSide: BorderSide.none),
- ),
- ),
- ),
- ]),
- ),
- ),
- const Divider(
- color: Colors.grey,
- thickness: 1,
- indent: 10,
- endIndent: 10,
- ),
- Padding(
- padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
- child: Container(
- alignment: Alignment.center,
- height: 50,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- const Text(
- "手机号",
- style: TextStyle(
- color: Colors.grey,
- ),
- ),
- Expanded(
- child: TextFormField(
- enabled: mobileCanEdit,
- controller: mobileController,
- maxLines: 1,
- onSaved: (value) {},
- textAlign: TextAlign.right,
- inputFormatters: [
- FilteringTextInputFormatter.digitsOnly,
- LengthLimitingTextInputFormatter(11)
- ],
- decoration: const InputDecoration(
- hintText: ('请输入手机号码'),
- hintStyle: TextStyle(
- color: Color(0xff999999),
- fontSize: 13,
- ),
- alignLabelWithHint: true,
- border:
- OutlineInputBorder(borderSide: BorderSide.none),
- ),
- ),
- ),
- ]),
- ),
- ),
- const Divider(
- color: Colors.grey,
- thickness: 1,
- indent: 10,
- endIndent: 10,
- ),
- Padding(
- padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
- child: Container(
- alignment: Alignment.center,
- height: 50,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- const Text(
- "就诊人地址",
- style: TextStyle(
- color: Colors.grey,
- ),
- ),
- Expanded(
- child: TextFormField(
- controller: homeAddressController,
- maxLines: 1,
- onSaved: (value) {},
- textAlign: TextAlign.right,
- // inputFormatters: [
- // FilteringTextInputFormatter.digitsOnly,
- // LengthLimitingTextInputFormatter(11)
- // ],
- decoration: const InputDecoration(
- hintText: ('选填'),
- hintStyle: TextStyle(
- color: Color(0xff999999),
- fontSize: 13,
- ),
- alignLabelWithHint: true,
- border:
- OutlineInputBorder(borderSide: BorderSide.none),
- ),
- ),
- ),
- ]),
- ),
- ),
- const Divider(
- color: Colors.grey,
- thickness: 1,
- indent: 10,
- endIndent: 10,
- ),
- Padding(
- padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- const Text(
- "设为默认就诊人",
- style: TextStyle(
- color: Colors.grey,
- ),
- ),
- Switch(
- value: switchSelected,
- onChanged: (value) {
- setState(() {
- switchSelected = value;
- });
- },
- ),
- ]),
- ),
- Padding(
- padding: const EdgeInsets.symmetric(horizontal: 20),
- child: SizedBox(
- width: double.infinity,
- child: ElevatedButton(
- style: const ButtonStyle(
- backgroundColor: WidgetStatePropertyAll(Colors.blue),
- ),
- onPressed: () {
- _validateInputs();
- },
- child: const Text("确定",
- style: TextStyle(color: Colors.white, fontSize: 15)),
- ),
- )),
- const SizedBox(
- height: 10,
- )
- ]),
- ),
- ),
- );
- }
- selectItem(List list, int item) {
- showModalBottomSheet(
- context: context,
- builder: (BuildContext context) {
- return Container(
- width: double.infinity,
- height: list.length * 50,
- child: Column(
- children: List.generate(
- list.length,
- (index) => GestureDetector(
- onTap: () {
- setState(() {
- switch (item) {
- case 0:
- relationship = list[index];
- if (relationship == "本人") {
- mobileCanEdit = false;
- mobileController.text = Global.loginPhoneNo;
- } else {
- mobileCanEdit = true;
- mobileController.text = "";
- }
- break;
- case 1:
- passport = list[index];
- break;
- case 2:
- previous = list[index];
- break;
- case 3:
- family = list[index];
- break;
- }
- });
- Navigator.pop(context);
- },
- child: Padding(
- padding: const EdgeInsets.all(10),
- child: Text(
- '${list[index]}',
- style: TextStyle(fontSize: 18),
- ),
- ),
- ),
- ),
- ),
- );
- },
- );
- }
- }
|