NoticeEdit.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <main class="safety-platform-container__main">
  3. <BasicForm ref="basicFormRef" :formData="ruleFormData" :formRules="formRules" :formConfig="ruleFormConfig">
  4. <template #noticeFiles>
  5. <UploadFiles label="上传附件" ref="uploadFilesRef" @uploadSuccess="handleUploadSuccess" />
  6. </template>
  7. <template #isPush>
  8. <el-radio-group v-model="ruleFormData.isPush">
  9. <el-radio :value="IS_PUSH.PUSH">是</el-radio>
  10. <el-radio :value="IS_PUSH.NOT_PUSH">否</el-radio>
  11. </el-radio-group>
  12. <SelectGroup
  13. v-if="ruleFormData.isPush === IS_PUSH.PUSH"
  14. ref="selectGroupRef"
  15. :userGroupList="ruleFormData.userGroupList || []"
  16. @userGroupListChange="handleUserGroupListChange"
  17. />
  18. </template>
  19. </BasicForm>
  20. </main>
  21. <footer class="safety-platform-container__footer">
  22. <el-button @click="router.back()">取消</el-button>
  23. <el-button type="primary" @click="handleSubmit">提交</el-button>
  24. </footer>
  25. <UploadLoading :form-loading="formLoading" v-if="formLoading" />
  26. </template>
  27. <script setup lang="ts">
  28. import BasicForm from '@/components/BasicForm.vue';
  29. import UploadFiles from '@/views/disaster/components/UploadFiles.vue';
  30. import SelectGroup from '@/components/PersonGroup/SelectGroup.vue';
  31. import { useFormConfigHook } from '@/hooks/useFormConfigHook';
  32. import { IS_PUSH } from '../constants';
  33. import { NOTICE_FORM_CONFIG, NOTICE_FORM_DATA, NOTICE_FORM_RULES } from '../configs/form';
  34. import { FileItem, NoticeRuleForm } from '../types';
  35. import { onMounted, ref } from 'vue';
  36. import UploadLoading from '@/components/UploadLoading.vue';
  37. import { useRouter } from 'vue-router';
  38. const props = defineProps<{
  39. id: number;
  40. }>();
  41. const getNoticeDetail = async () => {
  42. // TODO 获取详情并写入表单
  43. };
  44. const { ruleFormData, formRules, ruleFormConfig, cloneRuleFormData, beforeRouteLeave } =
  45. useFormConfigHook<NoticeRuleForm>(NOTICE_FORM_CONFIG, NOTICE_FORM_DATA, NOTICE_FORM_RULES);
  46. const basicFormRef = ref<InstanceType<typeof BasicForm>>();
  47. const selectGroupRef = ref<InstanceType<typeof SelectGroup>>();
  48. const handleUserGroupListChange = (userGroupList: number[]) => {
  49. ruleFormData.userGroupList = userGroupList;
  50. };
  51. const handleUploadSuccess = (fileList: FileItem[]) => {
  52. ruleFormData.noticeFiles = fileList;
  53. };
  54. const handleValidate = async () => {
  55. if (!basicFormRef.value) return;
  56. const parentValidateResult = await basicFormRef.value.validateForm();
  57. let childValidateResult = true;
  58. if (selectGroupRef.value) {
  59. childValidateResult = (await selectGroupRef.value.validateForm()) as boolean;
  60. }
  61. return parentValidateResult && childValidateResult;
  62. };
  63. const getFormData = () => {
  64. if (!ruleFormData.isPush) {
  65. ruleFormData.userGroupList = [];
  66. }
  67. cloneRuleFormData();
  68. return ruleFormData;
  69. };
  70. const formLoading = ref(false);
  71. const router = useRouter();
  72. const handleSubmit = () => {
  73. handleValidate();
  74. };
  75. // defineExpose({
  76. // handleValidate,
  77. // getFormData,
  78. // });
  79. onMounted(async () => {
  80. await getNoticeDetail();
  81. cloneRuleFormData();
  82. beforeRouteLeave();
  83. });
  84. </script>
  85. <style scoped lang="scss">
  86. @use '@/styles/page-details-layout.scss' as *;
  87. </style>