| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397 |
- import 'package:app_business/service/api.dart';
- import 'package:app_business/view/home/dialog_event_register.dart';
- import 'package:pretty_qr_code/pretty_qr_code.dart';
- import 'package:track_common/widget.dart';
- import 'package:track_common/widget/prelude.dart';
- import 'event_manage_controller.dart';
- class EventManage extends GetView<EventManagerController> {
- const EventManage({super.key});
- @override
- Widget build(BuildContext context) {
- return Level2View(
- level1: level1(),
- level2: level2(),
- level1Title: '赛事列表',
- level1Action: wDate(context),
- level2Title: '用户列表',
- level2SubTitle: Row(
- children: [
- Obx(() => Text(
- controller.selected?.name != null
- ? '(${controller.selected!.name})'
- : '',
- style: const TextStyle(color: Colors.grey, fontSize: 14.22),
- )),
- const Spacer(),
- SizedBox(
- height: 27.73,
- width: 260,
- child: Row(
- mainAxisSize: MainAxisSize.min,
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- SizedBox(
- width: 70,
- child: SmallButton(
- isOutline: true,
- color: Colors.orange,
- onPressed: controller.userRestartAll,
- child: const Text('一键重赛'),
- )),
- SizedBox(
- width: 70,
- child: SmallButton(
- isOutline: true,
- color: Colors.blue,
- onPressed: controller.routeAllocAll,
- child: const Text('一键分发'),
- )),
- SizedBox(
- width: 70,
- child: SmallButton(
- isOutline: true,
- color: Colors.green,
- onPressed: controller.userStartAll,
- child: const Text('一键开始'),
- ))
- ],
- ),
- ),
- const SizedBox(width: 20)
- ],
- ));
- }
- Widget wDate(BuildContext context) {
- return GestureDetector(
- onTap: () => _onTapDate(context),
- child: Obx(() => Container(
- height: 22.04,
- padding: const EdgeInsets.symmetric(horizontal: 8),
- decoration: BoxDecoration(
- border:
- Border.all(color: const Color(0xffe3e3e3), width: 0.71),
- borderRadius: BorderRadius.circular(2.13)),
- child: Text(controller.dateStr),
- )));
- }
- Future<void> _onTapDate(BuildContext context) async {
- final date = await showDatePicker(
- context: context,
- initialDate: controller.filterDate.value,
- firstDate: DateTime.now(),
- lastDate: DateTime.now().add(365.days));
- if (date != null) {
- controller.filterDate.value = date;
- controller.flushList();
- }
- }
- Widget level1() {
- return Obx(() => ListView(
- children: controller.eventList
- .map((e) => EventTitle(
- data: e,
- selected: controller.selectedId.value == e.id,
- onTap: () => controller.selectedId.value = e.id,
- ))
- .toList()));
- }
- Widget level2() {
- return Column(
- children: [
- Expanded(
- child: Obx(
- () => LineChart(titles: rightTitles(), children: rightUsers())))
- ],
- );
- }
- Iterable<LineChartTitle> rightTitles() {
- return [
- LineChartTitle(
- title: Checkbox(
- value: false,
- onChanged: (v) {
- controller.selectedUser.update((val) {
- final all = controller.userList.map((e) => e.checkId);
- val?.assignAll(all);
- });
- }),
- width: 32),
- const LineChartTitle(title: Text('序号'), width: 42),
- const LineChartTitle(title: Text('用户名'), width: 70),
- const LineChartTitle(title: Text('手机号'), width: 98),
- const LineChartTitle(title: Text('签到时间'), width: 78),
- const LineChartTitle(title: Text('手环'), width: 67),
- const LineChartTitle(title: Text('路线'), flex: 1),
- const LineChartTitle(title: Text('状态'), width: 67),
- const LineChartTitle(title: Text('操作'), width: 67),
- ];
- }
- Iterable<LineChartElem> rightUsers() {
- return controller.userList.indexed.map((e) {
- final (i, one) = e;
- var stateStr = '';
- var stateColor = Colors.white;
- var optStr = '删除';
- var optColor = Colors.red;
- VoidCallback? opt;
- if (one.isAllowDel) {
- opt = () => controller.deleteSignIn(one);
- }
- switch (one.state) {
- case UserState.idle:
- stateStr = '未分发';
- stateColor = Colors.blue;
- break;
- case UserState.isStart:
- stateStr = '已开始';
- stateColor = Colors.green;
- optStr = '结束';
- opt = () => controller.userStopGame(one);
- break;
- case UserState.isFinish:
- stateStr = '已结束';
- stateColor = Colors.orange;
- optStr = '重赛';
- optColor = Colors.orange;
- opt = () => controller.userRestartGame(one);
- break;
- default:
- }
- var snStr = '--';
- const n = 4;
- if (one.bandSN.length > n) {
- snStr = '-${one.bandSN.substring(one.bandSN.length - n)}';
- } else if (one.bandSN.isNotEmpty) {
- snStr = one.bandSN;
- }
- return LineChartElem([
- Checkbox(
- value: controller.selectedUser.value.contains(one.checkId),
- onChanged: (v) {
- controller.selectedUser.update((val) {
- if (v == true) {
- val?.add(one.checkId);
- } else {
- val?.remove(one.checkId);
- }
- });
- }),
- Text('${i + 1}'),
- Text(one.name),
- Text(one.phone),
- Text(one.checkTime),
- Text(snStr),
- one.state == UserState.idle
- ? button(
- color: Colors.blue,
- onPressed: () => routeSelect(one),
- text: '分发')
- : Row(mainAxisSize: MainAxisSize.min, children: [
- Expanded(
- child: Text(
- one.routeName,
- maxLines: 1,
- style: const TextStyle(overflow: TextOverflow.ellipsis),
- )),
- SizedBox(
- width: 32,
- child: one.state == UserState.hasRoute
- ? GestureDetector(
- onTap: () => routeSelect(one),
- child: const Icon(Icons.mode_edit_outline))
- : const SizedBox())
- ]),
- one.state == UserState.hasRoute
- ? button(
- color: Colors.green,
- onPressed: () => controller.userStart(one),
- text: '开始')
- : Text(stateStr, style: TextStyle(color: stateColor)),
- button(text: optStr, color: optColor, isOutline: true, onPressed: opt)
- ]);
- });
- }
- Widget button(
- {Color? color,
- VoidCallback? onPressed,
- isOutline = false,
- required String text}) {
- return SizedBox(
- height: 22.78,
- width: 51.2,
- child: SmallButton(
- color: color,
- onPressed: onPressed,
- isOutline: isOutline,
- child: Text(text),
- ));
- }
- Future<void> routeSelect(UserInManage user) async {
- final list = await controller.routeList(user);
- await Get.dialog(_RouteSelectDialog(list: list));
- final route = controller.tmpSelectRoute;
- if (route != null) {
- await controller.routeAlloc(user, route);
- }
- }
- }
- class _RouteSelectDialog extends GetView<EventManagerController> {
- const _RouteSelectDialog({required this.list});
- final Iterable<RouteInfo> list;
- @override
- Widget build(BuildContext context) {
- return AlertDialog(
- title: const Center(
- child: Text(
- '选择路线',
- style: TextStyle(fontSize: 17),
- )),
- backgroundColor: Colors.white,
- shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(17.78)),
- content: Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- SizedBox(
- width: 303.64,
- child: DropdownMenu<RouteInfo>(
- key: GlobalKey(),
- width: 303,
- hintText: '请选择路线',
- onSelected: (one) {
- controller.tmpSelectRoute = one;
- },
- inputDecorationTheme: InputDecorationTheme(
- border: textBorder,
- isDense: true,
- ),
- dropdownMenuEntries: list
- .map((e) =>
- DropdownMenuEntry<RouteInfo>(value: e, label: e.name))
- .toList())),
- const SizedBox(height: 30),
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceEvenly,
- children: [
- SizedBox(
- height: 38,
- width: 106.67,
- child: SmallButton(
- onPressed: () {
- Get.back();
- },
- color: Colors.orange,
- child: const Text('随机'))),
- SizedBox(
- height: 38,
- width: 106.67,
- child: SmallButton(
- onPressed: () {
- Get.back();
- },
- color: Colors.blue,
- child: const Text('确认'))),
- ],
- )
- ],
- ),
- );
- }
- }
- class EventTitle extends GetView<EventManagerController> {
- final bool selected;
- final EventInManage data;
- final VoidCallback onTap;
- const EventTitle(
- {super.key,
- required this.selected,
- required this.data,
- required this.onTap});
- @override
- Widget build(BuildContext context) {
- var children = <Widget>[
- AppTitleList(
- title: data.name,
- tail: Text('${data.userList.length}'),
- isSelected: selected,
- onTap: onTap,
- )
- ];
- if (selected) {
- children.add(const SizedBox(height: 2));
- children.add(Container(
- decoration: const BoxDecoration(
- color: Color(0xfff1f1f1),
- borderRadius: BorderRadius.only(
- bottomLeft: Radius.circular(14.22),
- bottomRight: Radius.circular(14.22))),
- padding: const EdgeInsets.all(16.3),
- width: 221.87,
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- Row(
- children: [
- DarkButton(
- onPressed: data.isAllowDel
- ? () => controller.deleteEvent(data)
- : null,
- child: const Text('删除')),
- const Spacer(),
- DarkButton(
- color: Colors.blue,
- onPressed: data.isAllowEdit
- ? () async {
- final r = await showEventEditDialog(
- controller.mapId!,
- EventRegisterInfo()..name = data.name);
- if (r != null) {
- controller.eventEdit(data.id, r);
- }
- }
- : null,
- child: const Text('修改')),
- ],
- ),
- const SizedBox(height: 24),
- SizedBox.square(
- dimension: 128, child: PrettyQrView.data(data: data.qrCode)),
- const SizedBox(height: 12),
- const Text(
- '用彩图奔跑APP扫码签到',
- style: TextStyle(color: Colors.red, fontSize: 14.22),
- )
- ],
- ),
- ));
- }
- return Column(
- mainAxisSize: MainAxisSize.min,
- children: children,
- );
- }
- }
|