confirm_registration.dart 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. import 'dart:io';
  2. import 'package:eitc_erm_app/success_registration.dart';
  3. import 'package:eitc_erm_app/utils/Component.dart';
  4. import 'package:eitc_erm_app/utils/Constants.dart';
  5. import 'package:eitc_erm_app/utils/logger.dart';
  6. import 'package:eitc_erm_app/widget/user_header.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:http/http.dart' as http;
  9. import 'package:permission_handler/permission_handler.dart';
  10. import 'bean/doctor_list.dart';
  11. import 'bean/normal_response2.dart';
  12. import 'bean/user_list.dart';
  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 Scaffold(
  93. resizeToAvoidBottomInset: false,
  94. backgroundColor: Color.fromARGB(0xff, 0xef, 0xef, 0xef),
  95. appBar: new AppBar(
  96. title: new Text('预约挂号',
  97. style: TextStyle(
  98. color: Colors.white,
  99. )),
  100. centerTitle: true,
  101. elevation: 0.5,
  102. backgroundColor: Global.StatusBarColor,
  103. leading: new IconButton(
  104. tooltip: '返回上一页',
  105. icon: const Icon(
  106. Icons.arrow_back_ios,
  107. color: Colors.white,
  108. ),
  109. onPressed: () {
  110. Navigator.of(context).pop();
  111. //_nextPage(-1);
  112. },
  113. ),
  114. ),
  115. body: Container(
  116. padding: EdgeInsets.all(10),
  117. child: SingleChildScrollView(
  118. child: Column(
  119. mainAxisSize: MainAxisSize.min,
  120. crossAxisAlignment: CrossAxisAlignment.center,
  121. children: <Widget>[
  122. ClipRRect(
  123. borderRadius: BorderRadius.circular(10.0),
  124. child: Container(
  125. color: Colors.white,
  126. padding: EdgeInsets.all(10),
  127. child: Column(
  128. mainAxisSize: MainAxisSize.min,
  129. crossAxisAlignment: CrossAxisAlignment.start,
  130. children: <Widget>[
  131. Row(children: [
  132. Padding(
  133. padding: const EdgeInsets.all(3),
  134. child: UserHeader(
  135. url:
  136. "${Global.ImageUrl}${mDoctorListEntity.data?[mWhich].avatar}",
  137. ),
  138. ),
  139. const SizedBox(
  140. width: 10,
  141. ),
  142. Column(
  143. crossAxisAlignment: CrossAxisAlignment.start,
  144. children: [
  145. Text(
  146. mDoctorListEntity.data![mWhich].nickName
  147. .toString(),
  148. style: Theme.of(context)
  149. .textTheme
  150. .titleLarge,
  151. ),
  152. SizedBox(height: 8),
  153. Text(
  154. mDoctorListEntity
  155. .data![mWhich].postNames ??
  156. "",
  157. style: TextStyle(
  158. fontSize: 15, color: Colors.grey),
  159. ),
  160. ]),
  161. ]),
  162. const SizedBox(
  163. height: 10,
  164. ),
  165. Text(
  166. mDoctorListEntity.data![mWhich].doctorBlurb ==
  167. null
  168. ? "简介:暂无。"
  169. : " " +
  170. mDoctorListEntity
  171. .data![mWhich].doctorBlurb
  172. .toString(),
  173. style:
  174. TextStyle(fontSize: 15, color: Colors.grey),
  175. ),
  176. ]),
  177. ),
  178. ),
  179. SizedBox(height: 8),
  180. ClipRRect(
  181. borderRadius: BorderRadius.circular(10.0),
  182. child: Container(
  183. color: Colors.white,
  184. padding: const EdgeInsets.all(10),
  185. child: Column(
  186. mainAxisSize: MainAxisSize.min,
  187. crossAxisAlignment: CrossAxisAlignment.start,
  188. children: <Widget>[
  189. Visibility(
  190. visible: false,
  191. child: Padding(
  192. padding: EdgeInsets.all(10),
  193. child: Row(
  194. mainAxisAlignment:
  195. MainAxisAlignment.spaceBetween,
  196. children: [
  197. Text(
  198. '挂号费',
  199. style: TextStyle(
  200. fontSize: 15, color: Colors.grey),
  201. ),
  202. Text(
  203. '¥12.5',
  204. style: TextStyle(fontSize: 15),
  205. ),
  206. ]),
  207. ),
  208. ),
  209. Padding(
  210. padding: EdgeInsets.all(10),
  211. child: Row(
  212. mainAxisAlignment:
  213. MainAxisAlignment.spaceBetween,
  214. children: [
  215. Text(
  216. '就诊人',
  217. style: TextStyle(
  218. fontSize: 15, color: Colors.grey),
  219. ),
  220. Text(
  221. mUserListEntity!
  222. .data![mWhichPatient].patientName
  223. .toString(),
  224. style: TextStyle(fontSize: 15),
  225. ),
  226. ]),
  227. ),
  228. Padding(
  229. padding: EdgeInsets.all(10),
  230. child: Row(
  231. mainAxisAlignment:
  232. MainAxisAlignment.spaceBetween,
  233. children: [
  234. Text(
  235. '就诊时间',
  236. style: TextStyle(
  237. fontSize: 15, color: Colors.grey),
  238. ),
  239. Text(
  240. '${mVisitTime}',
  241. style: TextStyle(fontSize: 15),
  242. ),
  243. ]),
  244. ),
  245. Padding(
  246. padding: EdgeInsets.all(10),
  247. child: Row(
  248. mainAxisAlignment:
  249. MainAxisAlignment.spaceBetween,
  250. children: [
  251. Text(
  252. '挂号科室',
  253. style: TextStyle(
  254. fontSize: 15, color: Colors.grey),
  255. ),
  256. Text(
  257. mDoctorListEntity.data![mWhich].deptName
  258. .toString(),
  259. style: TextStyle(fontSize: 15),
  260. ),
  261. ]),
  262. ),
  263. ]),
  264. ),
  265. ),
  266. SizedBox(height: 8),
  267. ClipRRect(
  268. borderRadius: BorderRadius.circular(10.0),
  269. child: Container(
  270. color: Colors.white,
  271. padding: const EdgeInsets.all(10),
  272. child: Column(
  273. mainAxisSize: MainAxisSize.min,
  274. crossAxisAlignment: CrossAxisAlignment.start,
  275. children: <Widget>[
  276. Padding(
  277. padding: EdgeInsets.all(10),
  278. child: Row(
  279. mainAxisAlignment:
  280. MainAxisAlignment.spaceBetween,
  281. children: [
  282. Expanded(
  283. child: TextField(
  284. maxLines: 5, // 设置最大行数
  285. controller: ctrlRemark,
  286. decoration: InputDecoration(
  287. border: OutlineInputBorder(),
  288. hintText:
  289. '温馨提示:\n预约后请与就诊当天到就诊室按照工作人员的安排就诊',
  290. hintStyle:
  291. TextStyle(color: Colors.grey),
  292. ),
  293. ),
  294. ),
  295. ]),
  296. ),
  297. ]),
  298. ),
  299. ),
  300. Padding(
  301. padding: EdgeInsets.all(10),
  302. child: Row(
  303. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  304. children: [
  305. Text(
  306. '',
  307. style: TextStyle(fontSize: 20, color: Colors.red),
  308. ),
  309. ElevatedButton(
  310. style: ButtonStyle(
  311. backgroundColor:
  312. MaterialStateProperty.all(Colors.blue),
  313. ),
  314. child: Text(
  315. '确定挂号',
  316. style: const TextStyle(
  317. fontSize: 15, color: Colors.white),
  318. ),
  319. onPressed: () {
  320. patientAppointment();
  321. /*Navigator.pushReplacement(
  322. context,
  323. MaterialPageRoute(
  324. builder: (context) =>
  325. SuccessRegistration()),
  326. );*/
  327. },
  328. ),
  329. ]),
  330. ),
  331. ]))));
  332. }
  333. Future<String?> patientAppointment() async {
  334. String url = 'patient-appointment';
  335. logd(
  336. '${mUserListEntity.data?[mWhichPatient].identificationCard} ${mDoctorListEntity.data?[mWhich].userId} ${mVisitTime} ${mVisitTimeEnd}');
  337. var params = {
  338. 'identificationCard':
  339. mUserListEntity.data?[mWhichPatient].identificationCard,
  340. 'attendingDoctor': mDoctorListEntity.data?[mWhich].userId,
  341. 'appointmentStartTime': mVisitTime,
  342. 'appointmentEndTime': mVisitTimeEnd,
  343. 'remark': ctrlRemark.text,
  344. };
  345. var response = await http.post(Uri.parse(Global.BaseUrl + url),
  346. body: encodeBody(params), headers: jsonHeaders(withToken: true));
  347. if (response.statusCode == 200) {
  348. final json = decodeBodyToJson(response.bodyBytes);
  349. logd("预约结果=$json");
  350. Normal2Response mNormal2Response = Normal2Response.fromJson(json);
  351. if (mNormal2Response.code == Global.responseSuccessCode) {
  352. Component.toast("预约成功!", 2);
  353. Navigator.pushReplacement(
  354. context,
  355. MaterialPageRoute(
  356. builder: (context) => SuccessRegistration(
  357. patient: mUserListEntity.data?[mWhichPatient].patientName,
  358. visitTime: mVisitTime,
  359. deptName: mDoctorListEntity.data?[mWhich].deptName,
  360. doctorName: mDoctorListEntity.data?[mWhich].nickName,
  361. key: new Key(''),
  362. remark: ctrlRemark.text,
  363. )),
  364. );
  365. } else {
  366. Component.toast(mNormal2Response.msg.toString(), 0);
  367. }
  368. return response.toString();
  369. } else {
  370. Component.toast("出错了,请稍后再试!", 0);
  371. return null;
  372. }
  373. }
  374. }