select.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <template>
  2. <BasicModal
  3. @ok="handleSubmit"
  4. :destroyOnClose="true"
  5. :maskClosable="false"
  6. v-bind="$attrs"
  7. @register="registerModal"
  8. :title="getTitle"
  9. :width="1002"
  10. showFooter
  11. >
  12. <BasicForm @register="registerForm" />
  13. </BasicModal>
  14. </template>
  15. <script setup lang="ts">
  16. import { ref, computed, unref } from 'vue';
  17. import { BasicModal, useModalInner } from '/@/components/Modal';
  18. import { BasicForm, useForm } from '/@/components/Form/index';
  19. import { formSchema } from '../data.config';
  20. import { postClasstimeClassTimeStatistics } from '/@/services/apis/ClassTimeStatisticsController';
  21. import { formatToDate } from '/@/utils/dateUtil';
  22. const isUpdate = ref(true);
  23. const emit = defineEmits(['success', 'register']);
  24. const [registerForm, { validate, resetFields }] = useForm({
  25. labelWidth: 100,
  26. schemas: formSchema,
  27. showActionButtonGroup: false,
  28. });
  29. const [registerModal, { closeModal, setModalProps }] = useModalInner(async (data) => {
  30. resetFields();
  31. setModalProps({ confirmLoading: false });
  32. isUpdate.value = !!data?.isUpdate;
  33. });
  34. const getTitle = computed(() =>
  35. !unref(isUpdate) ? '请选择需要统计课时时间段' : '请选择需要统计课时时间段',
  36. );
  37. const handleSubmit = async () => {
  38. try {
  39. const values = await validate();
  40. setModalProps({ confirmLoading: true });
  41. const postParams: Recordable = {
  42. year: formatToDate(values['yearMonth'], 'YYYY'),
  43. month: formatToDate(values['yearMonth'], 'MM'),
  44. startDate: values['date'][0],
  45. endDate: values['date'][1],
  46. };
  47. await postClasstimeClassTimeStatistics(postParams as API.AddClassTimeStatisticsDto);
  48. closeModal();
  49. emit('success');
  50. } finally {
  51. setModalProps({ confirmLoading: false });
  52. }
  53. };
  54. </script>
  55. <style scoped lang="less"></style>