From 0bbf5cde0b9afbe441a495a3c932a6ada054e51b Mon Sep 17 00:00:00 2001 From: AnandaTon Date: Tue, 5 Sep 2023 21:09:28 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1?= =?UTF-8?q?=E0=B9=80=E0=B8=87=E0=B8=B7=E0=B9=88=E0=B8=AD=E0=B8=99=E0=B9=84?= =?UTF-8?q?=E0=B8=82=E0=B8=81=E0=B8=A3=E0=B8=AD=E0=B8=81=E0=B9=83=E0=B8=AB?= =?UTF-8?q?=E0=B9=89=E0=B8=84=E0=B8=A3=E0=B8=9A=E0=B8=81=E0=B9=88=E0=B8=AD?= =?UTF-8?q?=E0=B8=99=E0=B8=AA=E0=B9=88=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/02_transfer/views/AddTransfer.vue | 291 +--- src/modules/03_leave/views/AddLeave.vue | 326 ++--- src/stores/mixin.ts | 1260 ++++++++--------- 3 files changed, 778 insertions(+), 1099 deletions(-) diff --git a/src/modules/02_transfer/views/AddTransfer.vue b/src/modules/02_transfer/views/AddTransfer.vue index a6aefed..c8edbc7 100644 --- a/src/modules/02_transfer/views/AddTransfer.vue +++ b/src/modules/02_transfer/views/AddTransfer.vue @@ -6,13 +6,30 @@
เพิ่มเรื่องขอโอน
รายละเอียดเรื่องขอโอน
-
+
- - + +
- -
-
- +
-
+ @@ -291,11 +63,13 @@ import { useRouter, useRoute } from "vue-router" import { useCounterMixin } from "@/stores/mixin" import http from "@/plugins/http" import config from "@/app.config" +import type { QForm } from "quasar" const router = useRouter() const $q = useQuasar() const mixin = useCounterMixin() -const { date2Thai, dateToISO, success, messageError, showLoader, hideLoader } = mixin +const myform = ref(null) +const { date2Thai, fails, success, messageError, showLoader, hideLoader } = mixin const fileDocDataUpload = ref([]) const route = useRoute() const files = ref() @@ -313,6 +87,17 @@ onMounted(() => { } }) +const saveData = async () => { + console.log(myform.value) + if (myform.value != null) { + await myform.value.validate().then(async (saveDataTest: Boolean) => { + if (saveDataTest) { + saveTransfer() + } + }) + } +} + const saveTransfer = () => { $q.dialog({ title: "ยืนยันการยื่นข้อมูลการโอน", @@ -327,7 +112,9 @@ const saveTransfer = () => { createTransfer() }) .onCancel(() => {}) - .onDismiss(() => {}) + .onDismiss(() => { + fails($q, "กรุณากรอกอัพโหลดเอกสารเพิ่มเติม") + }) } const createTransfer = async () => { diff --git a/src/modules/03_leave/views/AddLeave.vue b/src/modules/03_leave/views/AddLeave.vue index 20d34c7..bf71d0a 100644 --- a/src/modules/03_leave/views/AddLeave.vue +++ b/src/modules/03_leave/views/AddLeave.vue @@ -6,12 +6,20 @@
เพิ่มเรื่องลาออก
รายละเอียดเรื่องลาออก
-
+
- + - +
-
-
- ผลการพิจารณาของผู้บังคับบัญชา -
-
- -
-
-
-
สถานะ
-
- {{ - dataDetail.commanderReject !== null - ? statusOrder(dataDetail.commanderReject) - : "-" - }} -
-
-
-
วันสุดท้ายที่ยับยั้ง
-
- {{ - dataDetail.commanderRejectDate !== null - ? date2Thai(dataDetail.commanderRejectDate) - : "-" - }} -
-
-
-
ความคิดเห็นและเหตุผล
-
- {{ - dataDetail.commanderApproveReason !== null - ? dataDetail.commanderApproveReason - : "-" - }} -
-
- {{ - dataDetail.commanderRejectReason !== null - ? dataDetail.commanderRejectReason - : "-" - }} -
-
-
-
-
+
+
ผลการพิจารณาของผู้บังคับบัญชา
+
+ +
+
+
+
สถานะ
+
+ {{ dataDetail.commanderReject !== null ? statusOrder(dataDetail.commanderReject) : "-" }} +
+
+
+
วันสุดท้ายที่ยับยั้ง
+
+ {{ dataDetail.commanderRejectDate !== null ? date2Thai(dataDetail.commanderRejectDate) : "-" }} +
+
+
+
ความคิดเห็นและเหตุผล
+
+ {{ dataDetail.commanderApproveReason !== null ? dataDetail.commanderApproveReason : "-" }} +
+
+ {{ dataDetail.commanderRejectReason !== null ? dataDetail.commanderRejectReason : "-" }} +
+
+
+
+ - -
-
- ผลการพิจารณาของผู้มีอำนาจ -
-
- -
-
-
-
สถานะ
-
- {{ - dataDetail.oligarchReject !== null - ? statusOrder(dataDetail.oligarchReject) - : "-" - }} -
-
-
-
วันสุดท้ายที่ยับยั้ง
-
- {{ - dataDetail.oligarchRejectDate !== null - ? date2Thai(dataDetail.oligarchRejectDate) - : "-" - }} -
-
-
-
ความคิดเห็นและเหตุผล
-
- {{ - dataDetail.oligarchApproveReason !== null - ? dataDetail.oligarchApproveReason - : "-" - }} -
-
- {{ - dataDetail.oligarchRejectReason !== null - ? dataDetail.oligarchRejectReason - : "-" - }} -
-
-
-
-
-
- - -
+ +
+
ผลการพิจารณาของผู้มีอำนาจ
+
+ +
+
+
+
สถานะ
+
+ {{ dataDetail.oligarchReject !== null ? statusOrder(dataDetail.oligarchReject) : "-" }} +
+
+
+
วันสุดท้ายที่ยับยั้ง
+
+ {{ dataDetail.oligarchRejectDate !== null ? date2Thai(dataDetail.oligarchRejectDate) : "-" }} +
+
+
+
ความคิดเห็นและเหตุผล
+
+ {{ dataDetail.oligarchApproveReason !== null ? dataDetail.oligarchApproveReason : "-" }} +
+
+ {{ dataDetail.oligarchRejectReason !== null ? dataDetail.oligarchRejectReason : "-" }} +
+
+
+
+
+
+ + +
- +
-
+
@@ -221,11 +190,13 @@ import { useRouter, useRoute } from "vue-router" import { useCounterMixin } from "@/stores/mixin" import http from "@/plugins/http" import config from "@/app.config" +import type { QForm } from "quasar" const mixin = useCounterMixin() -const { date2Thai, dateToISO, success, messageError, showLoader, hideLoader } = mixin +const { date2Thai, dateToISO, success, messageError, showLoader, hideLoader, fails } = mixin const router = useRouter() const route = useRoute() +const myform = ref(null) const $q = useQuasar() const routeName = router.currentRoute.value.name const id = ref("") @@ -238,36 +209,36 @@ const noteReason = ref("") const nameFile = ref("") const dataDetail = ref({ - datetext: "", - activeDate: new Date(), - createdAt: new Date(), - firstName: "", - id: "", - isActive: true, - lastName: "", - location: "", - organizationPositionOld: "", - positionLevelOld: "", - positionNumberOld: "", - positionTypeOld: "", - prefix: "", - profileId: "", - reason: "", - salary: 0, - sendDate: new Date(), - status: "", - statustext: "", - fullname: "", -}); + datetext: "", + activeDate: new Date(), + createdAt: new Date(), + firstName: "", + id: "", + isActive: true, + lastName: "", + location: "", + organizationPositionOld: "", + positionLevelOld: "", + positionNumberOld: "", + positionTypeOld: "", + prefix: "", + profileId: "", + reason: "", + salary: 0, + sendDate: new Date(), + status: "", + statustext: "", + fullname: "", +}) const statusOrder = (val: boolean) => { - switch (val) { - case true: - return "ยับยั้งการลาออก"; - case false: - return "อนุมัติการลาออก"; - } -}; + switch (val) { + case true: + return "ยับยั้งการลาออก" + case false: + return "อนุมัติการลาออก" + } +} onMounted(() => { if (route.params.id !== undefined) { @@ -275,6 +246,18 @@ onMounted(() => { fectDataresign(id.value) } }) + +const saveData = async () => { + console.log(myform.value) + if (myform.value != null) { + await myform.value.validate().then(async (saveDataTest: Boolean) => { + if (saveDataTest) { + saveResing() + } + }) + } +} + const saveResing = () => { $q.dialog({ title: "ยืนยันการยื่นข้อมูลแบบสอบถาม", @@ -289,12 +272,14 @@ const saveResing = () => { createFormresign() }) .onCancel(() => {}) - .onDismiss(() => {}) + .onDismiss(() => { + fails($q, "กรุณากรอกอัพโหลดเอกสารเพิ่มเติม") + }) } const cancelResing = () => { - console.log(id); - + console.log(id) + $q.dialog({ title: "ยืนยันการยกเลิกการลาออก", message: "ต้องการยื่นข้อมูลยกเลิกการลาออกนี้ใช่หรือไม่?", @@ -305,33 +290,30 @@ const cancelResing = () => { persistent: true, }) .onOk(async () => { - if (route.params.id !== undefined) { - id.value = route.params.id.toString() - deleteResting(id.value) - } - + if (route.params.id !== undefined) { + id.value = route.params.id.toString() + deleteResting(id.value) + } }) .onCancel(() => {}) .onDismiss(() => {}) } - -const deleteResting = async(id :string) => { +const deleteResting = async (id: string) => { showLoader() await http - .delete(config.API.resingByid(id)) - .then(() => { - success($q, "ยกเลิกการลาออกขอสำเร็จ"); - }) - .catch((e) => { - messageError($q, e); - }) - .finally(() => { - hideLoader(); - }); + .delete(config.API.resingByid(id)) + .then(() => { + success($q, "ยกเลิกการลาออกขอสำเร็จ") + }) + .catch(e => { + messageError($q, e) + }) + .finally(() => { + hideLoader() + }) } - const createFormresign = async () => { const formData = new FormData() const blob = files.value.slice(0, files.value[0].size) @@ -364,8 +346,12 @@ const fectDataresign = async (id: string) => { .then((res: any) => { let data = res.data.result // console.log(data); - ;(tranferOrg.value = data.location), (dateCommand.value = data.sendDate), (dateLeave.value = data.activeDate), (noteReason.value = data.reason), (files.value = data.docs) ,(dataDetail.value = data) - + ;(tranferOrg.value = data.location), + (dateCommand.value = data.sendDate), + (dateLeave.value = data.activeDate), + (noteReason.value = data.reason), + (files.value = data.docs), + (dataDetail.value = data) }) .catch((e: any) => { console.log(e) diff --git a/src/stores/mixin.ts b/src/stores/mixin.ts index 3ac73c2..e6ac855 100644 --- a/src/stores/mixin.ts +++ b/src/stores/mixin.ts @@ -1,720 +1,626 @@ -import { defineStore } from "pinia"; -import moment from "moment"; -import CustomComponent from "@/components/CustomDialog.vue"; -import { Loading, QSpinnerCube } from "quasar"; +import { defineStore } from "pinia" +import moment from "moment" +import CustomComponent from "@/components/CustomDialog.vue" +import { Loading, QSpinnerCube } from "quasar" export const useCounterMixin = defineStore("mixin", () => { - /** - * ฟังก์ชันกลาง - */ + /** + * ฟังก์ชันกลาง + */ - const calAge = ( - srcDate: Date, - birthCal: Date = new Date(), - eng: boolean = false - ) => { - const year = eng ? "years" : "ปี"; - const month = eng ? "months" : "เดือน"; - const day = eng ? "days" : "วัน"; + const calAge = (srcDate: Date, birthCal: Date = new Date(), eng: boolean = false) => { + const year = eng ? "years" : "ปี" + const month = eng ? "months" : "เดือน" + const day = eng ? "days" : "วัน" - if (srcDate == null) { - return `0 ${year} 0 ${month} 0 ${day}`; - } + if (srcDate == null) { + return `0 ${year} 0 ${month} 0 ${day}` + } - const toDay = birthCal; - const birth = new Date(srcDate); + const toDay = birthCal + const birth = new Date(srcDate) - const yearNow = toDay.getFullYear(); - const monthNow = toDay.getMonth(); - const dateNow = toDay.getDate(); + const yearNow = toDay.getFullYear() + const monthNow = toDay.getMonth() + const dateNow = toDay.getDate() - const yearDob = birth.getFullYear(); - const monthDob = birth.getMonth(); - const dateDob = birth.getDate(); + const yearDob = birth.getFullYear() + const monthDob = birth.getMonth() + const dateDob = birth.getDate() - const lastYear = 12; - const subtractDate: Object = moment().subtract(1, "months").endOf("month"); + const lastYear = 12 + const subtractDate: Object = moment().subtract(1, "months").endOf("month") - const lastMonths = new Date(subtractDate.toString()).getDate(); + const lastMonths = new Date(subtractDate.toString()).getDate() - let yearAge = yearNow - yearDob; - let monthAge = 0; - let dateAge = 0; + let yearAge = yearNow - yearDob + let monthAge = 0 + let dateAge = 0 - if (monthNow >= monthDob) { - monthAge = monthNow - monthDob; - } else { - yearAge--; - monthAge = lastYear + monthNow - monthDob; - } + if (monthNow >= monthDob) { + monthAge = monthNow - monthDob + } else { + yearAge-- + monthAge = lastYear + monthNow - monthDob + } - if (dateNow >= dateDob) { - dateAge = dateNow - dateDob; - } else { - monthAge--; - dateAge = lastMonths + dateNow - dateDob; + if (dateNow >= dateDob) { + dateAge = dateNow - dateDob + } else { + monthAge-- + dateAge = lastMonths + dateNow - dateDob - if (monthAge < 0) { - monthAge = 11; - yearAge--; - } - } + if (monthAge < 0) { + monthAge = 11 + yearAge-- + } + } - const age = { - years: yearAge, - months: monthAge, - days: dateAge, - }; + const age = { + years: yearAge, + months: monthAge, + days: dateAge, + } - return `${yearAge} ${year} ${monthAge} ${month} ${dateAge} ${day}`; - }; + return `${yearAge} ${year} ${monthAge} ${month} ${dateAge} ${day}` + } - function date2Thai( - srcDate: Date, - isFullMonth: boolean = false, - isTime: boolean = false - ) { - if (srcDate == null) { - return null; - ` - `; - } - const date = new Date(srcDate); - const isValidDate = Boolean(+date); - if (!isValidDate) return srcDate.toString(); - if (isValidDate && date.getFullYear() < 1000) return srcDate.toString(); - const fullMonthThai = [ - "มกราคม", - "กุมภาพันธ์", - "มีนาคม", - "เมษายน", - "พฤษภาคม", - "มิถุนายน", - "กรกฎาคม", - "สิงหาคม", - "กันยายน", - "ตุลาคม", - "พฤศจิกายน", - "ธันวาคม", - ]; - const abbrMonthThai = [ - "ม.ค.", - "ก.พ.", - "มี.ค.", - "เม.ย.", - "พ.ค.", - "มิ.ย.", - "ก.ค.", - "ส.ค.", - "ก.ย.", - "ต.ค.", - "พ.ย.", - "ธ.ค.", - ]; - let dstYear = 0; - if (date.getFullYear() > 2500) { - dstYear = date.getFullYear(); - } else { - dstYear = date.getFullYear() + 543; - } - let dstMonth = ""; - if (isFullMonth) { - dstMonth = fullMonthThai[date.getMonth()]; - } else { - dstMonth = abbrMonthThai[date.getMonth()]; - } - let dstTime = ""; - if (isTime) { - const H = date.getHours().toString().padStart(2, "0"); - const M = date.getMinutes().toString().padStart(2, "0"); - // const S = date.getSeconds().toString().padStart(2, "0") - // dstTime = " " + H + ":" + M + ":" + S + " น." - dstTime = " " + H + ":" + M + " น."; - } - return ( - date.getDate().toString().padStart(2, "0") + - " " + - dstMonth + - " " + - dstYear + - dstTime - ); - } + function date2Thai(srcDate: Date, isFullMonth: boolean = false, isTime: boolean = false) { + if (srcDate == null) { + return null + ;` + ` + } + const date = new Date(srcDate) + const isValidDate = Boolean(+date) + if (!isValidDate) return srcDate.toString() + if (isValidDate && date.getFullYear() < 1000) return srcDate.toString() + const fullMonthThai = ["มกราคม", "กุมภาพันธ์", "มีนาคม", "เมษายน", "พฤษภาคม", "มิถุนายน", "กรกฎาคม", "สิงหาคม", "กันยายน", "ตุลาคม", "พฤศจิกายน", "ธันวาคม"] + const abbrMonthThai = ["ม.ค.", "ก.พ.", "มี.ค.", "เม.ย.", "พ.ค.", "มิ.ย.", "ก.ค.", "ส.ค.", "ก.ย.", "ต.ค.", "พ.ย.", "ธ.ค."] + let dstYear = 0 + if (date.getFullYear() > 2500) { + dstYear = date.getFullYear() + } else { + dstYear = date.getFullYear() + 543 + } + let dstMonth = "" + if (isFullMonth) { + dstMonth = fullMonthThai[date.getMonth()] + } else { + dstMonth = abbrMonthThai[date.getMonth()] + } + let dstTime = "" + if (isTime) { + const H = date.getHours().toString().padStart(2, "0") + const M = date.getMinutes().toString().padStart(2, "0") + // const S = date.getSeconds().toString().padStart(2, "0") + // dstTime = " " + H + ":" + M + ":" + S + " น." + dstTime = " " + H + ":" + M + " น." + } + return date.getDate().toString().padStart(2, "0") + " " + dstMonth + " " + dstYear + dstTime + } - function dateMonth2Thai(srcDate: Date, isFullMonth = false, isTime = false) { - if (!srcDate) return srcDate; - const date = new Date(srcDate); - const isValidDate = Boolean(+date); - if (!isValidDate) return srcDate; - if (isValidDate && date.getFullYear() < 1000) return srcDate; - const fullMonthThai = [ - "มกราคม", - "กุมภาพันธ์", - "มีนาคม", - "เมษายน", - "พฤษภาคม", - "มิถุนายน", - "กรกฎาคม", - "สิงหาคม", - "กันยายน", - "ตุลาคม", - "พฤศจิกายน", - "ธันวาคม", - ]; - const abbrMonthThai = [ - "ม.ค.", - "ก.พ.", - "มี.ค.", - "เม.ย.", - "พ.ค.", - "มิ.ย.", - "ก.ค.", - "ส.ค.", - "ก.ย.", - "ต.ค.", - "พ.ย.", - "ธ.ค.", - ]; - let dstYear = 0; - if (date.getFullYear() > 2500) { - dstYear = date.getFullYear(); - } else { - dstYear = date.getFullYear() + 543; - } - let dstMonth = ""; - if (isFullMonth) { - dstMonth = fullMonthThai[date.getMonth()]; - } else { - dstMonth = abbrMonthThai[date.getMonth()]; - } - let dstTime = ""; - if (isTime) { - const H = date.getHours().toString().padStart(2, "0"); - const M = date.getMinutes().toString().padStart(2, "0"); - // const S = date.getSeconds().toString().length === 1 ? "0" + date.getSeconds() : date.getSeconds() - // dstTime = " " + H + ":" + M + ":" + S + " น." - dstTime = " " + H + ":" + M + " น."; - } - return date.getDate().toString().padStart(2, "0") + " " + dstMonth; - } + function dateMonth2Thai(srcDate: Date, isFullMonth = false, isTime = false) { + if (!srcDate) return srcDate + const date = new Date(srcDate) + const isValidDate = Boolean(+date) + if (!isValidDate) return srcDate + if (isValidDate && date.getFullYear() < 1000) return srcDate + const fullMonthThai = ["มกราคม", "กุมภาพันธ์", "มีนาคม", "เมษายน", "พฤษภาคม", "มิถุนายน", "กรกฎาคม", "สิงหาคม", "กันยายน", "ตุลาคม", "พฤศจิกายน", "ธันวาคม"] + const abbrMonthThai = ["ม.ค.", "ก.พ.", "มี.ค.", "เม.ย.", "พ.ค.", "มิ.ย.", "ก.ค.", "ส.ค.", "ก.ย.", "ต.ค.", "พ.ย.", "ธ.ค."] + let dstYear = 0 + if (date.getFullYear() > 2500) { + dstYear = date.getFullYear() + } else { + dstYear = date.getFullYear() + 543 + } + let dstMonth = "" + if (isFullMonth) { + dstMonth = fullMonthThai[date.getMonth()] + } else { + dstMonth = abbrMonthThai[date.getMonth()] + } + let dstTime = "" + if (isTime) { + const H = date.getHours().toString().padStart(2, "0") + const M = date.getMinutes().toString().padStart(2, "0") + // const S = date.getSeconds().toString().length === 1 ? "0" + date.getSeconds() : date.getSeconds() + // dstTime = " " + H + ":" + M + ":" + S + " น." + dstTime = " " + H + ":" + M + " น." + } + return date.getDate().toString().padStart(2, "0") + " " + dstMonth + } - function monthYear2Thai(month: number, year: number, isFullMonth = false) { - const date = new Date(`${year}-${month + 1}-1`); - const fullMonthThai = [ - "มกราคม", - "กุมภาพันธ์", - "มีนาคม", - "เมษายน", - "พฤษภาคม", - "มิถุนายน", - "กรกฎาคม", - "สิงหาคม", - "กันยายน", - "ตุลาคม", - "พฤศจิกายน", - "ธันวาคม", - ]; - const abbrMonthThai = [ - "ม.ค.", - "ก.พ.", - "มี.ค.", - "เม.ย.", - "พ.ค.", - "มิ.ย.", - "ก.ค.", - "ส.ค.", - "ก.ย.", - "ต.ค.", - "พ.ย.", - "ธ.ค.", - ]; - let dstYear = 0; - if (date.getFullYear() > 2500) { - dstYear = date.getFullYear(); - } else { - dstYear = date.getFullYear() + 543; - } - let dstMonth = ""; - if (isFullMonth) { - dstMonth = fullMonthThai[date.getMonth()]; - } else { - dstMonth = abbrMonthThai[date.getMonth()]; - } - return dstMonth + " " + dstYear; - } + function monthYear2Thai(month: number, year: number, isFullMonth = false) { + const date = new Date(`${year}-${month + 1}-1`) + const fullMonthThai = ["มกราคม", "กุมภาพันธ์", "มีนาคม", "เมษายน", "พฤษภาคม", "มิถุนายน", "กรกฎาคม", "สิงหาคม", "กันยายน", "ตุลาคม", "พฤศจิกายน", "ธันวาคม"] + const abbrMonthThai = ["ม.ค.", "ก.พ.", "มี.ค.", "เม.ย.", "พ.ค.", "มิ.ย.", "ก.ค.", "ส.ค.", "ก.ย.", "ต.ค.", "พ.ย.", "ธ.ค."] + let dstYear = 0 + if (date.getFullYear() > 2500) { + dstYear = date.getFullYear() + } else { + dstYear = date.getFullYear() + 543 + } + let dstMonth = "" + if (isFullMonth) { + dstMonth = fullMonthThai[date.getMonth()] + } else { + dstMonth = abbrMonthThai[date.getMonth()] + } + return dstMonth + " " + dstYear + } - function dateToISO(date: Date) { - return ( - date.getFullYear() + - "-" + - appendLeadingZeroes(date.getMonth() + 1) + - "-" + - appendLeadingZeroes(date.getDate()) - ); - } + function dateToISO(date: Date) { + return date.getFullYear() + "-" + appendLeadingZeroes(date.getMonth() + 1) + "-" + appendLeadingZeroes(date.getDate()) + } - function appendLeadingZeroes(n: Number) { - if (n <= 9) return "0" + n; - return n; - } + function appendLeadingZeroes(n: Number) { + if (n <= 9) return "0" + n + return n + } - function textToPhone(n: string) { - const p = n.substr(0, 3) + "-" + n.substr(3, 3) + "-" + n.substr(6, 4); - return p; - } + function textToPhone(n: string) { + const p = n.substr(0, 3) + "-" + n.substr(3, 3) + "-" + n.substr(6, 4) + return p + } - function textToFax(n: string) { - const p = n.substr(0, 2) + "-" + n.substr(2, 3) + "-" + n.substr(5, 4); - return p; - } + function textToFax(n: string) { + const p = n.substr(0, 2) + "-" + n.substr(2, 3) + "-" + n.substr(5, 4) + return p + } - const success = (q: any, val: string) => { - // useQuasar ไม่สามารถใช้นอกไฟล์ .vue - if (val !== "") { - return q.notify({ - message: val, - color: "primary", - icon: "mdi-information", - position: "bottom-right", - multiLine: true, - timeout: 1000, - badgeColor: "positive", - classes: "my-notif-class", - }); - } - }; + const success = (q: any, val: string) => { + // useQuasar ไม่สามารถใช้นอกไฟล์ .vue + if (val !== "") { + return q.notify({ + message: val, + color: "primary", + icon: "mdi-information", + position: "bottom-right", + multiLine: true, + timeout: 1000, + badgeColor: "positive", + classes: "my-notif-class", + }) + } + } - function notify(q: any, val: string) { - if (val !== "") { - q.notify({ - color: "teal-10", - message: val, - icon: "mdi-information", - position: "bottom-right", - multiLine: true, - timeout: 7000, - actions: [{ label: "ปิด", color: "white", handler: () => {} }], - }); - } - } - function notifyError(q: any, val: string) { - if (val !== "") { - q.notify({ - color: "negative", - message: val, - icon: "mdi-alert-circle", - position: "top", - multiLine: true, - timeout: 12000, - actions: [{ label: "ปิด", color: "white", handler: () => {} }], - }); - } - } + const fails = (q: any, val: string) => { + // useQuasar ไม่สามารถใช้นอกไฟล์ .vue + if (val !== "") { + return q.notify({ + message: val, + color: "red", + icon: "mdi-information", + position: "bottom-right", + multiLine: true, + timeout: 1000, + badgeColor: "positive", + classes: "my-notif-class", + }) + } + } - const messageError = (q: any, e: any = "") => { - if (e.response !== undefined) { - if (e.response.data.status !== undefined) { - if (e.response.data.status == 401) { - //invalid_token - q.dialog({ - component: CustomComponent, - componentProps: { - title: `พบข้อผิดพลาด`, - message: `ล็อกอินหมดอายุ กรุณาล็อกอินใหม่อีกครั้ง`, - icon: "warning", - color: "red", - onlycancel: true, - }, - }); - } else { - q.dialog({ - component: CustomComponent, - componentProps: { - title: `พบข้อผิดพลาด`, - message: `${e.response.data.message}`, - icon: "warning", - color: "red", - onlycancel: true, - }, - }); - } - } else { - if (e.response.status == 401) { - //invalid_token - q.dialog({ - component: CustomComponent, - componentProps: { - title: `พบข้อผิดพลาด`, - message: `ล็อกอินหมดอายุ กรุณาล็อกอินใหม่อีกครั้ง`, - icon: "warning", - color: "red", - onlycancel: true, - }, - }); - } else { - q.dialog({ - component: CustomComponent, - componentProps: { - title: `พบข้อผิดพลาด`, - message: `ข้อมูลผิดพลาดทำให้เกิดการไม่ตอบสนองต่อการเรียกใช้งานดูเว็บไซต์`, - icon: "warning", - color: "red", - onlycancel: true, - }, - }); - } - } - } else { - q.dialog({ - component: CustomComponent, - componentProps: { - title: `พบข้อผิดพลาด`, - message: `ข้อมูลผิดพลาดทำให้เกิดการไม่ตอบสนองต่อการเรียกใช้งานดูเว็บไซต์`, - icon: "warning", - color: "red", - onlycancel: true, - }, - }); - } - }; + function notify(q: any, val: string) { + if (val !== "") { + q.notify({ + color: "teal-10", + message: val, + icon: "mdi-information", + position: "bottom-right", + multiLine: true, + timeout: 7000, + actions: [{ label: "ปิด", color: "white", handler: () => {} }], + }) + } + } + function notifyError(q: any, val: string) { + if (val !== "") { + q.notify({ + color: "negative", + message: val, + icon: "mdi-alert-circle", + position: "top", + multiLine: true, + timeout: 12000, + actions: [{ label: "ปิด", color: "white", handler: () => {} }], + }) + } + } - const dialogMessage = ( - // ไม่เอาใส่ undefined - q: any, - title: string | undefined, - message: string | undefined, - icon: string | undefined, - textOk: string | undefined, - color: string | undefined, - ok?: Function | undefined, - cancel?: Function | undefined, - onlycancel: Boolean = false - ) => { - q.dialog({ - component: CustomComponent, - componentProps: { - title: title, - message: message, - icon: icon, - color: color, - textOk: textOk, - onlycancel: onlycancel, - }, - }) - .onOk(() => { - if (ok != undefined) ok(); - }) - .onCancel(() => { - if (cancel != undefined) cancel(); - }); - }; + const messageError = (q: any, e: any = "") => { + if (e.response !== undefined) { + if (e.response.data.status !== undefined) { + if (e.response.data.status == 401) { + //invalid_token + q.dialog({ + component: CustomComponent, + componentProps: { + title: `พบข้อผิดพลาด`, + message: `ล็อกอินหมดอายุ กรุณาล็อกอินใหม่อีกครั้ง`, + icon: "warning", + color: "red", + onlycancel: true, + }, + }) + } else { + q.dialog({ + component: CustomComponent, + componentProps: { + title: `พบข้อผิดพลาด`, + message: `${e.response.data.message}`, + icon: "warning", + color: "red", + onlycancel: true, + }, + }) + } + } else { + if (e.response.status == 401) { + //invalid_token + q.dialog({ + component: CustomComponent, + componentProps: { + title: `พบข้อผิดพลาด`, + message: `ล็อกอินหมดอายุ กรุณาล็อกอินใหม่อีกครั้ง`, + icon: "warning", + color: "red", + onlycancel: true, + }, + }) + } else { + q.dialog({ + component: CustomComponent, + componentProps: { + title: `พบข้อผิดพลาด`, + message: `ข้อมูลผิดพลาดทำให้เกิดการไม่ตอบสนองต่อการเรียกใช้งานดูเว็บไซต์`, + icon: "warning", + color: "red", + onlycancel: true, + }, + }) + } + } + } else { + q.dialog({ + component: CustomComponent, + componentProps: { + title: `พบข้อผิดพลาด`, + message: `ข้อมูลผิดพลาดทำให้เกิดการไม่ตอบสนองต่อการเรียกใช้งานดูเว็บไซต์`, + icon: "warning", + color: "red", + onlycancel: true, + }, + }) + } + } - const showLoader = () => { - Loading.show({ - spinner: QSpinnerCube, - spinnerSize: 140, - spinnerColor: "primary", - backgroundColor: "white", - }); - }; + const dialogMessage = ( + // ไม่เอาใส่ undefined + q: any, + title: string | undefined, + message: string | undefined, + icon: string | undefined, + textOk: string | undefined, + color: string | undefined, + ok?: Function | undefined, + cancel?: Function | undefined, + onlycancel: Boolean = false + ) => { + q.dialog({ + component: CustomComponent, + componentProps: { + title: title, + message: message, + icon: icon, + color: color, + textOk: textOk, + onlycancel: onlycancel, + }, + }) + .onOk(() => { + if (ok != undefined) ok() + }) + .onCancel(() => { + if (cancel != undefined) cancel() + }) + } - const hideLoader = () => { - Loading.hide(); - }; + const showLoader = () => { + Loading.show({ + spinner: QSpinnerCube, + spinnerSize: 140, + spinnerColor: "primary", + backgroundColor: "white", + }) + } - function modalDelete( - q: any, - title: string, - message: string, - ok: Function, - cancel?: Function - ) { - q.dialog({ - title: `${title}`, - message: `${message}`, - cancel: { - flat: true, - color: "grey-14", - }, - ok: { - color: "red-6", - }, - focus: "none", - persistent: true, - html: true, - }) - .onOk(() => { - ok(); - }) - .onCancel(() => { - if (cancel != undefined) cancel(); - }) - .onDismiss(() => {}); - } + const hideLoader = () => { + Loading.hide() + } - function modalConfirm( - q: any, - title: string, - message: string, - ok: Function, - cancel?: Function - ) { - q.dialog({ - title: `${title}`, - message: `${message}`, - cancel: { - flat: true, - color: "grey", - }, - ok: { - color: "primary", - }, - focus: "none", - persistent: true, - html: true, - }) - .onOk(() => { - ok(); - }) - .onCancel(() => { - if (cancel != undefined) cancel(); - }) - .onDismiss(() => {}); - } + function modalDelete(q: any, title: string, message: string, ok: Function, cancel?: Function) { + q.dialog({ + title: `${title}`, + message: `${message}`, + cancel: { + flat: true, + color: "grey-14", + }, + ok: { + color: "red-6", + }, + focus: "none", + persistent: true, + html: true, + }) + .onOk(() => { + ok() + }) + .onCancel(() => { + if (cancel != undefined) cancel() + }) + .onDismiss(() => {}) + } - function modalWarning(q: any, title: string, message: string, ok?: Function) { - // q.dialog({ - // title: `${title}`, - // message: `${message}`, - // ok: { - // push: true, - // color: "primary", - // }, - // focus: "none", - // persistent: true, - // html: true, - // }) - // .onOk(() => { - // if (ok != undefined) ok(); - // }) - // .onCancel(() => {}) - // .onDismiss(() => {}); + function modalConfirm(q: any, title: string, message: string, ok: Function, cancel?: Function) { + q.dialog({ + title: `${title}`, + message: `${message}`, + cancel: { + flat: true, + color: "grey", + }, + ok: { + color: "primary", + }, + focus: "none", + persistent: true, + html: true, + }) + .onOk(() => { + ok() + }) + .onCancel(() => { + if (cancel != undefined) cancel() + }) + .onDismiss(() => {}) + } - q.dialog({ - component: CustomComponent, - componentProps: { - title: title, - message: message, - icon: "warning", - color: "warning", - onlycancel: true, - }, - }); - } + function modalWarning(q: any, title: string, message: string, ok?: Function) { + // q.dialog({ + // title: `${title}`, + // message: `${message}`, + // ok: { + // push: true, + // color: "primary", + // }, + // focus: "none", + // persistent: true, + // html: true, + // }) + // .onOk(() => { + // if (ok != undefined) ok(); + // }) + // .onCancel(() => {}) + // .onDismiss(() => {}); - function modalError(q: any, title: string, message: string, ok?: Function) { - // q.dialog({ - // title: `${title}`, - // message: `${message}`, - // ok: { - // push: true, - // color: "primary", - // }, - // focus: "none", - // persistent: true, - // html: true, - // }) - // .onOk(() => { - // if (ok != undefined) ok(); - // }) - // .onCancel(() => {}) - // .onDismiss(() => {}); + q.dialog({ + component: CustomComponent, + componentProps: { + title: title, + message: message, + icon: "warning", + color: "warning", + onlycancel: true, + }, + }) + } - q.dialog({ - component: CustomComponent, - componentProps: { - title: title, - message: message, - icon: "warning", - color: "red", - onlycancel: true, - }, - }); - } + function modalError(q: any, title: string, message: string, ok?: Function) { + // q.dialog({ + // title: `${title}`, + // message: `${message}`, + // ok: { + // push: true, + // color: "primary", + // }, + // focus: "none", + // persistent: true, + // html: true, + // }) + // .onOk(() => { + // if (ok != undefined) ok(); + // }) + // .onCancel(() => {}) + // .onDismiss(() => {}); - const dateText = (val: Date) => { - if (val != null) { - return date2Thai(val); - } else { - return "-"; - } - }; + q.dialog({ + component: CustomComponent, + componentProps: { + title: title, + message: message, + icon: "warning", + color: "red", + onlycancel: true, + }, + }) + } - /** - * แปลงช่วงวันที่ถ้า2ค่าเป็นวันเดียวกันจะโชววันเดียวแต่ถ้าไม่เท่ากันจะแสดงเป็นช่วง - * @param val ช่วงวันที่ - */ - const dateThaiRange = (val: [Date, Date]) => { - if (val === null) { - return ""; - } else if (date2Thai(val[0]) === date2Thai(val[1])) { - return `${date2Thai(val[0])}`; - } else { - return `${date2Thai(val[0])} - ${date2Thai(val[1])}`; - } - }; + const dateText = (val: Date) => { + if (val != null) { + return date2Thai(val) + } else { + return "-" + } + } - const weekThai = (val: Number) => { - switch (val) { - case 0: - return "วันอาทิตย์"; - case 1: - return "วันจันทร์"; - case 2: - return "วันอังคาร"; - case 3: - return "วันพุธ"; - case 4: - return "วันพฤหัสบดี"; - case 5: - return "วันศุกร์"; - case 6: - return "วันเสาร์"; - default: - return "-"; - } - }; + /** + * แปลงช่วงวันที่ถ้า2ค่าเป็นวันเดียวกันจะโชววันเดียวแต่ถ้าไม่เท่ากันจะแสดงเป็นช่วง + * @param val ช่วงวันที่ + */ + const dateThaiRange = (val: [Date, Date]) => { + if (val === null) { + return "" + } else if (date2Thai(val[0]) === date2Thai(val[1])) { + return `${date2Thai(val[0])}` + } else { + return `${date2Thai(val[0])} - ${date2Thai(val[1])}` + } + } - const genColor15 = (val: number) => { - val = val % 15; - switch (val) { - case 1: - return "pink"; - case 2: - return "purple"; - case 3: - return "deep-purple"; - case 4: - return "indigo"; - case 5: - return "blue"; - case 6: - return "light-blue"; - case 7: - return "cyan"; - case 8: - return "teal"; - case 9: - return "green"; - case 10: - return "light-green"; - case 11: - return "amber"; - case 12: - return "orange"; - case 13: - return "deep-orange"; - case 14: - return "brown"; - case 0: - return "blue-grey"; - default: - return ""; - } - }; + const weekThai = (val: Number) => { + switch (val) { + case 0: + return "วันอาทิตย์" + case 1: + return "วันจันทร์" + case 2: + return "วันอังคาร" + case 3: + return "วันพุธ" + case 4: + return "วันพฤหัสบดี" + case 5: + return "วันศุกร์" + case 6: + return "วันเสาร์" + default: + return "-" + } + } - const typeCategoryExam = (val: string) => { - switch (val) { - case "hygiene": - return "สำนักอนามัย"; - case "physician": - return "สำนักการแพทย์"; - case "city": - return "สำนักผังเมือง"; - case "culture": - return "สำนักวัฒนธรรม กีฬา และการท่องเที่ยว"; - default: - return "-"; - } - }; + const genColor15 = (val: number) => { + val = val % 15 + switch (val) { + case 1: + return "pink" + case 2: + return "purple" + case 3: + return "deep-purple" + case 4: + return "indigo" + case 5: + return "blue" + case 6: + return "light-blue" + case 7: + return "cyan" + case 8: + return "teal" + case 9: + return "green" + case 10: + return "light-green" + case 11: + return "amber" + case 12: + return "orange" + case 13: + return "deep-orange" + case 14: + return "brown" + case 0: + return "blue-grey" + default: + return "" + } + } - const typeRetire = (val: string) => { - switch (val) { - case "retire": - return "เกษียณอายุราชการ"; - case "resign": - return "ลาออก"; - case "transfer": - return "ให้โอน"; - case "death": - return "ถึงแก่กรรม"; - case "layoff": - return "ให้ออก"; - case "discharge": - return "ปลดออก"; - case "dismiss": - return "ไล่ออก"; - case "other": - return "อื่นๆ"; - default: - return "-"; - } - }; + const typeCategoryExam = (val: string) => { + switch (val) { + case "hygiene": + return "สำนักอนามัย" + case "physician": + return "สำนักการแพทย์" + case "city": + return "สำนักผังเมือง" + case "culture": + return "สำนักวัฒนธรรม กีฬา และการท่องเที่ยว" + default: + return "-" + } + } - const typeChangeName = (val: string) => { - switch (val) { - case "firstName": - return "เปลี่ยนชื่อ"; - case "lastName": - return "เปลี่ยนนามสกุล"; - case "all": - return "เปลี่ยนชื่อ-นามสกุล"; - default: - return "-"; - } - }; + const typeRetire = (val: string) => { + switch (val) { + case "retire": + return "เกษียณอายุราชการ" + case "resign": + return "ลาออก" + case "transfer": + return "ให้โอน" + case "death": + return "ถึงแก่กรรม" + case "layoff": + return "ให้ออก" + case "discharge": + return "ปลดออก" + case "dismiss": + return "ไล่ออก" + case "other": + return "อื่นๆ" + default: + return "-" + } + } - const statusLeave = (val: string) => { - switch (val) { - case "waitting": - return "รออนุมัติ"; - case "reject": - return "ไม่ผ่านการอนุมัติ"; - case "approve": - return "ผ่านการอนุมัติ"; - case "cancel": - return "ยกเลิก"; - default: - return "-"; - } - }; + const typeChangeName = (val: string) => { + switch (val) { + case "firstName": + return "เปลี่ยนชื่อ" + case "lastName": + return "เปลี่ยนนามสกุล" + case "all": + return "เปลี่ยนชื่อ-นามสกุล" + default: + return "-" + } + } - return { - calAge, - date2Thai, - dateToISO, - notify, - notifyError, - dateText, - monthYear2Thai, - dateMonth2Thai, - success, - weekThai, - genColor15, - typeCategoryExam, - textToPhone, - textToFax, - dateThaiRange, - modalDelete, - modalConfirm, - modalError, - dialogMessage, - messageError, - showLoader, - hideLoader, - typeRetire, - typeChangeName, - statusLeave, - modalWarning, - }; -}); + const statusLeave = (val: string) => { + switch (val) { + case "waitting": + return "รออนุมัติ" + case "reject": + return "ไม่ผ่านการอนุมัติ" + case "approve": + return "ผ่านการอนุมัติ" + case "cancel": + return "ยกเลิก" + default: + return "-" + } + } + + return { + calAge, + date2Thai, + dateToISO, + notify, + notifyError, + dateText, + monthYear2Thai, + dateMonth2Thai, + success, + weekThai, + genColor15, + typeCategoryExam, + textToPhone, + textToFax, + dateThaiRange, + modalDelete, + modalConfirm, + modalError, + dialogMessage, + messageError, + showLoader, + hideLoader, + typeRetire, + typeChangeName, + statusLeave, + modalWarning, + fails, + } +})