Refactoring code module 13_salary
This commit is contained in:
parent
c9dd0202c6
commit
4af366c03b
43 changed files with 1215 additions and 1167 deletions
|
|
@ -1,475 +0,0 @@
|
|||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted, watch } from "vue";
|
||||
import { checkPermission } from "@/utils/permissions";
|
||||
import { useQuasar } from "quasar";
|
||||
import { useRouter } from "vue-router";
|
||||
import http from "@/plugins/http";
|
||||
import config from "@/app.config";
|
||||
|
||||
/** importType*/
|
||||
import type { QTableProps } from "quasar";
|
||||
import type { NewPagination } from "@/modules/13_salary/interface/index/Main";
|
||||
import type { FormFilter } from "@/modules/13_salary/interface/request/EmployeeChart";
|
||||
import type { EmployeeSalary } from "@/modules/13_salary/interface/response/salaryEmployeeChart";
|
||||
|
||||
/** importComponents*/
|
||||
import DialogEmployeeChart from "@/modules/13_salary/components/salaryEmployeeChart/DialogEmployeeChart.vue"; //ผังบัญชีค่าจ้างลูกจ้างประจำ
|
||||
import DialogEmployeeUpload from "@/modules/13_salary/components/salaryEmployeeChart/DialogEmployeeUpload.vue"; //อัปโหลดเอกสารอ้างอิง
|
||||
|
||||
/** importStore*/
|
||||
import { useCounterMixin } from "@/stores/mixin";
|
||||
|
||||
/** use*/
|
||||
const router = useRouter();
|
||||
const $q = useQuasar();
|
||||
const {
|
||||
date2Thai,
|
||||
dialogRemove,
|
||||
messageError,
|
||||
showLoader,
|
||||
hideLoader,
|
||||
success,
|
||||
} = useCounterMixin();
|
||||
|
||||
const formFilter = reactive<FormFilter>({
|
||||
page: 1,
|
||||
pageSize: 10,
|
||||
keyword: "",
|
||||
});
|
||||
const maxPage = ref<number>(1);
|
||||
const totalList = ref<number>(0);
|
||||
|
||||
const modalDialogEmployeeChart = ref<boolean>(false);
|
||||
const isStatusEdit = ref<boolean>(false);
|
||||
const activeType = ref<string>("");
|
||||
const dataRow = ref<EmployeeSalary>();
|
||||
|
||||
/** ข้อมูล Table*/
|
||||
const rows = ref<EmployeeSalary[]>([]);
|
||||
const columns = ref<QTableProps["columns"]>([
|
||||
{
|
||||
name: "name",
|
||||
align: "left",
|
||||
label: "ชื่อผังบัญชีอัตราค่าจ้าง",
|
||||
sortable: true,
|
||||
field: "name",
|
||||
headerStyle: "font-size: 14px",
|
||||
style: "font-size: 14px",
|
||||
},
|
||||
{
|
||||
name: "group",
|
||||
align: "left",
|
||||
label: "กลุ่มของผังบัญชีอัตราค่าจ้าง",
|
||||
sortable: true,
|
||||
field: "group",
|
||||
headerStyle: "font-size: 14px",
|
||||
style: "font-size: 14px",
|
||||
},
|
||||
{
|
||||
name: "startDate",
|
||||
align: "left",
|
||||
label: "วันที่มีผลบังคับใช้",
|
||||
sortable: true,
|
||||
field: "startDate",
|
||||
headerStyle: "font-size: 14px",
|
||||
style: "font-size: 14px",
|
||||
},
|
||||
{
|
||||
name: "isActive",
|
||||
align: "left",
|
||||
label: "สถานะการใช้งาน",
|
||||
sortable: true,
|
||||
field: "isActive",
|
||||
headerStyle: "font-size: 14px",
|
||||
style: "font-size: 14px",
|
||||
},
|
||||
]);
|
||||
const visibleColumns = ref<string[]>([
|
||||
"name",
|
||||
"group",
|
||||
"startDate",
|
||||
"isActive",
|
||||
]);
|
||||
|
||||
/**
|
||||
* fetch ข้แมูลรายาการผังบัญชีค่าจ้างลูกจ้างประจำ
|
||||
*/
|
||||
function fetchListChart() {
|
||||
showLoader();
|
||||
http
|
||||
.get(
|
||||
config.API.salaryEmployeeChart +
|
||||
`?page=${formFilter.page}&pageSize=${formFilter.pageSize}&keyword=${formFilter.keyword}`
|
||||
)
|
||||
.then((res) => {
|
||||
rows.value = res.data.result.data;
|
||||
totalList.value = res.data.result.total;
|
||||
maxPage.value = Math.ceil(res.data.result.total / formFilter.pageSize);
|
||||
})
|
||||
.catch((err) => {
|
||||
messageError($q, err);
|
||||
})
|
||||
.finally(() => {
|
||||
hideLoader();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* openDialog แก้ไขผังบัญชีค่าจ้างลูกจ้างประจำ
|
||||
* @param data ข้อมูลผังบัญชีค่าจ้างลูกจ้างประจำ
|
||||
*/
|
||||
function onEdit(data: EmployeeSalary, type: string) {
|
||||
activeType.value = type;
|
||||
isStatusEdit.value = true;
|
||||
dataRow.value = data;
|
||||
modalDialogEmployeeChart.value = true;
|
||||
}
|
||||
|
||||
const modalDialogUpload = ref<boolean>(false);
|
||||
const salaryChartId = ref<string>("");
|
||||
const isActive = ref<boolean>(false);
|
||||
|
||||
/**
|
||||
* function เปิด Dialog อัปโหลดเอกสารอ้างอิง
|
||||
* @param id ผังบัญชีค่าจ้างลูกจ้างประจำ
|
||||
* @param status สะถานะการใช่งาน
|
||||
*/
|
||||
function onUpload(id: string, status: boolean) {
|
||||
modalDialogUpload.value = true;
|
||||
salaryChartId.value = id;
|
||||
isActive.value = status;
|
||||
}
|
||||
|
||||
/**
|
||||
* functiuon redirect page อัตราค่าจ้าง
|
||||
* @param id ผังบัญชีค่าจ้างลูกจ้างประจำ
|
||||
*/
|
||||
function onSalaryRate(id: string) {
|
||||
router.push(`/salary-employee/rate/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* funtion คัดลอกรายการผังบัญชีค่าจ้างลูกจ้างประจำ
|
||||
* @param id ผังบัญชีค่าจ้างลูกจ้างประจำ
|
||||
*/
|
||||
function onCoppy(id: string) {
|
||||
showLoader();
|
||||
http
|
||||
.post(config.API.salaryEmployeeChartCopy, { id: id })
|
||||
.then(async () => {
|
||||
await fetchListChart();
|
||||
await success($q, "คัดลอกข้อมูลสำเร็จ");
|
||||
})
|
||||
.catch((err) => {
|
||||
messageError($q, err);
|
||||
})
|
||||
.finally(() => {
|
||||
hideLoader();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* funtion ลบรายการผังบัญชีค่าจ้างลูกจ้างประจำ
|
||||
* @param id ผังบัญชีค่าจ้างลูกจ้างประจำ
|
||||
*/
|
||||
function onClickDelete(id: string) {
|
||||
dialogRemove($q, () => {
|
||||
showLoader();
|
||||
http
|
||||
.delete(config.API.salaryEmployeeChartByid(id))
|
||||
.then(async () => {
|
||||
await fetchListChart();
|
||||
await success($q, "ลบข้อมูลสำเร็จ");
|
||||
})
|
||||
.catch((err) => {
|
||||
messageError($q, err);
|
||||
})
|
||||
.finally(() => {
|
||||
hideLoader();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* function เปิด dialog เพิ่มผังบัญชีค่าจ้างลูกจ้างประจำ
|
||||
*/
|
||||
function onClickAdd() {
|
||||
isStatusEdit.value = false;
|
||||
modalDialogEmployeeChart.value = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* functionn fetch ข้อมูลรายการหน้าแรก*
|
||||
*/
|
||||
function filterFn() {
|
||||
formFilter.page = 1;
|
||||
fetchListChart();
|
||||
}
|
||||
|
||||
/**
|
||||
* function fetch ข้อมูลรายการตามหน้า
|
||||
* @param val หน้า
|
||||
*/
|
||||
function updatePage(val: number) {
|
||||
formFilter.page = val;
|
||||
fetchListChart();
|
||||
}
|
||||
|
||||
/** function อัปเดทแถวต่อหน้า*/
|
||||
function updatePageSize(newPagination: NewPagination) {
|
||||
formFilter.page = 1;
|
||||
formFilter.pageSize = newPagination.rowsPerPage;
|
||||
}
|
||||
|
||||
/** callbackFuntioon ทำงานเมื่อมี่การอัปเดทแถว */
|
||||
watch(
|
||||
() => formFilter.pageSize,
|
||||
() => {
|
||||
fetchListChart();
|
||||
}
|
||||
);
|
||||
|
||||
onMounted(() => {
|
||||
fetchListChart();
|
||||
});
|
||||
</script>
|
||||
<template>
|
||||
<q-toolbar class="text-primary" style="padding: 0px">
|
||||
<q-btn
|
||||
v-if="checkPermission($route)?.attrIsCreate"
|
||||
flat
|
||||
round
|
||||
dense
|
||||
icon="add"
|
||||
@click="onClickAdd()"
|
||||
>
|
||||
<q-tooltip>เพิ่มข้อมูล </q-tooltip>
|
||||
</q-btn>
|
||||
<q-space />
|
||||
<q-input
|
||||
borderless
|
||||
dense
|
||||
outlined
|
||||
v-model="formFilter.keyword"
|
||||
placeholder="ค้นหา"
|
||||
@keydown.enter.prevent="filterFn"
|
||||
>
|
||||
<template v-slot:append>
|
||||
<q-icon name="search" />
|
||||
</template>
|
||||
</q-input>
|
||||
<q-select
|
||||
for="#select"
|
||||
v-model="visibleColumns"
|
||||
multiple
|
||||
outlined
|
||||
dense
|
||||
options-dense
|
||||
:display-value="$q.lang.table.columns"
|
||||
emit-value
|
||||
map-options
|
||||
:options="columns"
|
||||
option-value="name"
|
||||
options-cover
|
||||
style="min-width: 150px"
|
||||
class="col-xs-12 col-sm-3 col-md-2 q-ml-sm"
|
||||
/>
|
||||
</q-toolbar>
|
||||
<d-table
|
||||
flat
|
||||
bordered
|
||||
dense
|
||||
:rows="rows"
|
||||
:columns="columns"
|
||||
row-key="name"
|
||||
:rows-per-page-options="[10, 20, 50, 100]"
|
||||
:visible-columns="visibleColumns"
|
||||
@update:pagination="updatePageSize"
|
||||
>
|
||||
<template v-slot:header="props">
|
||||
<q-tr :props="props">
|
||||
<q-th auto-width />
|
||||
<q-th v-for="col in props.cols" :key="col.name" :props="props">
|
||||
<span class="text-weight-medium">{{ col.label }}</span>
|
||||
</q-th>
|
||||
</q-tr>
|
||||
<q-separator />
|
||||
</template>
|
||||
<template v-slot:body="props">
|
||||
<q-tr :props="props">
|
||||
<q-td>
|
||||
<q-btn
|
||||
v-if="
|
||||
checkPermission($route)?.attrIsGet ||
|
||||
checkPermission($route)?.attrIsCreate ||
|
||||
(checkPermission($route)?.attrIsDelete &&
|
||||
props.row.isActive == false)
|
||||
"
|
||||
flat
|
||||
dense
|
||||
color="secondary"
|
||||
icon="mdi-dots-horizontal-circle-outline"
|
||||
round
|
||||
>
|
||||
<q-menu>
|
||||
<q-list dense style="min-width: 200px">
|
||||
<!-- อัตราเงินเดือน -->
|
||||
<q-item
|
||||
v-if="checkPermission($route)?.attrIsGet"
|
||||
clickable
|
||||
v-close-popup
|
||||
@click.stop="onSalaryRate(props.row.id)"
|
||||
>
|
||||
<q-item-section>
|
||||
<div class="row items-center">
|
||||
<q-icon
|
||||
color="secondary"
|
||||
size="xs"
|
||||
name="mdi-format-list-bulleted-triangle"
|
||||
/>
|
||||
<div class="q-pl-md">อัตราเงินเดือน</div>
|
||||
</div>
|
||||
</q-item-section>
|
||||
</q-item>
|
||||
|
||||
<!-- เอกสารอ้างอิง -->
|
||||
<q-item
|
||||
v-if="checkPermission($route)?.attrIsGet"
|
||||
clickable
|
||||
v-close-popup
|
||||
@click.stop="onUpload(props.row.id, props.row.isActive)"
|
||||
>
|
||||
<q-item-section>
|
||||
<div class="row items-center">
|
||||
<q-icon
|
||||
color="teal"
|
||||
size="xs"
|
||||
name="mdi-file-document-outline"
|
||||
/>
|
||||
<div class="q-pl-md">เอกสารอ้างอิง</div>
|
||||
</div>
|
||||
</q-item-section>
|
||||
</q-item>
|
||||
|
||||
<!-- รายละเอียด -->
|
||||
<q-item
|
||||
v-if="checkPermission($route)?.attrIsGet"
|
||||
clickable
|
||||
v-close-popup
|
||||
@click.stop="onEdit(props.row, 'view')"
|
||||
>
|
||||
<q-item-section>
|
||||
<div class="row items-center">
|
||||
<q-icon color="info" size="xs" name="mdi-eye" />
|
||||
<div class="q-pl-md">รายละเอียด</div>
|
||||
</div>
|
||||
</q-item-section>
|
||||
</q-item>
|
||||
|
||||
<!-- แก้ไข -->
|
||||
<q-item
|
||||
v-if="
|
||||
checkPermission($route)?.attrIsUpdate &&
|
||||
checkPermission($route)?.attrIsGet &&
|
||||
!props.row.isActive
|
||||
"
|
||||
clickable
|
||||
v-close-popup
|
||||
@click.stop="onEdit(props.row, 'edit')"
|
||||
>
|
||||
<q-item-section>
|
||||
<div class="row items-center">
|
||||
<q-icon color="edit" size="xs" name="edit" />
|
||||
<div class="q-pl-md">แก้ไข</div>
|
||||
</div>
|
||||
</q-item-section>
|
||||
</q-item>
|
||||
|
||||
<!-- คัดลอก -->
|
||||
<q-item
|
||||
v-if="checkPermission($route)?.attrIsCreate"
|
||||
clickable
|
||||
v-close-popup
|
||||
@click.stop="onCoppy(props.row.id)"
|
||||
>
|
||||
<q-item-section>
|
||||
<div class="row items-center">
|
||||
<q-icon color="blue-6" size="xs" name="content_copy" />
|
||||
<div class="q-pl-md">คัดลอก</div>
|
||||
</div>
|
||||
</q-item-section>
|
||||
</q-item>
|
||||
|
||||
<!-- ลบข้อมูล -->
|
||||
<q-item
|
||||
v-if="
|
||||
props.row.isActive == false &&
|
||||
checkPermission($route)?.attrIsDelete
|
||||
"
|
||||
clickable
|
||||
v-close-popup
|
||||
@click.stop="onClickDelete(props.row.id)"
|
||||
>
|
||||
<q-item-section>
|
||||
<div class="row items-center">
|
||||
<q-icon color="red" size="xs" name="delete" />
|
||||
<div class="q-pl-md">ลบข้อมูล</div>
|
||||
</div>
|
||||
</q-item-section>
|
||||
</q-item>
|
||||
</q-list>
|
||||
</q-menu>
|
||||
</q-btn>
|
||||
</q-td>
|
||||
<q-td v-for="col in props.cols" :key="col.name" :props="props">
|
||||
<div v-if="col.name === 'startDate'">
|
||||
{{ col.value ? date2Thai(col.value) : "-" }}
|
||||
</div>
|
||||
<div v-else-if="col.name === 'group'">
|
||||
{{ col.value ? `กลุ่มที่ ${col.value}` : "-" }}
|
||||
</div>
|
||||
<div v-else-if="col.name === 'isActive'">
|
||||
<q-icon
|
||||
:name="col.value ? 'done' : 'close'"
|
||||
:color="col.value ? 'primary' : 'grey'"
|
||||
size="24px"
|
||||
></q-icon>
|
||||
</div>
|
||||
<div v-else>{{ col.value ? col.value : "-" }}</div>
|
||||
</q-td>
|
||||
</q-tr>
|
||||
</template>
|
||||
<template v-slot:pagination="scope">
|
||||
ทั้งหมด {{ totalList }} รายการ
|
||||
<q-pagination
|
||||
v-model="formFilter.page"
|
||||
active-color="primary"
|
||||
color="dark"
|
||||
:max="maxPage"
|
||||
:max-pages="5"
|
||||
size="sm"
|
||||
boundary-links
|
||||
direction-links
|
||||
@update:model-value="updatePage"
|
||||
></q-pagination>
|
||||
</template>
|
||||
</d-table>
|
||||
|
||||
<!-- ผังบัญชีค่าจ้างลูกจ้างประจำ -->
|
||||
<DialogEmployeeChart
|
||||
v-model:modal="modalDialogEmployeeChart"
|
||||
:isStatusEdit="isStatusEdit"
|
||||
:data="dataRow as EmployeeSalary"
|
||||
:fetchData="fetchListChart"
|
||||
:activeType="activeType"
|
||||
/>
|
||||
|
||||
<!-- อัปโหลดเอกสารอ้างอิง -->
|
||||
<DialogEmployeeUpload
|
||||
v-model:modal="modalDialogUpload"
|
||||
:id="salaryChartId"
|
||||
:isActive="isActive"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
||||
Loading…
Add table
Add a link
Reference in a new issue