-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequestTask.vue
More file actions
118 lines (106 loc) · 3.46 KB
/
RequestTask.vue
File metadata and controls
118 lines (106 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<template>
<div class="w-full flex flex-col gap-y-6">
<CategoryDropDown
v-model="category1"
:options="mainCategoryArr"
:label-name="'1차 카테고리'"
:placeholderText="'1차 카테고리를 선택해주세요'"
:isDisabled="false" />
<CategoryDropDown
v-model="category2"
:options="afterSubCategoryArr"
:label-name="'2차 카테고리'"
:placeholderText="'2차 카테고리를 선택해주세요'"
:isDisabled="!category1" />
<RequestTaskInput
v-model="title"
:placeholderText="'제목을 입력해주세요'"
:label-name="'제목'"
:is-invalidate="isInvalidate" />
<RequestTaskTextArea
v-model="description"
:placeholderText="'부가 정보를 입력해주세요'" />
<RequestTaskFileInput v-model="file" />
<FormButtonContainer
:handleCancel="handleCancel"
:handleSubmit="handleSubmit"
cancelText="취소"
submitText="요청" />
<ModalView
:isOpen="isModalVisible"
:type="'successType'"
@close="handleCancel">
<template #header>작업이 요청되었습니다</template>
</ModalView>
</div>
</template>
<script lang="ts" setup>
import { getMainCategory, getSubCategory } from '@/api/common'
import { postTaskRequest } from '@/api/user'
import type { Category, SubCategory } from '@/types/common'
import { onMounted, ref, watch } from 'vue'
import { useRouter } from 'vue-router'
import FormButtonContainer from '../common/FormButtonContainer.vue'
import ModalView from '../ModalView.vue'
import CategoryDropDown from './CategoryDropDown.vue'
import RequestTaskFileInput from './RequestTaskFileInput.vue'
import RequestTaskInput from './RequestTaskInput.vue'
import RequestTaskTextArea from './RequestTaskTextArea.vue'
const category1 = ref<Category | null>(null)
const category2 = ref<Category | null>(null)
const title = ref('')
const description = ref('')
const file = ref(null as File[] | null)
const isInvalidate = ref('')
const isModalVisible = ref(false)
const mainCategoryArr = ref<Category[]>([])
const subCategoryArr = ref<SubCategory[]>([])
const afterSubCategoryArr = ref<SubCategory[]>([])
onMounted(async () => {
mainCategoryArr.value = await getMainCategory()
subCategoryArr.value = await getSubCategory()
afterSubCategoryArr.value = await getSubCategory()
})
watch(category1, async newValue => {
category2.value = null
afterSubCategoryArr.value = subCategoryArr.value.filter(
subCategory => subCategory.mainCategoryId === newValue?.id
)
})
const router = useRouter()
const handleCancel = () => {
category1.value = null
category2.value = null
title.value = ''
description.value = ''
file.value = []
router.back()
}
const handleSubmit = async () => {
if (!category1.value || !category2.value) {
isInvalidate.value = 'category'
return
} else if (!title.value) {
isInvalidate.value = 'input'
return
}
const formData = new FormData()
const taskInfo = {
categoryId: category2.value.id,
title: title.value,
description: description.value
}
const jsonTaskInfo = JSON.stringify(taskInfo)
const newBlob = new Blob([jsonTaskInfo], { type: 'application/json' })
formData.append('taskInfo', newBlob)
if (file.value && file.value.length > 0) {
file.value.forEach(f => formData.append('attachment', f))
}
try {
await postTaskRequest(formData)
isModalVisible.value = true
} catch (error) {
console.error('요청 실패:', error)
}
}
</script>