hrms-user/src/modules/02_transfer/views/AddTransfer.vue

217 lines
7.1 KiB
Vue
Raw Normal View History

2023-07-07 16:54:53 +07:00
<script setup lang="ts">
import { ref, onMounted } from "vue";
import { useQuasar } from "quasar";
import { useRouter, useRoute } from "vue-router";
2024-09-02 18:11:27 +07:00
import http from "@/plugins/http";
import config from "@/app.config";
2024-09-02 18:11:27 +07:00
import { useCounterMixin } from "@/stores/mixin";
import type { QForm } from "quasar";
2023-07-07 16:54:53 +07:00
const $q = useQuasar();
const route = useRoute();
2024-09-02 18:11:27 +07:00
const router = useRouter();
const mixin = useCounterMixin();
const { success, messageError, showLoader, hideLoader, dialogConfirm } = mixin;
2023-08-10 18:43:06 +07:00
2024-09-02 18:11:27 +07:00
const id = ref<string>(""); //id path
const files = ref<any>(); //ไฟล์
const tranferOrg = ref<string>(""); //ชื่อหน่วยงานที่ขอโอนไป
const noteReason = ref<string>(""); //เหตุผล
const routeName = router.currentRoute.value.name; //ชื่อ path
2023-08-11 10:04:47 +07:00
2024-09-02 18:11:27 +07:00
/** Dialog Save */
async function saveData() {
dialogConfirm(
$q,
() => {
createTransfer();
},
"ยืนยันการยื่นข้อมูลการโอน",
"ต้องการยื่นข้อมูลการโอนนี้ใช่หรือไม่"
);
2024-09-02 18:11:27 +07:00
}
2023-08-10 18:43:06 +07:00
2024-09-02 18:11:27 +07:00
/** ฟังก์ชั่นสร้างขอโอน */
async function createTransfer() {
showLoader();
const formData = new FormData();
formData.append("Organization", tranferOrg.value);
formData.append("Reason", noteReason.value);
formData.append("file", files.value);
await http
.post(config.API.listtransfer(), formData)
.then((res: any) => {
success($q, "บันทึกข้อมูลสำเร็จ");
router.push(`/transfer`);
})
.catch((e: any) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
2024-09-02 18:11:27 +07:00
}
2023-08-10 18:43:06 +07:00
/**
* งกนเรยกขอมลจาก Api
* @param id ไอดของขอม
*/
2024-09-02 18:11:27 +07:00
async function fecthDataTransfer(id: string) {
showLoader();
await http
.get(config.API.transferByid(id))
.then((res: any) => {
let data = res.data.result;
tranferOrg.value = data.organization;
noteReason.value = data.reason;
files.value = data.docs;
})
.catch((e: any) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
2024-09-02 18:11:27 +07:00
}
2023-08-11 10:04:47 +07:00
/**
2024-09-02 18:11:27 +07:00
* Func เปดไฟล
* @param url URL File
*/
function fileOpen(url: string) {
window.open(url, "_blank");
}
2024-09-02 18:11:27 +07:00
/**
* เรยกฟงกนทงหมดตอนเรยกใชไฟล
*/
onMounted(() => {
if (route.params.id !== undefined) {
id.value = route.params.id.toString();
fecthDataTransfer(id.value);
}
});
2023-07-07 16:54:53 +07:00
</script>
<template>
<div class="col-12 row justify-center">
<div class="col-xs-12 col-sm-12 col-md-11">
<div class="toptitle text-white col-12 row items-center">
<q-btn
icon="mdi-arrow-left"
unelevated
round
dense
flat
color="primary"
class="q-mr-sm"
@click="router.go(-1)"
/>
<div v-if="routeName == 'addTransfer'">เพิ่มเรื่องขอโอน</div>
<div v-else>รายละเอียดเรื่องขอโอน</div>
</div>
<q-form
class="col-12"
greedy
@submit.prevent
@validation-success="saveData"
>
<q-card bordered>
<div class="col-12 row q-col-gutter-md q-pa-md">
<div class="col-xs-12 col-sm-12">
<div class="col-12 row q-pa-sm q-col-gutter-sm">
<q-input
:class="
routeName != 'addTransfer' ? 'col-12' : 'col-12 inputgreen'
"
dense
outlined
v-model="tranferOrg"
hide-bottom-space
label="หน่วยงานที่ขอโอนไป"
:readonly="routeName != 'addTransfer'"
:rules="[(val:string) => !!val || `${'กรุณากรอกหน่วยงานที่ขอโอนไป'}`]"
/>
<q-input
:class="
routeName != 'addTransfer' ? 'col-12' : 'col-12 inputgreen'
"
dense
outlined
v-model="noteReason"
label="เหตุผล"
hide-bottom-space
type="textarea"
:readonly="routeName != 'addTransfer'"
:rules="[(val:string) => !!val || `${'กรุณากรอกเหตุผล'}`]"
/>
<div class="col-12 row" v-if="routeName == 'addTransfer'">
<q-file
v-model="files"
class="col-xs-12 col-sm-12 inputgreen"
outlined
dense
lazy-rules
hide-bottom-space
accept=".pdf"
:rules="[(val: string) => !!val || 'กรุณาเลือกไฟล์เอกสารเพิ่มเติม']"
label="เอกสารเพิ่มเติม"
2024-05-20 13:06:01 +07:00
>
<template v-slot:prepend>
<q-icon name="attach_file" /> </template
></q-file>
</div>
<div class="col-12 row" v-if="routeName != 'addTransfer'">
<q-card bordered flat class="full-width">
<div
class="bg-grey-1 q-pa-sm col-12 row items-center text-primary"
>
<div class="q-pl-sm text-weight-bold text-dark">
เอกสารเพมเต
</div>
</div>
<q-separator />
<q-list separator>
<q-item v-for="file in files" :key="file.key">
<q-item-section>
{{ file.fileName }}
</q-item-section>
<q-item-section avatar>
<q-btn
color="teal-5"
round
flat
icon="mdi-download"
@click="fileOpen(file.pathName)"
></q-btn>
</q-item-section>
</q-item>
</q-list>
</q-card>
</div>
</div>
</div>
</div>
<q-separator v-if="routeName == 'addTransfer'" />
<q-card-actions
align="right"
class="row col-12"
v-if="routeName == 'addTransfer'"
>
<q-space />
<q-btn
unelevated
class="q-px-md items-center"
color="primary"
label="ยื่นเรื่องขอโอน"
type="onsubmit"
/>
</q-card-actions>
</q-card>
</q-form>
</div>
</div>
</template>