detail.vue 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <div id="detail">
  3. <el-row>
  4. <el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
  5. <el-col :span="24" class="one">
  6. <cSearch :is_title="false" :is_back="true" @toBack="toBack"></cSearch>
  7. </el-col>
  8. <el-col :span="24" class="two">
  9. <cForm :span="24" :fields="fields" :form="form" :rules="rules" @save="toSave" label-width="auto">
  10. <template #information>
  11. <cEditor v-model="form.information" url="/files/ball/match/upload"></cEditor>
  12. </template>
  13. <template #status>
  14. <el-option v-for="i in statusList" :key="i.value" :label="i.label" :value="i.value"></el-option>
  15. </template>
  16. </cForm>
  17. </el-col>
  18. </el-col>
  19. </el-row>
  20. </div>
  21. </template>
  22. <script setup lang="ts">
  23. // 基础
  24. import type { Ref } from 'vue';
  25. import { ref, reactive, onMounted } from 'vue';
  26. import type { FormRules } from 'element-plus';
  27. import { ElMessage } from 'element-plus';
  28. import { useRoute } from 'vue-router';
  29. // 接口
  30. import { MatchStore } from '@/stores/match/match';
  31. import { DictDataStore } from '@/stores/dict/dictData'; // 字典表
  32. import type { IQueryResult } from '@/util/types.util';
  33. const matchAxios = MatchStore();
  34. const dictAxios = DictDataStore();
  35. const route = useRoute();
  36. // 加载中
  37. const loading: Ref<any> = ref(false);
  38. // 表单
  39. let form: Ref<any> = ref({});
  40. const rules = reactive<FormRules>({});
  41. let fields: Ref<any[]> = ref([
  42. { label: '比赛名称', model: 'name' },
  43. { label: '开始时间', model: 'start_time', type: 'datetime' },
  44. { label: '结束时间', model: 'end_time', type: 'datetime' },
  45. { label: '比赛地点', model: 'address' },
  46. { label: '报名截止时间', model: 'sign_deadline', type: 'datetime' },
  47. { label: '比赛信息', model: 'information', custom: true },
  48. { label: '状态', model: 'status', type: 'select' }
  49. ]);
  50. // 字典表
  51. const statusList: Ref<any> = ref([]);
  52. // 请求
  53. onMounted(async () => {
  54. loading.value = true;
  55. await searchOther();
  56. await search();
  57. loading.value = false;
  58. });
  59. const search = async () => {
  60. let id = route.query.id;
  61. if (id) {
  62. let res: IQueryResult = await matchAxios.fetch(id);
  63. if (res.errcode == '0') {
  64. let info: any = res.data as {};
  65. form.value = info;
  66. }
  67. }
  68. };
  69. // 保存
  70. const toSave = async (data) => {
  71. let res: IQueryResult;
  72. if (data._id) res = await matchAxios.update(data);
  73. else res = await matchAxios.create(data);
  74. if (res.errcode == 0) {
  75. ElMessage({ type: `success`, message: `维护信息成功` });
  76. toBack();
  77. }
  78. };
  79. // 查询其他信息
  80. const searchOther = async () => {
  81. let res: IQueryResult;
  82. // 状态
  83. res = await dictAxios.query({ type: 'match_status' });
  84. if (res.errcode == '0') statusList.value = res.data;
  85. };
  86. // 返回上一页
  87. const toBack = () => {
  88. window.history.go(-1);
  89. };
  90. </script>
  91. <style scoped lang="scss"></style>