hrms-user/src/components/Workflow/Main.vue

215 lines
6.9 KiB
Vue
Raw Normal View History

2024-10-16 09:51:36 +07:00
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { useQuasar } from "quasar";
import { useCounterMixin } from "@/stores/mixin";
2024-10-16 18:10:55 +07:00
import http from "@/plugins/http";
import config from "@/app.config";
2024-10-17 13:36:53 +07:00
import type { Permission } from "@/components/Workflow/interface/index/Main";
2024-10-16 18:10:55 +07:00
import type { DataListState } from "@/components/Workflow/interface/response/Main";
2024-10-16 09:51:36 +07:00
import DialogSelectPerson from "@/components/Workflow/DialogSelectPerson.vue";
const $q = useQuasar();
2024-10-16 18:10:55 +07:00
const { dialogConfirm, showLoader, hideLoader, messageError } =
useCounterMixin();
2024-10-16 09:51:36 +07:00
const { id, sysName } = defineProps({
id: { type: String, require: true },
sysName: { type: String, require: true },
});
2024-10-16 18:10:55 +07:00
const stateId = ref<string>(""); //id state ปัจุบัน
const state = ref<number>(1); //state ปัจุบัน
2024-10-17 13:36:53 +07:00
const isPermission = ref<boolean>(true); //การเข้าถึง Workflow
const permission = ref<Permission>({
isChangeState: false, //ส่งไปยังผู้บังคับบัญชา/ผู้มีอำนาจ
isOperate: false, //เปลี่ยนสถานะ (state) เอกสารได้
isView: false, //ดูเอกสารได้
isUpdate: false, //แก้ไขเอกสารได้
isDelete: false, //ลบเอกสารได้ (ถ้ามี)
isCancel: false, //ลบเอกสารได้ (ถ้ามี)
});
2024-10-16 18:10:55 +07:00
const modalSelectPerson = ref<boolean>(false); //เลือกรายชื่อ ส่งไปผู้บังคับบัญชา/ผู้มีอำนาจ
const itemState = ref<DataListState[]>([]);
2024-10-17 13:36:53 +07:00
/** ฟังก์ชันเรียกข้อมูล Workflow ที่อยู่ปัจุบัน*/
async function fetchCheckState() {
2024-10-16 18:10:55 +07:00
await http
2024-10-17 13:36:53 +07:00
.post(config.API.workflow + `check-user-now`, {
2024-10-16 18:10:55 +07:00
refId: id,
system: sysName,
})
.then(async (res) => {
2024-10-17 13:36:53 +07:00
await fetchData();
2024-10-16 18:10:55 +07:00
const data = await res.data.result;
2024-10-17 13:36:53 +07:00
stateId.value = data.stateId;
state.value = data.stateNo === 4 ? 5 : data.stateNo;
permission.value = {
isChangeState: data.can_change_state,
isOperate: data.can_operate,
isView: data.can_view,
isUpdate: data.can_update,
isDelete: data.can_delete,
isCancel: data.can_cancel,
};
2024-10-16 18:10:55 +07:00
})
2024-10-17 13:36:53 +07:00
.catch(() => {
isPermission.value = false;
2024-10-16 18:10:55 +07:00
});
}
2024-10-17 13:36:53 +07:00
/** ฟังก์ชันเรียกข้อมูล Workflow ทั้งหมด*/
async function fetchData() {
2024-10-16 18:10:55 +07:00
await http
2024-10-17 13:36:53 +07:00
.post(config.API.workflow + `check-state-all`, {
2024-10-16 18:10:55 +07:00
refId: id,
system: sysName,
})
.then(async (res) => {
const data = await res.data.result;
2024-10-17 13:36:53 +07:00
itemState.value = data;
2024-10-16 18:10:55 +07:00
})
.catch((err) => {
messageError($q, err);
});
2024-10-16 09:51:36 +07:00
}
2024-10-16 18:10:55 +07:00
/** ฟังก์ชันยืนยันการ NextStep*/
function onChangeState() {
dialogConfirm($q, async () => {
showLoader();
await http
.post(config.API.workflow + `state-next`, {
refId: id,
system: sysName,
})
.then(async () => {
2024-10-17 13:36:53 +07:00
await fetchCheckState();
2024-10-16 18:10:55 +07:00
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
2024-10-16 09:51:36 +07:00
});
}
2024-10-16 18:10:55 +07:00
onMounted(async () => {
2024-10-17 13:36:53 +07:00
await fetchCheckState();
});
defineExpose({
permission,
2024-10-16 09:51:36 +07:00
});
</script>
<template>
2024-10-17 13:36:53 +07:00
<q-card bordered class="row col-12" v-if="isPermission">
2024-10-16 09:51:36 +07:00
<div class="bg-grey-1 q-pa-sm col-12 row items-center">
<div class="q-pl-sm text-weight-bold text-dark">Workflow</div>
</div>
<div class="col-12"><q-separator /></div>
<q-card-section>
<div class="q-px-lg q-py-md">
<q-timeline color="primary">
<q-timeline-entry
v-for="(step, index) in itemState"
:key="index"
:title="step.stateName"
:icon="
state === index + 1
? 'mdi-pencil'
: state > index + 1
? 'done'
: `mdi-numeric-${index + 1}`
"
:color="state < index + 1 ? 'grey-4' : ''"
>
<!-- Darft -->
2024-10-17 11:23:48 +07:00
<div class="row q-col-gutter-sm" v-if="state === 1 && index === 0">
2024-10-16 09:51:36 +07:00
<div>
<q-btn
2024-10-17 13:36:53 +07:00
v-if="permission.isChangeState"
2024-10-16 18:10:55 +07:00
@click.prevent="onChangeState"
2024-10-16 09:51:36 +07:00
label="Next Step"
color="primary"
/>
</div>
</div>
<!-- Operate -->
<div
class="q-col-gutter-sm"
2024-10-16 18:10:55 +07:00
v-if="index > 0 && index < itemState.length - 1 && state > index"
2024-10-16 09:51:36 +07:00
>
2024-10-16 18:10:55 +07:00
<div v-if="step.stateUserComments.length !== 0">
2024-10-16 09:51:36 +07:00
<q-list bordered separator style="min-width: 20vw">
2024-10-16 18:10:55 +07:00
<q-item
v-for="(item, index) in step.stateUserComments"
:key="index"
>
2024-10-16 09:51:36 +07:00
<q-item-section>
<q-item-label
2024-10-17 11:23:48 +07:00
>{{
`${item.prefix}${item.firstName} ${item.lastName}`
}}
2024-10-16 18:10:55 +07:00
<!-- {{ `(${item.position})` }} -->
</q-item-label>
2024-10-16 09:51:36 +07:00
<q-item-label caption lines="2">{{
2024-10-16 18:10:55 +07:00
item.isReasonSetting ? item.reason : ""
2024-10-16 09:51:36 +07:00
}}</q-item-label>
</q-item-section>
<q-item-section side top>
<q-item-label class="text-green">
2024-10-16 18:10:55 +07:00
{{
item.isAcceptSetting
? item.isAccept
? "รับทราบ"
: ""
: item.isApproveSetting
? item.isApprove
? "อนุมันติ"
: ""
: ""
}}</q-item-label
2024-10-16 09:51:36 +07:00
>
</q-item-section>
</q-item>
</q-list>
</div>
2024-10-17 13:36:53 +07:00
<div v-if="permission.isOperate && state === index + 1">
2024-10-16 09:51:36 +07:00
<q-btn
@click.prevent="modalSelectPerson = true"
label="ส่งไปผู้บังคับบัญชา/ผู้มีอำนาจ"
color="public"
/>
</div>
2024-10-17 13:36:53 +07:00
<div v-if="permission.isChangeState && state === index + 1">
2024-10-16 09:51:36 +07:00
<q-btn
2024-10-16 18:10:55 +07:00
@click.prevent="onChangeState"
2024-10-16 09:51:36 +07:00
label="Next Step"
color="primary"
/>
</div>
</div>
</q-timeline-entry>
</q-timeline>
</div>
</q-card-section>
</q-card>
2024-10-16 18:10:55 +07:00
<DialogSelectPerson
v-model:modal="modalSelectPerson"
:state-id="stateId"
2024-10-17 13:36:53 +07:00
:fetch-data="fetchCheckState"
2024-10-16 18:10:55 +07:00
/>
2024-10-16 09:51:36 +07:00
</template>