hrms-mgt/src/modules/18_command/components/Main/TableMain.vue

415 lines
13 KiB
Vue
Raw Normal View History

2024-09-10 18:03:01 +07:00
<script setup lang="ts">
import { onMounted, ref, watch } from "vue";
2024-09-10 18:03:01 +07:00
import { useQuasar } from "quasar";
import { useRouter } from "vue-router";
2024-10-29 11:07:52 +07:00
import { checkPermission } from "@/utils/permissions";
2024-09-10 18:03:01 +07:00
import { useCounterMixin } from "@/stores/mixin";
import { useCommandListStore } from "@/modules/18_command/store/ListStore";
2024-10-29 11:07:52 +07:00
import http from "@/plugins/http";
import config from "@/app.config";
2024-09-10 18:03:01 +07:00
import type { QTableProps } from "quasar";
import type { Pagination } from "@/modules/18_command/interface/index/Main";
import DialogFormCommand from "@/modules/18_command/components/Main/DialogFormCommand.vue";
2024-09-10 18:03:01 +07:00
const $q = useQuasar();
const router = useRouter();
const store = useCommandListStore();
const {
showLoader,
hideLoader,
success,
messageError,
date2Thai,
dialogRemove,
dialogConfirm,
} = useCounterMixin();
const page = defineModel<number>("page", { required: true });
const pageSize = defineModel<number>("pageSize", { required: true });
const props = defineProps({
fetchList: { type: Function, required: true },
});
2024-09-10 18:03:01 +07:00
const columns = ref<QTableProps["columns"]>([
{
name: "commandNo",
2024-09-10 18:03:01 +07:00
align: "left",
label: "เลขที่คำสั่ง",
sortable: false,
field: "commandNo",
format(val, row) {
return val ? `${val} / ${row.commandYear + 543}` : "-";
},
2024-09-10 18:03:01 +07:00
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "issue",
align: "left",
2024-09-10 18:03:01 +07:00
label: "ชื่อคำสั่ง",
sortable: true,
field: "issue",
2024-09-10 18:03:01 +07:00
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
2024-09-25 13:57:10 +07:00
name: "commandAffectDate",
align: "left",
2024-09-10 18:03:01 +07:00
label: "วันที่ลงนาม",
sortable: false,
2024-09-25 13:57:10 +07:00
field: "commandAffectDate",
format(val) {
return val ? date2Thai(val) : "-";
},
2024-09-10 18:03:01 +07:00
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
2024-09-25 13:57:10 +07:00
name: "commandExcecuteDate",
align: "left",
2024-09-10 18:03:01 +07:00
label: "วันที่คำสั่งมีผล",
sortable: false,
2024-09-25 13:57:10 +07:00
field: "commandExcecuteDate",
format(val) {
return val ? date2Thai(val) : "-";
},
2024-09-10 18:03:01 +07:00
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "createdFullName",
align: "left",
2024-09-10 18:03:01 +07:00
label: "ผู้สร้าง",
sortable: false,
field: "createdFullName",
2024-09-10 18:03:01 +07:00
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "assignFullName",
align: "left",
2024-09-10 18:03:01 +07:00
label: "ผู้ลงนาม",
sortable: false,
field: "assignFullName",
2024-09-10 18:03:01 +07:00
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
]);
const modalCopy = ref<boolean>(false);
const isCheckPageSize = ref<boolean>(false);
2024-09-10 18:03:01 +07:00
const commandId = ref<string>("");
async function fetchListCommand() {
await props.fetchList?.();
}
2024-09-10 18:03:01 +07:00
function onRedirectToDetail(type: string, id: string) {
router.push(`/command/${type}/${id}`);
}
function onCopy(id: string) {
commandId.value = id;
modalCopy.value = true;
}
function onCancel(id: string) {
dialogRemove(
$q,
async () => {
showLoader();
await http
.put(config.API.commandAction(id, "cancel"))
.then(async () => {
await fetchListCommand();
success($q, "ลบรายการสำเร็จ");
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
},
"ยืนยันการลบคำสั่ง",
"ต้องการยืนยันการลบคำสั่งนี้ใช่หรือไม่?"
2024-09-10 18:03:01 +07:00
);
}
function onReCommand(id: string) {
dialogConfirm(
$q,
async () => {
showLoader();
await http
.put(config.API.commandAction(id, "resume"))
.then(async () => {
await fetchListCommand();
success($q, "ดึงไปทำคำสั่งใหม่สำเร็จ");
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
},
2024-09-10 18:03:01 +07:00
"ยืนยันการดึงไปทำคำสั่งใหม่",
"ต้องการยืนยืนยันการดึงไปทำคำสั่งใหม่ใช่หรือไม่ ?"
);
}
function onDeleteCommand(id: string) {
dialogRemove(
$q,
async () => {
showLoader();
await http
.delete(config.API.command + `/${id}`)
.then(async () => {
await fetchListCommand();
success($q, "ลบรายการสำเร็จ");
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
},
"ยืนยันการลบคำสั่งออกจากระบบ",
"หากคุณกดยืนยันคำสั่งจะถูกลบออกจากระบบทันที ต้องการยืนยืนยันการลบคำสั่งนี้ใช่หรือไม่?"
);
}
/**
* function updatePagination
* @param newPagination อม Pagination ใหม
*/
function updatePagination(newPagination: Pagination) {
page.value = 1;
pageSize.value = newPagination.rowsPerPage;
}
watch(pageSize, () => {
isCheckPageSize.value = true;
fetchListCommand();
});
onMounted(() => {
!isCheckPageSize.value && fetchListCommand();
});
2024-09-10 18:03:01 +07:00
</script>
<template>
<d-table
ref="table"
:columns="columns"
:rows="store.rows"
row-key="id"
flat
dense
bordered
:paging="true"
:rows-per-page-options="[10, 25, 50, 100]"
@update:pagination="updatePagination"
2024-09-10 18:03:01 +07:00
>
<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>
</template>
<template v-slot:body="props">
<q-tr :props="props">
<q-td auto-width>
<q-btn
flat
dense
round
color="secondary"
icon="mdi-dots-horizontal-circle-outline"
2024-10-29 11:07:52 +07:00
v-if="
2024-10-30 14:00:23 +07:00
store.tabsMain === 'DRAFT' || store.tabsMain === 'PENDING'
2024-10-29 11:07:52 +07:00
? checkPermission($route)?.attrIsGet ||
checkPermission($route)?.attrIsCreate ||
2024-10-30 14:00:23 +07:00
checkPermission($route)?.attrIsDelete ||
checkPermission($route)?.attrIsUpdate
2024-10-29 11:07:52 +07:00
: store.tabsMain === 'WAITING' || store.tabsMain === 'REPORTED'
? checkPermission($route)?.attrIsGet ||
checkPermission($route)?.attrIsCreate
2024-10-30 14:00:23 +07:00
: store.tabsMain === 'CANCEL'
? checkPermission($route)?.attrIsGet ||
checkPermission($route)?.attrIsCreate ||
checkPermission($route)?.attrIsDelete
2024-10-29 11:07:52 +07:00
: ''
"
2024-09-10 18:03:01 +07:00
>
<q-menu>
<q-list dense style="min-width: 200px">
<!-- แกไขขอม ไมแสดง Tabs ยกเล -->
<q-item
2024-09-25 11:33:00 +07:00
v-if="
store.tabsMain !== 'WAITING' &&
store.tabsMain !== 'CANCEL' &&
2024-10-29 11:07:52 +07:00
store.tabsMain !== 'REPORTED' &&
checkPermission($route)?.attrIsGet &&
2024-10-30 14:00:23 +07:00
checkPermission($route)?.attrIsUpdate
2024-09-25 11:33:00 +07:00
"
2024-09-10 18:03:01 +07:00
clickable
v-close-popup
@click.pervent="onRedirectToDetail('edit', props.row.id)"
>
<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
2024-10-29 11:07:52 +07:00
v-if="checkPermission($route)?.attrIsGet"
2024-09-10 18:03:01 +07:00
clickable
v-close-popup
@click.pervent="onRedirectToDetail('view', props.row.id)"
>
<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
2024-10-29 11:07:52 +07:00
v-if="checkPermission($route)?.attrIsCreate"
2024-09-10 18:03:01 +07:00
clickable
v-close-popup
@click.pervent="onCopy(props.row.id)"
>
<q-item-section>
<div class="row items-center">
<q-icon
color="blue-6"
size="xs"
name="mdi-content-copy"
/>
<div class="q-pl-md">ทำสำเนาคำส</div>
</div>
</q-item-section>
</q-item>
<!-- ยกเล ไมแสดง Tabs ยกเล -->
<q-item
v-if="
store.tabsMain !== 'WAITING' &&
store.tabsMain !== 'CANCEL' &&
2024-10-29 11:07:52 +07:00
store.tabsMain !== 'REPORTED' &&
checkPermission($route)?.attrIsDelete
"
2024-09-10 18:03:01 +07:00
clickable
v-close-popup
@click.pervent="onCancel(props.row.id)"
>
<q-item-section>
<div class="row items-center">
<q-icon
color="red"
size="xs"
name="close
"
/>
<div class="q-pl-md">ลบ</div>
2024-09-10 18:03:01 +07:00
</div>
</q-item-section>
</q-item>
<!-- งไปทำคำสงใหม แสดงแค Tabs ยกเล -->
<q-item
2024-10-29 11:07:52 +07:00
v-if="
store.tabsMain === 'CANCEL' &&
checkPermission($route)?.attrIsCreate
"
2024-09-10 18:03:01 +07:00
clickable
v-close-popup
@click.pervent="onReCommand(props.row.id)"
>
<q-item-section>
<div class="row items-center">
<q-icon color="amber-5" size="xs" name="mdi-replay" />
<div class="q-pl-md">งไปทำคำสงใหม</div>
</div>
</q-item-section>
</q-item>
<q-item
clickable
v-close-popup
2024-10-29 11:07:52 +07:00
v-if="
store.tabsMain === 'CANCEL' &&
checkPermission($route)?.attrIsDelete
"
@click.pervent="onDeleteCommand(props.row.id)"
>
<q-item-section>
<div class="row items-center">
<q-icon color="red" size="xs" name="mdi-delete" />
2024-09-25 11:33:00 +07:00
<div class="q-pl-md">ลบคำสงถาวร</div>
</div>
</q-item-section>
</q-item>
2024-09-10 18:03:01 +07:00
</q-list>
</q-menu>
</q-btn>
</q-td>
<q-td v-for="col in props.cols" :key="col.name" :props="props">
<div>
{{ col.value ?? "-" }}
</div>
</q-td>
</q-tr>
</template>
<template v-slot:pagination="scope">
งหมด {{ store.total }} รายการ
<q-pagination
v-model="page"
active-color="primary"
color="dark"
:max="Number(store.maxPage)"
size="sm"
boundary-links
direction-links
:max-pages="5"
@update:model-value="fetchListCommand"
></q-pagination>
</template>
2024-09-10 18:03:01 +07:00
</d-table>
<DialogFormCommand
v-model:modal="modalCopy"
:is-copy="true"
:command-id="commandId"
/>
2024-09-10 18:03:01 +07:00
</template>
<style scoped></style>