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

282 lines
7.6 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();
2023-08-11 13:29:19 +07:00
const { statusText } = transferStore;
const { date2Thai, messageError, showLoader, hideLoader } = mixin;
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",
"posType",
2023-08-11 13:29:19 +07:00
"organizationPositionOld",
"organization",
"status",
"createdAt",
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" }),
format(val, row) {
return `${row.prefix}${row.firstName} ${row.lastName}`;
},
2023-07-25 15:42:30 +07:00
},
{
name: "posType",
2023-07-25 15:42:30 +07:00
align: "left",
label: "ประเภทตำแหน่ง",
2023-07-25 15:42:30 +07:00
sortable: true,
field: "posType",
2023-07-25 15:42:30 +07:00
headerStyle: "font-size: 14px",
style: "font-size: 14px",
format(val, row) {
return row.positionTypeOld + " (" + row.positionLevelOld + ")";
},
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: "ตำแหน่งและหน่วยงานเดิม",
2023-07-25 15:42:30 +07:00
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: "createdAt",
align: "left",
label: "วันที่ดำเนินการ",
sortable: true,
field: "createdAt",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
format(val) {
return date2Thai(val);
},
2023-07-25 15:42:30 +07:00
},
{
name: "status",
2023-07-25 15:42:30 +07:00
align: "left",
label: "สถานะ",
sortable: true,
field: "status",
2023-07-25 15:42:30 +07:00
headerStyle: "font-size: 14px",
style: "font-size: 14px",
format: (val) => statusText(val),
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();
const row = filters.value.filter(
(r: ResponseData) =>
r.status == "APPROVE" &&
r.organizationPositionOld &&
r.positionTypeOld &&
2023-10-11 22:27:43 +07:00
r.positionLevelOld &&
r.positionNumberOld &&
r.salary !== null &&
r.organization &&
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) => {
rows.value = res.data.result;
filters.value = rows.value;
})
.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">
<q-td
v-for="col in props.cols"
:key="col.id"
class="cursor-pointer"
@click="router.push(`/transfer/${props.row.id}`)"
>
<div v-if="col.name === 'no'">
{{ props.rowIndex + 1 }}
2023-08-11 13:29:19 +07:00
</div>
<div v-else>
{{
col.value == null ? "" : col.value == "" ? "-" : col.value
}}
2023-08-11 13:29:19 +07:00
</div>
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>