hrms-mgt/src/modules/05_placement/components/Transfer/transferMain.vue

335 lines
9.8 KiB
Vue
Raw Normal View History

2023-07-25 15:42:30 +07:00
<script setup lang="ts">
import { ref, onMounted } from "vue";
2023-07-25 15:42:30 +07:00
import type { QTableProps } from "quasar";
import { useQuasar } from "quasar";
import { useRouter } from "vue-router";
import { useCounterMixin } from "@/stores/mixin";
2023-08-11 13:29:19 +07:00
import { useTransferDataStore } from "@/modules/05_placement/store";
import Dialogbody from "@/modules/05_placement/components/Transfer/Dialogbody.vue";
import http from "@/plugins/http";
import config from "@/app.config";
import type { ResponseData } from "@/modules/05_placement/interface/response/Transfer";
2023-07-25 15:42:30 +07:00
const $q = useQuasar();
const router = useRouter();
const mixin = useCounterMixin();
2023-08-11 13:29:19 +07:00
const transferStore = useTransferDataStore();
const { date2Thai, messageError, showLoader, hideLoader, success } = mixin;
2023-08-11 13:29:19 +07:00
const { statusText } = transferStore;
const modal = ref<boolean>(false);
const filterKeyword = ref<string>("");
const filterKeyword2 = ref<string>("");
const filterRef = ref<any>(null);
const rows = ref<ResponseData[]>([]);
const rows2 = ref<ResponseData[]>([]);
const filters = ref<ResponseData[]>([]);
//ค้นหา คอลัมน์ คอลัมน์ที่แสดง
2023-07-25 15:42:30 +07:00
const visibleColumns = ref<string[]>([
"no",
"fullname",
"position",
"positionLevel",
2023-08-11 13:29:19 +07:00
"organizationPositionOld",
"organization",
"statustext",
"dateText",
2023-07-25 15:42:30 +07:00
]);
2023-07-25 15:42:30 +07:00
const resetFilter = () => {
filterKeyword.value = "";
filterKeyword2.value = "";
filterRef.value.focus();
};
// หัวตาราง
2023-07-25 15:42:30 +07:00
const columns = ref<QTableProps["columns"]>([
{
name: "no",
align: "left",
label: "ลำดับ",
sortable: false,
2023-07-25 15:42:30 +07:00
field: "no",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "fullname",
align: "left",
label: "ชื่อ-นามสกุล",
sortable: true,
field: "fullname",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
2023-07-25 15:42:30 +07:00
},
{
name: "position",
align: "left",
label: "ตำแหน่งในสายงาน",
sortable: true,
field: "position",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
2023-07-25 15:42:30 +07:00
},
{
name: "positionLevel",
align: "left",
label: "ระดับ",
sortable: true,
field: "positionLevel",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
2023-07-25 15:42:30 +07:00
},
{
2023-08-11 13:29:19 +07:00
name: "organizationPositionOld",
2023-07-25 15:42:30 +07:00
align: "left",
label: "สังกัด",
sortable: true,
2023-08-11 13:29:19 +07:00
field: "organizationPositionOld",
2023-07-25 15:42:30 +07:00
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
2023-07-25 15:42:30 +07:00
},
{
2023-08-11 13:29:19 +07:00
name: "organization",
2023-07-25 15:42:30 +07:00
align: "left",
label: "หน่วยงานที่ขอโอนไป",
sortable: true,
2023-08-11 13:29:19 +07:00
field: "organization",
2023-07-25 15:42:30 +07:00
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "dateText",
align: "left",
label: "วันที่ดำเนินการ",
sortable: true,
field: "dateText",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
sortOrder: "da",
2023-07-25 15:42:30 +07:00
},
{
2023-08-11 13:29:19 +07:00
name: "statustext",
2023-07-25 15:42:30 +07:00
align: "left",
label: "สถานะ",
sortable: true,
2023-08-11 13:29:19 +07:00
field: "statustext",
2023-07-25 15:42:30 +07:00
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
2023-07-25 15:42:30 +07:00
},
]);
const openModal = () => (modal.value = true);
const closeModal = () => {
modal.value = false;
filterKeyword2.value = "";
};
// เปิดโมเดล
2023-08-11 13:29:19 +07:00
const openModalOrder = () => {
openModal();
2023-10-11 22:27:43 +07:00
console.log("filters===>",filters.value)
2023-08-11 13:29:19 +07:00
const row = filters.value.filter(
(r: ResponseData) =>
2023-10-11 22:27:43 +07:00
(r.status == "APPROVE") &&
r.organizationPositionOld &&
r.positionTypeOld &&
2023-10-11 22:27:43 +07:00
r.positionLevelOld &&
r.positionNumberOld &&
r.salary !== null &&
r.organization &&
2023-10-04 18:12:55 +07:00
r.date
2023-08-11 13:29:19 +07:00
);
rows2.value = row;
};
// เรียกข้อมูล api
const getData = async () => {
showLoader();
await http
.get(config.API.transfer)
.then((res: any) => {
const data = res.data.result;
let list: ResponseData[] = [];
data.map((r: ResponseData) => {
list.push({
dateText:
r.createdAt !== null ? date2Thai(new Date(r.createdAt)) : "-",
createdAt: r.createdAt !== null ? new Date(r.createdAt) : null,
2023-10-04 18:12:55 +07:00
date: r.date,
2023-08-11 13:29:19 +07:00
firstName: r.firstName ?? "",
id: r.id ?? "",
isActive: r.isActive ? r.isActive : false,
2023-08-11 13:29:19 +07:00
lastName: r.lastName ?? "",
organization: r.organization ?? "",
organizationPositionOld: r.organizationPositionOld ?? "",
posNo: r.posNo ?? "",
position: r.position ?? "",
positionLevel: r.positionLevel ?? "",
positionLevelOld: r.positionLevelOld ?? "",
positionNumberOld: r.positionNumberOld ?? "",
positionTypeOld: r.positionTypeOld ?? "",
2023-08-11 13:29:19 +07:00
prefix: r.prefix ?? "",
reason: r.reason ?? "",
salary: r.salary ? r.salary : 0,
status: r.status ?? "",
2023-08-11 13:29:19 +07:00
statustext: statusText(r.status ?? ""),
fullname: `${r.prefix ?? ""} ${r.firstName ?? ""} ${
r.lastName ?? ""
}`,
});
});
rows.value = list;
2023-08-11 13:29:19 +07:00
filters.value = list;
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
};
2023-08-11 13:29:19 +07:00
onMounted(async () => {
await getData();
});
2023-07-25 15:42:30 +07:00
</script>
<template>
<div class="toptitle text-dark col-12 row items-center">รายการขอโอน</div>
<q-card flat bordered class="col-12 q-mt-sm">
<q-separator />
<div class="row q-pa-md">
<div class="col-12">
<div class="row col-12">
<q-btn
2023-08-11 13:29:19 +07:00
@click="openModalOrder"
2023-07-25 15:42:30 +07:00
size="14px"
flat
round
color="add"
icon="mdi-account-arrow-right"
>
<q-tooltip>งไปออกคำส</q-tooltip>
2023-07-25 15:42:30 +07:00
</q-btn>
<q-space />
<q-input
class="col-xs-12 col-sm-3 col-md-2"
standout
dense
v-model="filterKeyword"
ref="filterRef"
outlined
debounce="300"
placeholder="ค้นหา"
>
<template v-slot:append>
<q-icon v-if="filterKeyword == ''" name="search" />
<q-icon
v-if="filterKeyword !== ''"
name="clear"
class="cursor-pointer"
@click="resetFilter"
/>
</template>
</q-input>
<q-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"
/>
</div>
<div class="col-12 q-pt-sm">
<d-table
2023-07-25 15:42:30 +07:00
:columns="columns"
:rows="rows"
:filter="filterKeyword"
row-key="id"
2023-07-25 15:42:30 +07:00
:visible-columns="visibleColumns"
>
<template v-slot:header="props">
<q-tr :props="props">
<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>
</template>
<template v-slot:body="props">
<q-tr
:props="props"
class="cursor-pointer"
@click="router.push(`/transfer/${props.row.id}`)"
2023-07-25 15:42:30 +07:00
>
<q-td key="no" :props="props">
{{ props.rowIndex + 1 }}
</q-td>
<q-td key="fullname" :props="props">
{{ props.row.fullname }}
</q-td>
<q-td key="position" :props="props">
{{ props.row.position }}
</q-td>
<q-td key="positionLevel" :props="props">
{{ props.row.positionLevel }}
</q-td>
2023-08-11 13:29:19 +07:00
<q-td key="organizationPositionOld" :props="props">
<div class="table_ellipsis">
{{ props.row.organizationPositionOld }}
</div>
2023-07-25 15:42:30 +07:00
</q-td>
2023-08-11 13:29:19 +07:00
<q-td key="organization" :props="props">
<div class="table_ellipsis">
{{ props.row.organization }}
</div>
2023-07-25 15:42:30 +07:00
</q-td>
<q-td key="dateText" :props="props">
{{ props.row.dateText }}
</q-td>
2023-08-11 13:29:19 +07:00
<q-td key="statustext" :props="props">
{{ props.row.statustext }}
2023-07-25 15:42:30 +07:00
</q-td>
</q-tr>
</template>
</d-table>
2023-07-25 15:42:30 +07:00
</div>
</div>
</div>
</q-card>
<Dialogbody
v-model:Modal="modal"
:closeModal="closeModal"
:rows2="rows2"
v-model:filterKeyword2="filterKeyword2"
:getData="getData"
/>
2023-07-25 15:42:30 +07:00
</template>
<style scoped lang="scss"></style>