Refactoring code module 13_salary
This commit is contained in:
parent
c9dd0202c6
commit
4af366c03b
43 changed files with 1215 additions and 1167 deletions
537
src/modules/13_salary/components/01_Salary/DialogFormMain.vue
Normal file
537
src/modules/13_salary/components/01_Salary/DialogFormMain.vue
Normal file
|
|
@ -0,0 +1,537 @@
|
|||
<script setup lang="ts">
|
||||
import { computed, ref, reactive, watch } from "vue";
|
||||
import { useQuasar } from "quasar";
|
||||
import http from "@/plugins/http";
|
||||
import config from "@/app.config";
|
||||
|
||||
import type {
|
||||
DataOption,
|
||||
FormData,
|
||||
} from "@/modules/13_salary/interface/index/Main";
|
||||
import type {
|
||||
SalaryPosType,
|
||||
SalaryPosLevel,
|
||||
} from "@/modules/13_salary/interface/response/Main";
|
||||
|
||||
import Header from "@/components/DialogHeader.vue";
|
||||
|
||||
import { useCounterMixin } from "@/stores/mixin";
|
||||
|
||||
const isReadonly = ref<boolean>(false);
|
||||
const $q = useQuasar();
|
||||
const {
|
||||
date2Thai,
|
||||
dialogConfirm,
|
||||
showLoader,
|
||||
hideLoader,
|
||||
messageError,
|
||||
success,
|
||||
} = useCounterMixin();
|
||||
|
||||
const modal = defineModel<boolean>("modal", { required: true });
|
||||
const props = defineProps({
|
||||
typeAction: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
data: {
|
||||
type: Object,
|
||||
defult: [],
|
||||
},
|
||||
fetchData: {
|
||||
type: Function,
|
||||
defult: () => {},
|
||||
},
|
||||
});
|
||||
|
||||
const salaryId = ref<string>(""); //id รายการผังบัญชีเงินเดือน
|
||||
const formData = reactive<FormData>({
|
||||
name: "", //*ชื่อผังบัญชีอัตราเงินเดือน
|
||||
posTypeId: "", //*ประเภทของตำแหน่ง
|
||||
posLevelId: "", //*ระดับของตำแหน่ง
|
||||
isActive: false, //*สถานะการใช้งาน
|
||||
date: null, //ให้ไว้ ณ วันที่
|
||||
startDate: null, //วันที่มีผลบังคับใช้
|
||||
endDate: null, //วันที่สิ้นสุดบังคับใช้
|
||||
details: "", //คำอธิบาย
|
||||
isSpecial: false,
|
||||
});
|
||||
|
||||
const posType = ref<SalaryPosType[]>([]); //ข้อมูลประเภทตำแหน่ง
|
||||
const salaryPosTypeOptionMain = ref<DataOption[]>([]); //ข้อมูลรายการประเภทตำแหน่ง
|
||||
const salaryPosTypeOption = ref<DataOption[]>([]); //ตัวเลือกรายการประเภทตำแหน่ง
|
||||
const salaryPosLevelOptionMain = ref<DataOption[]>([]); //ข้อมูลรายการระดับตำแหน่ง
|
||||
const salaryPosLevelOption = ref<DataOption[]>([]); //ตัวเลือกรายการระดับตำแหน่ง
|
||||
|
||||
//ชื่อ popup
|
||||
const title = computed(() => {
|
||||
const name =
|
||||
props.typeAction === "add"
|
||||
? "เพิ่มผังบัญชีเงินเดือน"
|
||||
: props.typeAction === "edit"
|
||||
? "แก้ไขผังบัญชีเงินเดือน"
|
||||
: props.typeAction === "view"
|
||||
? "รายละเอียด"
|
||||
: "บัญชีเงินเดือน";
|
||||
|
||||
return name;
|
||||
});
|
||||
|
||||
/**
|
||||
* fiunction fetch ข้อมูลประเภทตำแหน่ง
|
||||
*/
|
||||
function fetchPosType() {
|
||||
http
|
||||
.get(config.API.salaryPosType)
|
||||
.then((res) => {
|
||||
posType.value = res.data.result;
|
||||
const listOption = res.data.result.map((e: SalaryPosType) => ({
|
||||
id: e.id,
|
||||
name: e.posTypeName,
|
||||
}));
|
||||
salaryPosTypeOption.value = listOption;
|
||||
salaryPosTypeOptionMain.value = listOption;
|
||||
})
|
||||
.catch((err) => {
|
||||
messageError($q, err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* fiunction fetch ข้อมูลระดับตำแหน่ง
|
||||
*/
|
||||
function fetchPosLevel(id: string) {
|
||||
const filterLevel = posType.value.find((e: SalaryPosType) => e.id === id);
|
||||
const listOption =
|
||||
filterLevel?.posLevels.map((e: SalaryPosLevel) => ({
|
||||
id: e.id,
|
||||
name: e.posLevelName,
|
||||
})) || [];
|
||||
|
||||
salaryPosLevelOption.value = listOption;
|
||||
salaryPosLevelOptionMain.value = listOption;
|
||||
if (!listOption.some((e: DataOption) => e.id === formData.posLevelId)) {
|
||||
formData.posLevelId = "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* function fetch ข้อมูลผังบัญชีเงินเดือน
|
||||
* @param id ผังบัญชีเงินเดือน
|
||||
*/
|
||||
function fetchSalaryDetail(id: string) {
|
||||
showLoader();
|
||||
http
|
||||
.get(config.API.salaryChartByid(id))
|
||||
.then(async (res) => {
|
||||
const data = await res.data.result;
|
||||
formData.name = data.name;
|
||||
formData.posTypeId = data.posTypeId;
|
||||
formData.posLevelId = data.posLevelId;
|
||||
formData.isActive = data.isActive;
|
||||
formData.date = data.date;
|
||||
formData.startDate = data.startDate;
|
||||
formData.endDate = data.endDate;
|
||||
formData.details = data.details;
|
||||
formData.isSpecial = data.isSpecial;
|
||||
isReadonly.value = props.typeAction === "view" ? true : data.isActive;
|
||||
})
|
||||
.catch((err) => {
|
||||
messageError($q, err);
|
||||
})
|
||||
.finally(() => {
|
||||
hideLoader();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* callbackFunction ทำการ fetch ข้อมูลไฟล์เมื่อเปิด Dialog
|
||||
*/
|
||||
watch(
|
||||
() => modal.value,
|
||||
async () => {
|
||||
if (modal.value) {
|
||||
fetchPosType();
|
||||
|
||||
if (props.typeAction === "edit" || props.typeAction === "view") {
|
||||
showLoader();
|
||||
setTimeout(() => {
|
||||
if (props.data) {
|
||||
salaryId.value = props.data.id;
|
||||
fetchPosLevel(props?.data?.posTypeId);
|
||||
fetchSalaryDetail(props.data.id);
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* function ปืด Dialog
|
||||
*/
|
||||
function closeDialog() {
|
||||
modal.value = !modal.value;
|
||||
clearFormData();
|
||||
}
|
||||
|
||||
/**
|
||||
* function เคลียข้อมูล form
|
||||
*/
|
||||
function clearFormData() {
|
||||
formData.name = "";
|
||||
formData.posTypeId = "";
|
||||
formData.posLevelId = "";
|
||||
formData.isSpecial = false;
|
||||
formData.isActive = false;
|
||||
formData.date = null;
|
||||
formData.startDate = null;
|
||||
formData.endDate = null;
|
||||
formData.details = "";
|
||||
isReadonly.value = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* function บันทึกข้อมูลผังบัญชีเงินเดือน
|
||||
*/
|
||||
function onSubmit() {
|
||||
dialogConfirm($q, async () => {
|
||||
showLoader();
|
||||
try {
|
||||
const url =
|
||||
props.typeAction === "add"
|
||||
? config.API.salaryChart
|
||||
: config.API.salaryChartByid(salaryId.value);
|
||||
await http[props.typeAction === "add" ? "post" : "put"](url, formData);
|
||||
await props.fetchData?.();
|
||||
await success($q, "บันทีกข้อมูลสำเร็จ");
|
||||
closeDialog();
|
||||
} catch (err) {
|
||||
messageError($q, err);
|
||||
} finally {
|
||||
hideLoader();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* function checkEndDate
|
||||
*/
|
||||
function checkEndDate() {
|
||||
if (formData.endDate !== null && formData.startDate !== null) {
|
||||
if (formData.endDate < formData.startDate) {
|
||||
formData.endDate = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* function ค้นหาคำใน select
|
||||
* @param val คำค้นหา
|
||||
* @param update function
|
||||
* @param type ประเภท select
|
||||
*/
|
||||
function filterSelector(val: string, update: Function, type: string) {
|
||||
switch (type) {
|
||||
case "posType":
|
||||
update(() => {
|
||||
formData.posTypeId = "";
|
||||
salaryPosTypeOption.value = salaryPosTypeOptionMain.value.filter(
|
||||
(v: DataOption) => v.name.toLowerCase().indexOf(val) > -1
|
||||
);
|
||||
});
|
||||
break;
|
||||
case "posLevel":
|
||||
update(() => {
|
||||
formData.posLevelId = "";
|
||||
salaryPosLevelOption.value = salaryPosLevelOptionMain.value.filter(
|
||||
(v: DataOption) => v.name.toLowerCase().indexOf(val) > -1
|
||||
);
|
||||
});
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* class จัดรูปแบบแสดงระหว่างข้อมูลที่แก้ไขหรือแสดงเฉยๆ
|
||||
* @param val ข้อมูล input สำหรับแก้ไขหรือไม่
|
||||
*/
|
||||
const getClass = (val: boolean) => {
|
||||
return {
|
||||
"full-width inputgreen cursor-pointer": val,
|
||||
"full-width cursor-pointer": !val,
|
||||
};
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<q-dialog v-model="modal" persistent>
|
||||
<q-card class="col-12" style="width: 55%">
|
||||
<q-form greedy @submit.prevent @validation-success="onSubmit">
|
||||
<Header :tittle="title" :close="closeDialog" />
|
||||
<q-separator />
|
||||
<q-card-section class="scroll" style="max-height: 70vh">
|
||||
<div class="row col-12 q-col-gutter-sm">
|
||||
<div class="col-md-12">
|
||||
<div class="row col-12 q-col-gutter-sm">
|
||||
<div class="col-xs-12 col-md-4">
|
||||
<q-input
|
||||
:readonly="isReadonly"
|
||||
:class="getClass(!isReadonly)"
|
||||
ref="nameRef"
|
||||
dense
|
||||
hide-bottom-space
|
||||
outlined
|
||||
v-model="formData.name"
|
||||
label="ชื่อผังบัญชีอัตราเงินเดือน"
|
||||
:rules="[
|
||||
(val) => !!val || 'กรุณากรอกชื่อผังบัญชีอัตราเงินเดือน',
|
||||
]"
|
||||
lazy-rules
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="col-xs-12 col-md-4">
|
||||
<q-select
|
||||
:readonly="isReadonly"
|
||||
:class="getClass(!isReadonly)"
|
||||
ref="posTypeRef"
|
||||
dense
|
||||
hide-bottom-space
|
||||
outlined
|
||||
option-label="name"
|
||||
option-value="id"
|
||||
emit-value
|
||||
map-options
|
||||
v-model="formData.posTypeId"
|
||||
:options="salaryPosTypeOption"
|
||||
label="ประเภทตำแหน่ง/กลุ่ม"
|
||||
:rules="[(val) => !!val || 'กรุณาเลือกประเภทตำแหน่ง/กลุ่ม']"
|
||||
lazy-rules
|
||||
use-input
|
||||
@update:model-value="fetchPosLevel"
|
||||
@filter="(inputValue: string,
|
||||
doneFn: Function) => filterSelector(inputValue, doneFn ,'posType')"
|
||||
>
|
||||
<template v-slot:no-option>
|
||||
<q-item>
|
||||
<q-item-section class="text-grey">
|
||||
ไม่มีข้อมูล
|
||||
</q-item-section>
|
||||
</q-item>
|
||||
</template>
|
||||
</q-select>
|
||||
</div>
|
||||
|
||||
<div class="col-xs-12 col-md-4">
|
||||
<q-select
|
||||
:readonly="isReadonly"
|
||||
:class="getClass(!isReadonly)"
|
||||
ref="posLevelRef"
|
||||
dense
|
||||
hide-bottom-space
|
||||
outlined
|
||||
option-label="name"
|
||||
option-value="id"
|
||||
emit-value
|
||||
map-options
|
||||
v-model="formData.posLevelId"
|
||||
:options="salaryPosLevelOption"
|
||||
label="ระดับ"
|
||||
:rules="[(val) => !!val || 'กรุณาเลือกระดับ']"
|
||||
lazy-rules
|
||||
use-input
|
||||
:disable="formData.posTypeId === ''"
|
||||
@filter="(inputValue: string,
|
||||
doneFn: Function) => filterSelector(inputValue, doneFn ,'posLevel')"
|
||||
>
|
||||
<template v-slot:no-option>
|
||||
<q-item>
|
||||
<q-item-section class="text-grey">
|
||||
ไม่มีข้อมูล
|
||||
</q-item-section>
|
||||
</q-item>
|
||||
</template></q-select
|
||||
>
|
||||
</div>
|
||||
|
||||
<div class="row col-12">
|
||||
<q-checkbox
|
||||
:disable="isReadonly"
|
||||
size="md"
|
||||
v-model="formData.isSpecial"
|
||||
label="เฉพาะสายงานที่กำหนด"
|
||||
/>
|
||||
|
||||
<q-toggle
|
||||
:disable="isReadonly"
|
||||
color="primary"
|
||||
label="สถานะการใช้งาน"
|
||||
v-model="formData.isActive"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="col-xs-12 col-md-4">
|
||||
<datepicker
|
||||
menu-class-name="modalfix"
|
||||
v-model="formData.date"
|
||||
:locale="'th'"
|
||||
autoApply
|
||||
borderless
|
||||
:enableTimePicker="false"
|
||||
week-start="0"
|
||||
:readonly="isReadonly"
|
||||
:class="getClass(!isReadonly)"
|
||||
>
|
||||
<template #year="{ year }">
|
||||
{{ year + 543 }}
|
||||
</template>
|
||||
<template #year-overlay-value="{ value }">
|
||||
{{ parseInt(value + 543) }}
|
||||
</template>
|
||||
<template #trigger>
|
||||
<q-input
|
||||
:readonly="isReadonly"
|
||||
outlined
|
||||
dense
|
||||
hide-bottom-space
|
||||
:model-value="
|
||||
formData.date != null
|
||||
? date2Thai(formData.date)
|
||||
: null
|
||||
"
|
||||
label="ให้ไว้ ณ วันที่"
|
||||
>
|
||||
<template v-slot:prepend>
|
||||
<q-icon
|
||||
name="event"
|
||||
class="cursor-pointer"
|
||||
style="color: var(--q-primary)"
|
||||
>
|
||||
</q-icon>
|
||||
</template>
|
||||
</q-input>
|
||||
</template>
|
||||
</datepicker>
|
||||
</div>
|
||||
|
||||
<div class="col-xs-12 col-md-4">
|
||||
<datepicker
|
||||
:readonly="isReadonly"
|
||||
:class="getClass(!isReadonly)"
|
||||
menu-class-name="modalfix"
|
||||
v-model="formData.startDate"
|
||||
:locale="'th'"
|
||||
autoApply
|
||||
borderless
|
||||
:enableTimePicker="false"
|
||||
week-start="0"
|
||||
@update:model-value="checkEndDate"
|
||||
>
|
||||
<template #year="{ year }">
|
||||
{{ year + 543 }}
|
||||
</template>
|
||||
<template #year-overlay-value="{ value }">
|
||||
{{ parseInt(value + 543) }}
|
||||
</template>
|
||||
<template #trigger>
|
||||
<q-input
|
||||
:readonly="isReadonly"
|
||||
outlined
|
||||
dense
|
||||
hide-bottom-space
|
||||
:model-value="
|
||||
formData.startDate != null
|
||||
? date2Thai(formData.startDate)
|
||||
: null
|
||||
"
|
||||
label="วันที่มีผลบังคับใช้"
|
||||
>
|
||||
<template v-slot:prepend>
|
||||
<q-icon
|
||||
name="event"
|
||||
class="cursor-pointer"
|
||||
style="color: var(--q-primary)"
|
||||
>
|
||||
</q-icon>
|
||||
</template>
|
||||
</q-input>
|
||||
</template>
|
||||
</datepicker>
|
||||
</div>
|
||||
|
||||
<div class="col-xs-12 col-md-4">
|
||||
<datepicker
|
||||
:readonly="isReadonly"
|
||||
:class="getClass(!isReadonly)"
|
||||
menu-class-name="modalfix"
|
||||
v-model="formData.endDate"
|
||||
:locale="'th'"
|
||||
autoApply
|
||||
borderless
|
||||
:enableTimePicker="false"
|
||||
week-start="0"
|
||||
:min-date="formData.startDate"
|
||||
>
|
||||
<template #year="{ year }">
|
||||
{{ year + 543 }}
|
||||
</template>
|
||||
<template #year-overlay-value="{ value }">
|
||||
{{ parseInt(value + 543) }}
|
||||
</template>
|
||||
<template #trigger>
|
||||
<q-input
|
||||
:readonly="isReadonly"
|
||||
outlined
|
||||
dense
|
||||
:model-value="
|
||||
formData.endDate != null
|
||||
? date2Thai(formData.endDate)
|
||||
: null
|
||||
"
|
||||
label="วันที่สิ้นสุดบังคับใช้"
|
||||
>
|
||||
<template v-slot:prepend>
|
||||
<q-icon
|
||||
name="event"
|
||||
class="cursor-pointer"
|
||||
style="color: var(--q-primary)"
|
||||
>
|
||||
</q-icon>
|
||||
</template>
|
||||
</q-input>
|
||||
</template>
|
||||
</datepicker>
|
||||
</div>
|
||||
|
||||
<div class="col-12">
|
||||
<q-input
|
||||
:class="getClass(!isReadonly)"
|
||||
:readonly="isReadonly"
|
||||
v-model="formData.details"
|
||||
outlined
|
||||
dense
|
||||
type="textarea"
|
||||
label="คำอธิบาย"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</q-card-section>
|
||||
|
||||
<q-separator />
|
||||
<q-card-actions align="right" v-if="!isReadonly">
|
||||
<q-btn label="บันทึก" color="secondary" type="submit"
|
||||
><q-tooltip>บันทึกข้อมูล</q-tooltip></q-btn
|
||||
>
|
||||
</q-card-actions>
|
||||
</q-form>
|
||||
</q-card>
|
||||
</q-dialog>
|
||||
</template>
|
||||
|
||||
<style lang="scss" scoped></style>
|
||||
327
src/modules/13_salary/components/01_Salary/DialogFormRate.vue
Normal file
327
src/modules/13_salary/components/01_Salary/DialogFormRate.vue
Normal file
|
|
@ -0,0 +1,327 @@
|
|||
divdivdiv
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, reactive, watch } from "vue";
|
||||
import { useQuasar } from "quasar";
|
||||
import { useRoute } from "vue-router";
|
||||
import http from "@/plugins/http";
|
||||
import config from "@/app.config";
|
||||
|
||||
/** importType*/
|
||||
import type { FormSalaryRate } from "@/modules/13_salary/interface/index/Main";
|
||||
|
||||
/** importComponents*/
|
||||
import Header from "@/components/DialogHeader.vue";
|
||||
|
||||
/** importStore*/
|
||||
|
||||
import { useCounterMixin } from "@/stores/mixin";
|
||||
|
||||
/** use*/
|
||||
const $q = useQuasar();
|
||||
const route = useRoute();
|
||||
const { dialogConfirm, showLoader, hideLoader, messageError, success } =
|
||||
useCounterMixin();
|
||||
|
||||
/** props*/
|
||||
const modal = defineModel<boolean>("modal", { required: true });
|
||||
const props = defineProps({
|
||||
typeAction: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
data: {
|
||||
type: Object,
|
||||
defult: [],
|
||||
},
|
||||
fetchData: {
|
||||
type: Function,
|
||||
defult: () => {},
|
||||
},
|
||||
});
|
||||
|
||||
const salaryId = ref<string>(route.params.id.toString()); //id รายการอัตราเงินเดือน
|
||||
const isReadonly = ref<boolean>(false); //อ่านอย่างเดียว
|
||||
const formData = reactive<FormSalaryRate>({
|
||||
salaryId: "",
|
||||
salary: null, //เงินเดือนฐาน
|
||||
salaryHalf: null, //เลื่อน 0.5 ขั้น
|
||||
salaryHalfSpecial: null, //เงินพิเศษ
|
||||
salaryFull: null, //เลื่อน 1 ขั้น
|
||||
salaryFullSpecial: null, //เงินพิเศษ
|
||||
salaryFullHalf: null, //เลื่อน 1.5 ขั้น
|
||||
salaryFullHalfSpecial: null, //เงินพิเศษ
|
||||
isNext: false, //ทะลุขั้น
|
||||
});
|
||||
|
||||
//ชื่อ Popup
|
||||
const title = computed(() => {
|
||||
const name =
|
||||
props.typeAction === "add"
|
||||
? "เพิ่มอัตราเงินเดือน"
|
||||
: props.typeAction === "edit"
|
||||
? "แก้ไขอัตราเงินเดือน"
|
||||
: "อัตราเงินเดือน";
|
||||
|
||||
return name;
|
||||
});
|
||||
|
||||
/**
|
||||
* function ปืด Dialog*
|
||||
*/
|
||||
function closeDialog() {
|
||||
modal.value = !modal.value;
|
||||
clearFormData();
|
||||
}
|
||||
|
||||
/**
|
||||
* function เคลียข้อมูล form
|
||||
*/
|
||||
function clearFormData() {
|
||||
formData.salaryId = "";
|
||||
formData.salary = null;
|
||||
formData.salaryHalf = null;
|
||||
formData.salaryHalfSpecial = null;
|
||||
formData.salaryFull = null;
|
||||
formData.salaryFullSpecial = null;
|
||||
formData.salaryFullHalf = null;
|
||||
formData.salaryFullHalfSpecial = null;
|
||||
formData.isNext = false;
|
||||
}
|
||||
|
||||
/** function บันทึกข้อมูล*/
|
||||
function onSubmit() {
|
||||
dialogConfirm($q, async () => {
|
||||
showLoader();
|
||||
const body: any = {
|
||||
salary:
|
||||
typeof formData.salary === "number"
|
||||
? formData.salary
|
||||
: Number(formData.salary?.replace(/,/g, "")), //*เงินเดือนฐาน
|
||||
|
||||
salaryHalf:
|
||||
typeof formData.salaryHalf === "number"
|
||||
? formData.salaryHalf
|
||||
: Number(formData.salaryHalf?.replace(/,/g, "")), //0.5 ขั้น
|
||||
|
||||
salaryHalfSpecial:
|
||||
formData.salaryHalfSpecial === "" || formData.salaryHalfSpecial === null
|
||||
? null
|
||||
: typeof formData.salaryHalfSpecial === "number"
|
||||
? formData.salaryHalfSpecial
|
||||
: Number(formData.salaryHalfSpecial.replace(/,/g, "")), //0.5 ขั้น(เงินพิเศษ)
|
||||
|
||||
salaryFull:
|
||||
typeof formData.salaryFull === "number"
|
||||
? formData.salaryFull
|
||||
: Number(formData.salaryFull?.replace(/,/g, "")), //1 ขั้น
|
||||
|
||||
salaryFullSpecial:
|
||||
formData.salaryFullSpecial === "" || formData.salaryFullSpecial === null
|
||||
? null
|
||||
: typeof formData.salaryFullSpecial === "number"
|
||||
? formData.salaryFullSpecial
|
||||
: Number(formData.salaryFullSpecial?.replace(/,/g, "")), //1 ขั้น(เงินพิเศษ)
|
||||
|
||||
salaryFullHalf:
|
||||
typeof formData.salaryFullHalf === "number"
|
||||
? formData.salaryFullHalf
|
||||
: Number(formData.salaryFullHalf?.replace(/,/g, "")), //1.formData5 ขั้น
|
||||
|
||||
salaryFullHalfSpecial:
|
||||
formData.salaryFullHalfSpecial === "" ||
|
||||
formData.salaryFullHalfSpecial === null
|
||||
? null
|
||||
: typeof formData.salaryFullHalfSpecial === "number"
|
||||
? formData.salaryFullHalfSpecial
|
||||
: Number(formData.salaryFullHalfSpecial.replace(/,/g, "")), //1.5 ขั้น(เงินพิเศษ)
|
||||
isNext: formData.isNext, //*ทะลุขั้น
|
||||
};
|
||||
if (props.typeAction === "add") {
|
||||
body.salaryId = salaryId.value;
|
||||
}
|
||||
try {
|
||||
const url =
|
||||
props.typeAction === "add"
|
||||
? config.API.salaryRateList
|
||||
: config.API.salaryRateListByid(formData.salaryId);
|
||||
await http[props.typeAction === "add" ? "post" : "put"](url, body);
|
||||
await props.fetchData?.();
|
||||
await success($q, "บันทีกข้อมูลสำเร็จ");
|
||||
closeDialog();
|
||||
} catch (err) {
|
||||
messageError($q, err);
|
||||
} finally {
|
||||
hideLoader();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* class จัดรูปแบบแสดงระหว่างข้อมูลที่แก้ไขหรือแสดงเฉยๆ
|
||||
* @param val ข้อมูล input สำหรับแก้ไขหรือไม่
|
||||
*/
|
||||
const getClass = (val: boolean) => {
|
||||
return {
|
||||
"full-width inputgreen cursor-pointer": val,
|
||||
"full-width cursor-pointer": !val,
|
||||
};
|
||||
};
|
||||
|
||||
/** callbackFunction ทำการ fetch ข้อมูลไฟล์เมื่อเปิด Dialog*/
|
||||
watch(
|
||||
() => modal.value,
|
||||
() => {
|
||||
if (modal.value && props.typeAction === "edit") {
|
||||
if (props.data) {
|
||||
const data = props.data;
|
||||
formData.salaryId = data.id;
|
||||
formData.salary = data.salary;
|
||||
formData.salaryHalf = data.salaryHalf;
|
||||
formData.salaryHalfSpecial = data.salaryHalfSpecial;
|
||||
formData.salaryFull = data.salaryFull;
|
||||
formData.salaryFullSpecial = data.salaryFullSpecial;
|
||||
formData.salaryFullHalf = data.salaryFullHalf;
|
||||
formData.salaryFullHalfSpecial = data.salaryFullHalfSpecial;
|
||||
formData.isNext = data.isNext;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<q-dialog v-model="modal" persistent>
|
||||
<q-card style="width: 650px; max-width: 80vw">
|
||||
<q-form greedy @submit.prevent @validation-success="onSubmit">
|
||||
<Header :tittle="title" :close="closeDialog" />
|
||||
<q-separator />
|
||||
|
||||
<q-card-section>
|
||||
<div class="row col-xs-12 col-md-12 q-col-gutter-sm">
|
||||
<div class="col-6">
|
||||
<q-input
|
||||
:readonly="isReadonly"
|
||||
:class="getClass(!isReadonly)"
|
||||
ref="salaryRef"
|
||||
dense
|
||||
outlined
|
||||
v-model="formData.salary"
|
||||
label="เงินเดือนฐาน"
|
||||
mask="###,###,###,###"
|
||||
reverse-fill-mask
|
||||
:rules="[(val) => !!val || `${'กรุณากรอกเงินเดือนฐาน'}`]"
|
||||
lazy-rules
|
||||
hide-bottom-space
|
||||
/>
|
||||
</div>
|
||||
<div class="col-6 row items-center">
|
||||
<q-checkbox dense v-model="formData.isNext" label="ทะลุขั้น" />
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<q-input
|
||||
:readonly="isReadonly"
|
||||
:class="getClass(!isReadonly)"
|
||||
ref="salaryHalfRef"
|
||||
dense
|
||||
outlined
|
||||
v-model="formData.salaryHalf"
|
||||
label="เลื่อน 0.5 ขั้น"
|
||||
mask="###,###,###,###"
|
||||
reverse-fill-mask
|
||||
:rules="[(val) => !!val || `${'กรุณากรอกเลื่อน 0.5 ขั้น'}`]"
|
||||
lazy-rules
|
||||
hide-bottom-space
|
||||
/>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<q-input
|
||||
:readonly="isReadonly"
|
||||
:class="getClass(!isReadonly)"
|
||||
ref="salaryHalfSpecialRef"
|
||||
dense
|
||||
outlined
|
||||
v-model="formData.salaryHalfSpecial"
|
||||
label="เงินพิเศษ"
|
||||
mask="###,###,###,###"
|
||||
reverse-fill-mask
|
||||
lazy-rules
|
||||
hide-bottom-space
|
||||
/>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<q-input
|
||||
:readonly="isReadonly"
|
||||
:class="getClass(!isReadonly)"
|
||||
ref="salaryFullRef"
|
||||
dense
|
||||
outlined
|
||||
v-model="formData.salaryFull"
|
||||
label="เลื่อน 1 ขั้น"
|
||||
mask="###,###,###,###"
|
||||
reverse-fill-mask
|
||||
:rules="[(val) => !!val || `${'กรุณากรอกเลื่อน 1 ขั้น'}`]"
|
||||
lazy-rules
|
||||
hide-bottom-space
|
||||
/>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<q-input
|
||||
:readonly="isReadonly"
|
||||
:class="getClass(!isReadonly)"
|
||||
ref="salaryFullSpecialRef"
|
||||
dense
|
||||
outlined
|
||||
v-model="formData.salaryFullSpecial"
|
||||
label="เงินพิเศษ"
|
||||
mask="###,###,###,###"
|
||||
reverse-fill-mask
|
||||
lazy-rules
|
||||
hide-bottom-space
|
||||
/>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<q-input
|
||||
:readonly="isReadonly"
|
||||
:class="getClass(!isReadonly)"
|
||||
ref="salaryFullHalfRef"
|
||||
dense
|
||||
outlined
|
||||
v-model="formData.salaryFullHalf"
|
||||
label="เลื่อน 1.5 ขั้น"
|
||||
mask="###,###,###,###"
|
||||
reverse-fill-mask
|
||||
:rules="[(val) => !!val || `${'กรุณากรอกเลื่อน 1.5 ขั้น'}`]"
|
||||
lazy-rules
|
||||
hide-bottom-space
|
||||
/>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<q-input
|
||||
:readonly="isReadonly"
|
||||
:class="getClass(!isReadonly)"
|
||||
ref="salaryFullHalfSpecialRef"
|
||||
dense
|
||||
outlined
|
||||
v-model="formData.salaryFullHalfSpecial"
|
||||
label="เงินพิเศษ"
|
||||
mask="###,###,###,###"
|
||||
reverse-fill-mask
|
||||
lazy-rules
|
||||
hide-bottom-space
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</q-card-section>
|
||||
<q-separator />
|
||||
|
||||
<q-card-actions align="right">
|
||||
<q-btn label="บันทึก" color="secondary" type="submit"
|
||||
><q-tooltip>บันทึกข้อมูล</q-tooltip></q-btn
|
||||
>
|
||||
</q-card-actions>
|
||||
</q-form>
|
||||
</q-card>
|
||||
</q-dialog>
|
||||
</template>
|
||||
|
||||
<style lang="scss" scoped></style>
|
||||
313
src/modules/13_salary/components/01_Salary/DialogUpload.vue
Normal file
313
src/modules/13_salary/components/01_Salary/DialogUpload.vue
Normal file
|
|
@ -0,0 +1,313 @@
|
|||
<script setup lang="ts">
|
||||
import { ref, reactive, watch } from "vue";
|
||||
import { checkPermission } from "@/utils/permissions";
|
||||
import { useQuasar } from "quasar";
|
||||
import axios from "axios";
|
||||
import http from "@/plugins/http";
|
||||
import config from "@/app.config";
|
||||
|
||||
/** importComponents*/
|
||||
import Header from "@/components/DialogHeader.vue";
|
||||
|
||||
/** importStore*/
|
||||
import { useCounterMixin } from "@/stores/mixin";
|
||||
|
||||
/**use*/
|
||||
const $q = useQuasar();
|
||||
const { showLoader, hideLoader, messageError, success, dialogRemove } =
|
||||
useCounterMixin();
|
||||
|
||||
/**props*/
|
||||
const modal = defineModel<boolean>("modal", { required: true });
|
||||
const props = defineProps({
|
||||
typeAction: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
id: {
|
||||
type: String,
|
||||
defult: "",
|
||||
},
|
||||
isActive: {
|
||||
type: Boolean,
|
||||
defult: false,
|
||||
},
|
||||
fetchData: {
|
||||
type: Function,
|
||||
defult: () => {},
|
||||
},
|
||||
});
|
||||
|
||||
const salaryId = ref<string>("");
|
||||
|
||||
const documentFile = ref<any>(null);
|
||||
const itemsDocument = ref<any>([]);
|
||||
|
||||
/**
|
||||
* function fetch ข้อมูลรายการ ไฟล์
|
||||
* @param id ไฟล์
|
||||
*/
|
||||
async function fetchDocumentFile(id: string) {
|
||||
showLoader();
|
||||
await http
|
||||
.get(config.API.salaryChartFile(id))
|
||||
.then(async (res) => {
|
||||
const list = await res.data.map((e: any) => ({ name: e.fileName }));
|
||||
itemsDocument.value = list;
|
||||
})
|
||||
.catch((err) => {
|
||||
messageError($q, err);
|
||||
})
|
||||
.finally(() => {
|
||||
hideLoader();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* function ปืด Dialog*
|
||||
*/
|
||||
function closeDialog() {
|
||||
modal.value = !modal.value;
|
||||
documentFile.value = null;
|
||||
itemsDocument.value = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* function เรียก path อัปโหลดไฟล์
|
||||
*/
|
||||
async function uploadDocumentFile() {
|
||||
showLoader();
|
||||
const fileName = documentFile.value.name.replace(/\.(xlsx|docx|pdf)$/, "");
|
||||
const formData = new FormData();
|
||||
formData.append("file", documentFile.value);
|
||||
const body = {
|
||||
replace: false,
|
||||
fileList: {
|
||||
fileName: fileName,
|
||||
},
|
||||
};
|
||||
await http
|
||||
.post(config.API.salaryChartFile(salaryId.value), body)
|
||||
.then(async (res) => {
|
||||
const foundKey: any = Object.keys(res.data).find(
|
||||
(key) =>
|
||||
res.data[key]?.fileName !== undefined &&
|
||||
res.data[key]?.fileName !== ""
|
||||
);
|
||||
const link = res.data[foundKey]?.uploadUrl;
|
||||
await fileUpLoad(link);
|
||||
})
|
||||
.catch((err) => {
|
||||
messageError($q, err);
|
||||
hideLoader();
|
||||
});
|
||||
}
|
||||
/**
|
||||
* function อัปโหลดไฟล์
|
||||
* @param url link อัปโหลด
|
||||
*/
|
||||
async function fileUpLoad(url: string) {
|
||||
axios
|
||||
.put(url, documentFile.value, {
|
||||
headers: { "Content-Type": documentFile.value?.type },
|
||||
onUploadProgress: (e) => console.log(e),
|
||||
})
|
||||
.then(async () => {
|
||||
await fetchDocumentFile(salaryId.value);
|
||||
await success($q, "อัปโหลดไฟล์สำเร็จ");
|
||||
documentFile.value = null;
|
||||
})
|
||||
.catch((e) => {
|
||||
messageError($q, e);
|
||||
hideLoader();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* function ลบข้อมูลรายการไฟล์
|
||||
* @param fileName ชื่่อไฟล์
|
||||
*/
|
||||
function onClickDeleteFile(fileName: string) {
|
||||
dialogRemove($q, async () => {
|
||||
showLoader();
|
||||
await http
|
||||
.delete(config.API.salaryChartDelFile(salaryId.value, fileName))
|
||||
.then(async () => {
|
||||
setTimeout(async () => {
|
||||
await fetchDocumentFile(salaryId.value);
|
||||
await success($q, "ลบไฟล์สำเร็จ");
|
||||
}, 1500);
|
||||
})
|
||||
.catch((err) => {
|
||||
messageError($q, err);
|
||||
})
|
||||
.finally(() => {
|
||||
setTimeout(() => {
|
||||
hideLoader();
|
||||
}, 2000);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* function โหลดข้อมูลไฟล์
|
||||
* @param fileName ชื่่อไฟล์
|
||||
*/
|
||||
function onClickDonwload(fileName: string) {
|
||||
showLoader();
|
||||
http
|
||||
.get(config.API.salaryChartDelFile(salaryId.value, fileName))
|
||||
.then(async (res) => {
|
||||
const data = res.data;
|
||||
await downloadFile(data.downloadUrl, data.fileType, fileName);
|
||||
})
|
||||
.catch((err) => {
|
||||
messageError($q, err);
|
||||
hideLoader();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* function เรียกไฟล์ PDF
|
||||
* @param url link PDF
|
||||
* @param type ประเภทไฟล์
|
||||
* @param fileName ชือไฟล์
|
||||
*/
|
||||
function downloadFile(url: string, type: string, fileName: string) {
|
||||
axios
|
||||
.get(url, {
|
||||
method: "GET",
|
||||
responseType: "blob",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: type, // ถ้ามีการระบุเมื่ออัปโหลด
|
||||
},
|
||||
})
|
||||
.then((res) => {
|
||||
const a = document.createElement("a");
|
||||
a.href = window.URL.createObjectURL(res.data);
|
||||
a.download = fileName;
|
||||
a.click();
|
||||
})
|
||||
.catch(async (e) => {
|
||||
messageError($q, JSON.parse(await e.response.data.text()));
|
||||
})
|
||||
.finally(() => {
|
||||
hideLoader();
|
||||
});
|
||||
}
|
||||
|
||||
/** callbackFunction ทำการ fetch ข้อมูลไฟล์เมื่อเปิด Dialog*/
|
||||
watch(
|
||||
() => modal.value,
|
||||
() => {
|
||||
if (modal.value) {
|
||||
if (props.typeAction === "edit") {
|
||||
if (props.id) {
|
||||
salaryId.value = props.id;
|
||||
fetchDocumentFile(props.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<q-dialog v-model="modal" persistent>
|
||||
<q-card style="width: 700px; max-width: 80vw">
|
||||
<Header :tittle="`อัปโหลดเอกสารอ้างอิง`" :close="closeDialog" />
|
||||
<q-separator />
|
||||
<q-card-section class="scroll" style="max-height: 70vh">
|
||||
<div class="row col-12 q-col-gutter-sm">
|
||||
<div class="row col-12 q-col-gutter-y-sm">
|
||||
<div class="col-12 row">
|
||||
<div v-if="!props.isActive" class="full-width">
|
||||
<q-file
|
||||
v-if="
|
||||
props.typeAction === 'edit' &&
|
||||
checkPermission($route)?.attrIsUpdate
|
||||
"
|
||||
class="col-12"
|
||||
outlined
|
||||
dense
|
||||
v-model="documentFile"
|
||||
label="เอกสารอ้างอิง"
|
||||
hide-bottom-space
|
||||
>
|
||||
<template v-slot:prepend>
|
||||
<q-icon name="attach_file" color="primary" />
|
||||
</template>
|
||||
<template v-slot:after>
|
||||
<q-btn
|
||||
v-if="documentFile"
|
||||
size="14px"
|
||||
flat
|
||||
round
|
||||
dense
|
||||
color="add"
|
||||
icon="mdi-upload"
|
||||
@click="uploadDocumentFile"
|
||||
><q-tooltip>อัปโหลดเอกสาร</q-tooltip></q-btn
|
||||
>
|
||||
</template>
|
||||
</q-file>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="itemsDocument.length > 0" class="col-xs-12 row">
|
||||
<q-list class="full-width rounded-borders" bordered separator>
|
||||
<q-item
|
||||
v-for="file in itemsDocument"
|
||||
:key="file.id"
|
||||
clickable
|
||||
v-ripple
|
||||
>
|
||||
<q-item-section>{{ file.name }}</q-item-section>
|
||||
<q-item-section avatar>
|
||||
<div class="row q-col-gutter-md">
|
||||
<div>
|
||||
<q-btn
|
||||
dense
|
||||
flat
|
||||
round
|
||||
color="blue"
|
||||
icon="mdi-download"
|
||||
@click="onClickDonwload(file.name)"
|
||||
>
|
||||
<q-tooltip>ดาวน์โหลดไฟล์</q-tooltip>
|
||||
</q-btn>
|
||||
</div>
|
||||
<div
|
||||
v-if="
|
||||
!props.isActive &&
|
||||
checkPermission($route)?.attrIsUpdate
|
||||
"
|
||||
>
|
||||
<q-btn
|
||||
dense
|
||||
flat
|
||||
round
|
||||
color="red"
|
||||
icon="delete"
|
||||
@click="onClickDeleteFile(file.name)"
|
||||
><q-tooltip>ลบไฟล์</q-tooltip></q-btn
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</q-item-section>
|
||||
</q-item>
|
||||
</q-list>
|
||||
</div>
|
||||
|
||||
<div class="col-12" v-else>
|
||||
<q-card class="q-pa-md" bordered> ไม่มีรายการเอกสาร </q-card>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</q-card-section>
|
||||
</q-card>
|
||||
</q-dialog>
|
||||
</template>
|
||||
|
||||
<style lang="scss" scoped></style>
|
||||
Loading…
Add table
Add a link
Reference in a new issue