|
@@ -4,9 +4,6 @@
|
|
<div v-show="showSearch" class="mb-[10px]">
|
|
<div v-show="showSearch" class="mb-[10px]">
|
|
<el-card shadow="hover">
|
|
<el-card shadow="hover">
|
|
<el-form ref="queryFormRef" :model="queryParams" :inline="true">
|
|
<el-form ref="queryFormRef" :model="queryParams" :inline="true">
|
|
- <!-- <el-form-item label="赛事名称" prop="eventName">
|
|
|
|
- <el-input v-model="queryParams.eventName" placeholder="请输入赛事名称" clearable @keyup.enter="handleQuery" />
|
|
|
|
- </el-form-item> -->
|
|
|
|
<el-form-item label="队伍名称" prop="teamName">
|
|
<el-form-item label="队伍名称" prop="teamName">
|
|
<el-input v-model="queryParams.teamName" placeholder="请输入队伍名称" clearable @keyup.enter="handleQuery" />
|
|
<el-input v-model="queryParams.teamName" placeholder="请输入队伍名称" clearable @keyup.enter="handleQuery" />
|
|
</el-form-item>
|
|
</el-form-item>
|
|
@@ -69,9 +66,9 @@
|
|
</template>
|
|
</template>
|
|
</el-table-column>
|
|
</el-table-column>
|
|
<el-table-column label="年龄" align="center" prop="age" v-if="columns[5].visible" />
|
|
<el-table-column label="年龄" align="center" prop="age" v-if="columns[5].visible" />
|
|
- <el-table-column label="参与项目" align="center" prop="projectValue" width="200px" v-if="columns[6].visible">
|
|
|
|
|
|
+ <el-table-column label="参与项目" align="center" prop="projectList" width="200px" v-if="columns[6].visible">
|
|
<template #default="scope">
|
|
<template #default="scope">
|
|
- {{ formatProjectList(scope.row.projectValue) }}
|
|
|
|
|
|
+ {{ formatProjectList(scope.row.projectList) }}
|
|
</template>
|
|
</template>
|
|
</el-table-column>
|
|
</el-table-column>
|
|
<el-table-column label="证件号" align="center" prop="idCard" v-if="columns[7].visible" />
|
|
<el-table-column label="证件号" align="center" prop="idCard" v-if="columns[7].visible" />
|
|
@@ -190,7 +187,7 @@
|
|
<script setup name="GameAthlete" lang="ts">
|
|
<script setup name="GameAthlete" lang="ts">
|
|
import { nextTick, ref, onMounted } from 'vue';
|
|
import { nextTick, ref, onMounted } from 'vue';
|
|
import { listGameAthlete, getGameAthlete, delGameAthlete, addGameAthlete, updateGameAthlete } from '@/api/system/gameAthlete';
|
|
import { listGameAthlete, getGameAthlete, delGameAthlete, addGameAthlete, updateGameAthlete } from '@/api/system/gameAthlete';
|
|
-import { listGameTeam } from '@/api/system/gameTeam';
|
|
|
|
|
|
+import { listGameTeam, updateTeamAthletes } from '@/api/system/gameTeam';
|
|
import { listGameEventProject } from '@/api/system/gameEventProject';
|
|
import { listGameEventProject } from '@/api/system/gameEventProject';
|
|
// import { getDefaultEvent } from '@/api/system/gameEvent';
|
|
// import { getDefaultEvent } from '@/api/system/gameEvent';
|
|
import { GameAthleteVO, GameAthleteQuery, GameAthleteForm } from '@/api/system/gameAthlete/types';
|
|
import { GameAthleteVO, GameAthleteQuery, GameAthleteForm } from '@/api/system/gameAthlete/types';
|
|
@@ -275,16 +272,17 @@ const initFormData: GameAthleteForm = {
|
|
tshirtSize: undefined,
|
|
tshirtSize: undefined,
|
|
groupType: undefined,
|
|
groupType: undefined,
|
|
projectValue: undefined,
|
|
projectValue: undefined,
|
|
|
|
+ projectList: [],
|
|
selectedProjects: [], // 添加已选项目列表
|
|
selectedProjects: [], // 添加已选项目列表
|
|
status: undefined,
|
|
status: undefined,
|
|
remark: undefined
|
|
remark: undefined
|
|
};
|
|
};
|
|
const data = reactive<PageData<GameAthleteForm, GameAthleteQuery>>({
|
|
const data = reactive<PageData<GameAthleteForm, GameAthleteQuery>>({
|
|
- form: { ...initFormData, eventId: undefined },
|
|
|
|
|
|
+ form: { ...initFormData},
|
|
queryParams: {
|
|
queryParams: {
|
|
pageNum: 1,
|
|
pageNum: 1,
|
|
pageSize: 10,
|
|
pageSize: 10,
|
|
- eventId: undefined, // 会自动设置为默认赛事ID
|
|
|
|
|
|
+ eventId: undefined,
|
|
eventName: undefined,
|
|
eventName: undefined,
|
|
teamId: undefined,
|
|
teamId: undefined,
|
|
teamName: undefined,
|
|
teamName: undefined,
|
|
@@ -338,7 +336,6 @@ const getTeamNameById = (teamId: string | number) => {
|
|
// 获取赛事项目列表
|
|
// 获取赛事项目列表
|
|
const getProjectList = async (eventId?: string) => {
|
|
const getProjectList = async (eventId?: string) => {
|
|
const res = await listGameEventProject({
|
|
const res = await listGameEventProject({
|
|
- // eventId: eventId || String(form.value.eventId),
|
|
|
|
pageNum: 1,
|
|
pageNum: 1,
|
|
pageSize: 1000,
|
|
pageSize: 1000,
|
|
orderByColumn: '',
|
|
orderByColumn: '',
|
|
@@ -352,25 +349,20 @@ const getProjectList = async (eventId?: string) => {
|
|
};
|
|
};
|
|
|
|
|
|
// 格式化项目列表显示
|
|
// 格式化项目列表显示
|
|
-const formatProjectList = (projectValue: string) => {
|
|
|
|
- if (!projectValue) return '';
|
|
|
|
|
|
+const formatProjectList = (projectList: string[]) => {
|
|
|
|
+ if (!projectList) return '';
|
|
// 将逗号分隔的ID列表转换为项目名称列表
|
|
// 将逗号分隔的ID列表转换为项目名称列表
|
|
- const projectIds = projectValue.split(',');
|
|
|
|
- const projectNames = projectIds.map((id) => {
|
|
|
|
- const project = gameEventProjectList.value.find((p) => p.key === id);
|
|
|
|
- return project ? project.label : id;
|
|
|
|
- });
|
|
|
|
- return projectNames.join(', ');
|
|
|
|
|
|
+ // const projectIds = projectValue.split(',');
|
|
|
|
+ // const projectNames = projectIds.map((id) => {
|
|
|
|
+ // const project = gameEventProjectList.value.find((p) => p.key === id);
|
|
|
|
+ // return project ? project.label : id;
|
|
|
|
+ // });
|
|
|
|
+ const projectNames = gameEventProjectList.value.filter((p) => projectList.includes(p.key)).map((p) => p.label);
|
|
|
|
+ return projectNames.join(',');
|
|
};
|
|
};
|
|
|
|
|
|
/** 查询参赛队员列表 */
|
|
/** 查询参赛队员列表 */
|
|
const getList = async () => {
|
|
const getList = async () => {
|
|
- // if (!queryParams.value.eventId) {
|
|
|
|
- // proxy?.$modal.msgWarning('未获取到默认赛事信息');
|
|
|
|
- // loading.value = false;
|
|
|
|
- // return;
|
|
|
|
- // }
|
|
|
|
-
|
|
|
|
loading.value = true;
|
|
loading.value = true;
|
|
const res = await listGameAthlete(queryParams.value);
|
|
const res = await listGameAthlete(queryParams.value);
|
|
gameAthleteList.value = res.rows;
|
|
gameAthleteList.value = res.rows;
|
|
@@ -428,11 +420,11 @@ const handleAdd = () => {
|
|
dialog.visible = true;
|
|
dialog.visible = true;
|
|
dialog.title = '添加参赛队员';
|
|
dialog.title = '添加参赛队员';
|
|
// 获取项目列表
|
|
// 获取项目列表
|
|
- nextTick(() => {
|
|
|
|
- if (form.value.eventId) {
|
|
|
|
- getProjectList(String(form.value.eventId));
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
|
|
+ // nextTick(() => {
|
|
|
|
+ // if (form.value.eventId) {
|
|
|
|
+ // getProjectList(String(form.value.eventId));
|
|
|
|
+ // }
|
|
|
|
+ // });
|
|
};
|
|
};
|
|
|
|
|
|
/** 修改按钮操作 */
|
|
/** 修改按钮操作 */
|
|
@@ -452,11 +444,11 @@ const handleUpdate = async (row?: GameAthleteVO) => {
|
|
dialog.visible = true;
|
|
dialog.visible = true;
|
|
dialog.title = '修改参赛队员';
|
|
dialog.title = '修改参赛队员';
|
|
// 获取项目列表
|
|
// 获取项目列表
|
|
- nextTick(() => {
|
|
|
|
- if (form.value.eventId) {
|
|
|
|
- getProjectList(String(form.value.eventId));
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
|
|
+ // nextTick(() => {
|
|
|
|
+ // if (form.value.eventId) {
|
|
|
|
+ // getProjectList(String(form.value.eventId));
|
|
|
|
+ // }
|
|
|
|
+ // });
|
|
};
|
|
};
|
|
|
|
|
|
/** 提交按钮 */
|
|
/** 提交按钮 */
|
|
@@ -464,24 +456,85 @@ const submitForm = () => {
|
|
gameAthleteFormRef.value?.validate(async (valid: boolean) => {
|
|
gameAthleteFormRef.value?.validate(async (valid: boolean) => {
|
|
if (valid) {
|
|
if (valid) {
|
|
buttonLoading.value = true;
|
|
buttonLoading.value = true;
|
|
- // 处理项目列表数据,将数组转换为逗号分隔的字符串
|
|
|
|
- const submitForm = { ...form.value };
|
|
|
|
- if (submitForm.selectedProjects && submitForm.selectedProjects.length > 0) {
|
|
|
|
- submitForm.projectValue = submitForm.selectedProjects.join(',');
|
|
|
|
- } else {
|
|
|
|
- submitForm.projectValue = '';
|
|
|
|
|
|
+ try {
|
|
|
|
+ // 处理项目列表数据,将数组转换为逗号分隔的字符串
|
|
|
|
+ const submitForm = { ...form.value };
|
|
|
|
+ if (submitForm.selectedProjects && submitForm.selectedProjects.length > 0) {
|
|
|
|
+ submitForm.projectList = submitForm.selectedProjects;
|
|
|
|
+ // submitForm.projectValue = submitForm.selectedProjects.join(',');
|
|
|
|
+ } else {
|
|
|
|
+ // submitForm.projectValue = '';
|
|
|
|
+ submitForm.projectList = [];
|
|
|
|
+ }
|
|
|
|
+ // 删除selectedProjects属性,因为它不需要提交到后端
|
|
|
|
+ delete submitForm.selectedProjects;
|
|
|
|
+
|
|
|
|
+ let result;
|
|
|
|
+ if (form.value.athleteId) {
|
|
|
|
+ result = await updateGameAthlete(submitForm);
|
|
|
|
+ } else {
|
|
|
|
+ result = await addGameAthlete(submitForm);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 更新队伍表中的运动员列表
|
|
|
|
+ if (submitForm.teamId) {
|
|
|
|
+ try {
|
|
|
|
+ // 获取当前队伍的所有运动员
|
|
|
|
+ const currentTeamAthletes = gameAthleteList.value
|
|
|
|
+ .filter(athlete => athlete.teamId === submitForm.teamId)
|
|
|
|
+ .map(athlete => athlete.athleteId);
|
|
|
|
+
|
|
|
|
+ // 添加新运动员到列表中
|
|
|
|
+ if (!form.value.athleteId) {
|
|
|
|
+ // 新增运动员,需要从返回结果中获取新ID
|
|
|
|
+ const newAthleteId = result.data?.athleteId || submitForm.athleteId;
|
|
|
|
+ if (newAthleteId) {
|
|
|
|
+ currentTeamAthletes.push(newAthleteId);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ // 更新运动员,检查是否改变了队伍
|
|
|
|
+ const originalAthlete = gameAthleteList.value.find(a => a.athleteId === form.value.athleteId);
|
|
|
|
+ if (originalAthlete && originalAthlete.teamId !== submitForm.teamId) {
|
|
|
|
+ // 运动员改变了队伍,需要从原队伍中移除,添加到新队伍中
|
|
|
|
+
|
|
|
|
+ // 从原队伍中移除运动员
|
|
|
|
+ if (originalAthlete.teamId) {
|
|
|
|
+ const originalTeamAthletes = gameAthleteList.value
|
|
|
|
+ .filter(athlete => athlete.teamId === originalAthlete.teamId && athlete.athleteId !== form.value.athleteId)
|
|
|
|
+ .map(athlete => athlete.athleteId);
|
|
|
|
+
|
|
|
|
+ await updateTeamAthletes(originalAthlete.teamId, originalTeamAthletes);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 添加到新队伍中
|
|
|
|
+ if (!currentTeamAthletes.includes(form.value.athleteId)) {
|
|
|
|
+ currentTeamAthletes.push(form.value.athleteId);
|
|
|
|
+ }
|
|
|
|
+ } else if (originalAthlete && originalAthlete.teamId === submitForm.teamId) {
|
|
|
|
+ // 运动员在同一队伍中,确保在列表中
|
|
|
|
+ if (!currentTeamAthletes.includes(form.value.athleteId)) {
|
|
|
|
+ currentTeamAthletes.push(form.value.athleteId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 更新队伍表中的运动员列表
|
|
|
|
+ await updateTeamAthletes(submitForm.teamId, currentTeamAthletes);
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.error('更新队伍运动员列表失败:', error);
|
|
|
|
+ proxy?.$modal.msgWarning('运动员信息保存成功,但更新队伍运动员列表失败');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ proxy?.$modal.msgSuccess('操作成功');
|
|
|
|
+ dialog.visible = false;
|
|
|
|
+ await getList();
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.error('操作失败:', error);
|
|
|
|
+ proxy?.$modal.msgError('操作失败');
|
|
|
|
+ } finally {
|
|
|
|
+ buttonLoading.value = false;
|
|
}
|
|
}
|
|
- // 删除selectedProjects属性,因为它不需要提交到后端
|
|
|
|
- delete submitForm.selectedProjects;
|
|
|
|
-
|
|
|
|
- if (form.value.athleteId) {
|
|
|
|
- await updateGameAthlete(submitForm).finally(() => (buttonLoading.value = false));
|
|
|
|
- } else {
|
|
|
|
- await addGameAthlete(submitForm).finally(() => (buttonLoading.value = false));
|
|
|
|
- }
|
|
|
|
- proxy?.$modal.msgSuccess('操作成功');
|
|
|
|
- dialog.visible = false;
|
|
|
|
- await getList();
|
|
|
|
}
|
|
}
|
|
});
|
|
});
|
|
};
|
|
};
|
|
@@ -490,9 +543,42 @@ const submitForm = () => {
|
|
const handleDelete = async (row?: GameAthleteVO) => {
|
|
const handleDelete = async (row?: GameAthleteVO) => {
|
|
const _athleteIds = row?.athleteId || ids.value;
|
|
const _athleteIds = row?.athleteId || ids.value;
|
|
await proxy?.$modal.confirm('是否确认删除参赛队员编号为"' + _athleteIds + '"的数据项?').finally(() => (loading.value = false));
|
|
await proxy?.$modal.confirm('是否确认删除参赛队员编号为"' + _athleteIds + '"的数据项?').finally(() => (loading.value = false));
|
|
- await delGameAthlete(_athleteIds);
|
|
|
|
- proxy?.$modal.msgSuccess('删除成功');
|
|
|
|
- await getList();
|
|
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ await delGameAthlete(_athleteIds);
|
|
|
|
+
|
|
|
|
+ // 从队伍表中移除被删除的运动员
|
|
|
|
+ const athleteIdsToRemove = Array.isArray(_athleteIds) ? _athleteIds : [_athleteIds];
|
|
|
|
+ const teamsToUpdate = new Set<number | string>();
|
|
|
|
+
|
|
|
|
+ // 收集需要更新的队伍ID
|
|
|
|
+ athleteIdsToRemove.forEach(athleteId => {
|
|
|
|
+ const athlete = gameAthleteList.value.find(a => a.athleteId === athleteId);
|
|
|
|
+ if (athlete && athlete.teamId) {
|
|
|
|
+ teamsToUpdate.add(athlete.teamId);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ // 更新每个相关队伍中的运动员列表
|
|
|
|
+ for (const teamId of teamsToUpdate) {
|
|
|
|
+ try {
|
|
|
|
+ const currentTeamAthletes = gameAthleteList.value
|
|
|
|
+ .filter(athlete => athlete.teamId === teamId && !athleteIdsToRemove.includes(athlete.athleteId))
|
|
|
|
+ .map(athlete => athlete.athleteId);
|
|
|
|
+
|
|
|
|
+ await updateTeamAthletes(teamId, currentTeamAthletes);
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.error(`更新队伍 ${teamId} 运动员列表失败:`, error);
|
|
|
|
+ proxy?.$modal.msgWarning(`运动员删除成功,但更新队伍 ${teamId} 运动员列表失败`);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ proxy?.$modal.msgSuccess('删除成功');
|
|
|
|
+ await getList();
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.error('删除失败:', error);
|
|
|
|
+ proxy?.$modal.msgError('删除失败');
|
|
|
|
+ }
|
|
};
|
|
};
|
|
|
|
|
|
/** 导出按钮操作 */
|
|
/** 导出按钮操作 */
|
|
@@ -541,5 +627,6 @@ const importTemplate = () => {
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
getList();
|
|
getList();
|
|
getTeamList();
|
|
getTeamList();
|
|
|
|
+ getProjectList();
|
|
});
|
|
});
|
|
</script>
|
|
</script>
|