event_manage.dart 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. import 'package:app_business/service/api.dart';
  2. import 'package:app_business/view/home/dialog_event_register.dart';
  3. import 'package:pretty_qr_code/pretty_qr_code.dart';
  4. import 'package:track_common/model/event_state.dart';
  5. import 'package:track_common/utils.dart';
  6. import 'package:track_common/widget.dart';
  7. import 'package:track_common/widget/prelude.dart';
  8. import 'dialog_settings.dart';
  9. import 'event_manage_controller.dart';
  10. class EventManage extends GetView<EventManagerController> {
  11. const EventManage({super.key});
  12. @override
  13. Widget build(BuildContext context) {
  14. return Level2View(
  15. level1: level1(),
  16. level2: level2(),
  17. level1Title: '赛事列表',
  18. level1Action: wDate(context),
  19. level2Title: '用户列表',
  20. level2SubTitle: Row(
  21. children: [
  22. Obx(() => Text(
  23. controller.selected?.name != null
  24. ? '(${controller.selected!.name})'
  25. : '',
  26. style: const TextStyle(color: Colors.grey, fontSize: 14.22),
  27. )),
  28. const Spacer(),
  29. SizedBox(
  30. // height: 27.73,
  31. width: 360,
  32. child: wTopButtons(context),
  33. ),
  34. const SizedBox(width: 20)
  35. ],
  36. ));
  37. }
  38. Widget wTopButtons(BuildContext context) {
  39. return Obx(() {
  40. final enable = controller.selected?.state == EventState.start;
  41. final buttons = [
  42. (Colors.orange, '一键重赛', controller.userRestartAll),
  43. (Colors.blue, '一键分发', controller.routeAllocAll),
  44. (Colors.green, '一键开始', controller.userStartAll),
  45. (Colors.red, '一键删除', controller.userDelAll),
  46. ];
  47. final List<Widget> children = buttons.map((e) {
  48. return AppButton.outlined(
  49. color: e.$1,
  50. onPressed: onDoAll(context, enable, e.$2, e.$3),
  51. child: Text(e.$2),
  52. );
  53. }).toList();
  54. return Row(
  55. mainAxisSize: MainAxisSize.min,
  56. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  57. children: children,
  58. );
  59. });
  60. }
  61. void Function()? onDoAll(BuildContext context, bool enable, String title,
  62. Future<void> Function() then) {
  63. return enable ? () => doAll(context, title, then) : null;
  64. }
  65. Future<void> doAll(
  66. BuildContext context, String title, Future<void> Function() then) async {
  67. Get.dialog(AppDialog(
  68. title: Text('确认$title?'),
  69. onCancelText: '取消',
  70. onConfirmText: '确认',
  71. onConfirm: () => context.doCall(() async {
  72. await then();
  73. if (context.mounted) {
  74. ScaffoldMessenger.of(context)
  75. .showSnackBar(const SnackBar(content: Text('操作成功')));
  76. }
  77. }, onFinally: () => Get.back())));
  78. }
  79. Widget wDate(BuildContext context) {
  80. return GestureDetector(
  81. onTap: () => _onTapDate(context),
  82. child: Obx(() => Container(
  83. height: 22.04,
  84. padding: const EdgeInsets.symmetric(horizontal: 8),
  85. decoration: BoxDecoration(
  86. border:
  87. Border.all(color: const Color(0xffe3e3e3), width: 0.71),
  88. borderRadius: BorderRadius.circular(2.13)),
  89. child: Text(controller.dateStr),
  90. )));
  91. }
  92. Future<void> _onTapDate(BuildContext context) async {
  93. final date = await showDatePicker(
  94. context: context,
  95. initialDate: controller.filterDate.value,
  96. firstDate: DateTime.now(),
  97. lastDate: DateTime.now().add(365.days));
  98. if (date != null) {
  99. controller.filterDate.value = date;
  100. controller.flushList();
  101. }
  102. }
  103. Widget level1() {
  104. return Obx(() => ListView(
  105. children: controller.eventList
  106. .map((e) => EventTitle(
  107. data: e,
  108. selected: controller.selectedId.value == e.id,
  109. onTap: () => controller.selectedId.value = e.id,
  110. ))
  111. .toList()));
  112. }
  113. Widget level2() {
  114. return Column(
  115. children: [
  116. Expanded(
  117. child: Obx(
  118. () => LineChart(titles: rightTitles(), children: rightUsers())))
  119. ],
  120. );
  121. }
  122. Iterable<LineChartTitle> rightTitles() {
  123. return [
  124. LineChartTitle(
  125. title: Checkbox(
  126. value: false,
  127. onChanged: (v) {
  128. controller.selectedUser.update((val) {
  129. final all = controller.userList.map((e) => e.checkId);
  130. val?.assignAll(all);
  131. });
  132. }),
  133. width: 32),
  134. const LineChartTitle(title: Text('序号'), width: 42),
  135. const LineChartTitle(title: Text('用户名'), width: 70),
  136. const LineChartTitle(title: Text('手机号'), width: 98),
  137. const LineChartTitle(title: Text('签到时间'), width: 78),
  138. const LineChartTitle(title: Text('手环'), width: 67),
  139. const LineChartTitle(title: Text('路线'), flex: 1),
  140. const LineChartTitle(title: Text('状态'), width: 67),
  141. const LineChartTitle(title: Text('操作'), width: 67),
  142. ];
  143. }
  144. Iterable<LineChartElem> rightUsers() {
  145. return controller.userList.indexed.map((e) {
  146. final (i, one) = e;
  147. var stateStr = '';
  148. var stateColor = Colors.white;
  149. var optStr = '删除';
  150. var optColor = Colors.red;
  151. VoidCallback? opt;
  152. if (one.isAllowDel) {
  153. opt = () => controller.deleteSignIn(one);
  154. }
  155. switch (one.state) {
  156. case UserState.idle:
  157. stateStr = '未分发';
  158. stateColor = Colors.blue;
  159. break;
  160. case UserState.isStart:
  161. stateStr = '已开始';
  162. stateColor = Colors.green;
  163. optStr = '结束';
  164. opt = () => controller.userStopGame(one);
  165. break;
  166. case UserState.isFinish:
  167. stateStr = '已结束';
  168. stateColor = Colors.orange;
  169. optStr = '重赛';
  170. optColor = Colors.orange;
  171. opt = () => controller.userRestartGame(one);
  172. break;
  173. default:
  174. }
  175. var snStr = '--';
  176. const n = 4;
  177. if (one.bandSN.length > n) {
  178. snStr = '-${one.bandSN.substring(one.bandSN.length - n)}';
  179. } else if (one.bandSN.isNotEmpty) {
  180. snStr = one.bandSN;
  181. }
  182. return LineChartElem([
  183. _CheckBox(one),
  184. Text('${i + 1}'),
  185. Text(one.name),
  186. Text(one.phone),
  187. Text(one.checkTime),
  188. Text(snStr),
  189. one.state == UserState.idle
  190. ? button(
  191. color: Colors.blue,
  192. onPressed: () => routeSelect(one),
  193. text: '分发')
  194. : Row(mainAxisSize: MainAxisSize.min, children: [
  195. Expanded(
  196. child: Text(
  197. one.routeName,
  198. maxLines: 1,
  199. style: const TextStyle(overflow: TextOverflow.ellipsis),
  200. )),
  201. SizedBox(
  202. width: 32,
  203. child: one.state == UserState.hasRoute
  204. ? GestureDetector(
  205. onTap: () => routeSelect(one),
  206. child: const Icon(Icons.mode_edit_outline))
  207. : const SizedBox())
  208. ]),
  209. one.state == UserState.hasRoute
  210. ? button(
  211. color: Colors.green,
  212. onPressed: () => controller.userStart(one),
  213. text: '开始')
  214. : Text(stateStr, style: TextStyle(color: stateColor)),
  215. button(text: optStr, color: optColor, isOutline: true, onPressed: opt)
  216. ]);
  217. });
  218. }
  219. Widget button(
  220. {Color? color,
  221. VoidCallback? onPressed,
  222. isOutline = false,
  223. required String text}) {
  224. return SizedBox(
  225. height: 22.78,
  226. width: 51.2,
  227. child: SmallButton(
  228. color: color,
  229. onPressed: onPressed,
  230. isOutline: isOutline,
  231. child: Text(text),
  232. ));
  233. }
  234. Future<void> routeSelect(UserInManage user) async {
  235. final list = await controller.routeList(user);
  236. await Get.dialog(_RouteSelectDialog(list: list));
  237. final route = controller.tmpSelectRoute;
  238. if (route != null) {
  239. await controller.routeAlloc(user, route);
  240. }
  241. }
  242. }
  243. class _CheckBox extends GetView<EventManagerController> {
  244. const _CheckBox(this.one);
  245. final UserInManage one;
  246. @override
  247. Widget build(BuildContext context) {
  248. return Obx(() => Checkbox(
  249. value: controller.selectedUser.value.contains(one.checkId),
  250. onChanged: (v) {
  251. controller.selectedUser.update((val) {
  252. if (v == true) {
  253. val?.add(one.checkId);
  254. } else {
  255. val?.remove(one.checkId);
  256. }
  257. });
  258. }));
  259. }
  260. }
  261. class _RouteSelectDialog extends GetView<EventManagerController> {
  262. const _RouteSelectDialog({required this.list});
  263. final Iterable<RouteInfo> list;
  264. @override
  265. Widget build(BuildContext context) {
  266. return AlertDialog(
  267. title: const Center(
  268. child: Text(
  269. '选择路线',
  270. style: TextStyle(fontSize: 17),
  271. )),
  272. backgroundColor: Colors.white,
  273. shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(17.78)),
  274. content: Column(
  275. mainAxisSize: MainAxisSize.min,
  276. crossAxisAlignment: CrossAxisAlignment.center,
  277. children: [
  278. SizedBox(
  279. width: 303.64,
  280. child: DropdownMenu<RouteInfo>(
  281. key: GlobalKey(),
  282. width: 303,
  283. hintText: '请选择路线',
  284. onSelected: (one) {
  285. controller.tmpSelectRoute = one;
  286. },
  287. inputDecorationTheme: InputDecorationTheme(
  288. border: textBorder,
  289. isDense: true,
  290. ),
  291. dropdownMenuEntries: list
  292. .map((e) =>
  293. DropdownMenuEntry<RouteInfo>(value: e, label: e.name))
  294. .toList())),
  295. const SizedBox(height: 30),
  296. Row(
  297. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  298. children: [
  299. SizedBox(
  300. height: 38,
  301. width: 106.67,
  302. child: SmallButton(
  303. onPressed: () {
  304. Get.back();
  305. },
  306. color: Colors.orange,
  307. child: const Text('随机'))),
  308. SizedBox(
  309. height: 38,
  310. width: 106.67,
  311. child: SmallButton(
  312. onPressed: () {
  313. Get.back();
  314. },
  315. color: Colors.blue,
  316. child: const Text('确认'))),
  317. ],
  318. )
  319. ],
  320. ),
  321. );
  322. }
  323. }
  324. class EventTitle extends GetView<EventManagerController> {
  325. final bool selected;
  326. final EventInManage data;
  327. final VoidCallback onTap;
  328. const EventTitle(
  329. {super.key,
  330. required this.selected,
  331. required this.data,
  332. required this.onTap});
  333. @override
  334. Widget build(BuildContext context) {
  335. var children = <Widget>[
  336. AppTitleList(
  337. title: data.name,
  338. tail: Text('${data.userList.length}'),
  339. subtitle: Text.rich(TextSpan(
  340. text: '比赛时间:${data.startAt} - ${data.endAt} ',
  341. style: const TextStyle(
  342. fontSize: 9.9,
  343. fontWeight: FontWeight.w500,
  344. color: Color(0xff818181)),
  345. children: [
  346. TextSpan(
  347. text: data.state.toString(),
  348. style: TextStyle(color: data.state.toColor()))
  349. ])),
  350. isSelected: selected,
  351. onTap: onTap,
  352. )
  353. ];
  354. const buttonWidth = 52.0;
  355. if (selected && data.state != EventState.finish) {
  356. children.add(const SizedBox(height: 2));
  357. children.add(Container(
  358. decoration: const BoxDecoration(
  359. color: Color(0xfff1f1f1),
  360. borderRadius: BorderRadius.only(
  361. bottomLeft: Radius.circular(14.22),
  362. bottomRight: Radius.circular(14.22))),
  363. padding: const EdgeInsets.all(16.3),
  364. width: 221.87,
  365. child: Column(
  366. mainAxisSize: MainAxisSize.min,
  367. children: [
  368. SizedBox(
  369. height: 25,
  370. child: Row(
  371. children: [
  372. AppButton.cancel(
  373. width: buttonWidth,
  374. onPressed: data.isAllowDel
  375. ? () => controller.deleteEvent(data)
  376. : null,
  377. child: const Text('删除')),
  378. const Spacer(),
  379. AppButton.confirm(
  380. width: buttonWidth,
  381. onPressed: data.isAllowEdit
  382. ? () async {
  383. final r = await showEventSettingsDialog(data);
  384. if (r != null) {
  385. final msg =
  386. await controller.eventSettingsEdit(r);
  387. if (context.mounted) {
  388. ScaffoldMessenger.of(context).showSnackBar(
  389. SnackBar(content: Text(msg)));
  390. }
  391. }
  392. }
  393. : null,
  394. child: const Text('设置')),
  395. const SizedBox(width: 7),
  396. AppButton.confirm(
  397. width: buttonWidth,
  398. onPressed: data.isAllowEdit
  399. ? () async {
  400. final r = await showEventEditDialog(
  401. controller.mapId!,
  402. EventRegisterInfo()..name = data.name);
  403. if (r != null) {
  404. controller.eventEdit(data.id, r);
  405. }
  406. }
  407. : null,
  408. child: const Text('修改')),
  409. ],
  410. )),
  411. const SizedBox(height: 24),
  412. SizedBox.square(
  413. dimension: 128, child: PrettyQrView.data(data: data.qrCode)),
  414. const SizedBox(height: 12),
  415. const Text(
  416. '用彩图奔跑APP扫码签到',
  417. style: TextStyle(color: Colors.red, fontSize: 14.22),
  418. )
  419. ],
  420. ),
  421. ));
  422. }
  423. return Column(
  424. mainAxisSize: MainAxisSize.min,
  425. children: children,
  426. );
  427. }
  428. }
  429. Future<Iterable<Rule>?> showEventSettingsDialog(EventInManage event) async {
  430. return await Get.dialog(const DialogSettings(), arguments: event.id);
  431. }