hrms-mgt/src/modules/07_insignia/components/2_Manage/Tab1.vue

774 lines
24 KiB
Vue
Raw Normal View History

<script setup lang="ts">
2023-08-21 16:31:28 +07:00
import { onMounted, ref, watch, reactive } from "vue";
import { useCounterMixin } from "@/stores/mixin";
import { useQuasar } from "quasar";
2023-08-17 09:58:09 +07:00
import type { QTableProps } from "quasar";
2023-08-21 11:55:57 +07:00
import { useInsigniaDataStore } from "@/modules/07_insignia/store";
import http from "@/plugins/http";
import config from "@/app.config";
import { useRouter } from "vue-router";
const router = useRouter();
const mixin = useCounterMixin();
2023-08-21 16:31:28 +07:00
const {
dialogRemove,
dialogConfirm,
showLoader,
hideLoader,
messageError,
success,
} = mixin;
const $q = useQuasar();
2023-08-21 11:55:57 +07:00
const DataStore = useInsigniaDataStore();
const modalNote = ref<boolean>(false);
2023-08-21 16:31:28 +07:00
const modalAdd = ref<boolean>(false);
const modalEdit = ref<boolean>(false);
2023-08-21 16:31:28 +07:00
const organization = ref<string>("");
const organizationOptions = ref<any>([{ id: "1", name: "ทั้งหมด" }]);
const visibleColumns = ref<string[]>([
"no",
"citizenId",
"name",
"position",
"level",
"salary",
"insigniaType",
"insigniaSend",
"insigniaLevel",
"dateSend",
]);
// หัวตาราง
const columns = ref<QTableProps["columns"]>([
{
name: "no",
align: "left",
label: "ลำดับ",
sortable: true,
field: "no",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "citizenId",
align: "left",
label: "เลขบัตรประชาชน",
sortable: true,
field: "citizenId",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "name",
align: "left",
label: "ชื่อ-นามสกุล",
sortable: true,
field: "name",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "position",
align: "left",
label: "ตำแหน่ง",
sortable: true,
field: "position",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "level",
align: "left",
label: "อันดับ/ระดับ",
sortable: true,
field: "level",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "salary",
align: "left",
label: "เงินเดือน",
sortable: true,
field: "salary",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "insigniaType",
align: "left",
label: "ประเภทเครื่องราชฯ ปัจจุบัน",
sortable: true,
field: "insigniaType",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "insigniaSend",
align: "left",
label: "ประเภทเครื่องราชฯ ที่ยื่นขอ",
sortable: true,
field: "insigniaSend",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "insigniaLevel",
align: "left",
label: "ชั้นเครื่องราชฯ",
sortable: true,
field: "insigniaLevel",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "dateSend",
align: "left",
label: "วันที่ยื่นขอ",
sortable: true,
field: "dateSend",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
]);
2023-08-21 16:31:28 +07:00
const columns2 = ref<QTableProps["columns"]>([
{
name: "index",
required: true,
label: "ลำดับ",
field: "index",
align: "left",
},
{
name: "fullname",
required: true,
label: "ชื่อ-สกุล",
field: "fullname",
align: "left",
},
{
name: "position",
required: true,
label: "ตำแหน่งในสายงาน",
field: "position",
align: "left",
},
{
name: "level",
required: true,
label: "ระดับ",
field: "level",
align: "left",
},
{
name: "organizationOrganization",
required: true,
label: "สังกัด",
field: "organizationOrganization",
align: "left",
},
]);
2023-08-21 16:31:28 +07:00
const rows2 = ref<any[]>([]);
2023-08-17 09:58:09 +07:00
const person = ref<any>([]);
2023-08-21 11:55:57 +07:00
const props = defineProps({
tab: {
type: String,
},
roundId: {
type: String,
},
2023-08-21 16:31:28 +07:00
fecthInsigniaAll: {
type: Function,
},
fecthInsigniaByOc: {
type: Function,
},
roleUser: {
type: String,
},
2023-08-21 11:55:57 +07:00
});
2023-08-21 11:55:57 +07:00
onMounted(async () => {
// if (DataStore.typeOc == "") {
// // organization.value = DataStore.optionsTypeOc[2].id;
// DataStore.typeOc = organization.value;
// } else organization.value = DataStore.typeOc;
organization.value = await (DataStore.agency != null ? DataStore.agency : DataStore.typeOc);
organizationOptions.value = await DataStore.optionsTypeOc;
2023-08-21 16:31:28 +07:00
if (organization.value !== "" || organization.value !== undefined) {
if (props.fecthInsigniaByOc) {
props.fecthInsigniaByOc(
props.roundId,
organization.value,
"officer",
props.tab
);
}
}
2023-08-21 11:55:57 +07:00
});
2023-08-21 16:31:28 +07:00
const changtypeOc = () => {
if (props.fecthInsigniaByOc) {
props.fecthInsigniaByOc(
props.roundId,
organization.value,
"officer",
props.tab
);
}
DataStore.typeOc = organization.value;
2023-08-21 16:31:28 +07:00
};
const clickmodalAdd = () => {
showLoader();
fecthlistRetire();
};
// fecth profile
const fecthlistRetire = async () => {
await http
.get(config.API.profileOrganizRoot)
.then((res) => {
const id = res.data.result[0].id;
if (id !== "") {
fecthlistperson(id);
}
})
.catch((e) => {
// console.log(e);
2023-08-21 16:31:28 +07:00
messageError($q, e);
});
};
const fecthlistperson = async (id: string) => {
let data = [{}];
data = [
{
criteriaType: "is_retire",
criteriaValue: "false",
},
{
criteriaType: "is_probation",
criteriaValue: "false",
},
];
await http
.post(config.API.profileSearchNewOcIdType(id, "officer"), {
criterias: data,
})
.then((res) => {
// console.log(res);
2023-08-21 11:55:57 +07:00
2023-08-21 16:31:28 +07:00
rows2.value = res.data.result.map((e: any) => ({
id: e.id,
fullname: e.fullname == null ? "-" : e.fullname,
position: e.position == null ? "-" : e.position,
level: e.positionEmployeeLevel == null ? "-" : e.positionEmployeeLevel,
organizationOrganization: e.oc == null ? "-" : e.oc,
}));
modalAdd.value = true;
})
.catch((e) => {
// console.log(e);
2023-08-21 16:31:28 +07:00
messageError($q, e);
})
.finally(() => {
hideLoader();
});
};
2023-08-21 11:55:57 +07:00
2023-08-21 16:31:28 +07:00
const clickAdd = async (id: string) => {
dialogConfirm(
$q,
async () => {
await addlistperson(id);
2023-08-21 16:31:28 +07:00
},
"ยืนยันการเพิ่มรายชื่อขอพระราชทานเครื่องราชฯ",
"ต้องการยืนยันการเพิ่มรายชื่อขอพระราชทานเครื่องราชฯ นี้หรือไม่ ?"
);
};
2023-08-21 16:31:28 +07:00
const addlistperson = async (id: string) => {
showLoader();
let data = {
profileId: id,
// insigniaId: organization.value,
2023-08-21 16:31:28 +07:00
insigniaPeriodId: props.roundId,
};
// console.log(data);
2023-08-21 16:31:28 +07:00
await http
.post(config.API.insigniaCreate(), data)
.then(() => {
success($q, "เพิ่มรายชื่อสำเร็จ");
})
.catch((err) => {
// console.log(err);
2023-08-21 16:31:28 +07:00
messageError($q, err);
})
.finally(() => {
modalAdd.value = false;
if (props.fecthInsigniaByOc) {
props.fecthInsigniaByOc(
props.roundId,
organization.value,
"officer",
props.tab
);
}
hideLoader();
});
2023-08-21 11:55:57 +07:00
};
2023-08-21 16:31:28 +07:00
// const clickAction = (props: any, action: string) => {
// Note.value = "";
// person.value = props;
// titleModal.value = props.name;
// actionModal.value = action;
// modalNote.value = true;
// };
const clickmodalEdit = (props: any) => {
insignia.value = props.insigniaSend;
// insigniaType.value = props.insigniaLevel;
person.value = props;
modalEdit.value = true;
fecthInsignia();
// fecthInsigniaType();
};
const clickSave = () => {
2023-08-21 16:31:28 +07:00
dialogConfirm(
$q,
async () => {
await listEdit(person.value.id);
2023-08-21 16:31:28 +07:00
},
"ยืนยันการแก้ไขเครื่องราชฯ ที่ยื่นขอ",
"ต้องการยืนยันการแก้ไขเครื่องราชฯ ที่ยื่นขอนี้หรือไม่ ?"
);
};
const listEdit = async (profileId: string) => {
let data: any = {
insigniaId: insignia.value,
// insigniaTypeId: insigniaType.value,
};
2023-08-21 16:31:28 +07:00
await http
.put(config.API.insigniaEdit(profileId), data)
2023-08-21 16:31:28 +07:00
.then(() => {
success($q, "แก้ไขเครื่องราชฯ ที่ยื่นขอสำเร็จ");
})
.catch((err) => {
messageError($q, err);
})
.finally(async () => {
modalEdit.value = false;
if (props.fecthInsigniaByOc) {
await props.fecthInsigniaByOc(
props.roundId,
organization.value,
"officer",
props.tab
);
}
2023-08-21 16:31:28 +07:00
});
};
const clickReject = (profileId: string) => {
2023-08-21 16:31:28 +07:00
dialogConfirm(
$q,
async () => {
await listreject(profileId);
2023-08-21 16:31:28 +07:00
},
"ยืนยันการย้ายข้อมูล",
"ต้องการยืนยันการย้ายข้อมูลนี้หรือไม่ ?"
);
};
const listreject = async (profileId: string) => {
2023-08-21 16:31:28 +07:00
await http
.get(config.API.insigniaReject(profileId))
2023-08-21 16:31:28 +07:00
.then(() => {
success($q, "ย้ายข้อมูลสำเร็จ");
})
.catch((err) => {
messageError($q, err);
})
.finally(async () => {
if (props.fecthInsigniaByOc) {
await props.fecthInsigniaByOc(
props.roundId,
organization.value,
"officer",
props.tab
);
}
2023-08-21 16:31:28 +07:00
});
};
const clickDelete = (profileId: string) => {
2023-08-21 16:31:28 +07:00
dialogRemove(
$q,
async () => {
await listdelete(profileId);
2023-08-21 16:31:28 +07:00
},
"ยืนยันการลบออกข้ออมูล",
"ต้องการยืนยันการลบข้อมูลนี้หรือไม่ ?"
);
};
const listdelete = async (profileId: string) => {
2023-08-21 16:31:28 +07:00
await http
.get(config.API.insigniaDelete(profileId))
2023-08-21 16:31:28 +07:00
.then(() => {
success($q, "ลบข้อมูลสำเร็จ");
})
.catch((err) => {
messageError($q, err);
})
.finally(async () => {
if (props.fecthInsigniaByOc) {
await props.fecthInsigniaByOc(
props.roundId,
organization.value,
"officer",
props.tab
);
}
2023-08-21 16:31:28 +07:00
});
};
const insignia = ref<string>("");
const insigniaOptions = ref<any>([]);
const insigniaType = ref<string>("");
// const insigniaTypeOptions = ref<any>([]);
const fecthInsignia = async () => {
await http
.get(config.API.insignia)
.then((res) => {
insigniaOptions.value = res.data.result;
})
.catch(() => {
// console.log(err);
});
};
// const fecthInsigniaType = async () => {
// await http(config.API.insigniaType)
// .then((res) => {
// insigniaTypeOptions.value = res.data.result;
// })
// .catch((err) => {});
// };
const nextPage = (id: string) => {
router.push(`/registry/${id}`);
};
const filterKeyword = ref<string>("");
2023-08-21 16:31:28 +07:00
const filterKeyword2 = ref<string>("");
const filterRef = ref<any>(null);
const resetFilter = () => {
filterKeyword.value = "";
2023-08-21 16:31:28 +07:00
filterKeyword2.value = "";
filterRef.value.focus();
};
const pagination = ref({
sortBy: "desc",
descending: false,
page: 1,
rowsPerPage: 10,
});
2023-08-21 16:31:28 +07:00
const pagination2 = ref({
sortBy: "desc",
descending: false,
page: 1,
rowsPerPage: 10,
});
const paging = ref<boolean>(true);
2023-08-21 16:31:28 +07:00
const paging2 = ref<boolean>(true);
const paginationLabel = (start: number, end: number, total: number) => {
if (paging.value == true) return " " + start + "-" + end + " ใน " + total;
else return start + "-" + end + " ใน " + total;
};
const paginationLabel2 = (start: number, end: number, total: number) => {
2023-08-21 16:31:28 +07:00
if (paging2.value == true) return " " + start + "-" + end + " ใน " + total;
else return start + "-" + end + " ใน " + total;
};
</script>
<template>
<div class="col-12 row q-pa-md">
<div class="row col-12">
<div class="row col-12 q-col-gutter-sm">
<!-- {{ DataStore.typeinsigniaOptions }} -->
<q-select v-if="props.roleUser == 'admin'" v-model="organization" label="หน่วยงาน" dense emit-value map-options
:options="organizationOptions" option-value="id" option-label="name" lazy-rules hide-bottom-space
:readonly="false" :borderless="false" :outlined="true" :hide-dropdown-icon="false" style="min-width: 150px"
@update:model-value="changtypeOc" />
<q-select v-model="DataStore.typeinsignia" label="ปรเภทเครื่องราชฯ" dense emit-value map-options
:options="DataStore.typeinsigniaOptions" option-value="id" option-label="name" lazy-rules hide-bottom-space
:readonly="false" :borderless="false" :outlined="true" :hide-dropdown-icon="false" style="min-width: 150px"
@update:model-value="DataStore.searchFilterTable" />
<div>
<q-btn size="md" icon="mdi-download" flat round color="primary">
<q-tooltip>ดาวนโหลด</q-tooltip>
</q-btn>
<q-btn size="12px" flat round color="add" icon="mdi-plus" @click="clickmodalAdd">
<q-tooltip>เพ</q-tooltip>
</q-btn>
</div>
<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" />
</div>
<div class="col-12 q-pt-sm">
<q-table ref="table" :columns="columns" :rows="DataStore.rows" :filter="filterKeyword" row-key="name" flat
bordered :paging="true" dense class="custom-header-table" :visible-columns="visibleColumns"
:pagination-label="paginationLabel" v-model:pagination="pagination">
<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-th auto-width />
</q-tr>
</template>
<template v-slot:body="props">
<q-tr :props="props" class="cursor-pointer" @click.stop="nextPage(props.row.profileId)">
<q-td key="no" :props="props">
{{ props.rowIndex + 1 }}
</q-td>
<q-td key="citizenId" :props="props">
{{ props.row.citizenId }}
</q-td>
<q-td key="name" :props="props">
{{ props.row.name }}
</q-td>
<q-td key="position" :props="props">
{{ props.row.position }}
</q-td>
<q-td key="level" :props="props">
{{ props.row.level }}
</q-td>
<q-td key="salary" :props="props">
{{ Number(props.row.salary).toLocaleString() }}
</q-td>
<q-td key="insigniaType" :props="props">
{{ props.row.insigniaType }}
</q-td>
<q-td key="insigniaSend" :props="props">
{{ props.row.insigniaSend }}
</q-td>
<q-td key="insigniaLevel" :props="props">
{{ props.row.insigniaLevel }}
</q-td>
<q-td key="dateSend" :props="props">
{{ props.row.dateSend }}
</q-td>
<q-td auto-width>
<q-btn icon="mdi-dots-vertical" size="12px" color="grey-7" flat round dense @click.stop>
<q-menu transition-show="jump-down" transition-hide="jump-up">
2023-08-21 16:31:28 +07:00
<q-list dense style="min-width: 250px">
<q-item clickable v-close-popup @click.stop="clickmodalEdit(props.row)">
<q-item-section style="min-width: 0px" avatar class="q-py-sm">
2023-08-21 16:31:28 +07:00
<q-tooltip>แกไขเครองราชฯ นขอ</q-tooltip>
<q-icon color="primary" size="xs" name="mdi-pencil" />
</q-item-section>
<q-item-section>แกไขเครองราชฯ นขอ</q-item-section>
2023-08-21 16:31:28 +07:00
</q-item>
<q-item clickable v-close-popup @click.stop="clickReject(props.row.profileId)">
<q-item-section style="min-width: 0px" avatar class="q-py-sm">
2023-08-17 09:58:09 +07:00
<q-tooltip>ไมนขอ</q-tooltip>
<q-icon color="blue" size="xs" name="mdi-alert-circle-outline" />
</q-item-section>
2023-08-17 09:58:09 +07:00
<q-item-section>ไมนขอ</q-item-section>
</q-item>
<q-item clickable v-close-popup @click.stop="clickDelete(props.row.profileId)">
<q-item-section style="min-width: 0px" avatar class="q-py-sm">
2023-08-17 09:58:09 +07:00
<q-tooltip>ลบออก</q-tooltip>
<q-icon color="red" size="xs" name="mdi-delete" />
</q-item-section>
2023-08-17 09:58:09 +07:00
<q-item-section>ลบออก</q-item-section>
</q-item>
</q-list>
</q-menu>
</q-btn>
</q-td>
</q-tr>
</template>
<template v-slot:pagination="scope">
<q-pagination v-model="pagination.page" active-color="primary" color="primary" :max="scope.pagesNumber"
:max-pages="5" size="sm" boundary-links direction-links></q-pagination>
</template>
</q-table>
</div>
</div>
</div>
2023-08-21 16:31:28 +07:00
<!-- add -->
<q-dialog v-model="modalAdd">
<q-card style="width: 850px; max-width: 80vw" class="q-pb-md">
<q-toolbar class="q-py-md">
<q-toolbar-title class="text-h6">เพมรายช </q-toolbar-title>
<q-btn icon="close" unelevated round dense @click="modalAdd = false"
style="color: #ff8080; background-color: #ffdede" />
2023-08-21 16:31:28 +07:00
</q-toolbar>
<q-separator />
<div class="q-pa-md">
<q-toolbar style="padding: 0">
<q-input borderless outlined dense debounce="300" placeholder="ค้นหา" style="width: 850px; max-width: auto"
v-model="filterKeyword2">
2023-08-21 16:31:28 +07:00
<template v-slot:append>
<q-icon name="search" />
</template>
</q-input>
</q-toolbar>
<q-table flat bordered dense :rows="rows2" :columns="columns2" :filter="filterKeyword2" row-key="name"
class="custom-header-table" :pagination-label="paginationLabel2" v-model:pagination="pagination2">
2023-08-21 16:31:28 +07:00
<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-th auto-width />
</q-tr>
</template>
<template v-slot:body="props">
<q-tr :props="props" class="cursor-pointer">
<q-td>{{ props.rowIndex + 1 }}</q-td>
<!-- <q-td key="order" :props="props">
{{ props.row.order }}
</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="level" :props="props">{{ props.row.level }}</q-td>
<q-td key="organizationOrganization" :props="props">
{{ props.row.organizationOrganization }}
</q-td>
<q-td>
<q-btn outline :props="props" label="เพิ่ม" class="text-teal-5" @click="clickAdd(props.row.id)" />
2023-08-21 16:31:28 +07:00
<q-tooltip>เพ</q-tooltip>
</q-td>
</q-tr>
</template>
<template v-slot:pagination="scope">
<q-pagination v-model="pagination2.page" color="primary" :max="scope.pagesNumber" :max-pages="5" size="sm"
boundary-links direction-links></q-pagination>
2023-08-21 16:31:28 +07:00
</template>
</q-table>
</div>
</q-card>
</q-dialog>
<!-- Edit -->
<q-dialog v-model="modalEdit" persistent>
<q-card style="width: 450px; max-width: 80vw" class="q-pb-md">
<q-toolbar class="q-py-md">
<q-toolbar-title class="text-h6">แกไขเครองราชฯ นขอ
</q-toolbar-title>
<q-btn icon="close" unelevated round dense @click="modalEdit = false"
style="color: #ff8080; background-color: #ffdede" />
</q-toolbar>
<q-separator />
<div class="q-pa-md">
<div class="row q-col-gutter-sm">
<div class="col">
<q-select v-model="insignia" label="ชื่อเครื่องราชฯ" dense emit-value map-options :options="insigniaOptions"
option-value="id" option-label="name" lazy-rules hide-bottom-space :readonly="false" :borderless="false"
:outlined="true" :hide-dropdown-icon="false" style="min-width: 150px" />
</div>
<!-- <div class="col">
<q-select
v-model="insigniaType"
label="ชั้นเครื่องราชฯ"
dense
emit-value
map-options
:options="insigniaTypeOptions"
option-value="id"
option-label="name"
lazy-rules
hide-bottom-space
:readonly="false"
:borderless="false"
:outlined="true"
:hide-dropdown-icon="false"
style="min-width: 150px"
/>
</div> -->
</div>
</div>
<q-separator />
<div class="q-pa-md">
<div class="row justify-end">
<q-btn label="บันทึก" @click="clickSave" color="public" />
</div>
</div>
</q-card>
</q-dialog>
2023-08-21 16:31:28 +07:00
<!-- note -->
<!-- <q-dialog v-model="modalNote" persistent>
<q-card style="min-width: 350px">
<q-toolbar>
<q-toolbar-title class="text-subtitle2 text-bold">
2023-08-21 16:31:28 +07:00
<div v-if="actionModal == 'note'">
เปนเหตผลทไมนขอ {{ titleModal }}
</div>
2023-08-17 09:58:09 +07:00
<div v-if="actionModal == 'delete'">ลบออก {{ titleModal }}</div>
</q-toolbar-title>
<q-btn
icon="close"
unelevated
round
dense
@click="modalNote = false"
style="color: #ff8080; background-color: #ffdede"
/> </q-toolbar
><q-separator />
<q-card-section class="q-pt-none"></q-card-section>
<q-card-section class="q-pt-none">
<q-input
dense
outlined
type="textarea"
2023-08-21 16:31:28 +07:00
label="เหตุผลที่ไม่ยื่นขอ"
v-model="Note"
@keyup.enter="modalNote = false"
2023-08-21 16:31:28 +07:00
:rules="[(val) => !!val || 'เหตุผลที่ไม่ยื่นขอ']"
/>
</q-card-section>
<q-card-actions align="right" class="bg-white text-teal">
2023-08-17 09:58:09 +07:00
<q-btn
v-if="actionModal == 'note'"
label="บันทึก"
@click="clickSavenote"
color="public"
:disable="Note === ''"
/>
<q-btn
v-if="actionModal == 'delete'"
label="บันทึก"
@click="clickDelete"
color="public"
:disable="Note === ''"
/>
</q-card-actions>
</q-card>
</q-dialog> -->
</template>