modifyTask.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <a-modal
  3. v-model:visible="visible"
  4. title-align="start"
  5. :width="800"
  6. :footer="false"
  7. top="10vh"
  8. :align-center="false"
  9. @before-open="modalBeforeOpen"
  10. >
  11. <template #title> {{ title }} </template>
  12. <a-tabs
  13. v-if="isEdit"
  14. v-model:activeKey="compType"
  15. type="card-gutter"
  16. hide-content
  17. >
  18. <a-tab-pane key="rule" title="基础规则"> </a-tab-pane>
  19. <a-tab-pane key="time" title="预约时段"> </a-tab-pane>
  20. <a-tab-pane key="notice" title="考试说明"> </a-tab-pane>
  21. </a-tabs>
  22. <component
  23. :is="formComp"
  24. v-if="visible && taskData"
  25. :row-data="taskData"
  26. @cancel="close"
  27. @modified="modifiedHandle"
  28. ></component>
  29. </a-modal>
  30. </template>
  31. <script setup lang="ts">
  32. import { computed, ref } from 'vue';
  33. import useModal from '@/hooks/modal';
  34. import { TaskItem, TaskItemDetail } from '@/api/types/order';
  35. import { taskDetailInfo } from '@/api/order';
  36. import ruleForm from './ruleForm.vue';
  37. import timeForm from './timeForm.vue';
  38. import noticeForm from './noticeForm.vue';
  39. defineOptions({
  40. name: 'ModifyTask',
  41. });
  42. /* modal */
  43. const { visible, open, close } = useModal();
  44. defineExpose({ open, close });
  45. const props = defineProps<{
  46. rowData: TaskItem;
  47. }>();
  48. const emit = defineEmits(['modified']);
  49. const isEdit = computed(() => !!props.rowData.id);
  50. const title = computed(() => `${isEdit.value ? '编辑' : '新增'}任务`);
  51. const comps = {
  52. rule: ruleForm,
  53. time: timeForm,
  54. notice: noticeForm,
  55. };
  56. type CompNameType = keyof typeof comps;
  57. const compType = ref<CompNameType>('rule');
  58. const formComp = computed(() => comps[compType.value]);
  59. const taskData = ref<TaskItemDetail | null>(null);
  60. async function getDetail() {
  61. taskData.value = await taskDetailInfo(props.rowData.id);
  62. }
  63. function modifiedHandle() {
  64. if (props.rowData.id) getDetail();
  65. emit('modified');
  66. if (isEdit.value) return;
  67. close();
  68. }
  69. async function modalBeforeOpen() {
  70. if (props.rowData.id) {
  71. taskData.value = null;
  72. await getDetail();
  73. } else {
  74. taskData.value = {} as TaskItemDetail;
  75. }
  76. compType.value = 'rule';
  77. }
  78. </script>