RefereeForm.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <el-dialog :title="dialog.title" v-model="dialog.visible" width="800px" append-to-body>
  3. <el-form ref="refereeFormRef" :model="form" :rules="rules" label-width="80px">
  4. <el-form-item label="账号" prop="account">
  5. <el-input v-model="form.account" placeholder="请输入账号" />
  6. </el-form-item>
  7. <el-form-item label="密码" prop="password">
  8. <el-input type="password" v-model="form.password" placeholder="请输入密码" show-password />
  9. </el-form-item>
  10. <el-form-item label="赛事项目" prop="projectIds">
  11. <!-- 合并为一个 el-transfer -->
  12. <el-transfer
  13. v-model="form.projectIds"
  14. :data="allProjects"
  15. :titles="['可选项目', '已选项目']"
  16. :button-texts="['移除', '添加']"
  17. />
  18. </el-form-item>
  19. </el-form>
  20. <template #footer>
  21. <div class="dialog-footer">
  22. <el-button @click="cancel">取 消</el-button>
  23. <el-button type="primary" @click="submitForm">确 定</el-button>
  24. </div>
  25. </template>
  26. </el-dialog>
  27. </template>
  28. <script setup name="RefereeForm" lang="ts">
  29. import { reactive, ref } from 'vue';
  30. import { ElMessage } from 'element-plus';
  31. import { listGameEventProject } from '@/api/system/gameEventProject';
  32. import { addGameReferee } from '@/api/system/gameReferee';
  33. const dialog = reactive({
  34. visible: false,
  35. title: '添加裁判'
  36. });
  37. const form = reactive({
  38. account: '',
  39. password: '',
  40. projectIds: [] as string[]
  41. });
  42. const rules = {
  43. account: [
  44. { required: true, message: '请输入账号', trigger: 'blur' }
  45. ],
  46. password: [
  47. { required: true, message: '请输入密码', trigger: 'blur' }
  48. ]
  49. };
  50. const refereeFormRef = ref<any>(null);
  51. const allProjects = ref<{key: string, label: string }[]>([]);
  52. const eventId = ref<string>(''); // 新增:用于存储赛事ID
  53. const loadProjects = async () => {
  54. const res = await listGameEventProject({
  55. eventId: eventId.value, // 使用传递进来的赛事ID
  56. pageNum: 1,
  57. pageSize: 1000,
  58. orderByColumn: '',
  59. isAsc: ''
  60. });
  61. allProjects.value = res.rows.map(item => ({
  62. key: String(item.projectId),
  63. label: `${item.projectName} - ${item.groupType}`
  64. }));
  65. };
  66. const openDialog = async (eventIdParam: string) => {
  67. eventId.value = eventIdParam; // 接收并设置赛事ID
  68. await loadProjects();
  69. dialog.visible = true;
  70. };
  71. const cancel = () => {
  72. dialog.visible = false;
  73. };
  74. // 修改: 确保 form 在提交时包含 eventId
  75. const submitForm = () => {
  76. refereeFormRef.value.validate(async (valid: boolean) => {
  77. if (valid) {
  78. try {
  79. // 在 form 中添加 eventId
  80. const formData = { ...form, eventId: eventId.value };
  81. await addGameReferee(formData);
  82. ElMessage.success('添加成功');
  83. dialog.visible = false;
  84. } catch (error) {
  85. ElMessage.error('添加失败');
  86. }
  87. }
  88. });
  89. };
  90. defineExpose({ openDialog });
  91. </script>
  92. <!-- 添加默认导出以解决导入问题 -->
  93. <script lang="ts">
  94. import { defineComponent } from 'vue';
  95. export default defineComponent({
  96. name: 'RefereeForm'
  97. });
  98. </script>