event_manage.dart 12 KB

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