123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579 |
- <template>
- <div class="p-2">
- <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
- <div v-show="showSearch" class="mb-[10px]">
- <el-card shadow="hover">
- <el-form ref="queryFormRef" :model="queryParams" :inline="true">
- <el-form-item label="项目类型" prop="projectTypeFilter">
- <el-select v-model="projectTypeFilter" placeholder="请选择项目类型" clearable @change="handleProjectTypeFilterChange">
- <el-option
- v-for="dict in game_project_type"
- :key="dict.value"
- :label="dict.label"
- :value="dict.value"
- />
- </el-select>
- </el-form-item>
- <el-form-item label="项目" prop="projectId">
- <el-select v-model="queryParams.projectId" placeholder="请选择项目" clearable>
- <el-option
- v-for="project in filteredProjectList"
- :key="project.projectId"
- :label="project.projectName"
- :value="project.projectId"
- />
- </el-select>
- </el-form-item>
- <el-form-item label="组别" prop="groupName">
- <el-input v-model="queryParams.groupName" placeholder="请输入组别名称" clearable @keyup.enter="handleQuery" />
- </el-form-item>
- <el-form-item>
- <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
- <el-button icon="Refresh" @click="resetQuery">重置</el-button>
- </el-form-item>
- </el-form>
- </el-card>
- </div>
- </transition>
- <el-card shadow="never">
- <template #header>
- <el-row :gutter="10" class="mb8">
- <el-col :span="1.5">
- <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['system:gameEventGroup:add']"> 新增 </el-button>
- </el-col>
- <el-col :span="1.5">
- <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['system:gameEventGroup:edit']"
- >修改
- </el-button>
- </el-col>
- <el-col :span="1.5">
- <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['system:gameEventGroup:remove']"
- >删除
- </el-button>
- </el-col>
- <!-- <el-col :span="1.5">
- <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['system:gameEventGroup:export']">导出 </el-button>
- </el-col> -->
- <right-toolbar v-model:showSearch="showSearch" :columns="columns" @queryTable="getList"></right-toolbar>
- </el-row>
- </template>
- <el-table v-loading="loading" border :data="gameEventGroupList" @selection-change="handleSelectionChange">
- <el-table-column type="selection" width="55" align="center" />
- <el-table-column label="组别id" align="center" prop="groupId" v-if="columns[0].visible" />
- <el-table-column label="项目类型" align="center" v-if="columns[1].visible">
- <template #default="scope">
- <dict-tag :options="game_project_type" :value="getProjectTypeByProjectId(scope.row.projectId) || ''" />
- </template>
- </el-table-column>
- <el-table-column label="项目" align="center" v-if="columns[2].visible">
- <template #default="scope">
- {{ getProjectNameByProjectId(scope.row.projectId) }}
- </template>
- </el-table-column>
- <el-table-column label="组别" align="center" prop="groupName" v-if="columns[3].visible" />
- <el-table-column label="人/组" align="center" prop="personNum" v-if="columns[4].visible" />
- <el-table-column label="组数" align="center" prop="includeGroupNum" v-if="columns[5].visible" />
- <el-table-column label="道数" align="center" prop="trackNum" v-if="columns[6].visible" />
- <el-table-column label="场地数量" align="center" prop="fieldNum" v-if="columns[7].visible" />
- <el-table-column label="每组用时(分钟)" align="center" prop="duration" v-if="columns[8].visible" />
- <el-table-column label="比赛时间" align="center" v-if="columns[9].visible">
- <template #default="scope">
- {{ scope.row.beginTime }} - {{ scope.row.endTime }}
- </template>
- </el-table-column>
- <el-table-column label="成员性别" align="center" prop="memberGender" v-if="columns[10].visible">
- <template #default="scope">
- <dict-tag :options="sys_user_sex" :value="scope.row.memberGender" />
- </template>
- </el-table-column>
- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
- <template #default="scope">
- <el-tooltip content="分组" placement="top">
- <el-button link type="success" icon="Grid" @click="handleGroup(scope.row)" v-hasPermi="['system:gameEventGroup:edit']"></el-button>
- </el-tooltip>
- <el-tooltip content="修改" placement="top">
- <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:gameEventGroup:edit']"></el-button>
- </el-tooltip>
- <el-tooltip content="删除" placement="top">
- <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['system:gameEventGroup:remove']"></el-button>
- </el-tooltip>
- </template>
- </el-table-column>
- </el-table>
- <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
- </el-card>
- <!-- 添加或修改赛事分组对话框 -->
- <el-dialog :title="dialog.title" v-model="dialog.visible" width="900px" append-to-body>
- <el-form ref="gameEventGroupFormRef" :model="form" :rules="rules" label-width="120px">
- <el-row :gutter="20">
- <el-col :span="12">
- <el-form-item label="项目类型" prop="projectTypeFilter">
- <el-select
- v-model="formProjectTypeFilter"
- placeholder="请选择项目类型"
- style="width: 100%"
- @change="handleFormProjectTypeFilterChange"
- :disabled="!!form.groupId"
- >
- <el-option
- v-for="dict in game_project_type"
- :key="dict.value"
- :label="dict.label"
- :value="dict.value"
- />
- </el-select>
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="项目" prop="projectId">
- <el-select
- v-model="form.projectId"
- placeholder="请选择项目"
- style="width: 100%"
- @change="handleFormProjectChange"
- :disabled="!formProjectTypeFilter || !!form.groupId"
- >
- <el-option
- v-for="project in filteredFormProjectList"
- :key="project.projectId"
- :label="project.projectName"
- :value="project.projectId"
- />
- </el-select>
- </el-form-item>
- </el-col>
- </el-row>
-
- <el-row :gutter="20">
- <el-col :span="12">
- <el-form-item label="组别名称" prop="groupName">
- <el-input v-model="form.groupName" placeholder="请输入组别名称" />
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="成员性别" prop="memberGender">
- <el-select v-model="form.memberGender" placeholder="请选择性别" style="width: 100%">
- <el-option
- v-for="dict in sys_user_sex"
- :key="dict.value"
- :label="dict.label"
- :value="dict.value"
- />
- </el-select>
- </el-form-item>
- </el-col>
- </el-row>
- <el-row :gutter="20">
- <el-col :span="12">
- <el-form-item label="人/组" prop="personNum">
- <el-input-number v-model="form.personNum" :min="1" placeholder="请输入每组人数" style="width: 100%" />
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="组数" prop="includeGroupNum">
- <el-input-number v-model="form.includeGroupNum" :min="1" placeholder="请输入组数" style="width: 100%" />
- </el-form-item>
- </el-col>
- </el-row>
- <el-row :gutter="20">
- <el-col :span="12">
- <el-form-item label="道数" prop="trackNum">
- <el-input-number v-model="form.trackNum" :min="1" placeholder="请输入道数" style="width: 100%" />
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="场地数量" prop="fieldNum">
- <el-input-number v-model="form.fieldNum" :min="1" placeholder="请输入场地数量" style="width: 100%" />
- </el-form-item>
- </el-col>
- </el-row>
- <el-row :gutter="20">
- <el-col :span="12">
- <el-form-item label="每组用时(分钟)" prop="duration">
- <el-input-number v-model="form.duration" :min="1" placeholder="请输入每组用时" style="width: 100%" />
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="组别开始时间" prop="beginTime">
- <el-time-picker
- v-model="form.beginTime"
- placeholder="选择开始时间"
- format="HH:mm"
- value-format="HH:mm"
- style="width: 100%"
- :disabled="!form.projectId"
- />
- </el-form-item>
- </el-col>
- </el-row>
- <el-row :gutter="20">
- <el-col :span="12">
- <el-form-item label="预计结束时间" prop="endTime">
- <el-input v-model="calculatedEndTime" placeholder="自动计算" disabled style="width: 100%" />
- </el-form-item>
- </el-col>
- </el-row>
- <el-form-item label="备注" prop="remark">
- <el-input v-model="form.remark" type="textarea" placeholder="请输入备注内容" />
- </el-form-item>
- </el-form>
- <template #footer>
- <div class="dialog-footer">
- <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
- <el-button @click="cancel">取 消</el-button>
- </div>
- </template>
- </el-dialog>
- </div>
- </template>
- <script setup name="GameEventGroup" lang="ts">
- import { nextTick, ref, onMounted, computed } from 'vue';
- import { useRouter } from 'vue-router';
- import { listGameEventGroup, getGameEventGroup, delGameEventGroup, addGameEventGroup, updateGameEventGroup } from '@/api/system/gameEventGroup';
- import { listGameEventProject } from '@/api/system/gameEventProject';
- import { GameEventGroupVO, GameEventGroupQuery, GameEventGroupForm } from '@/api/system/gameEventGroup/types';
- import { GameEventProjectVO } from '@/api/system/gameEventProject/types';
- const { proxy } = getCurrentInstance() as ComponentInternalInstance;
- const router = useRouter();
- // 字典数据
- const { game_project_type, sys_user_sex } = toRefs<any>(proxy?.useDict('game_project_type', 'sys_user_sex'));
- const gameEventGroupList = ref<GameEventGroupVO[]>([]);
- const projectList = ref<GameEventProjectVO[]>([]);
- const buttonLoading = ref(false);
- const loading = ref(true);
- const showSearch = ref(true);
- const ids = ref<Array<string | number>>([]);
- const single = ref(true);
- const multiple = ref(true);
- const total = ref(0);
- // 项目类型过滤器(用于查询和表单,不存储在数据中)
- const projectTypeFilter = ref<string>('');
- const formProjectTypeFilter = ref<string>('');
- // 列显隐数据
- const columns = ref<FieldOption[]>([
- { key: 0, label: '组别id', visible: false },
- { key: 1, label: '项目类型', visible: true },
- { key: 2, label: '项目', visible: true },
- { key: 3, label: '组别', visible: true },
- { key: 4, label: '人/组', visible: true },
- { key: 5, label: '组数', visible: true },
- { key: 6, label: '道数', visible: true },
- { key: 7, label: '场地数量', visible: true },
- { key: 8, label: '每组用时(分钟)', visible: true },
- { key: 9, label: '比赛时间', visible: true },
- { key: 10, label: '成员性别', visible: true },
- ]);
- const queryFormRef = ref<ElFormInstance>();
- const gameEventGroupFormRef = ref<ElFormInstance>();
- const dialog = reactive<DialogOption>({
- visible: false,
- title: ''
- });
- const initFormData: GameEventGroupForm = {
- groupId: undefined,
- eventId: undefined,
- groupName: undefined,
- projectList: undefined,
- selectedProjects: [],
- memberGender: undefined,
- sortOrder: undefined,
- sortRule: undefined,
- status: undefined,
- remark: undefined,
- includeGroupNum: undefined,
- projectId: undefined,
- personNum: undefined,
- beginTime: undefined,
- endTime: undefined,
- trackNum: undefined,
- fieldNum: undefined,
- duration: undefined
- };
- const data = reactive<PageData<GameEventGroupForm, GameEventGroupQuery>>({
- form: { ...initFormData },
- queryParams: {
- pageNum: 1,
- pageSize: 10,
- orderByColumn: undefined,
- isAsc: undefined,
- projectId: undefined,
- groupName: undefined
- },
- rules: {
- projectId: [{ required: true, message: '请选择项目', trigger: 'change' }],
- groupName: [{ required: true, message: '组别名称不能为空', trigger: 'blur' }],
- memberGender: [{ required: true, message: '成员性别不能为空', trigger: 'change' }],
- personNum: [{ required: true, message: '每组人数不能为空', trigger: 'blur' }],
- includeGroupNum: [{ required: true, message: '组数不能为空', trigger: 'blur' }],
- trackNum: [{ required: true, message: '道数不能为空', trigger: 'blur' }],
- fieldNum: [{ required: true, message: '场地数量不能为空', trigger: 'blur' }],
- duration: [{ required: true, message: '每组用时不能为空', trigger: 'blur' }],
- beginTime: [{ required: true, message: '开始时间不能为空', trigger: 'change' }]
- }
- });
- const { queryParams, form, rules } = toRefs(data);
- // 过滤后的项目列表(用于查询)
- const filteredProjectList = computed(() => {
- if (!projectTypeFilter.value) return projectList.value;
- return projectList.value.filter(project => project.projectType === projectTypeFilter.value);
- });
- // 过滤后的项目列表(用于表单)
- const filteredFormProjectList = computed(() => {
- if (!formProjectTypeFilter.value) return [];
- return projectList.value.filter(project => project.projectType === formProjectTypeFilter.value);
- });
- // 根据项目ID获取项目类型
- const getProjectTypeByProjectId = (projectId: string | number) => {
- if (!projectId) return '';
- const project = projectList.value.find(p => p.projectId === projectId);
- return project?.projectType || '';
- };
- // 根据项目ID获取项目名称
- const getProjectNameByProjectId = (projectId: string | number) => {
- if (!projectId) return '';
- const project = projectList.value.find(p => p.projectId === projectId);
- return project?.projectName || '';
- };
- // 计算预计结束时间
- const calculatedEndTime = computed(() => {
- if (!form.value.beginTime || !form.value.duration || !form.value.includeGroupNum) {
- return '';
- }
-
- const beginTime = new Date(`2000-01-01 ${form.value.beginTime}`);
- const totalMinutes = form.value.duration * form.value.includeGroupNum;
- const endTime = new Date(beginTime.getTime() + totalMinutes * 60 * 1000);
-
- return endTime.toTimeString().slice(0, 5); // 返回 HH:mm 格式
- });
- /** 查询赛事分组列表 */
- const getList = async () => {
- loading.value = true;
- const res = await listGameEventGroup(queryParams.value);
- gameEventGroupList.value = res.rows;
- total.value = res.total;
- loading.value = false;
- };
- // 获取赛事项目列表
- const getProjectList = async () => {
- const res = await listGameEventProject({
- pageNum: 1,
- pageSize: 1000,
- orderByColumn: '',
- isAsc: ''
- });
- projectList.value = res.rows;
- };
- // 查询条件中项目类型变化
- const handleProjectTypeFilterChange = () => {
- queryParams.value.projectId = undefined;
- };
- // 表单中项目类型变化
- const handleFormProjectTypeFilterChange = () => {
- form.value.projectId = undefined;
- form.value.beginTime = undefined;
- form.value.endTime = undefined;
- form.value.trackNum = undefined;
- form.value.fieldNum = undefined;
- form.value.duration = undefined;
- };
- // 表单中项目变化
- const handleFormProjectChange = () => {
- if (form.value.projectId) {
- const selectedProject = projectList.value.find(p => p.projectId === form.value.projectId);
- if (selectedProject) {
- // 可以在这里设置一些默认值或者进行其他处理
- console.log('选中的项目:', selectedProject);
- }
- }
- };
- /** 取消按钮 */
- const cancel = () => {
- reset();
- dialog.visible = false;
- };
- /** 表单重置 */
- const reset = () => {
- form.value = { ...initFormData };
- formProjectTypeFilter.value = '';
- gameEventGroupFormRef.value?.resetFields();
- };
- /** 搜索按钮操作 */
- const handleQuery = () => {
- queryParams.value.pageNum = 1;
- getList();
- };
- /** 重置按钮操作 */
- const resetQuery = () => {
- queryFormRef.value?.resetFields();
- projectTypeFilter.value = '';
- handleQuery();
- };
- /** 多选框选中数据 */
- const handleSelectionChange = (selection: GameEventGroupVO[]) => {
- ids.value = selection.map((item) => item.groupId);
- single.value = selection.length != 1;
- multiple.value = !selection.length;
- };
- /** 新增按钮操作 */
- const handleAdd = () => {
- reset();
- dialog.visible = true;
- dialog.title = '添加赛事分组';
- // 获取项目列表
- nextTick(() => {
- getProjectList();
- });
- };
- /** 修改按钮操作 */
- const handleUpdate = async (row?: GameEventGroupVO) => {
- reset();
- const _groupId = row?.groupId || ids.value[0];
- const res = await getGameEventGroup(_groupId);
- Object.assign(form.value, res.data);
- // 根据项目ID设置项目类型过滤器
- if (res.data.projectId) {
- const project = projectList.value.find(p => p.projectId === res.data.projectId);
- if (project) {
- formProjectTypeFilter.value = project.projectType;
- }
- }
- dialog.visible = true;
- dialog.title = '修改赛事分组';
- // 获取项目列表
- nextTick(() => {
- getProjectList();
- });
- };
- /** 提交按钮 */
- const submitForm = () => {
- gameEventGroupFormRef.value?.validate(async (valid: boolean) => {
- if (valid) {
- // 校验组数和道数的关系
- if (form.value.includeGroupNum && form.value.trackNum && form.value.personNum) {
- const totalCapacity = form.value.includeGroupNum * form.value.trackNum;
- if (totalCapacity < form.value.personNum) {
- const recommendedGroupNum = Math.ceil(form.value.personNum / form.value.trackNum);
- proxy?.$modal.msgError(`组数过小请重新输入,推荐组数:${recommendedGroupNum}`);
- return;
- }
- }
- // 自动计算结束时间
- if (form.value.beginTime && form.value.duration && form.value.includeGroupNum) {
- const beginTime = new Date(`2000-01-01 ${form.value.beginTime}`);
- const totalMinutes = form.value.duration * form.value.includeGroupNum;
- const endTime = new Date(beginTime.getTime() + totalMinutes * 60 * 1000);
- form.value.endTime = endTime.toTimeString().slice(0, 5);
- }
- // 验证时间范围
- if (form.value.beginTime && form.value.endTime) {
- const beginTime = new Date(`2000-01-01 ${form.value.beginTime}`);
- const endTime = new Date(`2000-01-01 ${form.value.endTime}`);
-
- if (beginTime >= endTime) {
- proxy?.$modal.msgError('组别结束时间必须晚于开始时间');
- return;
- }
-
- // 验证组别时间是否在项目时间范围内
- if (form.value.projectId) {
- const selectedProject = projectList.value.find(p => p.projectId === form.value.projectId);
- if (selectedProject && selectedProject.startTime && selectedProject.endTime) {
- const projectStart = new Date(`2000-01-01 ${selectedProject.startTime}`);
- const projectEnd = new Date(`2000-01-01 ${selectedProject.endTime}`);
-
- if (beginTime < projectStart || endTime > projectEnd) {
- proxy?.$modal.msgError('组别比赛时间必须在项目比赛时间范围内');
- return;
- }
- }
- }
- }
- buttonLoading.value = true;
- const submitForm = { ...form.value };
-
- if (form.value.groupId) {
- await updateGameEventGroup(submitForm).finally(() => (buttonLoading.value = false));
- } else {
- await addGameEventGroup(submitForm).finally(() => (buttonLoading.value = false));
- }
- proxy?.$modal.msgSuccess('操作成功');
- dialog.visible = false;
- await getList();
- }
- });
- };
- /** 删除按钮操作 */
- const handleDelete = async (row?: GameEventGroupVO) => {
- const _groupIds = row?.groupId || ids.value;
- await proxy?.$modal.confirm('是否确认删除赛事分组编号为"' + _groupIds + '"的数据项?').finally(() => (loading.value = false));
- await delGameEventGroup(_groupIds);
- proxy?.$modal.msgSuccess('删除成功');
- await getList();
- };
- /** 导出按钮操作 */
- const handleExport = () => {
- proxy?.download(
- 'system/gameEventGroup/export',
- {
- ...queryParams.value
- },
- `gameEventGroup_${new Date().getTime()}.xlsx`
- );
- };
- /** 分组按钮操作 */
- const handleGroup = (row: GameEventGroupVO) => {
- router.push({ path: '/system/gameEventGroup/detail', query: { id: row.groupId } });
- };
- onMounted(() => {
- getList();
- getProjectList();
- });
- </script>
|