event_manage.dart 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  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. final enable = controller.selected?.state == EventState.start;
  183. return LineChartElem([
  184. _CheckBox(one),
  185. Text('${i + 1}'),
  186. Text(one.name),
  187. Text(one.phone),
  188. Text(one.checkTime),
  189. Text(snStr),
  190. one.state == UserState.idle
  191. ? button(
  192. color: Colors.blue,
  193. onPressed: enable ? () => routeSelect(one) : null,
  194. text: '分发')
  195. : Row(mainAxisSize: MainAxisSize.min, children: [
  196. Expanded(
  197. child: Text(
  198. one.routeName,
  199. maxLines: 1,
  200. style: const TextStyle(overflow: TextOverflow.ellipsis),
  201. )),
  202. SizedBox(
  203. width: 32,
  204. child: one.state == UserState.hasRoute
  205. ? GestureDetector(
  206. onTap: enable ? () => routeSelect(one) : null,
  207. child: const Icon(Icons.mode_edit_outline))
  208. : const SizedBox())
  209. ]),
  210. one.state == UserState.hasRoute
  211. ? button(
  212. color: Colors.green,
  213. onPressed: enable ? () => controller.userStart(one) : null,
  214. text: '开始')
  215. : Text(stateStr, style: TextStyle(color: stateColor)),
  216. button(
  217. text: optStr,
  218. color: optColor,
  219. isOutline: true,
  220. onPressed: enable ? opt : null)
  221. ]);
  222. });
  223. }
  224. Widget button(
  225. {Color? color,
  226. VoidCallback? onPressed,
  227. isOutline = false,
  228. required String text}) {
  229. return SizedBox(
  230. height: 22.78,
  231. width: 51.2,
  232. child: SmallButton(
  233. color: color,
  234. onPressed: onPressed,
  235. isOutline: isOutline,
  236. child: Text(text),
  237. ));
  238. }
  239. Future<void> routeSelect(UserInManage user) async {
  240. final list = await controller.routeList(user);
  241. await Get.dialog(_RouteSelectDialog(list: list));
  242. final route = controller.tmpSelectRoute;
  243. if (route != null) {
  244. await controller.routeAlloc(user, route);
  245. }
  246. }
  247. }
  248. class _CheckBox extends GetView<EventManagerController> {
  249. const _CheckBox(this.one);
  250. final UserInManage one;
  251. @override
  252. Widget build(BuildContext context) {
  253. return Obx(() => Checkbox(
  254. value: controller.selectedUser.value.contains(one.checkId),
  255. onChanged: (v) {
  256. controller.selectedUser.update((val) {
  257. if (v == true) {
  258. val?.add(one.checkId);
  259. } else {
  260. val?.remove(one.checkId);
  261. }
  262. });
  263. }));
  264. }
  265. }
  266. class _RouteSelectDialog extends GetView<EventManagerController> {
  267. const _RouteSelectDialog({required this.list});
  268. final Iterable<RouteInfo> list;
  269. @override
  270. Widget build(BuildContext context) {
  271. return AlertDialog(
  272. title: const Center(
  273. child: Text(
  274. '选择路线',
  275. style: TextStyle(fontSize: 17),
  276. )),
  277. backgroundColor: Colors.white,
  278. shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(17.78)),
  279. content: Column(
  280. mainAxisSize: MainAxisSize.min,
  281. crossAxisAlignment: CrossAxisAlignment.center,
  282. children: [
  283. SizedBox(
  284. width: 303.64,
  285. child: DropdownMenu<RouteInfo>(
  286. key: GlobalKey(),
  287. width: 303,
  288. hintText: '请选择路线',
  289. onSelected: (one) {
  290. controller.tmpSelectRoute = one;
  291. },
  292. inputDecorationTheme: InputDecorationTheme(
  293. border: textBorder,
  294. isDense: true,
  295. ),
  296. dropdownMenuEntries: list
  297. .map((e) =>
  298. DropdownMenuEntry<RouteInfo>(value: e, label: e.name))
  299. .toList())),
  300. const SizedBox(height: 30),
  301. Row(
  302. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  303. children: [
  304. SizedBox(
  305. height: 38,
  306. width: 106.67,
  307. child: SmallButton(
  308. onPressed: () {
  309. Get.back();
  310. },
  311. color: Colors.orange,
  312. child: const Text('随机'))),
  313. SizedBox(
  314. height: 38,
  315. width: 106.67,
  316. child: SmallButton(
  317. onPressed: () {
  318. Get.back();
  319. },
  320. color: Colors.blue,
  321. child: const Text('确认'))),
  322. ],
  323. )
  324. ],
  325. ),
  326. );
  327. }
  328. }
  329. class EventTitle extends GetView<EventManagerController> {
  330. final bool selected;
  331. final EventInManage data;
  332. final VoidCallback onTap;
  333. const EventTitle(
  334. {super.key,
  335. required this.selected,
  336. required this.data,
  337. required this.onTap});
  338. @override
  339. Widget build(BuildContext context) {
  340. var children = <Widget>[
  341. AppTitleList(
  342. title: data.name,
  343. tail: Text('${data.userList.length}'),
  344. subtitle: Text.rich(TextSpan(
  345. text: '比赛时间:${data.startAt} - ${data.endAt} ',
  346. style: const TextStyle(
  347. fontSize: 9.9,
  348. fontWeight: FontWeight.w500,
  349. color: Color(0xff818181)),
  350. children: [
  351. TextSpan(
  352. text: data.state.toString(),
  353. style: TextStyle(color: data.state.toColor()))
  354. ])),
  355. isSelected: selected,
  356. onTap: onTap,
  357. )
  358. ];
  359. const buttonWidth = 52.0;
  360. if (selected && data.state != EventState.finish) {
  361. children.add(const SizedBox(height: 2));
  362. children.add(Container(
  363. decoration: const BoxDecoration(
  364. color: Color(0xfff1f1f1),
  365. borderRadius: BorderRadius.only(
  366. bottomLeft: Radius.circular(14.22),
  367. bottomRight: Radius.circular(14.22))),
  368. padding: const EdgeInsets.all(16.3),
  369. width: 221.87,
  370. child: Column(
  371. mainAxisSize: MainAxisSize.min,
  372. children: [
  373. SizedBox(
  374. height: 25,
  375. child: Row(
  376. children: [
  377. AppButton.cancel(
  378. width: buttonWidth,
  379. onPressed: data.isAllowDel
  380. ? () => controller.deleteEvent(data)
  381. : null,
  382. child: const Text('删除')),
  383. const Spacer(),
  384. AppButton.confirm(
  385. width: buttonWidth,
  386. onPressed: data.isAllowEdit
  387. ? () async {
  388. final r = await showEventSettingsDialog(data);
  389. if (r != null) {
  390. final msg =
  391. await controller.eventSettingsEdit(r);
  392. if (context.mounted) {
  393. ScaffoldMessenger.of(context).showSnackBar(
  394. SnackBar(content: Text(msg)));
  395. }
  396. }
  397. }
  398. : null,
  399. child: const Text('设置')),
  400. const SizedBox(width: 7),
  401. AppButton.confirm(
  402. width: buttonWidth,
  403. onPressed: data.isAllowEdit
  404. ? () async {
  405. final r = await showEventEditDialog(
  406. controller.mapId!,
  407. EventRegisterInfo()..name = data.name);
  408. if (r != null) {
  409. controller.eventEdit(data.id, r);
  410. }
  411. }
  412. : null,
  413. child: const Text('修改')),
  414. ],
  415. )),
  416. const SizedBox(height: 24),
  417. SizedBox.square(
  418. dimension: 128, child: PrettyQrView.data(data: data.qrCode)),
  419. const SizedBox(height: 12),
  420. const Text(
  421. '用彩图奔跑APP扫码签到',
  422. style: TextStyle(color: Colors.red, fontSize: 14.22),
  423. )
  424. ],
  425. ),
  426. ));
  427. }
  428. return Column(
  429. mainAxisSize: MainAxisSize.min,
  430. children: children,
  431. );
  432. }
  433. }
  434. Future<Iterable<Rule>?> showEventSettingsDialog(EventInManage event) async {
  435. return await Get.dialog(const DialogSettings(), arguments: event.id);
  436. }