2023-03-21 12:06:30 +07:00
|
|
|
<!-- card อัปโหลดเอกสาร -->
|
2023-03-16 19:57:00 +07:00
|
|
|
<template>
|
2023-03-29 16:39:45 +07:00
|
|
|
<HeaderTop
|
|
|
|
|
v-model:edit="edit"
|
2023-04-05 14:02:36 +07:00
|
|
|
:header="
|
|
|
|
|
$q.screen.gt.xs
|
|
|
|
|
? 'อัปโหลดเอกสาร(เช่น สำเนาบัตรประชาชน ทะเบียนบ้าน วุฒิการศึกษา)'
|
|
|
|
|
: 'อัปโหลดเอกสาร'
|
|
|
|
|
"
|
2023-03-29 16:39:45 +07:00
|
|
|
icon="mdi-file-document"
|
|
|
|
|
:addData="true"
|
|
|
|
|
:editOnly="true"
|
|
|
|
|
:editData="status == 'register' || status == 'rejectRegister'"
|
|
|
|
|
/>
|
2023-03-21 11:19:23 +07:00
|
|
|
|
2023-03-29 16:39:45 +07:00
|
|
|
<div v-if="edit" class="row justify-center row col-12">
|
|
|
|
|
<q-input
|
2023-03-31 17:49:36 +07:00
|
|
|
class="q-mt-sm col-12 q-pb-xs"
|
2023-03-29 16:39:45 +07:00
|
|
|
:outlined="edit"
|
|
|
|
|
dense
|
|
|
|
|
lazy-rules
|
|
|
|
|
:readonly="!edit"
|
|
|
|
|
:borderless="!edit"
|
|
|
|
|
v-model="name"
|
2023-03-31 17:49:36 +07:00
|
|
|
hide-bottom-space
|
2023-03-29 16:39:45 +07:00
|
|
|
:rules="[(val) => !!val || `${'กรุณากรอกชื่อเอกสาร'}`]"
|
|
|
|
|
:label="`${'ชื่อเอกสาร'}`"
|
|
|
|
|
/>
|
|
|
|
|
<q-uploader
|
2023-03-31 17:49:36 +07:00
|
|
|
color="gray"
|
2023-03-29 16:39:45 +07:00
|
|
|
type="file"
|
|
|
|
|
flat
|
|
|
|
|
:factory="fileUpload"
|
2023-04-05 14:02:36 +07:00
|
|
|
ref="uploader"
|
2023-03-29 16:39:45 +07:00
|
|
|
class="full-width"
|
2023-03-31 17:49:36 +07:00
|
|
|
text-color="dark"
|
2023-03-29 16:39:45 +07:00
|
|
|
:max-size="10000000"
|
|
|
|
|
accept=".jpg,.png,.pdf,.csv,.doc"
|
|
|
|
|
bordered
|
|
|
|
|
label="[ไฟล์ jpg,png,pdf,csv,doc ขนาดไม่เกิน 10MB]"
|
2023-04-05 14:02:36 +07:00
|
|
|
@added="fileAdd"
|
|
|
|
|
>
|
|
|
|
|
<template v-slot:header="scope">
|
|
|
|
|
<div class="row no-wrap items-center q-pa-sm q-gutter-xs">
|
|
|
|
|
<q-btn
|
|
|
|
|
v-if="scope.queuedFiles.length > 0"
|
|
|
|
|
icon="clear_all"
|
|
|
|
|
@click="scope.removeQueuedFiles"
|
|
|
|
|
round
|
|
|
|
|
dense
|
|
|
|
|
flat
|
|
|
|
|
>
|
|
|
|
|
<q-tooltip>ลบทั้งหมด</q-tooltip>
|
|
|
|
|
</q-btn>
|
|
|
|
|
<q-btn
|
|
|
|
|
v-if="scope.uploadedFiles.length > 0"
|
|
|
|
|
icon="done_all"
|
|
|
|
|
@click="scope.removeUploadedFiles"
|
|
|
|
|
round
|
|
|
|
|
dense
|
|
|
|
|
flat
|
|
|
|
|
>
|
|
|
|
|
<q-tooltip>ลบไฟล์ที่อัปโหลด</q-tooltip>
|
|
|
|
|
</q-btn>
|
|
|
|
|
<q-spinner v-if="scope.isUploading" class="q-uploader__spinner" />
|
|
|
|
|
<div class="col">
|
|
|
|
|
<div class="q-uploader__title">{{ '[ไฟล์ jpg,png,pdf,csv,doc ขนาดไม่เกิน 10MB]' }}</div>
|
|
|
|
|
<div class="q-uploader__subtitle">
|
|
|
|
|
{{ scope.uploadSizeLabel }} / {{ scope.uploadProgressLabel }}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<q-btn
|
|
|
|
|
v-if="scope.canAddFiles"
|
|
|
|
|
type="a"
|
|
|
|
|
icon="add_box"
|
|
|
|
|
@click="scope.pickFiles"
|
|
|
|
|
round
|
|
|
|
|
dense
|
|
|
|
|
flat
|
|
|
|
|
>
|
|
|
|
|
<q-uploader-add-trigger />
|
|
|
|
|
<q-tooltip>เลือกไฟล์</q-tooltip>
|
|
|
|
|
</q-btn>
|
|
|
|
|
<q-btn
|
|
|
|
|
v-if="scope.canUpload"
|
|
|
|
|
icon="cloud_upload"
|
|
|
|
|
label="อัพโหลดไฟล์"
|
|
|
|
|
@click="scope.upload"
|
|
|
|
|
round
|
|
|
|
|
dense
|
|
|
|
|
flat
|
|
|
|
|
>
|
|
|
|
|
<q-tooltip>อัพโหลดไฟล์</q-tooltip>
|
|
|
|
|
</q-btn>
|
|
|
|
|
|
|
|
|
|
<q-btn v-if="scope.isUploading" icon="clear" @click="scope.abort" round dense flat>
|
|
|
|
|
<q-tooltip>ยกเลิกการอัปโหลด</q-tooltip>
|
|
|
|
|
</q-btn>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
</q-uploader>
|
2023-03-29 16:39:45 +07:00
|
|
|
</div>
|
|
|
|
|
<q-card bordered flat class="full-width q-my-md">
|
|
|
|
|
<q-list separator>
|
2023-04-05 14:02:36 +07:00
|
|
|
<q-item v-for="file in files" :key="file.id" class="q-my-xs">
|
2023-03-29 16:39:45 +07:00
|
|
|
<q-item-section>
|
|
|
|
|
<q-item-label class="full-width ellipsis">
|
2023-04-05 14:02:36 +07:00
|
|
|
{{ file.fileName }}
|
2023-03-29 16:39:45 +07:00
|
|
|
</q-item-label>
|
|
|
|
|
|
2023-04-05 14:02:36 +07:00
|
|
|
<q-item-label caption> สถานะ: {{ file.fileType }} / {{ file.fileSize }} </q-item-label>
|
2023-03-29 16:39:45 +07:00
|
|
|
</q-item-section>
|
|
|
|
|
<q-item-section top side>
|
|
|
|
|
<div class="q-gutter-sm">
|
2023-04-05 14:02:36 +07:00
|
|
|
<q-btn
|
|
|
|
|
size="12px"
|
|
|
|
|
flat
|
|
|
|
|
dense
|
|
|
|
|
round
|
|
|
|
|
color="blue"
|
|
|
|
|
icon="mdi-download-outline"
|
|
|
|
|
@click="downloadData(file.id)"
|
|
|
|
|
>
|
2023-03-29 16:39:45 +07:00
|
|
|
<q-tooltip>ดาวน์โหลด</q-tooltip>
|
|
|
|
|
</q-btn>
|
2023-04-05 14:02:36 +07:00
|
|
|
<q-btn
|
|
|
|
|
size="12px"
|
|
|
|
|
flat
|
|
|
|
|
dense
|
|
|
|
|
round
|
|
|
|
|
color="red"
|
|
|
|
|
icon="mdi-delete-outline"
|
|
|
|
|
v-if="edit"
|
|
|
|
|
@click="deleteData(file.id)"
|
|
|
|
|
>
|
2023-03-29 16:39:45 +07:00
|
|
|
<q-tooltip>ลบไฟล์</q-tooltip>
|
|
|
|
|
</q-btn>
|
|
|
|
|
</div>
|
|
|
|
|
</q-item-section>
|
|
|
|
|
</q-item>
|
|
|
|
|
</q-list>
|
2023-03-16 19:57:00 +07:00
|
|
|
</q-card>
|
|
|
|
|
</template>
|
|
|
|
|
<script setup lang="ts">
|
2023-03-19 00:43:28 +07:00
|
|
|
import { onMounted, ref, watch } from 'vue'
|
2023-03-16 19:57:00 +07:00
|
|
|
import HeaderTop from '@/components/top.vue'
|
2023-04-05 14:02:36 +07:00
|
|
|
import http from '@/plugins/http'
|
|
|
|
|
import config from '@/app.config'
|
|
|
|
|
import { useRoute } from 'vue-router'
|
|
|
|
|
import type { uploadType } from '@/modules/01_exam/interface/index/Main'
|
2023-03-16 19:57:00 +07:00
|
|
|
|
2023-03-19 00:43:28 +07:00
|
|
|
const props = defineProps({
|
2023-03-25 01:07:18 +07:00
|
|
|
status: {
|
|
|
|
|
type: String,
|
2023-03-19 00:43:28 +07:00
|
|
|
required: true
|
|
|
|
|
}
|
|
|
|
|
})
|
2023-04-05 14:02:36 +07:00
|
|
|
const route = useRoute()
|
|
|
|
|
const examId = ref<string>(route.params.id.toString())
|
2023-04-06 03:05:54 +07:00
|
|
|
const positionId = ref<string>(route.params.positionId.toString())
|
2023-04-05 14:02:36 +07:00
|
|
|
const uploader = ref<any>()
|
|
|
|
|
const loader = ref<boolean>(false)
|
2023-03-28 14:51:48 +07:00
|
|
|
const edit = ref<boolean>(props.status == 'register' || props.status == 'rejectRegister')
|
2023-03-20 13:01:27 +07:00
|
|
|
const name = ref<string>('')
|
2023-04-05 14:02:36 +07:00
|
|
|
const fileDataUpload = ref<File>()
|
|
|
|
|
const files = ref<uploadType[]>([
|
|
|
|
|
// {
|
|
|
|
|
// key: 1,
|
|
|
|
|
// name: 'เอกสารข้อมูลการเปลี่ยนชื่อ',
|
|
|
|
|
// status: 'อัปโหลดเสร็จสิ้น',
|
|
|
|
|
// sizeLabel: '176MB'
|
|
|
|
|
// },
|
|
|
|
|
// {
|
|
|
|
|
// key: 2,
|
|
|
|
|
// name: 'เอกสารข้อมูลการสมรส',
|
|
|
|
|
// status: 'อัปโหลดเสร็จสิ้น',
|
|
|
|
|
// sizeLabel: '89MB'
|
|
|
|
|
// }
|
2023-03-16 19:57:00 +07:00
|
|
|
])
|
2023-03-30 22:37:24 +07:00
|
|
|
const emit = defineEmits(['update:loader'])
|
2023-03-19 00:43:28 +07:00
|
|
|
|
2023-04-05 14:02:36 +07:00
|
|
|
onMounted(async () => {
|
|
|
|
|
await getData()
|
|
|
|
|
})
|
2023-03-19 00:43:28 +07:00
|
|
|
|
2023-04-05 14:02:36 +07:00
|
|
|
const fileAdd = async (file: any) => {
|
2023-03-21 12:05:29 +07:00
|
|
|
name.value = file[0].name
|
2023-04-05 14:02:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const fileUpload = async (file: any) => {
|
|
|
|
|
// fileDataUpload.value = file[0]
|
|
|
|
|
const blob = file.slice(0, file.size, file[0].type)
|
|
|
|
|
const newFile = new File([blob], name.value, { type: file[0].type })
|
|
|
|
|
fileDataUpload.value = newFile
|
|
|
|
|
await uploadData()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const getData = async () => {
|
|
|
|
|
loader.value = true
|
|
|
|
|
await http
|
2023-04-06 03:05:54 +07:00
|
|
|
.get(config.API.candidateUpload(examId.value, positionId.value))
|
2023-04-05 14:02:36 +07:00
|
|
|
.then((res) => {
|
|
|
|
|
const data = res.data.result
|
|
|
|
|
// console.log(data)
|
|
|
|
|
files.value = data
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {})
|
|
|
|
|
.finally(() => {
|
|
|
|
|
loader.value = false
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const deleteData = async (id: string) => {
|
|
|
|
|
loader.value = true
|
|
|
|
|
const params = {
|
|
|
|
|
documentId: id
|
2023-03-16 19:57:00 +07:00
|
|
|
}
|
2023-04-05 14:02:36 +07:00
|
|
|
await http
|
2023-04-06 03:05:54 +07:00
|
|
|
.delete(config.API.candidateUpload(examId.value, positionId.value), {
|
2023-04-05 14:02:36 +07:00
|
|
|
params
|
|
|
|
|
})
|
|
|
|
|
.then((res) => {
|
|
|
|
|
const data = res.data.result
|
|
|
|
|
console.log(data)
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {})
|
|
|
|
|
.finally(async () => {
|
|
|
|
|
loader.value = false
|
|
|
|
|
await getData()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const uploadData = async () => {
|
|
|
|
|
loader.value = true
|
|
|
|
|
const formData = new FormData()
|
|
|
|
|
formData.append('FileData', fileDataUpload.value)
|
|
|
|
|
await http
|
2023-04-06 03:05:54 +07:00
|
|
|
.put(config.API.candidateUpload(examId.value, positionId.value), formData)
|
2023-04-05 14:02:36 +07:00
|
|
|
.then((res) => {
|
|
|
|
|
const data = res.data.result
|
|
|
|
|
console.log(data)
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {})
|
|
|
|
|
.finally(async () => {
|
|
|
|
|
loader.value = false
|
|
|
|
|
name.value = ''
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
uploader.value.reset()
|
|
|
|
|
}, 100)
|
|
|
|
|
await getData()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const downloadData = async (id: string) => {
|
|
|
|
|
loader.value = true
|
|
|
|
|
await http
|
|
|
|
|
.get(config.API.candidateDownload(id))
|
|
|
|
|
.then((res) => {
|
|
|
|
|
const data = res
|
|
|
|
|
console.log(data)
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {})
|
|
|
|
|
.finally(() => {
|
|
|
|
|
loader.value = false
|
|
|
|
|
})
|
2023-03-16 19:57:00 +07:00
|
|
|
}
|
|
|
|
|
</script>
|