index.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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="eventName">
  8. <el-input v-model="queryParams.eventName" placeholder="请输入赛事名称" clearable @keyup.enter="handleQuery" />
  9. </el-form-item> -->
  10. <el-form-item label="队伍名称" prop="teamName">
  11. <el-input v-model="queryParams.teamName" placeholder="请输入队伍名称" clearable @keyup.enter="handleQuery" />
  12. </el-form-item>
  13. <el-form-item label="运动员编号" prop="athleteCode">
  14. <el-input v-model="queryParams.athleteCode" placeholder="请输入运动员编号" clearable @keyup.enter="handleQuery" />
  15. </el-form-item>
  16. <el-form-item label="姓名" prop="name">
  17. <el-input v-model="queryParams.name" placeholder="请输入姓名" clearable @keyup.enter="handleQuery" />
  18. </el-form-item>
  19. <el-form-item label="手机号" prop="phone">
  20. <el-input v-model="queryParams.phone" placeholder="请输入手机号" clearable @keyup.enter="handleQuery" />
  21. </el-form-item>
  22. <el-form-item label="居住地址" prop="location">
  23. <el-input v-model="queryParams.location" placeholder="请输入居住地址" clearable @keyup.enter="handleQuery" />
  24. </el-form-item>
  25. <el-form-item>
  26. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  27. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  28. </el-form-item>
  29. </el-form>
  30. </el-card>
  31. </div>
  32. </transition>
  33. <el-card shadow="never">
  34. <template #header>
  35. <el-row :gutter="10" class="mb8">
  36. <el-col :span="1.5">
  37. <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['system:gameAthlete:add']"> 新增 </el-button>
  38. </el-col>
  39. <el-col :span="1.5">
  40. <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['system:gameAthlete:edit']"
  41. >修改
  42. </el-button>
  43. </el-col>
  44. <el-col :span="1.5">
  45. <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['system:gameAthlete:remove']"
  46. >删除
  47. </el-button>
  48. </el-col>
  49. <el-col :span="1.5">
  50. <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['system:gameAthlete:export']">导出 </el-button>
  51. </el-col>
  52. <el-col :span="1.5">
  53. <el-button type="info" plain icon="Upload" @click="handleImport" v-hasPermi="['system:gameAthlete:import']"> 导入 </el-button>
  54. </el-col>
  55. <right-toolbar v-model:showSearch="showSearch" :columns="columns" @queryTable="getList"></right-toolbar>
  56. </el-row>
  57. </template>
  58. <el-table v-loading="loading" border :data="gameAthleteList" @selection-change="handleSelectionChange">
  59. <el-table-column type="selection" width="55" align="center" />
  60. <el-table-column label="主键" align="center" prop="athleteId" v-if="columns[0].visible" />
  61. <el-table-column label="赛事名称" align="center" prop="eventName" width="120px" v-if="columns[1].visible" />
  62. <el-table-column label="运动员编号" align="center" prop="athleteCode" width="100px" v-if="columns[2].visible" />
  63. <el-table-column label="姓名" align="center" prop="name" v-if="columns[3].visible" />
  64. <el-table-column label="性别" align="center" prop="gender" v-if="columns[4].visible">
  65. <template #default="scope">
  66. <dict-tag :options="sys_user_sex" :value="scope.row.gender" />
  67. </template>
  68. </el-table-column>
  69. <el-table-column label="年龄" align="center" prop="age" v-if="columns[5].visible" />
  70. <el-table-column label="参与项目" align="center" prop="projectValue" width="200px" v-if="columns[6].visible">
  71. <template #default="scope">
  72. {{ formatProjectList(scope.row.projectValue) }}
  73. </template>
  74. </el-table-column>
  75. <el-table-column label="证件号" align="center" prop="idCard" v-if="columns[7].visible" />
  76. <el-table-column label="队伍" align="center" prop="teamId" v-if="columns[8].visible">
  77. <template #default="scope">
  78. {{ getTeamNameById(scope.row.teamId) }}
  79. </template>
  80. </el-table-column>
  81. <el-table-column label="芯片号" align="center" prop="chipCode" v-if="columns[9].visible" />
  82. <el-table-column label="手机号" align="center" prop="phone" v-if="columns[10].visible" />
  83. <el-table-column label="居住地址" align="center" prop="location" v-if="columns[11].visible" />
  84. <el-table-column label="T恤尺码" align="center" prop="tshirtSize" v-if="columns[12].visible" />
  85. <el-table-column label="组别" align="center" prop="groupType" v-if="columns[13].visible" />
  86. <el-table-column label="号码" align="center" prop="number" v-if="columns[14].visible" />
  87. <el-table-column label="状态" align="center" prop="status" v-if="columns[15].visible" />
  88. <el-table-column label="备注" align="center" prop="remark" v-if="columns[16].visible" />
  89. <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
  90. <template #default="scope">
  91. <el-tooltip content="修改" placement="top">
  92. <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:gameAthlete:edit']"></el-button>
  93. </el-tooltip>
  94. <el-tooltip content="删除" placement="top">
  95. <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['system:gameAthlete:remove']"></el-button>
  96. </el-tooltip>
  97. </template>
  98. </el-table-column>
  99. </el-table>
  100. <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
  101. </el-card>
  102. <!-- 添加或修改参赛队员对话框 -->
  103. <el-dialog :title="dialog.title" v-model="dialog.visible" width="800px" append-to-body>
  104. <el-form ref="gameAthleteFormRef" :model="form" :rules="rules" label-width="80px">
  105. <!-- <el-form-item label="用户ID" prop="userId">
  106. <el-input v-model="form.userId" placeholder="请输入用户ID" />
  107. </el-form-item> -->
  108. <el-form-item label="队伍" prop="teamId">
  109. <el-select v-model="form.teamId" placeholder="请选择队伍">
  110. <el-option v-for="team in gameTeamList" :key="team.teamId" :label="team.teamName" :value="team.teamId" />
  111. </el-select>
  112. </el-form-item>
  113. <el-form-item label="运动员编号" prop="athleteCode">
  114. <el-input v-model="form.athleteCode" placeholder="请输入运动员编号" />
  115. </el-form-item>
  116. <el-form-item label="姓名" prop="name">
  117. <el-input v-model="form.name" placeholder="请输入姓名" />
  118. </el-form-item>
  119. <el-form-item label="性别" prop="gender">
  120. <el-radio-group v-model="form.gender">
  121. <el-radio v-for="dict in sys_user_sex" :key="dict.value" :value="dict.value">{{ dict.label }}</el-radio>
  122. </el-radio-group>
  123. </el-form-item>
  124. <el-form-item label="年龄" prop="age">
  125. <el-input v-model="form.age" placeholder="请输入年龄" />
  126. </el-form-item>
  127. <el-form-item label="参与项目" prop="projectValue">
  128. <el-transfer
  129. v-model="form.selectedProjects"
  130. :data="gameEventProjectList"
  131. :titles="['可选项目', '已选项目']"
  132. :button-texts="['移除', '添加']"
  133. filterable
  134. style="width: 100%"
  135. />
  136. </el-form-item>
  137. <el-form-item label="备注" prop="remark">
  138. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
  139. </el-form-item>
  140. </el-form>
  141. <template #footer>
  142. <div class="dialog-footer">
  143. <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
  144. <el-button @click="cancel">取 消</el-button>
  145. </div>
  146. </template>
  147. </el-dialog>
  148. <!-- 用户导入对话框 -->
  149. <el-dialog v-model="upload.open" :title="upload.title" width="400px" append-to-body>
  150. <el-upload
  151. ref="uploadRef"
  152. :limit="1"
  153. accept=".xlsx, .xls"
  154. :headers="upload.headers"
  155. :action="upload.url + '?updateSupport=' + upload.updateSupport"
  156. :disabled="upload.isUploading"
  157. :on-progress="handleFileUploadProgress"
  158. :on-success="handleFileSuccess"
  159. :auto-upload="false"
  160. drag
  161. >
  162. <el-icon class="el-icon--upload">
  163. <i-ep-upload-filled />
  164. </el-icon>
  165. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  166. <template #tip>
  167. <div class="text-center el-upload__tip">
  168. <!-- <div class="el-upload__tip">-->
  169. <!-- <el-checkbox v-model="upload.updateSupport" />-->
  170. <!-- 是否更新已经存在的用户数据-->
  171. <!-- </div>-->
  172. <span>仅允许导入xls、xlsx格式文件。</span>
  173. <el-link type="primary" :underline="false" style="font-size: 12px; vertical-align: baseline" @click="importTemplate">下载模板 </el-link>
  174. </div>
  175. </template>
  176. </el-upload>
  177. <template #footer>
  178. <div class="dialog-footer">
  179. <el-button type="primary" @click="submitFileForm">确 定</el-button>
  180. <el-button @click="upload.open = false">取 消</el-button>
  181. </div>
  182. </template>
  183. </el-dialog>
  184. </div>
  185. </template>
  186. <script setup name="GameAthlete" lang="ts">
  187. import { nextTick, ref, onMounted } from 'vue';
  188. import { listGameAthlete, getGameAthlete, delGameAthlete, addGameAthlete, updateGameAthlete } from '@/api/system/gameAthlete';
  189. import { listGameTeam } from '@/api/system/gameTeam';
  190. import { listGameEventProject } from '@/api/system/gameEventProject';
  191. // import { getDefaultEvent } from '@/api/system/gameEvent';
  192. import { GameAthleteVO, GameAthleteQuery, GameAthleteForm } from '@/api/system/gameAthlete/types';
  193. import { GameTeamVO } from '@/api/system/gameTeam/types';
  194. import { GameEventVO } from '@/api/system/gameEvent/types';
  195. import { globalHeaders } from '@/utils/request';
  196. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  197. const { sys_user_sex } = toRefs<any>(proxy?.useDict('sys_user_sex'));
  198. const defaultEvent = ref<GameEventVO | null>(null); // 默认赛事信息
  199. const gameTeamList = ref<GameTeamVO[]>([]); // 队伍列表
  200. const gameAthleteList = ref<GameAthleteVO[]>([]);
  201. const gameEventProjectList = ref<Array<{ key: string; label: string }>>([]); // 赛事项目列表(用于穿梭框)
  202. const buttonLoading = ref(false);
  203. const loading = ref(true);
  204. const showSearch = ref(true);
  205. const ids = ref<Array<string | number>>([]);
  206. const single = ref(true);
  207. const multiple = ref(true);
  208. const total = ref(0);
  209. // 列显隐数据
  210. const columns = ref<FieldOption[]>([
  211. { key: 0, label: '主键', visible: false },
  212. { key: 1, label: '赛事名称', visible: true },
  213. { key: 2, label: '运动员编号', visible: true },
  214. { key: 3, label: '姓名', visible: true },
  215. { key: 4, label: '性别', visible: true },
  216. { key: 5, label: '年龄', visible: true },
  217. { key: 6, label: '参与项目', visible: true },
  218. { key: 7, label: '证件号', visible: true },
  219. { key: 8, label: '队伍', visible: true },
  220. { key: 9, label: '芯片号', visible: true },
  221. { key: 10, label: '手机号', visible: true },
  222. { key: 11, label: '居住地址', visible: true },
  223. { key: 12, label: 'T恤尺码', visible: true },
  224. { key: 13, label: '组别', visible: true },
  225. { key: 14, label: '号码', visible: true },
  226. { key: 15, label: '状态', visible: true },
  227. { key: 16, label: '备注', visible: true },
  228. ]);
  229. const queryFormRef = ref<ElFormInstance>();
  230. const gameAthleteFormRef = ref<ElFormInstance>();
  231. const uploadRef = ref<ElUploadInstance>();
  232. const dialog = reactive<DialogOption>({
  233. visible: false,
  234. title: ''
  235. });
  236. /*** 用户导入参数 */
  237. const upload = reactive<ImportOption>({
  238. // 是否显示弹出层(用户导入)
  239. open: false,
  240. // 弹出层标题(用户导入)
  241. title: '',
  242. // 是否禁用上传
  243. isUploading: false,
  244. // 是否更新已经存在的用户数据
  245. updateSupport: 0,
  246. // 设置上传的请求头部
  247. headers: globalHeaders(),
  248. // 上传的地址
  249. url: import.meta.env.VITE_APP_BASE_API + '/system/gameAthlete/import'
  250. });
  251. const initFormData: GameAthleteForm = {
  252. athleteId: undefined,
  253. userId: undefined,
  254. eventId: undefined,
  255. teamId: undefined,
  256. athleteCode: undefined,
  257. name: undefined,
  258. gender: undefined,
  259. age: undefined,
  260. idCard: undefined,
  261. chipCode: undefined,
  262. phone: undefined,
  263. location: undefined,
  264. tshirtSize: undefined,
  265. groupType: undefined,
  266. projectValue: undefined,
  267. selectedProjects: [], // 添加已选项目列表
  268. status: undefined,
  269. remark: undefined
  270. };
  271. const data = reactive<PageData<GameAthleteForm, GameAthleteQuery>>({
  272. form: { ...initFormData, eventId: undefined },
  273. queryParams: {
  274. pageNum: 1,
  275. pageSize: 10,
  276. eventId: undefined, // 会自动设置为默认赛事ID
  277. eventName: undefined,
  278. teamId: undefined,
  279. teamName: undefined,
  280. athleteCode: undefined,
  281. name: undefined,
  282. groupType: undefined,
  283. status: undefined,
  284. phone: undefined,
  285. location: undefined,
  286. params: {},
  287. orderByColumn: '',
  288. isAsc: ''
  289. },
  290. rules: {
  291. teamId: [{ required: true, message: '队伍ID不能为空', trigger: 'blur' }],
  292. athleteCode: [{ required: true, message: '运动员编号不能为空', trigger: 'blur' }],
  293. gender: [{ required: true, message: '性别不能为空', trigger: 'blur' }],
  294. age: [{ required: true, message: '年龄不能为空', trigger: 'blur' }]
  295. }
  296. });
  297. // 添加额外的ref用于处理默认事件ID
  298. const defaultEventId = computed(() => defaultEvent.value?.eventId);
  299. // 监听默认事件变化
  300. watchEffect(() => {
  301. if (defaultEventId.value) {
  302. form.value.eventId = defaultEventId.value;
  303. queryParams.value.eventId = defaultEventId.value;
  304. }
  305. });
  306. const { queryParams, form, rules } = toRefs(data);
  307. /** 获取默认赛事 */
  308. // const getDefaultEventInfo = async () => {
  309. // try {
  310. // const res = await getDefaultEvent();
  311. // defaultEvent.value = res.data;
  312. // } catch (error) {
  313. // proxy?.$modal.msgError('获取默认赛事信息失败');
  314. // }
  315. // };
  316. /** 获取队伍名称 */
  317. const getTeamNameById = (teamId: string | number) => {
  318. const team = gameTeamList.value.find((team) => team.teamId === teamId);
  319. return team ? team.teamName : '';
  320. };
  321. // 获取赛事项目列表
  322. const getProjectList = async (eventId?: string) => {
  323. const res = await listGameEventProject({
  324. // eventId: eventId || String(form.value.eventId),
  325. pageNum: 1,
  326. pageSize: 1000,
  327. orderByColumn: '',
  328. isAsc: ''
  329. });
  330. console.log(res);
  331. gameEventProjectList.value = res.rows.map((item) => ({
  332. key: String(item.projectId),
  333. label: `${item.projectName}`
  334. }));
  335. };
  336. // 格式化项目列表显示
  337. const formatProjectList = (projectValue: string) => {
  338. if (!projectValue) return '';
  339. // 将逗号分隔的ID列表转换为项目名称列表
  340. const projectIds = projectValue.split(',');
  341. const projectNames = projectIds.map((id) => {
  342. const project = gameEventProjectList.value.find((p) => p.key === id);
  343. return project ? project.label : id;
  344. });
  345. return projectNames.join(', ');
  346. };
  347. /** 查询参赛队员列表 */
  348. const getList = async () => {
  349. // if (!queryParams.value.eventId) {
  350. // proxy?.$modal.msgWarning('未获取到默认赛事信息');
  351. // loading.value = false;
  352. // return;
  353. // }
  354. loading.value = true;
  355. const res = await listGameAthlete(queryParams.value);
  356. gameAthleteList.value = res.rows;
  357. total.value = res.total;
  358. loading.value = false;
  359. };
  360. // 获取队伍列表
  361. const getTeamList = async () => {
  362. const res = await listGameTeam({
  363. pageNum: 1,
  364. pageSize: 1000,
  365. orderByColumn: '',
  366. isAsc: ''
  367. });
  368. gameTeamList.value = res.rows || [];
  369. };
  370. /** 取消按钮 */
  371. const cancel = () => {
  372. reset();
  373. dialog.visible = false;
  374. };
  375. /** 表单重置 */
  376. const reset = () => {
  377. form.value = { ...initFormData };
  378. gameAthleteFormRef.value?.resetFields();
  379. };
  380. /** 搜索按钮操作 */
  381. const handleQuery = () => {
  382. queryParams.value.pageNum = 1;
  383. getList();
  384. };
  385. /** 重置按钮操作 */
  386. const resetQuery = () => {
  387. queryFormRef.value?.resetFields();
  388. // // 保留默认赛事ID
  389. // queryParams.value.eventId = defaultEvent.value?.eventId;
  390. handleQuery();
  391. };
  392. /** 多选框选中数据 */
  393. const handleSelectionChange = (selection: GameAthleteVO[]) => {
  394. ids.value = selection.map((item) => item.athleteId);
  395. single.value = selection.length != 1;
  396. multiple.value = !selection.length;
  397. };
  398. /** 新增按钮操作 */
  399. const handleAdd = () => {
  400. reset();
  401. dialog.visible = true;
  402. dialog.title = '添加参赛队员';
  403. // 获取项目列表
  404. nextTick(() => {
  405. if (form.value.eventId) {
  406. getProjectList(String(form.value.eventId));
  407. }
  408. });
  409. };
  410. /** 修改按钮操作 */
  411. const handleUpdate = async (row?: GameAthleteVO) => {
  412. reset();
  413. const _athleteId = row?.athleteId || ids.value[0];
  414. const res = await getGameAthlete(_athleteId);
  415. Object.assign(form.value, res.data);
  416. // 处理项目列表,将逗号分隔的字符串转换为数组
  417. if (res.data.projectValue) {
  418. form.value.selectedProjects = res.data.projectValue.split(',');
  419. } else {
  420. form.value.selectedProjects = [];
  421. }
  422. dialog.visible = true;
  423. dialog.title = '修改参赛队员';
  424. // 获取项目列表
  425. nextTick(() => {
  426. if (form.value.eventId) {
  427. getProjectList(String(form.value.eventId));
  428. }
  429. });
  430. };
  431. /** 提交按钮 */
  432. const submitForm = () => {
  433. gameAthleteFormRef.value?.validate(async (valid: boolean) => {
  434. if (valid) {
  435. buttonLoading.value = true;
  436. // 处理项目列表数据,将数组转换为逗号分隔的字符串
  437. const submitForm = { ...form.value };
  438. if (submitForm.selectedProjects && submitForm.selectedProjects.length > 0) {
  439. submitForm.projectValue = submitForm.selectedProjects.join(',');
  440. } else {
  441. submitForm.projectValue = '';
  442. }
  443. // 删除selectedProjects属性,因为它不需要提交到后端
  444. delete submitForm.selectedProjects;
  445. if (form.value.athleteId) {
  446. await updateGameAthlete(submitForm).finally(() => (buttonLoading.value = false));
  447. } else {
  448. await addGameAthlete(submitForm).finally(() => (buttonLoading.value = false));
  449. }
  450. proxy?.$modal.msgSuccess('操作成功');
  451. dialog.visible = false;
  452. await getList();
  453. }
  454. });
  455. };
  456. /** 删除按钮操作 */
  457. const handleDelete = async (row?: GameAthleteVO) => {
  458. const _athleteIds = row?.athleteId || ids.value;
  459. await proxy?.$modal.confirm('是否确认删除参赛队员编号为"' + _athleteIds + '"的数据项?').finally(() => (loading.value = false));
  460. await delGameAthlete(_athleteIds);
  461. proxy?.$modal.msgSuccess('删除成功');
  462. await getList();
  463. };
  464. /** 导出按钮操作 */
  465. const handleExport = () => {
  466. proxy?.download(
  467. 'system/gameAthlete/export',
  468. {
  469. ...queryParams.value
  470. },
  471. `gameAthlete_${new Date().getTime()}.xlsx`
  472. );
  473. };
  474. /** 导入按钮操作 */
  475. const handleImport = () => {
  476. upload.title = '参赛队员导入';
  477. upload.open = true;
  478. };
  479. /**文件上传中处理 */
  480. const handleFileUploadProgress = () => {
  481. upload.isUploading = true;
  482. };
  483. /** 文件上传成功处理 */
  484. const handleFileSuccess = (response: any, file: UploadFile) => {
  485. upload.open = false;
  486. upload.isUploading = false;
  487. uploadRef.value?.handleRemove(file);
  488. ElMessageBox.alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + '</div>', '导入结果', {
  489. dangerouslyUseHTMLString: true
  490. });
  491. getList();
  492. };
  493. /** 提交上传文件 */
  494. function submitFileForm() {
  495. uploadRef.value?.submit();
  496. }
  497. /** 下载模板操作 */
  498. const importTemplate = () => {
  499. proxy?.download('system/gameAthlete/importTemplate', {}, `game_athlete_template_${new Date().getTime()}.xlsx`);
  500. };
  501. onMounted(() => {
  502. getList();
  503. getTeamList();
  504. });
  505. </script>