select_clinic.dart 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import 'dart:convert';
  2. import 'dart:io';
  3. import 'package:eitc_erm_app/select_department.dart';
  4. import 'package:eitc_erm_app/select_doctor.dart';
  5. import 'package:eitc_erm_app/utils/Component.dart';
  6. import 'package:eitc_erm_app/utils/Constants.dart';
  7. import 'package:eitc_erm_app/utils/DateUtils.dart';
  8. import 'package:eitc_erm_app/utils/Utils.dart';
  9. import 'package:eitc_erm_app/widget/line.dart';
  10. import 'package:eitc_erm_app/widget/loading.dart';
  11. import 'package:flutter/material.dart';
  12. import 'package:fluttertoast/fluttertoast.dart';
  13. import 'bean/chat_list.dart';
  14. import 'bean/clinic_list.dart';
  15. import 'bean/pda_patrol_time_list.dart';
  16. import 'package:http/http.dart' as http;
  17. import 'bean/synchronize_data.dart';
  18. import 'bottom_navigation.dart';
  19. import 'chat/chat_home.dart';
  20. import 'confirm_registration.dart';
  21. import 'doctor_talk_list.dart';
  22. import 'login.dart';
  23. /*void main() => runApp(DoctorTalkList());*/
  24. class SelectClinic extends StatelessWidget {
  25. DateTime now = DateTime.now();
  26. ValueNotifier<dynamic> result = ValueNotifier(null);
  27. late Future<ClinicList?> _future = fetchData();
  28. String mFrom = "";
  29. SelectClinic(String from) {
  30. mFrom = from;
  31. }
  32. Future<ClinicList?> fetchData() async {
  33. String url = '${Global.BaseUrl}api/clinicList';
  34. final response = await http.get(Uri.parse(url), headers: {
  35. HttpHeaders.contentTypeHeader: "application/json; charset=utf-8",
  36. });
  37. print(url);
  38. if (response.statusCode == 200) {
  39. final jsonString = utf8.decode(response.bodyBytes);
  40. final jsonResponse = jsonDecode(jsonString);
  41. print(jsonResponse);
  42. ClinicList mClinicList = new ClinicList.fromJson(jsonResponse);
  43. if (mClinicList.code == Global.responseSuccessCode) {
  44. } else {
  45. Component.toast(mClinicList.msg.toString(), 0);
  46. }
  47. return mClinicList;
  48. } else {
  49. Component.toast("出错了,请稍后再试!", 0);
  50. }
  51. }
  52. Future<SynchronizeData?> synchronizeData(BuildContext context) async {
  53. String url = '${Global.BaseUrl}api/synchronizeData?id=${Global.userId}&identificationCard=${Global.userIdentificationCard}&phoneNumber=${Global.loginPhoneNo}';
  54. final response = await http.get(Uri.parse(url), headers: {
  55. HttpHeaders.contentTypeHeader: "application/json; charset=utf-8",
  56. });
  57. print(url);
  58. if (response.statusCode == 200) {
  59. final jsonString = utf8.decode(response.bodyBytes);
  60. final jsonResponse = jsonDecode(jsonString);
  61. print(jsonResponse);
  62. SynchronizeData mSynchronizeData = new SynchronizeData.fromJson(jsonResponse);
  63. if (mSynchronizeData.code == Global.responseSuccessCode) {
  64. Global.token = mSynchronizeData.data!.token.toString();
  65. Navigator.pushReplacementNamed(context, '/home');
  66. } else {
  67. Component.toast(mSynchronizeData.msg.toString(), 0);
  68. }
  69. return mSynchronizeData;
  70. } else {
  71. Component.toast("出错了,请稍后再试!", 0);
  72. }
  73. }
  74. @override
  75. Widget build(BuildContext context) {
  76. return MaterialApp(
  77. home: Scaffold(
  78. appBar: new AppBar(
  79. title: new Text('请选择您需要挂号的医院/诊所',
  80. style: TextStyle(
  81. color: Colors.white,
  82. )),
  83. centerTitle: true,
  84. elevation: 0.5,
  85. backgroundColor: Global.StatusBarColor,
  86. ),
  87. body: Column(children: [
  88. Expanded(
  89. child: FutureBuilder<ClinicList?>(
  90. future: _future,
  91. builder: (context, snapshot) {
  92. if (snapshot.hasData) {
  93. ClinicList? data = snapshot.data;
  94. return ListView.builder(
  95. shrinkWrap: true,
  96. itemCount: data?.data?.length,
  97. itemBuilder: (context, index) {
  98. return Center(
  99. child: ListTile(
  100. shape: RoundedRectangleBorder(
  101. borderRadius: BorderRadius.only(
  102. topLeft: Radius.circular(5),
  103. topRight: Radius.circular(5),
  104. bottomRight: Radius.circular(5),
  105. bottomLeft: Radius.circular(5))),
  106. tileColor: Colors.white,
  107. iconColor: Colors.white,
  108. title: Text(
  109. '${data!.data?[index].clinicName}',
  110. textAlign: TextAlign.center,
  111. style: const TextStyle(
  112. fontSize: 18, color: Colors.black),
  113. ),
  114. subtitle: Line(),
  115. onTap: () async {
  116. Global.clinic = data!.data![index].clinicName!;
  117. Global.RootUrl = data!.data![index].clinicIp!;
  118. Global.Port = data!.data![index].serverPost!;
  119. Global.ChatPort = data!.data![index].webSocketPost!;
  120. if(mFrom == "fromHome") {
  121. synchronizeData(context);
  122. } else if (!(await Utils.readData("token")).isEmpty) {
  123. Global.token = await Utils.readData("token");
  124. Global.userId = await Utils.readData("userId");
  125. print("2222 " + Global.userId);
  126. Navigator.pushReplacementNamed(context, '/home');
  127. } /*else if (!(await Utils.readData("doctorToken"))
  128. .isEmpty) {
  129. Global.token = await Utils.readData("doctorToken");
  130. Navigator.pushReplacementNamed(context, '/doctor');
  131. }*/ else
  132. Navigator.pushReplacementNamed(context, '/login');
  133. },
  134. ));
  135. },
  136. );
  137. } else if (snapshot.hasError) {
  138. return Text('Error: ${snapshot.error}');
  139. }
  140. return ColorLoader();
  141. },
  142. ),
  143. ),
  144. ]),
  145. ),
  146. routes: {
  147. '/login': (context) => Login(),
  148. '/home': (context) => BottomNavigationWidget(),
  149. '/doctor': (context) => DoctorTalkList(),
  150. },
  151. );
  152. }
  153. }