hrms-admin/src/components/Dialogs/PopupReplyInbox.vue

128 lines
3.5 KiB
Vue
Raw Normal View History

2024-05-29 17:58:57 +07:00
<script setup lang="ts">
2024-09-03 10:53:11 +07:00
import { ref } from "vue";
import { useQuasar } from "quasar";
2024-05-29 17:58:57 +07:00
import http from "@/plugins/http";
import config from "@/app.config";
2024-09-03 10:53:11 +07:00
import { useCounterMixin } from "@/stores/mixin";
2024-05-29 17:58:57 +07:00
import DialogHeader from "@/components/DialogHeader.vue";
2024-09-03 10:53:11 +07:00
const $q = useQuasar();
const { showLoader, hideLoader, success, messageError, dialogConfirm } =
useCounterMixin(); //เรียกฟังก์ชันกลาง
2024-05-29 17:58:57 +07:00
2024-09-03 10:53:11 +07:00
/**
* props จาก components Dashborad
*/
2024-05-29 17:58:57 +07:00
const props = defineProps({
modal: {
type: Boolean,
default: false,
},
idInbox: {
type: String,
default: "",
},
clickClose: {
type: Function,
default: () => {},
},
type: {
type: String,
default: "",
},
2024-05-29 17:58:57 +07:00
});
2024-09-03 10:53:11 +07:00
const subject = ref<string>(""); // หัวข้อ
const body = ref<string>(""); //ข้อความ
/**
* นยนการจตอบกลบการสงขอความ
*/
function onSubmit() {
dialogConfirm($q, async () => {
showLoader();
const pathAPI =
props.type === "Administrator"
? config.API.replyMessage(props.idInbox)
: config.API.replyMessage(props.idInbox);
2024-09-03 10:53:11 +07:00
await http
.put(pathAPI, {
2024-09-03 10:53:11 +07:00
subject: subject.value,
body: body.value,
})
.then(() => {
success($q, "ส่งข้อความสำเร็จ");
onClose();
2024-09-03 10:53:11 +07:00
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
2024-05-29 17:58:57 +07:00
});
}
function onClose() {
subject.value = "";
body.value = "";
props.clickClose();
}
2024-05-29 17:58:57 +07:00
</script>
<template>
<q-dialog v-model="props.modal" persistent>
<q-card style="width: 40vw; max-width: 40vw">
2024-09-03 10:53:11 +07:00
<q-form greedy @submit.prevent @validation-success="onSubmit">
<DialogHeader
:tittle="
type === 'Administrator'
? 'ส่งข้อความไปยังผู้ดูแลระบบของหน่วยงาน'
: 'ส่งข้อความ'
"
:close="onClose"
/>
2024-05-29 17:58:57 +07:00
<q-separator />
<q-card-section class="q-pa-sm bg-grey-1">
<div class="row col-12 q-col-gutter-sm">
<div class="col-xs-12">
<div class="col-12 row q-py-sm items-center q-col-gutter-sm">
<q-input
class="full-width inputgreen cursor-pointer"
hide-bottom-space
outlined
dense
lazy-rules
2024-09-03 10:53:11 +07:00
:rules="[(val:string) => !!val || 'กรุณากรอกหัวข้อ']"
2024-05-29 17:58:57 +07:00
v-model="subject"
label="หัวข้อ"
/>
<q-input
type="textarea"
class="full-width inputgreen cursor-pointer"
hide-bottom-space
outlined
dense
lazy-rules
2024-09-03 10:53:11 +07:00
:rules="[(val:string) => !!val || 'กรุณากรอกข้อความ']"
2024-05-29 17:58:57 +07:00
v-model="body"
label="ข้อความ"
/>
</div>
</div>
</div>
</q-card-section>
<q-separator />
<q-card-actions align="right">
2024-09-03 10:53:11 +07:00
<q-btn label="ส่งข้อความ" color="public" type="submit">
2024-05-29 17:58:57 +07:00
<q-tooltip>นท</q-tooltip>
</q-btn>
</q-card-actions>
</q-form>
</q-card>
</q-dialog>
</template>