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

134 lines
3.8 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() {
2024-11-13 11:02:08 +07:00
dialogConfirm(
$q,
async () => {
showLoader();
const pathAPI =
props.type === "Administrator"
? config.API.msgNotiAdmin
: config.API.replyMessage(props.idInbox);
const method = props.type === "Administrator" ? http.post : http.put;
2024-11-12 17:07:34 +07:00
2024-11-13 11:02:08 +07:00
await method(pathAPI, {
subject: subject.value,
body: body.value,
2024-09-03 10:53:11 +07:00
})
2024-11-13 11:02:08 +07:00
.then(() => {
success($q, "ส่งข้อความสำเร็จ");
onClose();
})
.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
2024-11-13 11:02:08 +07:00
class="full-width inputgreen cursor-pointer bg-white"
2024-05-29 17:58:57 +07:00
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"
2024-11-13 11:02:08 +07:00
class="full-width inputgreen cursor-pointer bg-white"
2024-05-29 17:58:57 +07:00
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>