Refactoring code module 03_retire

This commit is contained in:
STW_TTTY\stwtt 2024-09-03 11:48:07 +07:00
parent 9fbbbd753f
commit 763ec2fd95
6 changed files with 171 additions and 224 deletions

View file

@ -0,0 +1,63 @@
interface QuestionDescription {
question1Desc: string;
question2Desc: string;
question3Desc: string;
question4Desc: string;
question5Desc: string;
question6Desc: string;
question7Desc: string;
question8Desc: string;
question9Desc: string;
question10Desc: string;
[key: string]: string;
}
interface OptionQuestions {
label: string;
value: number;
}
interface OptionQuestions2 {
label: string;
value: boolean;
}
interface MainList {
id: string;
location: string;
sendDate: string;
activeDate: string;
reason: string;
approveReason: string | null;
rejectReason: string | null;
status: string;
isActive: boolean;
}
interface MainList {
id: string;
placeLeave: string;
dateStartLeave: string;
dateLeave: string;
status: string;
statustext: string;
}
interface MainListResponse {
id: string;
location: string;
sendDate: Date | null;
activeDate: Date | null;
reason: string;
approveReason: string | null;
rejectReason: string | null;
status: string;
isActive: boolean;
}
export type {
QuestionDescription,
OptionQuestions,
OptionQuestions2,
MainList,
MainListResponse,
};

View file

@ -1,24 +0,0 @@
interface QuestionDescription {
question1Desc: string;
question2Desc: string;
question3Desc: string;
question4Desc: string;
question5Desc: string;
question6Desc: string;
question7Desc: string;
question8Desc: string;
question9Desc: string;
question10Desc: string;
[key: string]: string;
}
interface OptionQuestions {
label: string;
value: number;
}
interface OptionQuestions2 {
label: string;
value: boolean;
}
export type { QuestionDescription, OptionQuestions, OptionQuestions2 };

View file

@ -2,40 +2,39 @@
import { ref, defineModel } from "vue";
import { useQuasar } from "quasar";
import { useRoute } from "vue-router";
import http from "@/plugins/http";
import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
/** importCompouents*/
import Header from "@/components/DialogHeader.vue";
/** importStore*/
import { useCounterMixin } from "@/stores/mixin";
/** use*/
const $q = useQuasar();
const route = useRoute();
const mixin = useCounterMixin();
const { dialogConfirm, messageError, showLoader, hideLoader, success } = mixin;
const id = ref<string>(route.params.id ? route.params.id.toString() : "");
const modal = defineModel<boolean>("modal", { required: true });
const props = defineProps({
fectData: { type: Function, require: true },
});
const id = ref<string>(route.params.id ? route.params.id.toString() : "");
const mixin = useCounterMixin();
const { dialogConfirm, messageError, showLoader, hideLoader, success } = mixin;
const reason = ref<string>("");
const reason = ref<string>(""); //
/*** ฟังก์ชั่นสำหรับ validate ฟอร์ม */
function validateForm() {
onSubmit();
}
/** ปิด dialog */
function close() {
modal.value = false;
reason.value = "";
}
/** save data */
function onSubmit() {
dialogConfirm(
$q,
@ -89,7 +88,6 @@ function onSubmit() {
<q-separator />
<q-card-actions align="right" class="bg-white text-teal">
<!-- <q-btn flat label="OK" v-close-popup /> -->
<q-btn
type="submit"
for="#submitForm"

View file

@ -1,13 +1,19 @@
<script setup lang="ts">
import { ref, onMounted } from "vue";
import { useQuasar } from "quasar";
import type { QForm } from "quasar";
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";
import { useCounterMixin } from "@/stores/mixin";
import Dialog from "@/modules/03_retire/views/DialogRetire.vue";
const $q = useQuasar();
const route = useRoute();
const router = useRouter();
const routeName = router.currentRoute.value.name;
const mixin = useCounterMixin();
const {
date2Thai,
@ -18,21 +24,15 @@ const {
hideLoader,
dialogConfirm,
} = mixin;
const router = useRouter();
const route = useRoute();
const $q = useQuasar();
const routeName = router.currentRoute.value.name;
/**
* วแปรทใชงาน
*/
const id = ref<string>("");
const myform = ref<QForm | null>(null);
const tranferOrg = ref("");
const dateCommand = ref<Date>(new Date());
const dateLeave = ref<Date>(new Date());
const noteReason = ref("");
const modal = ref<boolean>(false);
const id = ref<string>(""); // id path
const myform = ref<QForm | null>(null); //form
const tranferOrg = ref(""); //
const dateCommand = ref<Date>(new Date()); //
const dateLeave = ref<Date>(new Date()); //
const noteReason = ref(""); //
const modal = ref<boolean>(false); // dialog
/** ข้อมูล v-model ของฟอร์ม */
const dataDetail = ref<any>({
datetext: "",
@ -57,40 +57,23 @@ const dataDetail = ref<any>({
fullname: "",
});
/**
* งกนยอนกลบไปยงหนารายการลาออก
*/
const clickBack = () => {
router.push(`/retire`);
};
/**
* งกนเปลยนเป string ของ status
* @param val value ของ status true/false
*/
const statusOrder = (val: boolean) => {
function statusOrder(val: boolean) {
switch (val) {
case true:
return "ยับยั้ง";
case false:
return "อนุญาต";
}
};
/**
* เรยกฟงกนทงหมดตอนเรยกใชไฟล
*/
onMounted(() => {
if (route.params.id !== undefined) {
id.value = route.params.id.toString();
fectDataresign(id.value);
}
});
}
/**
* นทกขอมลการลาออก
*/
const onSubmit = async () => {
async function onSubmit() {
dialogConfirm(
$q,
() => {
@ -119,21 +102,21 @@ const onSubmit = async () => {
"ยืนยันการยื่นข้อมูลลาออก",
"ต้องการยื่นข้อมูลลาออกนี้ใช่หรือไม่"
);
};
}
const files = ref<any>();
const checkCancleLeave = ref<boolean>(false);
//
const cancelResing = () => {
function cancelResing() {
modal.value = true;
};
}
const checkCancleLeave = ref<boolean>(false);
/**
* งกนเรยกขอมลจาก Api
* @param id ไอดของขอม
*/
const fectDataresign = async (id: string) => {
async function fectDataresign(id: string) {
showLoader();
await http
.get(config.API.resingByid(id))
@ -158,11 +141,24 @@ const fectDataresign = async (id: string) => {
.finally(() => {
hideLoader();
});
};
}
/**
* เป tab ใหม
* @param data path file
*/
function downloadFile(data: string) {
window.open(data, "_blank");
}
/**
* เรยกฟงกนทงหมดตอนเรยกใชไฟล
*/
onMounted(() => {
if (route.params.id !== undefined) {
id.value = route.params.id.toString();
fectDataresign(id.value);
}
});
</script>
<template>
<div class="col-12 row justify-center">

View file

@ -1,21 +1,28 @@
<script setup lang="ts">
import type { QTableProps } from "quasar";
import { ref, onMounted } from "vue";
import { ref, onMounted, onBeforeMount } from "vue";
import { useQuasar } from "quasar";
import { useRouter } from "vue-router";
import { useCounterMixin } from "@/stores/mixin";
import http from "@/plugins/http";
import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
import { useRestDataStore } from "@/modules/03_retire/store";
import Table from "@/components/Table.vue";
const RestData = useRestDataStore();
const { statusText } = RestData;
const router = useRouter();
import type {
MainList,
MainListResponse,
} from "@/modules/03_retire/interface/Main";
const $q = useQuasar();
const router = useRouter();
const mixin = useCounterMixin();
const { date2Thai, messageError, showLoader, hideLoader } = mixin;
const RestData = useRestDataStore();
const { statusText } = RestData; //Func status to text
const rows = ref<MainList[]>([]);
const filter = ref<string>("");
const pagination = ref({
sortBy: "desc",
descending: false,
@ -23,11 +30,6 @@ const pagination = ref({
rowsPerPage: 10,
});
/**
* เพมหวขอตาราง
*/
const rows = ref<any>([]);
const filter = ref<string>("");
const visibleColumns = ref<String[]>([
"no",
"placeLeave",
@ -35,6 +37,7 @@ const visibleColumns = ref<String[]>([
"dateLeave",
"statustext",
]);
const columns = ref<QTableProps["columns"]>([
{
name: "no",
@ -83,28 +86,13 @@ const columns = ref<QTableProps["columns"]>([
},
]);
/**
* งค pagination
*/
const initialPagination = ref({
rowsPerPage: 0,
});
/**
* เรยกฟงกนทงหมดตอนเรยกใชไฟล
*/
onMounted(() => {
fectListleave();
});
//
const fectListleave = async () => {
showLoader();
/** ดึงข้อมูล */
async function fectListleave() {
await http
.get(config.API.listUser())
.then((res: any) => {
let data = res.data.result;
rows.value = data.map((e: any) => ({
.then(async (res) => {
let data = await res.data.result;
rows.value = data.map((e: MainListResponse) => ({
id: e.id,
placeLeave: e.location,
dateStartLeave: date2Thai(e.sendDate),
@ -116,41 +104,33 @@ const fectListleave = async () => {
.catch((e: any) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
};
.finally(() => {});
}
/**
* งกนกดเพมไปหนาเพมลาออก
*/
const clickAdd = async () => {
async function clickAdd() {
router.push(`/retire/add`);
};
}
/** ทำก่อน mounted */
onBeforeMount(() => {
showLoader();
});
/**
* กดเพอยอนกล
* เรยกฟงกนทงหมดตอนเรยกใชไฟล
*/
const clickBack = () => {
router.push(`/`);
};
onMounted(async () => {
await fectListleave();
hideLoader();
});
</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="clickBack"
/> -->
ขอลาออก
</div>
<div class="toptitle text-white col-12 row items-center">ขอลาออก</div>
<div class="col-12">
<q-card bordered class="q-pa-md">
<div class="q-pb-sm row">

View file

@ -1,20 +1,21 @@
<script setup lang="ts">
import { ref, reactive, onMounted } from "vue";
import { ref, onMounted } from "vue";
import { useQuasar } from "quasar";
import { useRouter, useRoute } from "vue-router";
import { useCounterMixin } from "@/stores/mixin";
import http from "@/plugins/http";
import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
import type {
QuestionDescription,
OptionQuestions,
OptionQuestions2,
} from "@/modules/03_retire/interface/request/Main";
} from "@/modules/03_retire/interface/Main";
const $q = useQuasar();
const route = useRoute();
const router = useRouter();
const $q = useQuasar();
const mixin = useCounterMixin();
const {
success,
@ -29,100 +30,25 @@ const dataId = ref<any>(route.params.id.toString());
/**
* วแปรแบบสอบถาม
*/
const realReason = ref<string>("");
const notExitFactor = ref<string>("");
const suggestion = ref<string>("");
/** check box */
const exitFactor = ref<any>([]);
const reasonWork = ref<any>([]);
const adjust = ref<any>([]);
const timeThink = ref<any>();
const realReason = ref<any>("");
const notExitFactor = ref<any>("");
const haveJob = ref<any>();
const suggestFriends = ref<any>();
const futureWork = ref<any>();
const suggestion = ref<any>("");
const reasonWorkOther = ref("");
// const reasonWork_option = ref<any>([
// { label: " ", value: 0 },
// { label: "/", value: 1 },
// { label: " ", value: 2 },
// { label: " ", value: 3 },
// { label: " ", value: 4 },
// { label: " ", value: 5 },
// { label: "", value: 6 },
// { label: " ", value: 7 },
// { label: " ", value: 8 },
// { label: " ", value: 9 },
// { label: " ", value: 10 },
// { label: " ", value: 11 },
// { label: " () ", value: 12 },
// ]);
const exitFactorOther = ref("");
// const exitFactor_option = ref<any>([
// { label: " ", value: 0 },
// { label: "", value: 1 },
// { label: " ", value: 2 },
// { label: " ", value: 3 },
// { label: " ", value: 4 },
// { label: " ", value: 5 },
// { label: "", value: 6 },
// { label: " ", value: 7 },
// { label: " ", value: 8 },
// { label: " ", value: 9 },
// { label: " ", value: 10 },
// { label: " ", value: 11 },
// { label: " ", value: 12 },
// { label: " ", value: 13 },
// { label: " ", value: 14 },
// { label: " () ", value: 15 },
// ]);
const suggestFriendsReason = ref("");
// const suggestFriends_option = ref<any>([
// { label: " ", value: 0 },
// { label: " ()", value: 1 },
// ]);
// const timeThink_option = ref<any>([
// { label: " 2 ", value: 0 },
// { label: "1 - 3 ", value: 1 },
// { label: "3 - 6 ", value: 2 },
// { label: "6 ", value: 3 },
// ]);
const haveJobReason = ref<any>("");
// const haveJob_option = ref<any>([
// { label: " ()", value: 0 },
// { label: "", value: 1 },
// ]);
const futureWorkReason = ref<any>("");
// const futureWork_option = ref<any>([
// { label: "", value: 0 },
// { label: " ()", value: 1 },
// ]);
const adjustOther = ref("");
// const adjust_option = ref<any>([
// { label: " ", value: 0 },
// { label: "", value: 1 },
// { label: " ", value: 2 },
// { label: " ", value: 3 },
// { label: " ", value: 4 },
// { label: " ", value: 5 },
// { label: "", value: 6 },
// { label: " ", value: 7 },
// { label: " ", value: 8 },
// { label: " ", value: 9 },
// { label: " ", value: 10 },
// { label: " ", value: 11 },
// { label: " ", value: 12 },
// { label: " ", value: 13 },
// { label: " ", value: 14 },
// { label: " () ", value: 15 },
// ]);
/**
* เรยกฟงกนทงหมดตอนเรยกใชไฟล
*/
onMounted(async () => {
showLoader();
await fecthQuestion();
});
const reasonWorkOther = ref<string>("");
const exitFactorOther = ref<string>("");
const suggestFriendsReason = ref<string>("");
const haveJobReason = ref<string>("");
const futureWorkReason = ref<string>("");
const adjustOther = ref<string>("");
//
//
@ -226,7 +152,7 @@ async function fecthQuestion() {
/**
* นทกเเบบสอบถาม
*/
const saveForm = () => {
function saveForm() {
let hasError = false;
if (
reasonWork.value.length === 0 ||
@ -267,12 +193,12 @@ const saveForm = () => {
if (hasError === true) {
notifyError($q, "กรุณากรอกข้อมูลให้ครบ");
}
};
}
/**
* สรางเบบสอบถามไปย api
*/
const createResult = async () => {
async function createResult() {
const data = {
RetirementResignId: dataId.value,
ReasonWork: reasonWork.value,
@ -301,7 +227,15 @@ const createResult = async () => {
.catch((e: any) => {
messageError($q, e);
});
};
}
/**
* เรยกฟงกนทงหมดตอนเรยกใชไฟล
*/
onMounted(async () => {
showLoader();
await fecthQuestion();
});
</script>
<template>