|
@@ -115,7 +115,7 @@
|
|
|
|
|
|
<script setup name="GameReferee" lang="ts">
|
|
|
import { listGameReferee, getGameReferee, delGameReferee, addGameReferee, updateGameReferee } from '@/api/system/gameReferee';
|
|
|
-import { listGameEventProject } from '@/api/system/gameEventProject';
|
|
|
+import { getGameEventProject, listGameEventProject, updateGameEventProject } from '@/api/system/gameEventProject';
|
|
|
import { GameRefereeVO, GameRefereeQuery, GameRefereeForm } from '@/api/system/gameReferee/types';
|
|
|
import { toDataURL } from 'qrcode';
|
|
|
|
|
@@ -167,18 +167,18 @@ const dialog = reactive<DialogOption>({
|
|
|
title: ''
|
|
|
});
|
|
|
|
|
|
-// 定义表单数据结构,参考athlete.vue的实现方式
|
|
|
+// 定义表单数据结构
|
|
|
const form = reactive({
|
|
|
refereeId: undefined as string | number | undefined,
|
|
|
eventId: undefined as string | number | undefined,
|
|
|
- name: '',
|
|
|
- groupName: '',
|
|
|
- account: '',
|
|
|
- password: '',
|
|
|
+ name: undefined,
|
|
|
+ groupName: undefined,
|
|
|
+ account: undefined,
|
|
|
+ password: undefined,
|
|
|
projectList: [] as string[], // 存储所负责的项目
|
|
|
- refereeCode: '',
|
|
|
- createTime: '',
|
|
|
- updateTime: ''
|
|
|
+ refereeCode: undefined,
|
|
|
+ createTime: undefined,
|
|
|
+ updateTime: undefined,
|
|
|
});
|
|
|
|
|
|
const queryParams = reactive<GameRefereeQuery>({
|
|
@@ -186,8 +186,8 @@ const queryParams = reactive<GameRefereeQuery>({
|
|
|
pageSize: 10,
|
|
|
name: undefined,
|
|
|
params: {},
|
|
|
- orderByColumn: '',
|
|
|
- isAsc: ''
|
|
|
+ orderByColumn: undefined,
|
|
|
+ isAsc: undefined,
|
|
|
});
|
|
|
|
|
|
const rules = {
|
|
@@ -212,9 +212,9 @@ const getList = async () => {
|
|
|
// 加载所有项目信息
|
|
|
const projectRes = await listGameEventProject({
|
|
|
pageNum: 1,
|
|
|
- pageSize: 1000,
|
|
|
- orderByColumn: '',
|
|
|
- isAsc: ''
|
|
|
+ pageSize: 10,
|
|
|
+ orderByColumn: undefined,
|
|
|
+ isAsc: undefined,
|
|
|
});
|
|
|
|
|
|
// 获取项目ID数组
|
|
@@ -246,14 +246,14 @@ const reset = () => {
|
|
|
Object.assign(form, {
|
|
|
refereeId: undefined,
|
|
|
eventId: undefined,
|
|
|
- name: '',
|
|
|
- groupName: '',
|
|
|
- account: '',
|
|
|
- password: '',
|
|
|
+ name: undefined,
|
|
|
+ groupName: undefined,
|
|
|
+ account: undefined,
|
|
|
+ password: undefined,
|
|
|
projectList: [],
|
|
|
- refereeCode: '',
|
|
|
- createTime: '',
|
|
|
- updateTime: ''
|
|
|
+ refereeCode: undefined,
|
|
|
+ createTime: undefined,
|
|
|
+ updateTime: undefined,
|
|
|
});
|
|
|
gameRefereeFormRef.value?.resetFields();
|
|
|
}
|
|
@@ -288,9 +288,8 @@ const loadProjects = async () => {
|
|
|
// 赛事项目穿梭框可选数据拼接
|
|
|
allProjects.value = res.rows.map(item => ({
|
|
|
key: String(item.projectId),
|
|
|
- label: `${item.projectName}-${item.groupType}` // 根据规范,只显示项目名称,不拼接组别
|
|
|
+ label: `${item.projectName}-${item.groupType}`
|
|
|
}));
|
|
|
-
|
|
|
};
|
|
|
|
|
|
/** 新增按钮操作 */
|
|
@@ -311,7 +310,7 @@ const handleUpdate = async (row?: GameRefereeVO) => {
|
|
|
// 如果是修改操作,先加载项目列表
|
|
|
await loadProjects();
|
|
|
|
|
|
- // 处理项目列表数据格式,参考athlete.vue的实现方式
|
|
|
+ // 处理项目列表数据格式
|
|
|
if (res.data.projectList && typeof res.data.projectList === 'string') {
|
|
|
form.projectList = res.data.projectList.split(',').filter(id => id);
|
|
|
} else if (Array.isArray(res.data.projectList)) {
|
|
@@ -329,7 +328,7 @@ const submitForm = async () => {
|
|
|
const valid = await gameRefereeFormRef.value?.validate();
|
|
|
if (valid) {
|
|
|
buttonLoading.value = true;
|
|
|
- // 提交前处理项目列表数据格式,参考athlete.vue的实现方式
|
|
|
+ // 提交前处理项目列表数据格式
|
|
|
const submitForm: any = { ...form };
|
|
|
if (Array.isArray(form.projectList)) {
|
|
|
submitForm.projectList = form.projectList.join(',');
|
|
@@ -337,13 +336,91 @@ const submitForm = async () => {
|
|
|
|
|
|
try {
|
|
|
if (form.refereeId) {
|
|
|
+ // 如果是更新操作,需要先获取原裁判信息,然后更新项目表中的裁判组
|
|
|
+ const originalReferee = await getGameReferee(form.refereeId);
|
|
|
+ const originalProjectList = originalReferee.data.projectList || '';
|
|
|
+ const newProjectList = submitForm.projectList || '';
|
|
|
+
|
|
|
+ // 获取当前项目列表中的项目ID集合
|
|
|
+ const currentProjectIds = new Set<string>(newProjectList.split(',').filter(id => id.trim()));
|
|
|
+
|
|
|
+ // 获取原项目列表中的项目ID集合
|
|
|
+ const originalProjectIds = new Set<string>(originalProjectList.split(',').filter(id => id.trim()));
|
|
|
+
|
|
|
+ // 筛选出在原项目列表中但不在当前项目列表中的项目(即被删除的项目)
|
|
|
+ const removedProjectIds = Array.from(currentProjectIds).filter(id => !originalProjectIds.has(id));
|
|
|
+
|
|
|
+ // 从被删除的项目中移除该裁判
|
|
|
+ for (const projectId of removedProjectIds) {
|
|
|
+ const projectRes = await getGameEventProject(projectId);
|
|
|
+
|
|
|
+ if (projectRes) {
|
|
|
+ const project = projectRes.data;
|
|
|
+ let currentRefereeGroups = project.refereeGroups || [];
|
|
|
+
|
|
|
+ // 从裁判组中移除该裁判ID
|
|
|
+ if (currentRefereeGroups) {
|
|
|
+ const refereeIds = currentRefereeGroups.filter(id => id.trim() !== String(form.refereeId));
|
|
|
+ // 更新项目表中的裁判组字段
|
|
|
+ await updateGameEventProject({
|
|
|
+ ...project,
|
|
|
+ refereeGroups: refereeIds
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 向新项目中添加该裁判
|
|
|
+ const newProjectIds = Array.from<string>(currentProjectIds).filter(id => !originalProjectIds.has(id));
|
|
|
+ for (const projectId of newProjectIds) {
|
|
|
+ const projectRes = await getGameEventProject(projectId);
|
|
|
+
|
|
|
+ if (projectRes) {
|
|
|
+ const project = projectRes.data;
|
|
|
+ let currentRefereeGroups = project.refereeGroups || [];
|
|
|
+ // 如果该项目的裁判组中没有该裁判,则添加
|
|
|
+ if(!project.refereeGroups.includes(String(form.refereeId))){
|
|
|
+ currentRefereeGroups.push(String(form.refereeId)) ;
|
|
|
+ await updateGameEventProject({
|
|
|
+ ...project,
|
|
|
+ refereeGroups: currentRefereeGroups
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
await updateGameReferee(submitForm as GameRefereeForm);
|
|
|
} else {
|
|
|
- await addGameReferee(submitForm as GameRefereeForm);
|
|
|
+ // 新增裁判
|
|
|
+ const refereeResult = await addGameReferee(submitForm as GameRefereeForm);
|
|
|
+
|
|
|
+ // 获取新添加的裁判ID
|
|
|
+ const newRefereeId = refereeResult.data?.refereeId || refereeResult.data;
|
|
|
+
|
|
|
+ // 更新所选项目的裁判组字段
|
|
|
+ if (newRefereeId && form.projectList.length > 0) {
|
|
|
+ for (const projectId of form.projectList) {
|
|
|
+ const projectRes = await getGameEventProject(projectId);
|
|
|
+
|
|
|
+ if (projectRes) {
|
|
|
+ const project = projectRes.data;
|
|
|
+ let currentRefereeGroups = project.refereeGroups || [];
|
|
|
+ currentRefereeGroups.push(String(newRefereeId));
|
|
|
+ await updateGameEventProject({
|
|
|
+ ...project,
|
|
|
+ refereeGroups: currentRefereeGroups
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
proxy?.$modal.msgSuccess("操作成功");
|
|
|
dialog.visible = false;
|
|
|
await getList();
|
|
|
+ } catch (error) {
|
|
|
+ console.error('操作失败:', error);
|
|
|
+ proxy?.$modal.msgError("操作失败");
|
|
|
} finally {
|
|
|
buttonLoading.value = false;
|
|
|
}
|
|
@@ -352,11 +429,52 @@ const submitForm = async () => {
|
|
|
|
|
|
/** 删除按钮操作 */
|
|
|
const handleDelete = async (row?: GameRefereeVO) => {
|
|
|
- const _refereeIds = row?.refereeId || ids.value;
|
|
|
- await proxy?.$modal.confirm('是否确认删除裁判编号为"' + _refereeIds + '"的数据项?').finally(() => loading.value = false);
|
|
|
- await delGameReferee(_refereeIds);
|
|
|
- proxy?.$modal.msgSuccess("删除成功");
|
|
|
- await getList();
|
|
|
+ const _refereeId = row?.refereeId || ids.value;
|
|
|
+ await proxy?.$modal.confirm('是否确认删除裁判编号为"' + _refereeId + '"的数据项?').finally(() => loading.value = false);
|
|
|
+
|
|
|
+ try {
|
|
|
+ await delGameReferee(_refereeId);
|
|
|
+
|
|
|
+ // 如果是单个删除,需要从项目表中移除该裁判
|
|
|
+ if (row) {
|
|
|
+ const refereeId = row.refereeId;
|
|
|
+ if (row.projectList) {
|
|
|
+ const projectIds = row.projectList.split(',').filter(id => id.trim());
|
|
|
+
|
|
|
+ for (const projectId of projectIds) {
|
|
|
+ // 获取当前项目信息
|
|
|
+ const projectRes = await listGameEventProject({
|
|
|
+ projectId: projectId.trim(),
|
|
|
+ pageNum: 1,
|
|
|
+ pageSize: 10,
|
|
|
+ orderByColumn: undefined,
|
|
|
+ isAsc: undefined,
|
|
|
+ });
|
|
|
+
|
|
|
+ if (projectRes.rows.length > 0) {
|
|
|
+ const project = projectRes.rows[0];
|
|
|
+ let currentRefereeGroups = project.refereeGroups || [];
|
|
|
+
|
|
|
+ // 从裁判组中移除该裁判ID
|
|
|
+ if (currentRefereeGroups) {
|
|
|
+ const refereeIds = currentRefereeGroups.filter(id => id.trim() !== String(refereeId));
|
|
|
+ // 更新项目表中的裁判组字段
|
|
|
+ await updateGameEventProject({
|
|
|
+ ...project,
|
|
|
+ refereeGroups: refereeIds
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ proxy?.$modal.msgSuccess("删除成功");
|
|
|
+ await getList();
|
|
|
+ } catch (error) {
|
|
|
+ console.error('删除裁判失败:', error);
|
|
|
+ proxy?.$modal.msgError("删除失败");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/** 生成裁判二维码 */
|