hrms-mgt/src/modules/07_insignia/components/5_Borrow/Main.vue

554 lines
18 KiB
Vue
Raw Normal View History

<script setup lang="ts">
import { ref, onMounted, watch } from "vue";
import { useCounterMixin } from "@/stores/mixin";
import http from "@/plugins/http";
import config from "@/app.config";
import { useBrrowDataStore } from "@/modules/07_insignia/storeBrrow";
import DialogForm from "@/modules/07_insignia/components/5_Borrow/DialogForm.vue";
import type { OptionDataYear } from "@/modules/07_insignia/interface/index/Main";
import type { QTableProps, QInput } from "quasar";
import { useQuasar } from "quasar";
// const router = useRouter();
const DataStore = useBrrowDataStore();
const mixin = useCounterMixin();
const {
date2Thai,
dialogConfirm,
showLoader,
hideLoader,
messageError,
success,
} = mixin;
const $q = useQuasar();
const tab = ref<string>("");
const selectRound = ref<string>();
const selectRoundOption = ref<OptionDataYear[]>([]);
const selectRoundAllOption = ref<OptionDataYear[]>([]);
const modal = ref<boolean>(false);
const action = ref<string>("");
const personId = ref<string>();
const profileId = ref<string>("");
const roundYear = ref<any>();
const insigniaListAll = ref<any>([]);
const insigniaList = ref<any>([]);
onMounted(async () => {
await fecthRound();
await fecthInsigniaType();
});
const fecthRound = async () => {
await http
.get(config.API.noteround())
.then((res) => {
let data = res.data.result;
selectRoundAllOption.value = [{
name: "ทั้งหมด",
2023-08-28 15:31:30 +07:00
id: "00000000-0000-0000-0000-000000000000",
year: 0,
}]
data.map((e: any) => {
selectRoundOption.value = [...selectRoundOption.value, {
name: "รอบการเสนอขอพระราชทานเครื่องราชปี" + " " + (e.year + 543),
id: e.id,
year: e.year
}]
selectRoundAllOption.value = [...selectRoundAllOption.value, {
name: "รอบการเสนอขอพระราชทานเครื่องราชปี" + " " + (e.year + 543),
id: e.id,
year: e.year
}]
});
selectRound.value = data[0].id;
roundYear.value = data[0].year;
})
.catch((err) => {
console.log(err);
});
};
const fecthInsignia = async () => {
await http
.get(config.API.insignia)
.then((res) => {
// console.log(res);
let data = res.data.result;
DataStore.fetchDataInsignia(data);
})
.catch((err) => {
console.log(err);
}).finally(async () => {
insigniaList.value = await DataStore.insigniaOp.filter((x: any) => x.type == tab.value || x.type == '')
})
};
const fecthInsigniaType = async () => {
await http(config.API.insigniaType)
.then(async (res) => {
// console.log(res);
let data = res.data.result;
DataStore.fetchDatainsigniaType(data);
tab.value = DataStore.insigniaType[0].name;
await fecthInsignia();
})
.catch((err) => {
console.log(err);
});
};
const visibleColumns = ref<String[]>([
"no",
"status",
"citizenId",
"name",
"type",
"employeeType",
"page",
"number",
"vatnumber",
"datepay",
"typepay",
"address",
"borrowOrganization",
"borrowDate",
"returnOrganization",
"returnDate",
"returnReason",
"action",
]);
const columns = ref<QTableProps["columns"]>([
{
name: "no",
align: "left",
label: "ลำดับ",
field: "no",
sortable: true,
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "citizenId",
align: "left",
label: "เลขบัตรประชาชน",
field: "citizenId",
sortable: true,
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "name",
align: "left",
label: "ชื่อ - สกุล",
field: "name",
sortable: true,
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "type",
align: "left",
label: "ประเภทเครื่องราชฯ",
field: "type",
sortable: true,
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "employeeType",
align: "left",
label: "สถานภาพ",
field: "employeeType",
sortable: true,
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "page",
align: "left",
label: "หน้าในราชกิจนุเบกษา",
field: "page",
sortable: true,
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "number",
align: "left",
label: "ลำดับที่ในราชกิจจานุเบกษา",
field: "number",
sortable: true,
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "vatnumber",
align: "left",
label: "หมายเลขใบกำกับ",
field: "vatnumber",
sortable: true,
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "datepay",
align: "left",
label: "วันที่จ่ายใบกำกับฯ",
field: "datepay",
sortable: true,
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "typepay",
align: "left",
label: "รูปแบบการจ่าย",
field: "typepay",
sortable: true,
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "address",
align: "left",
label: "ที่อยู่ที่จ่าย",
field: "address",
sortable: true,
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "borrowOrganization",
align: "left",
label: "หน่วยงานที่ยืม",
field: "borrowOrganization",
sortable: true,
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "borrowDate",
align: "left",
label: "วันที่ยืม",
field: "borrowDate",
sortable: true,
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "returnOrganization",
align: "left",
label: "หน่วยงานที่คืน",
field: "returnOrganization",
sortable: true,
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "returnDate",
align: "left",
2023-08-28 15:31:30 +07:00
label: "วันที่คืน",
field: "returnDate",
sortable: true,
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "returnReason",
align: "left",
label: "เหตุผลการคืน",
field: "returnReason",
sortable: true,
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "action",
align: "left",
label: "",
field: "",
},
]);
2023-08-26 18:37:58 +07:00
watch(tab, async () => {
insigniaList.value = await DataStore.insigniaOp.filter((x: any) => x.type == tab.value || x.type == '')
DataStore.insignia = ''
fecthlistInsignia();
});
2023-08-28 15:31:30 +07:00
const selectorInsignia = async() => {
const dataCopy = await DataStore.listInsignia;
rows.value = DataStore.insignia != '' ? dataCopy.filter((x:any)=>x.requestInsigniaId == DataStore.insignia): dataCopy
};
2023-08-28 15:31:30 +07:00
// const selectorRound = (round: string) => {
// selectRound.value = round;
// };
const rows = ref<any[]>([]);
const fecthlistInsignia = async () => {
showLoader();
await http
.get(config.API.insigniaManageBorrowList(Number(roundYear.value), tab.value))
2023-08-28 15:31:30 +07:00
.then(async (res) => {
await DataStore.fetchlistinsignia(res.data.result)
rows.value = DataStore.rows
})
.catch((err) => {
console.log(err);
messageError($q, err);
})
.finally(() => {
hideLoader();
});
};
const filterRef = ref<QInput>();
const filter = ref<string>("");
const close = () => {
modal.value = false;
};
const closeAndFecth = () => {
modal.value = false;
fecthlistInsignia()
};
const addData = () => {
modal.value = true;
action.value = "addData";
};
const editData = (id: any) => {
profileId.value = id;
action.value = "editData";
modal.value = true;
2023-08-28 15:31:30 +07:00
};
const resetFilter = () => {
// reset ค่าที่ค้นหาเมื่อกดปุ่ม X ในกล่องค้นหา
filter.value = "";
filterRef.value!.focus();
};
</script>
<template>
<div class="toptitle text-dark col-12 row items-center">
-นเครองราชฯ
</div>
<q-card flat bordered class="col-12 q-my-md q-mt-sm rounded-borders">
<q-tabs dense v-model="tab" align="left" class="bg-white text-grey" active-color="primary" indicator-color="primary">
<div v-for="item in DataStore.insigniaType">
<q-tab :name="item.name" :label="item.label" />
</div>
</q-tabs>
<q-separator />
<div>
<div v-for="item in DataStore.insigniaType">
<div v-if="tab == item.name" class="q-pa-md">
<div class="row col-12 q-pb-sm q-col-gutter-x-xs">
2023-08-28 15:31:30 +07:00
<!-- <div>
<q-select v-model="selectRound" dense outlined lazy-rules hide-bottom-space
2023-08-28 15:31:30 +07:00
:label="`${'รอบการเสนอขอเครื่องราชฯ'}`" emit-value map-options option-label="name"
:options="selectRoundAllOption" option-value="id" :borderless="false"
style="min-width: 150px" @update:emit-value="selectorRound" />
2023-08-28 15:31:30 +07:00
</div> -->
<div>
<q-select v-model="DataStore.insignia" dense outlined lazy-rules hide-bottom-space
:label="`${'เครื่องราชฯ'}`" emit-value map-options option-label="name" :options="insigniaList"
option-value="id" :readonly="false" :borderless="false" style="min-width: 150px"
@update:model-value="selectorInsignia" />
</div>
<div>
<q-btn @click="addData()" size="12px" flat round color="add" icon="mdi-plus">
<q-tooltip>เพ</q-tooltip>
</q-btn>
</div>
<q-space />
<div class="items-center" style="display: flex">
<!-- นหาขอความใน table -->
<q-input standout dense v-model="filter" ref="filterRef" outlined debounce="300" placeholder="ค้นหา"
style="max-width: 200px" class="q-ml-sm">
<template v-slot:append>
<q-icon v-if="filter == ''" name="search" />
<q-icon v-if="filter !== ''" name="clear" class="cursor-pointer" @click="resetFilter" />
</template>
</q-input>
<!-- แสดงคอลมนใน table -->
<q-select v-model="visibleColumns" :display-value="$q.lang.table.columns" multiple outlined dense
:options="columns" options-dense option-value="name" map-options emit-value style="min-width: 150px"
class="gt-xs q-ml-sm" />
</div>
</div>
<d-table :rows="rows" :columns="columns" :visible-columns="visibleColumns" :filter="filter" row-key="name">
<template v-slot:body-cell="props">
<q-td :props="props">
<div v-if="props.col.name == 'no'">
{{ props.rowIndex + 1 }}
</div>
2023-08-28 15:31:30 +07:00
<div v-else-if="props.col.name == 'action' && props.row.returnDate == '-'">
<q-td>
2023-08-28 15:31:30 +07:00
<q-btn label="คืนเครื่องราชฯ" @click="editData(props.row.id)" color="blue" />
</q-td>
</div>
<div v-else>
{{ props.value }}
</div>
</q-td>
</template>
</d-table>
</div>
<div v-else-if="tab == item.name" class="q-pa-md">
<div class="row col-12 q-pb-sm q-col-gutter-x-xs">
<selector outlined dense lazy-rules v-model="DataStore.insignia" hide-bottom-space :label="`${'เครื่องราชฯ'}`"
emit-value map-options option-label="name" :options="DataStore.insigniaOp" option-value="id" use-input
input-debounce="0" style="min-width: 150px" />
<div>
<q-btn @click="addData()" size="12px" flat round color="add" icon="mdi-plus">
<q-tooltip>เพ</q-tooltip>
</q-btn>
</div>
<q-space />
<div class="items-center" style="display: flex">
<!-- นหาขอความใน table -->
<q-input standout dense v-model="filter" ref="filterRef" outlined debounce="300" placeholder="ค้นหา"
style="max-width: 200px" class="q-ml-sm">
<template v-slot:append>
<q-icon v-if="filter == ''" name="search" />
<q-icon v-if="filter !== ''" name="clear" class="cursor-pointer" @click="resetFilter" />
</template>
</q-input>
<!-- แสดงคอลมนใน table -->
<q-select v-model="visibleColumns" :display-value="$q.lang.table.columns" multiple outlined dense
:options="columns" options-dense option-value="name" map-options emit-value style="min-width: 150px"
class="gt-xs q-ml-sm" />
</div>
</div>
<d-table :rows="rows" :columns="columns" :visible-columns="visibleColumns" :filter="filter" row-key="name">
<template v-slot:body-cell="props">
<q-td :props="props">
<div v-if="props.col.name == 'no'">
{{ props.rowIndex + 1 }}
</div>
2023-08-28 15:31:30 +07:00
<div v-else-if="props.col.name == 'action' && props.row.returnDate == '-'">
<q-td>
<q-btn label="คืนเครื่องราชฯ" @click="editData(props.row.id)" color="blue" />
</q-td>
</div>
<div v-else>
{{ props.value }}
</div>
</q-td>
</template>
</d-table>
</div>
<div v-else-if="tab == item.name" class="q-pa-md">
<div class="row col-12 q-pb-sm q-col-gutter-x-xs">
<selector outlined dense lazy-rules v-model="DataStore.insignia" hide-bottom-space :label="`${'เครื่องราชฯ'}`"
emit-value map-options option-label="name" :options="DataStore.insigniaOp" option-value="id" use-input
input-debounce="0" style="min-width: 150px" />
<div>
<q-btn @click="addData()" size="12px" flat round color="add" icon="mdi-plus">
<q-tooltip>เพ</q-tooltip>
</q-btn>
</div>
<q-space />
<div class="items-center" style="display: flex">
<!-- นหาขอความใน table -->
<q-input standout dense v-model="filter" ref="filterRef" outlined debounce="300" placeholder="ค้นหา"
style="max-width: 200px" class="q-ml-sm">
<template v-slot:append>
<q-icon v-if="filter == ''" name="search" />
<q-icon v-if="filter !== ''" name="clear" class="cursor-pointer" @click="resetFilter" />
</template>
</q-input>
<!-- แสดงคอลมนใน table -->
<q-select v-model="visibleColumns" :display-value="$q.lang.table.columns" multiple outlined dense
:options="columns" options-dense option-value="name" map-options emit-value style="min-width: 150px"
class="gt-xs q-ml-sm" />
</div>
</div>
<d-table :rows="rows" :columns="columns" :visible-columns="visibleColumns" :filter="filter" row-key="name">
<template v-slot:body-cell="props">
<q-td :props="props">
<div v-if="props.col.name == 'no'">
{{ props.rowIndex + 1 }}
</div>
2023-08-28 15:31:30 +07:00
<div v-else-if="props.col.name == 'action' && props.row.returnDate == '-'">
<q-td>
<q-btn label="คืนเครื่องราชฯ" @click="editData(props.row.id)" color="blue" />
</q-td>
</div>
<div v-else>
{{ props.value }}
</div>
</q-td>
</template>
</d-table>
</div>
</div>
</div>
2023-08-28 15:31:30 +07:00
<DialogForm :modal="modal" :close="close" :close-and-fecth="closeAndFecth"
:round-id="selectRound == '00000000-0000-0000-0000-000000000000' ? 'all' : selectRound" :action="action"
:profile-id="profileId" :select-round-option="selectRoundOption" :type-id="tab" />
</q-card>
</template>
<style lang="scss" scoped>
.arrow {
transition: transform 0.5s;
}
.arrow-active {
transition: transform 0.5s;
transform: rotate(-90deg);
}
.bg-base {
background-color: #f3f3f398;
}
.v-enter-active,
.v-leave-active {
transition: opacity 0.5s ease;
}
.v-enter-from,
.v-leave-to {
opacity: 0;
}
.flexsave {
display: flex;
justify-content: flex-end;
}
</style>