index.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. <template>
  2. <div class="p-2">
  3. <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
  4. <div v-show="showSearch" class="mb-[10px]">
  5. <el-card shadow="hover">
  6. <el-form ref="queryFormRef" :model="queryParams" :inline="true">
  7. <el-form-item label="项目类型" prop="projectTypeFilter">
  8. <el-select v-model="projectTypeFilter" placeholder="请选择项目类型" clearable @change="handleProjectTypeFilterChange">
  9. <el-option
  10. v-for="dict in game_project_type"
  11. :key="dict.value"
  12. :label="dict.label"
  13. :value="dict.value"
  14. />
  15. </el-select>
  16. </el-form-item>
  17. <el-form-item label="项目" prop="projectId">
  18. <el-select v-model="queryParams.projectId" placeholder="请选择项目" clearable>
  19. <el-option
  20. v-for="project in filteredProjectList"
  21. :key="project.projectId"
  22. :label="project.projectName"
  23. :value="project.projectId"
  24. />
  25. </el-select>
  26. </el-form-item>
  27. <el-form-item label="组别" prop="groupName">
  28. <el-input v-model="queryParams.groupName" placeholder="请输入组别名称" clearable @keyup.enter="handleQuery" />
  29. </el-form-item>
  30. <el-form-item>
  31. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  32. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  33. </el-form-item>
  34. </el-form>
  35. </el-card>
  36. </div>
  37. </transition>
  38. <el-card shadow="never">
  39. <template #header>
  40. <el-row :gutter="10" class="mb8">
  41. <el-col :span="1.5">
  42. <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['system:gameEventGroup:add']"> 新增 </el-button>
  43. </el-col>
  44. <el-col :span="1.5">
  45. <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['system:gameEventGroup:edit']"
  46. >修改
  47. </el-button>
  48. </el-col>
  49. <el-col :span="1.5">
  50. <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['system:gameEventGroup:remove']"
  51. >删除
  52. </el-button>
  53. </el-col>
  54. <!-- <el-col :span="1.5">
  55. <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['system:gameEventGroup:export']">导出 </el-button>
  56. </el-col> -->
  57. <right-toolbar v-model:showSearch="showSearch" :columns="columns" @queryTable="getList"></right-toolbar>
  58. </el-row>
  59. </template>
  60. <el-table v-loading="loading" border :data="gameEventGroupList" @selection-change="handleSelectionChange">
  61. <el-table-column type="selection" width="55" align="center" />
  62. <el-table-column label="组别id" align="center" prop="groupId" v-if="columns[0].visible" />
  63. <el-table-column label="项目类型" align="center" v-if="columns[1].visible">
  64. <template #default="scope">
  65. <dict-tag :options="game_project_type" :value="getProjectTypeByProjectId(scope.row.projectId) || ''" />
  66. </template>
  67. </el-table-column>
  68. <el-table-column label="项目" align="center" v-if="columns[2].visible">
  69. <template #default="scope">
  70. {{ getProjectNameByProjectId(scope.row.projectId) }}
  71. </template>
  72. </el-table-column>
  73. <el-table-column label="组别" align="center" prop="groupName" v-if="columns[3].visible" />
  74. <el-table-column label="人/组" align="center" prop="personNum" v-if="columns[4].visible" />
  75. <el-table-column label="组数" align="center" prop="includeGroupNum" v-if="columns[5].visible" />
  76. <el-table-column label="道数" align="center" prop="trackNum" v-if="columns[6].visible" />
  77. <el-table-column label="场地数量" align="center" prop="fieldNum" v-if="columns[7].visible" />
  78. <el-table-column label="每组用时(分钟)" align="center" prop="duration" v-if="columns[8].visible" />
  79. <el-table-column label="比赛时间" align="center" v-if="columns[9].visible">
  80. <template #default="scope">
  81. {{ scope.row.beginTime }} - {{ scope.row.endTime }}
  82. </template>
  83. </el-table-column>
  84. <el-table-column label="成员性别" align="center" prop="memberGender" v-if="columns[10].visible">
  85. <template #default="scope">
  86. <dict-tag :options="sys_user_sex" :value="scope.row.memberGender" />
  87. </template>
  88. </el-table-column>
  89. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  90. <template #default="scope">
  91. <el-tooltip content="分组" placement="top">
  92. <el-button link type="success" icon="Grid" @click="handleGroup(scope.row)" v-hasPermi="['system:gameEventGroup:edit']"></el-button>
  93. </el-tooltip>
  94. <el-tooltip content="修改" placement="top">
  95. <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:gameEventGroup:edit']"></el-button>
  96. </el-tooltip>
  97. <el-tooltip content="删除" placement="top">
  98. <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['system:gameEventGroup:remove']"></el-button>
  99. </el-tooltip>
  100. </template>
  101. </el-table-column>
  102. </el-table>
  103. <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
  104. </el-card>
  105. <!-- 添加或修改赛事分组对话框 -->
  106. <el-dialog :title="dialog.title" v-model="dialog.visible" width="900px" append-to-body>
  107. <el-form ref="gameEventGroupFormRef" :model="form" :rules="rules" label-width="120px">
  108. <el-row :gutter="20">
  109. <el-col :span="12">
  110. <el-form-item label="项目类型" prop="projectTypeFilter">
  111. <el-select
  112. v-model="formProjectTypeFilter"
  113. placeholder="请选择项目类型"
  114. style="width: 100%"
  115. @change="handleFormProjectTypeFilterChange"
  116. :disabled="!!form.groupId"
  117. >
  118. <el-option
  119. v-for="dict in game_project_type"
  120. :key="dict.value"
  121. :label="dict.label"
  122. :value="dict.value"
  123. />
  124. </el-select>
  125. </el-form-item>
  126. </el-col>
  127. <el-col :span="12">
  128. <el-form-item label="项目" prop="projectId">
  129. <el-select
  130. v-model="form.projectId"
  131. placeholder="请选择项目"
  132. style="width: 100%"
  133. @change="handleFormProjectChange"
  134. :disabled="!formProjectTypeFilter || !!form.groupId"
  135. >
  136. <el-option
  137. v-for="project in filteredFormProjectList"
  138. :key="project.projectId"
  139. :label="project.projectName"
  140. :value="project.projectId"
  141. />
  142. </el-select>
  143. </el-form-item>
  144. </el-col>
  145. </el-row>
  146. <el-row :gutter="20">
  147. <el-col :span="12">
  148. <el-form-item label="组别名称" prop="groupName">
  149. <el-input v-model="form.groupName" placeholder="请输入组别名称" />
  150. </el-form-item>
  151. </el-col>
  152. <el-col :span="12">
  153. <el-form-item label="成员性别" prop="memberGender">
  154. <el-select v-model="form.memberGender" placeholder="请选择性别" style="width: 100%">
  155. <el-option
  156. v-for="dict in sys_user_sex"
  157. :key="dict.value"
  158. :label="dict.label"
  159. :value="dict.value"
  160. />
  161. </el-select>
  162. </el-form-item>
  163. </el-col>
  164. </el-row>
  165. <el-row :gutter="20">
  166. <el-col :span="12">
  167. <el-form-item label="人/组" prop="personNum">
  168. <el-input-number v-model="form.personNum" :min="1" placeholder="请输入每组人数" style="width: 100%" />
  169. </el-form-item>
  170. </el-col>
  171. <el-col :span="12">
  172. <el-form-item label="组数" prop="includeGroupNum">
  173. <el-input-number v-model="form.includeGroupNum" :min="1" placeholder="请输入组数" style="width: 100%" />
  174. </el-form-item>
  175. </el-col>
  176. </el-row>
  177. <el-row :gutter="20">
  178. <el-col :span="12">
  179. <el-form-item label="道数" prop="trackNum">
  180. <el-input-number v-model="form.trackNum" :min="1" placeholder="请输入道数" style="width: 100%" />
  181. </el-form-item>
  182. </el-col>
  183. <el-col :span="12">
  184. <el-form-item label="场地数量" prop="fieldNum">
  185. <el-input-number v-model="form.fieldNum" :min="1" placeholder="请输入场地数量" style="width: 100%" />
  186. </el-form-item>
  187. </el-col>
  188. </el-row>
  189. <el-row :gutter="20">
  190. <el-col :span="12">
  191. <el-form-item label="每组用时(分钟)" prop="duration">
  192. <el-input-number v-model="form.duration" :min="1" placeholder="请输入每组用时" style="width: 100%" />
  193. </el-form-item>
  194. </el-col>
  195. <el-col :span="12">
  196. <el-form-item label="组别开始时间" prop="beginTime">
  197. <el-time-picker
  198. v-model="form.beginTime"
  199. placeholder="选择开始时间"
  200. format="HH:mm"
  201. value-format="HH:mm"
  202. style="width: 100%"
  203. :disabled="!form.projectId"
  204. />
  205. </el-form-item>
  206. </el-col>
  207. </el-row>
  208. <el-row :gutter="20">
  209. <el-col :span="12">
  210. <el-form-item label="预计结束时间" prop="endTime">
  211. <el-input v-model="calculatedEndTime" placeholder="自动计算" disabled style="width: 100%" />
  212. </el-form-item>
  213. </el-col>
  214. </el-row>
  215. <el-form-item label="备注" prop="remark">
  216. <el-input v-model="form.remark" type="textarea" placeholder="请输入备注内容" />
  217. </el-form-item>
  218. </el-form>
  219. <template #footer>
  220. <div class="dialog-footer">
  221. <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
  222. <el-button @click="cancel">取 消</el-button>
  223. </div>
  224. </template>
  225. </el-dialog>
  226. </div>
  227. </template>
  228. <script setup name="GameEventGroup" lang="ts">
  229. import { nextTick, ref, onMounted, computed } from 'vue';
  230. import { useRouter } from 'vue-router';
  231. import { listGameEventGroup, getGameEventGroup, delGameEventGroup, addGameEventGroup, updateGameEventGroup } from '@/api/system/gameEventGroup';
  232. import { listGameEventProject } from '@/api/system/gameEventProject';
  233. import { GameEventGroupVO, GameEventGroupQuery, GameEventGroupForm } from '@/api/system/gameEventGroup/types';
  234. import { GameEventProjectVO } from '@/api/system/gameEventProject/types';
  235. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  236. const router = useRouter();
  237. // 字典数据
  238. const { game_project_type, sys_user_sex } = toRefs<any>(proxy?.useDict('game_project_type', 'sys_user_sex'));
  239. const gameEventGroupList = ref<GameEventGroupVO[]>([]);
  240. const projectList = ref<GameEventProjectVO[]>([]);
  241. const buttonLoading = ref(false);
  242. const loading = ref(true);
  243. const showSearch = ref(true);
  244. const ids = ref<Array<string | number>>([]);
  245. const single = ref(true);
  246. const multiple = ref(true);
  247. const total = ref(0);
  248. // 项目类型过滤器(用于查询和表单,不存储在数据中)
  249. const projectTypeFilter = ref<string>('');
  250. const formProjectTypeFilter = ref<string>('');
  251. // 列显隐数据
  252. const columns = ref<FieldOption[]>([
  253. { key: 0, label: '组别id', visible: false },
  254. { key: 1, label: '项目类型', visible: true },
  255. { key: 2, label: '项目', visible: true },
  256. { key: 3, label: '组别', visible: true },
  257. { key: 4, label: '人/组', visible: true },
  258. { key: 5, label: '组数', visible: true },
  259. { key: 6, label: '道数', visible: true },
  260. { key: 7, label: '场地数量', visible: true },
  261. { key: 8, label: '每组用时(分钟)', visible: true },
  262. { key: 9, label: '比赛时间', visible: true },
  263. { key: 10, label: '成员性别', visible: true },
  264. ]);
  265. const queryFormRef = ref<ElFormInstance>();
  266. const gameEventGroupFormRef = ref<ElFormInstance>();
  267. const dialog = reactive<DialogOption>({
  268. visible: false,
  269. title: ''
  270. });
  271. const initFormData: GameEventGroupForm = {
  272. groupId: undefined,
  273. eventId: undefined,
  274. groupName: undefined,
  275. projectList: undefined,
  276. selectedProjects: [],
  277. memberGender: undefined,
  278. sortOrder: undefined,
  279. sortRule: undefined,
  280. status: undefined,
  281. remark: undefined,
  282. includeGroupNum: undefined,
  283. projectId: undefined,
  284. personNum: undefined,
  285. beginTime: undefined,
  286. endTime: undefined,
  287. trackNum: undefined,
  288. fieldNum: undefined,
  289. duration: undefined
  290. };
  291. const data = reactive<PageData<GameEventGroupForm, GameEventGroupQuery>>({
  292. form: { ...initFormData },
  293. queryParams: {
  294. pageNum: 1,
  295. pageSize: 10,
  296. orderByColumn: undefined,
  297. isAsc: undefined,
  298. projectId: undefined,
  299. groupName: undefined
  300. },
  301. rules: {
  302. projectId: [{ required: true, message: '请选择项目', trigger: 'change' }],
  303. groupName: [{ required: true, message: '组别名称不能为空', trigger: 'blur' }],
  304. memberGender: [{ required: true, message: '成员性别不能为空', trigger: 'change' }],
  305. personNum: [{ required: true, message: '每组人数不能为空', trigger: 'blur' }],
  306. includeGroupNum: [{ required: true, message: '组数不能为空', trigger: 'blur' }],
  307. trackNum: [{ required: true, message: '道数不能为空', trigger: 'blur' }],
  308. fieldNum: [{ required: true, message: '场地数量不能为空', trigger: 'blur' }],
  309. duration: [{ required: true, message: '每组用时不能为空', trigger: 'blur' }],
  310. beginTime: [{ required: true, message: '开始时间不能为空', trigger: 'change' }]
  311. }
  312. });
  313. const { queryParams, form, rules } = toRefs(data);
  314. // 过滤后的项目列表(用于查询)
  315. const filteredProjectList = computed(() => {
  316. if (!projectTypeFilter.value) return projectList.value;
  317. return projectList.value.filter(project => project.projectType === projectTypeFilter.value);
  318. });
  319. // 过滤后的项目列表(用于表单)
  320. const filteredFormProjectList = computed(() => {
  321. if (!formProjectTypeFilter.value) return [];
  322. return projectList.value.filter(project => project.projectType === formProjectTypeFilter.value);
  323. });
  324. // 根据项目ID获取项目类型
  325. const getProjectTypeByProjectId = (projectId: string | number) => {
  326. if (!projectId) return '';
  327. const project = projectList.value.find(p => p.projectId === projectId);
  328. return project?.projectType || '';
  329. };
  330. // 根据项目ID获取项目名称
  331. const getProjectNameByProjectId = (projectId: string | number) => {
  332. if (!projectId) return '';
  333. const project = projectList.value.find(p => p.projectId === projectId);
  334. return project?.projectName || '';
  335. };
  336. // 计算预计结束时间
  337. const calculatedEndTime = computed(() => {
  338. if (!form.value.beginTime || !form.value.duration || !form.value.includeGroupNum) {
  339. return '';
  340. }
  341. const beginTime = new Date(`2000-01-01 ${form.value.beginTime}`);
  342. const totalMinutes = form.value.duration * form.value.includeGroupNum;
  343. const endTime = new Date(beginTime.getTime() + totalMinutes * 60 * 1000);
  344. return endTime.toTimeString().slice(0, 5); // 返回 HH:mm 格式
  345. });
  346. /** 查询赛事分组列表 */
  347. const getList = async () => {
  348. loading.value = true;
  349. const res = await listGameEventGroup(queryParams.value);
  350. gameEventGroupList.value = res.rows;
  351. total.value = res.total;
  352. loading.value = false;
  353. };
  354. // 获取赛事项目列表
  355. const getProjectList = async () => {
  356. const res = await listGameEventProject({
  357. pageNum: 1,
  358. pageSize: 1000,
  359. orderByColumn: '',
  360. isAsc: ''
  361. });
  362. projectList.value = res.rows;
  363. };
  364. // 查询条件中项目类型变化
  365. const handleProjectTypeFilterChange = () => {
  366. queryParams.value.projectId = undefined;
  367. };
  368. // 表单中项目类型变化
  369. const handleFormProjectTypeFilterChange = () => {
  370. form.value.projectId = undefined;
  371. form.value.beginTime = undefined;
  372. form.value.endTime = undefined;
  373. form.value.trackNum = undefined;
  374. form.value.fieldNum = undefined;
  375. form.value.duration = undefined;
  376. };
  377. // 表单中项目变化
  378. const handleFormProjectChange = () => {
  379. if (form.value.projectId) {
  380. const selectedProject = projectList.value.find(p => p.projectId === form.value.projectId);
  381. if (selectedProject) {
  382. // 可以在这里设置一些默认值或者进行其他处理
  383. console.log('选中的项目:', selectedProject);
  384. }
  385. }
  386. };
  387. /** 取消按钮 */
  388. const cancel = () => {
  389. reset();
  390. dialog.visible = false;
  391. };
  392. /** 表单重置 */
  393. const reset = () => {
  394. form.value = { ...initFormData };
  395. formProjectTypeFilter.value = '';
  396. gameEventGroupFormRef.value?.resetFields();
  397. };
  398. /** 搜索按钮操作 */
  399. const handleQuery = () => {
  400. queryParams.value.pageNum = 1;
  401. getList();
  402. };
  403. /** 重置按钮操作 */
  404. const resetQuery = () => {
  405. queryFormRef.value?.resetFields();
  406. projectTypeFilter.value = '';
  407. handleQuery();
  408. };
  409. /** 多选框选中数据 */
  410. const handleSelectionChange = (selection: GameEventGroupVO[]) => {
  411. ids.value = selection.map((item) => item.groupId);
  412. single.value = selection.length != 1;
  413. multiple.value = !selection.length;
  414. };
  415. /** 新增按钮操作 */
  416. const handleAdd = () => {
  417. reset();
  418. dialog.visible = true;
  419. dialog.title = '添加赛事分组';
  420. // 获取项目列表
  421. nextTick(() => {
  422. getProjectList();
  423. });
  424. };
  425. /** 修改按钮操作 */
  426. const handleUpdate = async (row?: GameEventGroupVO) => {
  427. reset();
  428. const _groupId = row?.groupId || ids.value[0];
  429. const res = await getGameEventGroup(_groupId);
  430. Object.assign(form.value, res.data);
  431. // 根据项目ID设置项目类型过滤器
  432. if (res.data.projectId) {
  433. const project = projectList.value.find(p => p.projectId === res.data.projectId);
  434. if (project) {
  435. formProjectTypeFilter.value = project.projectType;
  436. }
  437. }
  438. dialog.visible = true;
  439. dialog.title = '修改赛事分组';
  440. // 获取项目列表
  441. nextTick(() => {
  442. getProjectList();
  443. });
  444. };
  445. /** 提交按钮 */
  446. const submitForm = () => {
  447. gameEventGroupFormRef.value?.validate(async (valid: boolean) => {
  448. if (valid) {
  449. // 校验组数和道数的关系
  450. if (form.value.includeGroupNum && form.value.trackNum && form.value.personNum) {
  451. const totalCapacity = form.value.includeGroupNum * form.value.trackNum;
  452. if (totalCapacity < form.value.personNum) {
  453. const recommendedGroupNum = Math.ceil(form.value.personNum / form.value.trackNum);
  454. proxy?.$modal.msgError(`组数过小请重新输入,推荐组数:${recommendedGroupNum}`);
  455. return;
  456. }
  457. }
  458. // 自动计算结束时间
  459. if (form.value.beginTime && form.value.duration && form.value.includeGroupNum) {
  460. const beginTime = new Date(`2000-01-01 ${form.value.beginTime}`);
  461. const totalMinutes = form.value.duration * form.value.includeGroupNum;
  462. const endTime = new Date(beginTime.getTime() + totalMinutes * 60 * 1000);
  463. form.value.endTime = endTime.toTimeString().slice(0, 5);
  464. }
  465. // 验证时间范围
  466. if (form.value.beginTime && form.value.endTime) {
  467. const beginTime = new Date(`2000-01-01 ${form.value.beginTime}`);
  468. const endTime = new Date(`2000-01-01 ${form.value.endTime}`);
  469. if (beginTime >= endTime) {
  470. proxy?.$modal.msgError('组别结束时间必须晚于开始时间');
  471. return;
  472. }
  473. // 验证组别时间是否在项目时间范围内
  474. if (form.value.projectId) {
  475. const selectedProject = projectList.value.find(p => p.projectId === form.value.projectId);
  476. if (selectedProject && selectedProject.startTime && selectedProject.endTime) {
  477. const projectStart = new Date(`2000-01-01 ${selectedProject.startTime}`);
  478. const projectEnd = new Date(`2000-01-01 ${selectedProject.endTime}`);
  479. if (beginTime < projectStart || endTime > projectEnd) {
  480. proxy?.$modal.msgError('组别比赛时间必须在项目比赛时间范围内');
  481. return;
  482. }
  483. }
  484. }
  485. }
  486. buttonLoading.value = true;
  487. const submitForm = { ...form.value };
  488. if (form.value.groupId) {
  489. await updateGameEventGroup(submitForm).finally(() => (buttonLoading.value = false));
  490. } else {
  491. await addGameEventGroup(submitForm).finally(() => (buttonLoading.value = false));
  492. }
  493. proxy?.$modal.msgSuccess('操作成功');
  494. dialog.visible = false;
  495. await getList();
  496. }
  497. });
  498. };
  499. /** 删除按钮操作 */
  500. const handleDelete = async (row?: GameEventGroupVO) => {
  501. const _groupIds = row?.groupId || ids.value;
  502. await proxy?.$modal.confirm('是否确认删除赛事分组编号为"' + _groupIds + '"的数据项?').finally(() => (loading.value = false));
  503. await delGameEventGroup(_groupIds);
  504. proxy?.$modal.msgSuccess('删除成功');
  505. await getList();
  506. };
  507. /** 导出按钮操作 */
  508. const handleExport = () => {
  509. proxy?.download(
  510. 'system/gameEventGroup/export',
  511. {
  512. ...queryParams.value
  513. },
  514. `gameEventGroup_${new Date().getTime()}.xlsx`
  515. );
  516. };
  517. /** 分组按钮操作 */
  518. const handleGroup = (row: GameEventGroupVO) => {
  519. router.push({ path: '/system/gameEventGroup/detail', query: { id: row.groupId } });
  520. };
  521. onMounted(() => {
  522. getList();
  523. getProjectList();
  524. });
  525. </script>