2727 :limit-length =" 200" />
2828 <RequestTaskFileInput
2929 v-model =" file"
30+ :initFileArr =" initFileArr"
3031 :isEdit =" true" />
3132 <FormButtonContainer
3233 :handleCancel =" handleCancel"
4647 <template #header >작업{{ statusText }}을 실패했습니다</template >
4748 <template #body >잠시후 시도해주세요</template >
4849 </ModalView >
50+ <ModalView
51+ :isOpen =" isModalVisible === 'loading'"
52+ type =" loadingType" >
53+ <template #header >작업을 요청 중입니다...</template >
54+ <template #body >잠시만 기다려주세요</template >
55+ </ModalView >
4956 </div >
5057</template >
5158
5259<script lang="ts" setup>
5360import { getMainCategory , getSubCategory } from ' @/api/common'
54- import { getTaskDetailUser , patchTaskRequest , postTaskRequest } from ' @/api/user'
61+ import {
62+ getSubCategoryDetail ,
63+ getTaskDetailUser ,
64+ patchTaskRequest ,
65+ postTaskRequest
66+ } from ' @/api/user'
5567import type { Category , SubCategory } from ' @/types/common'
5668import type { AttachmentResponse } from ' @/types/user'
69+ import getPossibleCategory from ' @/utils/possibleCategory'
5770import { computed , onMounted , ref , watch } from ' vue'
5871import { useRouter } from ' vue-router'
5972import FormButtonContainer from ' ../common/FormButtonContainer.vue'
@@ -91,7 +104,12 @@ const handleCancel = () => {
91104}
92105
93106onMounted (async () => {
94- mainCategoryArr .value = await getMainCategory ()
107+ const mainCategory = await getMainCategory ()
108+ const mainIds = await getPossibleCategory ()
109+ const filteredMainCategory = mainCategory .filter ((category : Category ) =>
110+ mainIds .includes (category .mainCategoryId )
111+ )
112+ mainCategoryArr .value = filteredMainCategory
95113 subCategoryArr .value = await getSubCategory ()
96114 afterSubCategoryArr .value = await getSubCategory ()
97115 const data = await getTaskDetailUser (Number (id ))
@@ -103,6 +121,7 @@ onMounted(async () => {
103121 )
104122 title .value = data .title
105123 description .value = data .description
124+
106125 file .value = data .attachmentResponses .map ((attachment : AttachmentResponse ) => {
107126 return new File ([attachment .fileUrl ], attachment .fileName , { type: ' application/pdf' })
108127 })
@@ -120,6 +139,13 @@ watch(category1, async newValue => {
120139 )
121140})
122141
142+ watch (category2 , async newVal => {
143+ if (newVal ) {
144+ const res = await getSubCategoryDetail (newVal .subCategoryId )
145+ description .value = res .descriptionExample
146+ }
147+ })
148+
123149const handleSubmit = async () => {
124150 if (isSubmitting .value || isModalVisible .value ) return
125151
@@ -140,11 +166,9 @@ const handleSubmit = async () => {
140166 return
141167 }
142168
143- isSubmitting .value = true
144-
145169 const formData = new FormData ()
146-
147170 isSubmitting .value = true
171+ isModalVisible .value = ' loading'
148172
149173 const attachmentsToDelete = initFileArr .value
150174 .filter (initFile => ! file .value ?.some (f => f .name === initFile .fileName ))
@@ -161,7 +185,7 @@ const handleSubmit = async () => {
161185 attachmentsToDelete: attachmentsToDelete
162186 }
163187
164- const jsonTaskInfo = JSON .stringify (taskInfoEdit )
188+ const jsonTaskInfo = JSON .stringify (reqType === ' edit ' ? taskInfoEdit : taskInfo )
165189 const newBlob = new Blob ([jsonTaskInfo ], { type: ' application/json' })
166190 formData .append (' taskInfo' , newBlob )
167191
@@ -177,13 +201,16 @@ const handleSubmit = async () => {
177201 formData .append (' attachment' , f )
178202 })
179203 }
180-
181- if (reqType === ' re' ) {
182- await postTaskRequest (formData )
183- } else {
184- await patchTaskRequest (id , formData )
204+ try {
205+ if (reqType === ' re' ) {
206+ await postTaskRequest (formData )
207+ } else {
208+ await patchTaskRequest (id , formData )
209+ }
210+ isModalVisible .value = ' success'
211+ } finally {
212+ isSubmitting .value = false
213+ if (isModalVisible .value !== ' success' ) isModalVisible .value = ' '
185214 }
186- isModalVisible .value = ' success'
187- isSubmitting .value = false
188215}
189216 </script >
0 commit comments