123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661 |
- import 'package:eitc_erm_app/select_department.dart';
- import 'package:eitc_erm_app/utils/Component.dart';
- import 'package:eitc_erm_app/utils/Constants.dart';
- import 'package:eitc_erm_app/utils/DateUtils.dart';
- import 'package:eitc_erm_app/utils/logger.dart';
- import 'package:eitc_erm_app/widget/loading.dart';
- import 'package:eitc_erm_app/widget/user_header.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:http/http.dart' as http;
- import 'bean/doctor_list.dart' as dcl;
- import 'bean/user_list.dart';
- import 'confirm_registration.dart';
- import 'doctor_detail.dart';
- // void main() => runApp(Registration());
- UserListEntity mUserListEntity = new UserListEntity();
- int mWhichPatient = 0;
- class Registration extends StatefulWidget {
- Registration(
- {required Key key, required userListEntity, required whichPatient})
- : super(key: key) {
- mUserListEntity = userListEntity;
- mWhichPatient = whichPatient;
- }
- @override
- State<StatefulWidget> createState() => RegistrationState();
- }
- class RegistrationState extends State<Registration> {
- DateTime now = DateTime.now();
- ValueNotifier<dynamic> result = ValueNotifier(null);
- late Future<dcl.DoctorListEntity?>? _future = null;
- String searchDeptName = "";
- int selectItem = -1;
- String selectDateStr = "";
- String halfHourLater = "";
- @override
- void initState() {
- super.initState();
- _future = fetchData();
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: const Text('预约挂号',
- style: 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: Column(children: [
- Row(children: [
- GestureDetector(
- onTap: () {
- _showDatePicker(0);
- },
- child: Container(
- alignment: Alignment.center,
- height: 50.0,
- width: 50,
- color: Global.StatusBarColor,
- child: const Column(
- mainAxisSize: MainAxisSize.min,
- children: <Widget>[
- Icon(
- Icons.calendar_month_outlined,
- size: 15,
- color: Colors.white,
- ),
- Text(
- '全部',
- style: TextStyle(fontSize: 12, color: Colors.white),
- ),
- ],
- ),
- )),
- Expanded(
- child: Container(
- height: 50.0,
- width: 350,
- color: Global.StatusBarColor,
- child: ListView(
- scrollDirection: Axis.horizontal,
- children: <Widget>[
- GestureDetector(
- onTap: () {
- setState(() {
- selectItem = 0;
- _showDatePicker(0);
- });
- },
- child: Container(
- alignment: Alignment.center,
- margin: const EdgeInsets.all(3),
- padding: const EdgeInsets.only(right: 5.0, left: 5.0),
- decoration: selectItem == 0
- ? const BoxDecoration(
- borderRadius:
- BorderRadius.all(Radius.circular(10.0)),
- color: Colors.white)
- : null,
- child: Text(
- "今天\n ${LocalDateUtils.getMMDD(now, "-")} ",
- textAlign: TextAlign.center,
- style: TextStyle(
- fontSize: 10,
- color: (selectItem == 0)
- ? Global.StatusBarColor
- : Colors.white,
- ),
- ),
- ),
- ),
- GestureDetector(
- onTap: () {
- setState(() {
- _showDatePicker(1);
- selectItem = 1;
- });
- },
- child: Container(
- alignment: Alignment.center,
- margin: const EdgeInsets.all(3),
- padding: const EdgeInsets.only(right: 5.0, left: 5.0),
- decoration: selectItem == 1
- ? const BoxDecoration(
- borderRadius:
- BorderRadius.all(Radius.circular(10.0)),
- color: Colors.white)
- : null,
- child: Text(
- "${LocalDateUtils.getWeekday(now.add(const Duration(days: 1)))}\n ${LocalDateUtils.getMMDD(now.add(const Duration(days: 1)), "-")} ",
- style: TextStyle(
- fontSize: 10,
- color: (selectItem == 1)
- ? Global.StatusBarColor
- : Colors.white,
- ),
- ),
- ),
- ),
- GestureDetector(
- onTap: () {
- setState(() {
- _showDatePicker(2);
- selectItem = 2;
- });
- },
- child: Container(
- alignment: Alignment.center,
- margin: const EdgeInsets.all(3),
- padding: const EdgeInsets.only(right: 5.0, left: 5.0),
- decoration: selectItem == 2
- ? const BoxDecoration(
- borderRadius:
- BorderRadius.all(Radius.circular(10.0)),
- color: Colors.white)
- : null,
- child: Text(
- "${LocalDateUtils.getWeekday(now.add(const Duration(days: 2)))}\n ${LocalDateUtils.getMMDD(now.add(const Duration(days: 2)), "-")} ",
- style: TextStyle(
- fontSize: 10,
- color: (selectItem == 2)
- ? Global.StatusBarColor
- : Colors.white,
- ),
- ),
- ),
- ),
- GestureDetector(
- onTap: () {
- setState(() {
- _showDatePicker(3);
- selectItem = 3;
- });
- },
- child: Container(
- alignment: Alignment.center,
- margin: const EdgeInsets.all(3),
- padding: const EdgeInsets.only(right: 5.0, left: 5.0),
- decoration: selectItem == 3
- ? const BoxDecoration(
- borderRadius:
- BorderRadius.all(Radius.circular(10.0)),
- color: Colors.white)
- : null,
- child: Text(
- "${LocalDateUtils.getWeekday(now.add(const Duration(days: 3)))}\n ${LocalDateUtils.getMMDD(now.add(const Duration(days: 3)), "-")} ",
- style: TextStyle(
- fontSize: 10,
- color: (selectItem == 3)
- ? Global.StatusBarColor
- : Colors.white,
- ),
- ),
- ),
- ),
- GestureDetector(
- onTap: () {
- setState(() {
- _showDatePicker(4);
- selectItem = 4;
- });
- },
- child: Container(
- alignment: Alignment.center,
- margin: const EdgeInsets.all(3),
- padding: const EdgeInsets.only(right: 5.0, left: 5.0),
- decoration: selectItem == 4
- ? const BoxDecoration(
- borderRadius:
- BorderRadius.all(Radius.circular(10.0)),
- color: Colors.white)
- : null,
- child: Text(
- "${LocalDateUtils.getWeekday(now.add(const Duration(days: 4)))}\n ${LocalDateUtils.getMMDD(now.add(const Duration(days: 4)), "-")} ",
- style: TextStyle(
- fontSize: 10,
- color: (selectItem == 4)
- ? Global.StatusBarColor
- : Colors.white,
- ),
- ),
- ),
- ),
- GestureDetector(
- onTap: () {
- setState(() {
- _showDatePicker(5);
- selectItem = 5;
- });
- },
- child: Container(
- alignment: Alignment.center,
- margin: const EdgeInsets.all(3),
- padding: const EdgeInsets.only(right: 5.0, left: 5.0),
- decoration: selectItem == 5
- ? const BoxDecoration(
- borderRadius:
- BorderRadius.all(Radius.circular(10.0)),
- color: Colors.white)
- : null,
- child: Text(
- "${LocalDateUtils.getWeekday(now.add(const Duration(days: 5)))}\n ${LocalDateUtils.getMMDD(now.add(const Duration(days: 5)), "-")} ",
- style: TextStyle(
- fontSize: 10,
- color: (selectItem == 5)
- ? Global.StatusBarColor
- : Colors.white,
- ),
- ),
- ),
- ),
- GestureDetector(
- onTap: () {
- setState(() {
- _showDatePicker(6);
- selectItem = 6;
- });
- },
- child: Container(
- alignment: Alignment.center,
- margin: const EdgeInsets.all(3),
- padding: const EdgeInsets.only(right: 5.0, left: 5.0),
- decoration: selectItem == 6
- ? const BoxDecoration(
- borderRadius:
- BorderRadius.all(Radius.circular(10.0)),
- color: Colors.white)
- : null,
- child: Text(
- "${LocalDateUtils.getWeekday(now.add(const Duration(days: 6)))}\n ${LocalDateUtils.getMMDD(now.add(const Duration(days: 6)), "-")} ",
- style: TextStyle(
- fontSize: 10,
- color: (selectItem == 6)
- ? Global.StatusBarColor
- : Colors.white,
- ),
- ),
- ),
- ),
- // 更多的子Widget根据需要添加
- ],
- ),
- ),
- ),
- ]),
- InkWell(
- onTap: () async {
- final result = await Navigator.push(
- context,
- MaterialPageRoute(builder: (context) => SelectDepartment()),
- );
- setState(() {
- searchDeptName = result;
- _future = fetchData();
- });
- },
- child: Container(
- width: double.infinity,
- alignment: Alignment.center,
- padding: const EdgeInsets.symmetric(vertical: 15),
- child: const Text(
- "点击查找科室",
- style: TextStyle(fontSize: 18, color: Colors.blue),
- ),
- ),
- ),
- const Divider(
- indent: 5,
- endIndent: 5,
- height: 0,
- ),
- const SizedBox(
- height: 5,
- ),
- Align(
- alignment: Alignment.centerLeft,
- child: Padding(
- padding: const EdgeInsets.only(left: 5),
- child: Text(
- "坐诊医生",
- style: Theme.of(context).textTheme.titleMedium,
- ),
- ),
- ),
- const SizedBox(
- height: 5,
- ),
- Expanded(
- child: FutureBuilder<dynamic>(
- future: _future,
- builder: (context, snapshot) {
- if (snapshot.hasData) {
- dcl.DoctorListEntity data = snapshot.data;
- return ListView.builder(
- itemCount: data.data!.length,
- itemBuilder: (context, index) {
- return _getListItem(
- context, index, data, data.data?[index]);
- },
- );
- } else if (snapshot.hasError) {
- return Text('Error: ${snapshot.error}');
- }
- return const ColorLoader();
- },
- ),
- ),
- ]),
- );
- }
- Widget _getListItem(BuildContext context, int index,
- dcl.DoctorListEntity listEntity, dcl.Data? data) {
- if (data == null) {
- return const SizedBox();
- }
- return Container(
- color: Colors.white,
- margin: const EdgeInsets.all(5.0),
- child: Container(
- padding: const EdgeInsets.all(10.0),
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- Row(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- UserHeader(url: "${Global.ImageUrl}${data.avatar}"),
- const SizedBox(
- width: 5,
- ),
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Row(children: [
- Expanded(
- child: Text.rich(
- TextSpan(children: [
- TextSpan(
- text: data.nickName,
- style:
- Theme.of(context).textTheme.titleSmall),
- TextSpan(
- text: " ${data.deptName}",
- style: Theme.of(context).textTheme.bodySmall),
- ]),
- overflow: TextOverflow.ellipsis,
- ),
- ),
- OutlinedButton(
- style: ButtonStyle(
- padding: const WidgetStatePropertyAll(
- EdgeInsets.fromLTRB(10, 3, 10, 3)),
- minimumSize:
- const WidgetStatePropertyAll(Size.zero),
- side: const WidgetStatePropertyAll(
- BorderSide(color: Colors.blue)),
- tapTargetSize: MaterialTapTargetSize.shrinkWrap,
- shape: WidgetStatePropertyAll(
- RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(5)))),
- child: const Text(
- "查看详情",
- style: TextStyle(fontSize: 12, color: Colors.blue),
- ),
- onPressed: () {
- Navigator.push(
- context,
- MaterialPageRoute(
- builder: (context) => DoctorDetail(
- doctorListEntity: listEntity,
- key: const Key(''),
- which: index)),
- );
- },
- ),
- ]),
- data.doctorBlurb == null
- ? const SizedBox()
- : Text(data.doctorBlurb!,
- style: Theme.of(context)
- .textTheme
- .bodySmall
- ?.copyWith(color: Colors.black54)),
- ],
- ),
- ),
- ],
- ),
- Column(
- crossAxisAlignment: CrossAxisAlignment.end,
- mainAxisSize: MainAxisSize.min,
- children: [
- const Divider(),
- ElevatedButton(
- style: ButtonStyle(
- padding: const WidgetStatePropertyAll(
- EdgeInsets.fromLTRB(10, 3, 10, 3)),
- minimumSize: const WidgetStatePropertyAll(Size.zero),
- backgroundColor:
- const WidgetStatePropertyAll(Colors.blue),
- tapTargetSize: MaterialTapTargetSize.shrinkWrap,
- shape: WidgetStatePropertyAll(RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(5)))),
- onPressed: () {
- logd(selectDateStr);
- if (selectDateStr.isEmpty) {
- Component.toast("请选择预约时间", 0);
- return;
- }
- Navigator.push(
- context,
- MaterialPageRoute(
- builder: (context) => ConfirmRegistration(
- visitTime: selectDateStr,
- visitTimeEnd: halfHourLater,
- userListEntity: mUserListEntity,
- whichPatient: mWhichPatient,
- doctorListEntity: listEntity,
- key: const Key(''),
- which: index)));
- },
- child: const Text("挂号",
- style: TextStyle(color: Colors.white, fontSize: 12)),
- ),
- ],
- )
- ],
- ),
- ),
- );
- }
- void _showDatePicker(int addDay) async {
- /*DateTime now = DateTime.now();
- DateTime late = now.add(const Duration(days: 365));
- showBoardDateTimePicker(
- context: context,
- pickerType: DateTimePickerType.datetime,
- options: const BoardDateTimeOptions(
- languages: BoardPickerLanguages(
- today: "今天", tomorrow: "明天", now: "现在", locale: "zh")));
- return;*/
- DateTime dateTime = DateTime(
- DateTime.now().year,
- DateTime.now().month,
- DateTime.now().day + addDay,
- DateTime.now().minute > 30
- ? DateTime.now().hour + 1
- : DateTime.now().hour,
- DateTime.now().minute > 30 ? 0 : 30);
- // 默认时间
- selectDateStr = dateTime.toString().replaceAll(":00.000", "");
- halfHourLater = dateTime
- .add(const Duration(minutes: 30))
- .toString()
- .replaceAll(":00.000", "");
- // 显示对话框
- await showCupertinoModalPopup<void>(
- context: context,
- builder: (BuildContext context) {
- return Column(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- SizedBox(height: 500),
- Expanded(
- child: Container(
- alignment: Alignment.center,
- decoration: BoxDecoration(
- borderRadius: BorderRadius.only(
- topLeft: Radius.circular(10),
- topRight: Radius.circular(10)),
- color: Colors.white),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- Padding(
- padding: const EdgeInsets.fromLTRB(30, 10, 30, 0),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Material(
- color: Colors.grey,
- borderRadius: BorderRadius.circular(5),
- child: InkWell(
- onTap: () {
- selectDateStr = "";
- Navigator.of(context).pop();
- },
- child: Container(
- height: 30,
- width: 50,
- alignment: Alignment.center,
- child: Text(
- "取消",
- style: TextStyle(
- color: Colors.white,
- ),
- )),
- ),
- ),
- Material(
- color: Colors.green,
- borderRadius: BorderRadius.circular(5),
- child: InkWell(
- onTap: () {
- _future = fetchData();
- Navigator.of(context).pop();
- },
- child: Container(
- height: 30,
- width: 50,
- alignment: Alignment.center,
- child: const Text(
- "确定",
- style: TextStyle(
- color: Colors.white,
- ),
- )),
- ),
- ),
- ],
- ),
- ),
- Expanded(
- child: CupertinoDatePicker(
- mode: CupertinoDatePickerMode.dateAndTime,
- // 日期选择器模式 `time`,`date`,`dateAndTime`, 默认`dateAndTime`
- initialDateTime: DateTime(
- DateTime.now().year,
- DateTime.now().month,
- DateTime.now().day + addDay,
- DateTime.now().minute > 30
- ? DateTime.now().hour + 1
- : DateTime.now().hour,
- DateTime.now().minute > 30 ? 0 : 30),
- // 初始化日期
- minimumDate: DateTime(2024, 07, 09),
- // 最小可选日期
- maximumDate: DateTime(2025, 07, 22),
- // 最大可选日期
- minimumYear: 2024,
- // 最小年份
- maximumYear: 2025,
- // 最大年份
- minuteInterval: 30,
- // 分钟间隔 initialDateTime.minute 必须可以整除 minuteInterval 必须是 60 的整数因子
- use24hFormat: true,
- // 是否使用24小时制
- dateOrder: DatePickerDateOrder.dmy,
- // 日期选择器排序方式 默认年/月/日
- backgroundColor: Colors.white,
- // 选中日期变化回调
- onDateTimeChanged: (dateTime) {
- logd(dateTime);
- selectDateStr =
- dateTime.toString().replaceAll(":00.000", "");
- halfHourLater = dateTime
- .add(const Duration(minutes: 30))
- .toString()
- .replaceAll(":00.000", "");
- // _chooseDateTime = dateTime;
- },
- ),
- ),
- ]),
- ),
- ),
- ]);
- },
- );
- }
- Future<dcl.DoctorListEntity?> fetchData() async {
- Map<String, String> headers = {
- 'token': Global.token,
- };
- const timeout = Duration(seconds: 30);
- final response = await http
- .get(
- Uri.parse(
- '${Global.BaseUrl}doctor/list?deptName=$searchDeptName&selectDateStr=$selectDateStr'),
- headers: jsonHeaders(withToken: true))
- .timeout(timeout);
- logd(
- '${Global.BaseUrl}doctor/list?deptName=$searchDeptName&selectDateStr=$selectDateStr');
- if (response.statusCode == 200) {
- final json = decodeBodyToJson(response.bodyBytes);
- logd("医生列表=$json");
- dcl.DoctorListEntity mDoctorListEntity =
- dcl.DoctorListEntity.fromJson(json);
- return mDoctorListEntity;
- } else {
- Component.toast("出错了,请稍后再试!", 0);
- }
- }
- }
|