375 lines
11 KiB
Vue
375 lines
11 KiB
Vue
<template>
|
|
<div>
|
|
<v-toolbar dark>
|
|
<v-spacer />
|
|
<v-toolbar-title>FAQ</v-toolbar-title>
|
|
<v-spacer />
|
|
</v-toolbar>
|
|
|
|
<br>
|
|
|
|
<v-container>
|
|
<v-row>
|
|
<v-col cols="9">
|
|
<v-radio-group
|
|
v-model="selected_category"
|
|
row
|
|
@change="getFaqs"
|
|
>
|
|
<v-radio
|
|
v-for="category in categories"
|
|
:key="category"
|
|
:label="category"
|
|
:value="category"
|
|
/>
|
|
</v-radio-group>
|
|
</v-col>
|
|
<v-spacer />
|
|
<v-col>
|
|
<v-btn
|
|
block
|
|
color="#9970ff"
|
|
dark
|
|
depressed
|
|
@click="showWriteDialog"
|
|
>
|
|
FAQ 등록
|
|
</v-btn>
|
|
</v-col>
|
|
</v-row>
|
|
<v-row>
|
|
<v-col>
|
|
<v-simple-table
|
|
class="elevation-10"
|
|
dark
|
|
>
|
|
<template>
|
|
<thead>
|
|
<tr>
|
|
<th class="text-center">
|
|
NO
|
|
</th>
|
|
<th class="text-center">
|
|
카테고리
|
|
</th>
|
|
<th class="text-center">
|
|
질문
|
|
</th>
|
|
<th class="text-center">
|
|
답변
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr
|
|
v-for="item in faqs"
|
|
:key="item.id"
|
|
@click="clickFaq(item)"
|
|
>
|
|
<td>
|
|
{{ item.id }}
|
|
</td>
|
|
<td>
|
|
{{ item.category }}
|
|
</td>
|
|
<td class="text-left">
|
|
{{ item.question }}
|
|
</td>
|
|
<td class="text-left">
|
|
<div v-html="item.answer" />
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</template>
|
|
</v-simple-table>
|
|
</v-col>
|
|
</v-row>
|
|
</v-container>
|
|
<v-row>
|
|
<v-dialog
|
|
v-model="show_write_dialog"
|
|
max-width="1000px"
|
|
persistent
|
|
>
|
|
<v-card>
|
|
<v-card-text />
|
|
<v-card-text>
|
|
<v-radio-group
|
|
v-model="faq.category"
|
|
row
|
|
>
|
|
<v-radio
|
|
v-for="category in categories"
|
|
:key="category"
|
|
:label="category"
|
|
:value="category"
|
|
/>
|
|
</v-radio-group>
|
|
</v-card-text>
|
|
<v-card-text>
|
|
<v-text-field
|
|
v-model="faq.question"
|
|
label="제목"
|
|
/>
|
|
</v-card-text>
|
|
<v-card-text>
|
|
<VueEditor
|
|
v-model="faq.answer"
|
|
:editor-toolbar="customToolbar"
|
|
/>
|
|
</v-card-text>
|
|
<v-card-actions v-show="!is_loading">
|
|
<v-btn
|
|
v-show="is_modify"
|
|
color="blue darken-1"
|
|
text
|
|
@click="deleteFaq"
|
|
>
|
|
삭제
|
|
</v-btn>
|
|
<v-spacer />
|
|
<v-btn
|
|
color="blue darken-1"
|
|
text
|
|
@click="cancel"
|
|
>
|
|
취소
|
|
</v-btn>
|
|
<v-btn
|
|
v-if="is_modify"
|
|
color="blue darken-1"
|
|
text
|
|
@click="modify"
|
|
>
|
|
수정
|
|
</v-btn>
|
|
<v-btn
|
|
v-else
|
|
color="blue darken-1"
|
|
text
|
|
@click="submit"
|
|
>
|
|
등록
|
|
</v-btn>
|
|
</v-card-actions>
|
|
</v-card>
|
|
</v-dialog>
|
|
</v-row>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import * as api from '@/api/faq'
|
|
import {VueEditor} from "vue2-editor";
|
|
|
|
export default {
|
|
name: "FaqView",
|
|
|
|
components: {
|
|
VueEditor,
|
|
},
|
|
|
|
data() {
|
|
return {
|
|
is_loading: false,
|
|
is_modify: false,
|
|
categories: [],
|
|
selected_category: '',
|
|
selected_faq: {},
|
|
faqs: [],
|
|
faq: {},
|
|
show_write_dialog: false,
|
|
show_delete_confirm_dialog: false,
|
|
customToolbar: [
|
|
[{header: [false, 1, 2, 3, 4, 5, 6]}],
|
|
["bold", "italic", "underline"],
|
|
[
|
|
{align: ""},
|
|
{align: "center"},
|
|
{align: "right"},
|
|
{align: "justify"}
|
|
],
|
|
[{list: "ordered"}, {list: "bullet"}],
|
|
[{color: []}, {background: []}],
|
|
]
|
|
}
|
|
},
|
|
|
|
async created() {
|
|
await this.getFaqCategories()
|
|
},
|
|
|
|
methods: {
|
|
notifyError(message) {
|
|
this.$dialog.notify.error(message)
|
|
},
|
|
|
|
notifySuccess(message) {
|
|
this.$dialog.notify.success(message)
|
|
},
|
|
|
|
async getFaqCategories() {
|
|
this.is_loading = true
|
|
try {
|
|
const res = await api.getCategories()
|
|
if (res.status === 200 && res.data.success === true) {
|
|
const data = res.data.data
|
|
|
|
this.categories = data
|
|
this.selected_category = data[0]
|
|
await this.getFaqs()
|
|
} else {
|
|
this.notifyError(res.data.message || '알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
|
|
}
|
|
} catch (e) {
|
|
this.notifyError('알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
|
|
} finally {
|
|
this.is_loading = false
|
|
}
|
|
},
|
|
|
|
async getFaqs() {
|
|
this.is_loading = true
|
|
|
|
this.faqs = []
|
|
try {
|
|
const res = await api.getFaqs(this.selected_category)
|
|
if (res.status === 200 && res.data.success === true) {
|
|
this.faqs = res.data.data
|
|
} else {
|
|
this.notifyError(res.data.message || '알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
|
|
}
|
|
} catch (e) {
|
|
this.notifyError('알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
|
|
} finally {
|
|
this.is_loading = false
|
|
}
|
|
},
|
|
|
|
async submit() {
|
|
if (!this.validate()) return;
|
|
if (this.is_loading) return;
|
|
|
|
this.is_loading = true
|
|
|
|
try {
|
|
const res = await api.save(this.faq.question, this.faq.answer, this.faq.category)
|
|
if (res.status === 200 && res.data.success === true) {
|
|
this.show_write_dialog = false
|
|
this.notifySuccess('등록되었습니다.')
|
|
this.faq = {}
|
|
await this.getFaqs()
|
|
} else {
|
|
this.notifyError(res.data.message || '알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
|
|
}
|
|
} catch (e) {
|
|
this.notifyError('알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
|
|
} finally {
|
|
this.is_loading = false
|
|
}
|
|
},
|
|
|
|
async deleteFaq() {
|
|
this.is_loading = true
|
|
try {
|
|
const res = await api.deleteFaq(this.faq.id)
|
|
if (res.status === 200 && res.data.success === true) {
|
|
this.show_write_dialog = false
|
|
this.notifySuccess(res.data.message || '삭제되었습니다.')
|
|
this.faq = {}
|
|
await this.getFaqs()
|
|
} else {
|
|
this.notifyError(res.data.message || '알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
|
|
}
|
|
} catch (e) {
|
|
this.notifyError('알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
|
|
} finally {
|
|
this.is_loading = false
|
|
this.is_modify = false
|
|
}
|
|
},
|
|
|
|
async modify() {
|
|
if (this.is_loading) return;
|
|
|
|
this.is_loading = true
|
|
try {
|
|
let request = {id: this.faq.id}
|
|
|
|
if (this.faq.question !== this.selected_faq.question) {
|
|
request.question = this.faq.question
|
|
}
|
|
|
|
if (this.faq.answer !== this.selected_faq.answer) {
|
|
request.answer = this.faq.answer
|
|
}
|
|
|
|
if (this.faq.category !== this.selected_faq.category) {
|
|
request.category = this.faq.category
|
|
}
|
|
|
|
const res = await api.modify(request)
|
|
if (res.status === 200 && res.data.success === true) {
|
|
this.show_write_dialog = false
|
|
this.notifySuccess(res.data.message || '수정되었습니다.')
|
|
this.faq = {}
|
|
await this.getFaqs()
|
|
} else {
|
|
this.notifyError(res.data.message || '알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
|
|
}
|
|
} catch (e) {
|
|
this.notifyError('알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
|
|
} finally {
|
|
this.is_loading = false
|
|
this.is_modify = false
|
|
}
|
|
},
|
|
|
|
clickFaq(item) {
|
|
this.faq.id = item.id
|
|
this.faq.question = item.question
|
|
this.faq.answer = item.answer
|
|
this.faq.category = item.category
|
|
|
|
this.selected_faq = item
|
|
this.is_modify = true
|
|
this.show_write_dialog = true
|
|
},
|
|
|
|
cancel() {
|
|
this.faq = {}
|
|
this.selected_faq = {}
|
|
this.is_modify = false
|
|
this.show_write_dialog = false
|
|
},
|
|
|
|
showWriteDialog() {
|
|
this.show_write_dialog = true
|
|
},
|
|
|
|
validate() {
|
|
if (this.faq.question == null || this.faq.question.trim().length === 0) {
|
|
this.notifyError("질문을 입력하세요.")
|
|
return false;
|
|
}
|
|
|
|
if (this.faq.answer == null || this.faq.answer.trim().length === 0) {
|
|
this.notifyError("답변을 입력하세요.")
|
|
return false;
|
|
}
|
|
|
|
if (this.faq.category == null || this.faq.category.trim().length === 0) {
|
|
this.notifyError("카테고리를 선택하세요.")
|
|
return false;
|
|
}
|
|
|
|
return true
|
|
},
|
|
},
|
|
}
|
|
</script>
|
|
|
|
<style scoped>
|
|
|
|
</style>
|