confirm_registration.dart 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. import 'dart:convert';
  2. import 'dart:io';
  3. import 'package:eitc_erm_app/success_registration.dart';
  4. import 'package:eitc_erm_app/utils/Component.dart';
  5. import 'package:eitc_erm_app/utils/Constants.dart';
  6. import 'package:flutter/cupertino.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:permission_handler/permission_handler.dart';
  9. import 'bean/doctor_list.dart';
  10. import 'bean/normal_response2.dart';
  11. import 'bean/user_list.dart';
  12. import 'package:http/http.dart' as http;
  13. // void main() {
  14. // WidgetsFlutterBinding.ensureInitialized();
  15. // runApp(ConfirmRegistration());
  16. // }
  17. String mVisitTime = "";
  18. String mVisitTimeEnd = "";
  19. late DoctorListEntity mDoctorListEntity = new DoctorListEntity();
  20. int mWhich = 0;
  21. UserListEntity mUserListEntity = new UserListEntity();
  22. int mWhichPatient = 0;
  23. TextEditingController ctrlRemark = TextEditingController();
  24. class ConfirmRegistration extends StatefulWidget {
  25. ConfirmRegistration(
  26. {required String visitTime,
  27. required String visitTimeEnd,
  28. required userListEntity,
  29. required whichPatient,
  30. required Key key,
  31. required doctorListEntity,
  32. which})
  33. : super(key: key) {
  34. mVisitTime = visitTime;
  35. mVisitTimeEnd = visitTimeEnd;
  36. mUserListEntity = userListEntity;
  37. mWhichPatient = whichPatient;
  38. mDoctorListEntity = doctorListEntity;
  39. mWhich = which;
  40. }
  41. @override
  42. State<StatefulWidget> createState() => ConfirmRegistrationState();
  43. }
  44. class ConfirmRegistrationState extends State<ConfirmRegistration> {
  45. final GlobalKey<ScaffoldState> _scaffoldKey =
  46. GlobalKey<ScaffoldState>(); //重要代码 需要绑定key不然切换页面会停止摄像头采集
  47. @override
  48. void initState() {
  49. super.initState();
  50. initPlatformState(); //检查权限
  51. //延迟1秒 直播推流
  52. Future.delayed(Duration(milliseconds: 1000), () {});
  53. }
  54. Future<void> initPlatformState() async {
  55. //相机权限
  56. if (await requestCameraPermission() == false) {
  57. return;
  58. }
  59. //录音权限
  60. if (await requestMicrophonePermission() == false) {
  61. return;
  62. }
  63. }
  64. Future<bool> requestCameraPermission() async {
  65. var status = await Permission.camera.status;
  66. if (status == PermissionStatus.granted) {
  67. return true;
  68. } else {
  69. status = await Permission.camera.request();
  70. if (status == PermissionStatus.granted) {
  71. return true;
  72. } else {
  73. return false;
  74. }
  75. }
  76. }
  77. Future<bool> requestMicrophonePermission() async {
  78. var status = await Permission.microphone.status;
  79. if (status == PermissionStatus.granted) {
  80. return true;
  81. } else {
  82. status = await Permission.microphone.request();
  83. if (status == PermissionStatus.granted) {
  84. return true;
  85. } else {
  86. return false;
  87. }
  88. }
  89. }
  90. @override
  91. Widget build(BuildContext context) {
  92. return MaterialApp(
  93. home: Scaffold(
  94. resizeToAvoidBottomInset: false,
  95. backgroundColor: Color.fromARGB(0xff, 0xef, 0xef, 0xef),
  96. appBar: new AppBar(
  97. title: new Text('预约挂号',
  98. style: TextStyle(
  99. color: Colors.white,
  100. )),
  101. centerTitle: true,
  102. elevation: 0.5,
  103. backgroundColor: Global.StatusBarColor,
  104. leading: new IconButton(
  105. tooltip: '返回上一页',
  106. icon: const Icon(
  107. Icons.arrow_back_ios,
  108. color: Colors.white,
  109. ),
  110. onPressed: () {
  111. Navigator.of(context).pop();
  112. //_nextPage(-1);
  113. },
  114. ),
  115. ),
  116. body: Container(
  117. padding: EdgeInsets.all(10),
  118. child: SingleChildScrollView(
  119. child: Column(
  120. mainAxisSize: MainAxisSize.min,
  121. crossAxisAlignment: CrossAxisAlignment.center,
  122. children: <Widget>[
  123. ClipRRect(
  124. borderRadius: BorderRadius.circular(10.0),
  125. child: Container(
  126. color: Colors.white,
  127. padding: EdgeInsets.all(10),
  128. child: Column(
  129. mainAxisSize: MainAxisSize.min,
  130. crossAxisAlignment: CrossAxisAlignment.start,
  131. children: <Widget>[
  132. Row(children: [
  133. Padding(
  134. padding: const EdgeInsets.all(3),
  135. child: Image.network(
  136. "${Global.ImageUrl}${mDoctorListEntity.data?[mWhich].avatar}",
  137. width: 60,
  138. fit: BoxFit.cover,
  139. excludeFromSemantics: true,
  140. errorBuilder: (context, error, stackTrace) => Icon(
  141. Icons.person_pin,
  142. size: 60,
  143. color: Colors.grey,
  144. ),
  145. ),
  146. ),
  147. Column(
  148. crossAxisAlignment:
  149. CrossAxisAlignment.start,
  150. children: [
  151. Text(
  152. mDoctorListEntity
  153. .data![mWhich].nickName
  154. .toString(),
  155. style: TextStyle(fontSize: 20),
  156. ),
  157. SizedBox(height: 8),
  158. Text(
  159. mDoctorListEntity
  160. .data![mWhich].postNames
  161. .toString(),
  162. style: TextStyle(
  163. fontSize: 15, color: Colors.grey),
  164. ),
  165. ]),
  166. ]),
  167. Text(
  168. mDoctorListEntity.data![mWhich].doctorBlurb ==
  169. null
  170. ? "简介:暂无。"
  171. : " " + mDoctorListEntity
  172. .data![mWhich].doctorBlurb
  173. .toString(),
  174. style: TextStyle(
  175. fontSize: 15, color: Colors.grey),
  176. ),
  177. ]),
  178. ),
  179. ),
  180. SizedBox(height: 8),
  181. ClipRRect(
  182. borderRadius: BorderRadius.circular(10.0),
  183. child: Container(
  184. color: Colors.white,
  185. padding: const EdgeInsets.all(10),
  186. child: Column(
  187. mainAxisSize: MainAxisSize.min,
  188. crossAxisAlignment: CrossAxisAlignment.start,
  189. children: <Widget>[
  190. Visibility(
  191. visible: false,
  192. child: Padding(
  193. padding: EdgeInsets.all(10),
  194. child: Row(
  195. mainAxisAlignment:
  196. MainAxisAlignment.spaceBetween,
  197. children: [
  198. Text(
  199. '挂号费',
  200. style: TextStyle(
  201. fontSize: 15,
  202. color: Colors.grey),
  203. ),
  204. Text(
  205. '¥12.5',
  206. style: TextStyle(fontSize: 15),
  207. ),
  208. ]),
  209. ),
  210. ),
  211. Padding(
  212. padding: EdgeInsets.all(10),
  213. child: Row(
  214. mainAxisAlignment:
  215. MainAxisAlignment.spaceBetween,
  216. children: [
  217. Text(
  218. '就诊人',
  219. style: TextStyle(
  220. fontSize: 15, color: Colors.grey),
  221. ),
  222. Text(
  223. mUserListEntity!
  224. .data![mWhichPatient].patientName
  225. .toString(),
  226. style: TextStyle(fontSize: 15),
  227. ),
  228. ]),
  229. ),
  230. Padding(
  231. padding: EdgeInsets.all(10),
  232. child: Row(
  233. mainAxisAlignment:
  234. MainAxisAlignment.spaceBetween,
  235. children: [
  236. Text(
  237. '就诊时间',
  238. style: TextStyle(
  239. fontSize: 15, color: Colors.grey),
  240. ),
  241. Text(
  242. '${mVisitTime}',
  243. style: TextStyle(fontSize: 15),
  244. ),
  245. ]),
  246. ),
  247. Padding(
  248. padding: EdgeInsets.all(10),
  249. child: Row(
  250. mainAxisAlignment:
  251. MainAxisAlignment.spaceBetween,
  252. children: [
  253. Text(
  254. '挂号科室',
  255. style: TextStyle(
  256. fontSize: 15, color: Colors.grey),
  257. ),
  258. Text(
  259. mDoctorListEntity
  260. .data![mWhich].deptName
  261. .toString(),
  262. style: TextStyle(fontSize: 15),
  263. ),
  264. ]),
  265. ),
  266. ]),
  267. ),
  268. ),
  269. SizedBox(height: 8),
  270. ClipRRect(
  271. borderRadius: BorderRadius.circular(10.0),
  272. child: Container(
  273. color: Colors.white,
  274. padding: const EdgeInsets.all(10),
  275. child: Column(
  276. mainAxisSize: MainAxisSize.min,
  277. crossAxisAlignment: CrossAxisAlignment.start,
  278. children: <Widget>[
  279. Padding(
  280. padding: EdgeInsets.all(10),
  281. child: Row(
  282. mainAxisAlignment:
  283. MainAxisAlignment.spaceBetween,
  284. children: [
  285. Expanded(
  286. child: TextField(
  287. maxLines: 5, // 设置最大行数
  288. controller: ctrlRemark,
  289. decoration: InputDecoration(
  290. border: OutlineInputBorder(),
  291. hintText:
  292. '温馨提示:\n预约后请与就诊当天到就诊室按照工作人员的安排就诊',
  293. hintStyle:
  294. TextStyle(color: Colors.grey),
  295. ),
  296. ),
  297. ),
  298. ]),
  299. ),
  300. ]),
  301. ),
  302. ),
  303. Padding(
  304. padding: EdgeInsets.all(10),
  305. child: Row(
  306. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  307. children: [
  308. Text(
  309. '',
  310. style:
  311. TextStyle(fontSize: 20, color: Colors.red),
  312. ),
  313. ElevatedButton(
  314. style: ButtonStyle(
  315. backgroundColor:
  316. MaterialStateProperty.all(Colors.blue),
  317. ),
  318. child: Text(
  319. '确定挂号',
  320. style: const TextStyle(
  321. fontSize: 15, color: Colors.white),
  322. ),
  323. onPressed: () {
  324. patientAppointment();
  325. /*Navigator.pushReplacement(
  326. context,
  327. MaterialPageRoute(
  328. builder: (context) =>
  329. SuccessRegistration()),
  330. );*/
  331. },
  332. ),
  333. ]),
  334. ),
  335. ])))));
  336. }
  337. Future<String?> patientAppointment() async {
  338. Map<String, String> headers = {
  339. HttpHeaders.contentTypeHeader: "application/json; charset=utf-8",
  340. 'token': '${Global.token}',
  341. };
  342. String url = 'patient-appointment';
  343. print(
  344. '${mUserListEntity.data?[mWhichPatient].identificationCard} ${mDoctorListEntity.data?[mWhich].userId} ${mVisitTime} ${mVisitTimeEnd}');
  345. var params = {
  346. 'identificationCard':
  347. mUserListEntity.data?[mWhichPatient].identificationCard,
  348. 'attendingDoctor': mDoctorListEntity.data?[mWhich].userId,
  349. 'appointmentStartTime': mVisitTime,
  350. 'appointmentEndTime': mVisitTimeEnd,
  351. 'remark': ctrlRemark.text,
  352. };
  353. var response = await http.post(Uri.parse(Global.BaseUrl + url),
  354. body: jsonEncode(params), headers: headers);
  355. print(response.body.toString());
  356. if (response.statusCode == 200) {
  357. final jsonString = utf8.decode(response.bodyBytes);
  358. final jsonResponse = jsonDecode(jsonString);
  359. print(jsonString);
  360. Normal2Response mNormal2Response =
  361. new Normal2Response.fromJson(jsonResponse);
  362. if (mNormal2Response.code == Global.responseSuccessCode) {
  363. Component.toast("预约成功!", 2);
  364. Navigator.pushReplacement(
  365. context,
  366. MaterialPageRoute(
  367. builder: (context) => SuccessRegistration(
  368. patient: mUserListEntity.data?[mWhichPatient].patientName,
  369. visitTime: mVisitTime,
  370. deptName: mDoctorListEntity.data?[mWhich].deptName,
  371. doctorName: mDoctorListEntity.data?[mWhich].nickName,
  372. key: new Key(''),
  373. remark: ctrlRemark.text,
  374. )),
  375. );
  376. } else {
  377. Component.toast(mNormal2Response.msg.toString(), 0);
  378. }
  379. return response.toString();
  380. } else {
  381. Component.toast("出错了,请稍后再试!", 0);
  382. return null;
  383. }
  384. }
  385. }