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

352 lines
12 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 { Pagination } from "@/modules/18_command/interface/index/Main";
import DialogFormCommand from "@/modules/18_command/components/Main/DialogFormCommand.vue";
2026-03-11 16:37:32 +07:00
import DialogAssign from "@/modules/18_command/components/DialogAssign.vue";
2024-09-10 18:03:01 +07:00
const $q = useQuasar();
const router = useRouter();
const store = useCommandListStore();
const {
showLoader,
hideLoader,
success,
messageError,
dialogRemove,
dialogConfirm,
} = useCounterMixin();
2025-09-30 14:12:12 +07:00
const pagination = defineModel<Pagination>("pagination", { required: true });
const props = defineProps({
fetchList: { type: Function, required: true },
2025-09-30 14:12:12 +07:00
onRequest: { type: Function, required: true },
checkAndUpdatePage: { type: Function, required: true },
});
2024-09-10 18:03:01 +07:00
const modalCopy = ref<boolean>(false);
const isCheckPageSize = ref<boolean>(false);
2024-09-10 18:03:01 +07:00
const commandId = ref<string>("");
2026-03-11 16:37:32 +07:00
const modalAssign = ref<boolean>(false);
2024-09-10 18:03:01 +07:00
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 () => {
2025-09-30 14:12:12 +07:00
await props.checkAndUpdatePage(store.rows.length);
await fetchListCommand();
success($q, "ดึงไปทำคำสั่งใหม่สำเร็จ");
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
},
2024-09-10 18:03:01 +07:00
"ยืนยันการดึงไปทำคำสั่งใหม่",
"ต้องการยืนยืนยันการดึงไปทำคำสั่งใหม่ใช่หรือไม่ ?"
);
}
2026-03-11 16:37:32 +07:00
function onDeleteCommand(id: string) {
dialogRemove(
$q,
async () => {
showLoader();
await http
.delete(config.API.command + `/${id}`)
.then(async () => {
2025-09-30 14:12:12 +07:00
await props.checkAndUpdatePage(store.rows.length);
await fetchListCommand();
success($q, "ลบรายการสำเร็จ");
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
},
"ยืนยันการลบคำสั่งออกจากระบบ",
"หากคุณกดยืนยันคำสั่งจะถูกลบออกจากระบบทันที ต้องการยืนยืนยันการลบคำสั่งนี้ใช่หรือไม่?"
);
}
2026-03-11 16:37:32 +07:00
function onAssignCommand(id: string) {
commandId.value = id;
modalAssign.value = true;
}
onMounted(() => {
!isCheckPageSize.value && fetchListCommand();
});
2024-09-10 18:03:01 +07:00
</script>
<template>
2025-09-30 14:12:12 +07:00
<p-table
2024-09-10 18:03:01 +07:00
ref="table"
:columns="store.columns"
:visible-columns="store.visibleColumns"
2024-09-10 18:03:01 +07:00
:rows="store.rows"
row-key="id"
flat
dense
bordered
:paging="true"
:rows-per-page-options="[10, 25, 50, 100]"
2025-09-30 14:12:12 +07:00
@request="onRequest"
v-model:pagination="pagination"
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
2025-07-09 10:38:40 +07:00
@click.prevent="onRedirectToDetail('edit', props.row.id)"
2024-09-10 18:03:01 +07:00
>
<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
2025-07-09 10:38:40 +07:00
@click.prevent="onRedirectToDetail('view', props.row.id)"
2024-09-10 18:03:01 +07:00
>
<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
2025-07-09 10:38:40 +07:00
@click.prevent="onCopy(props.row.id)"
2024-09-10 18:03:01 +07:00
>
<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>
2026-03-11 16:37:32 +07:00
<!-- หมอบหมายคำส -->
<q-item
clickable
v-close-popup
v-if="checkPermission($route)?.attrOwnership === 'OWNER'"
@click.prevent="onAssignCommand(props.row.id)"
>
<q-item-section>
<div class="row items-center">
<q-icon
color="green-6"
size="xs"
name="mdi-account-check"
/>
<div class="q-pl-md">หมอบหมายคำส</div>
</div>
</q-item-section>
</q-item>
2024-09-10 18:03:01 +07:00
<!-- ยกเล ไมแสดง 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
2025-07-09 10:38:40 +07:00
@click.prevent="onCancel(props.row.id)"
2024-09-10 18:03:01 +07:00
>
<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
2025-07-09 10:38:40 +07:00
@click.prevent="onReCommand(props.row.id)"
2024-09-10 18:03:01 +07:00
>
<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
"
2025-07-09 10:38:40 +07:00
@click.prevent="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>
2025-09-30 14:12:12 +07:00
</p-table>
2024-09-10 18:03:01 +07:00
<DialogFormCommand
v-model:modal="modalCopy"
:is-copy="true"
:command-id="commandId"
/>
2026-03-11 16:37:32 +07:00
<DialogAssign v-model:modal="modalAssign" :command-id="commandId" :fetch-list-command="fetchListCommand" />
2024-09-10 18:03:01 +07:00
</template>
<style scoped></style>