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

207 lines
6.8 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";
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 ปัจุบัน
const isChangeState = ref<boolean>(false); //ส่งไปยังผู้บังคับบัญชา/ผู้มีอำนาจ
const isOperate = ref<boolean>(true); //เปลี่ยนสถานะ (state) เอกสารได้
const isView = ref<boolean>(true); //ดูเอกสารได้
const isUpdate = ref<boolean>(true); //แก้ไขเอกสารได้
const isDelete = ref<boolean>(true); //ลบเอกสารได้ (ถ้ามี)
const isCancel = ref<boolean>(true); //ลบเอกสารได้ (ถ้ามี)
const modalSelectPerson = ref<boolean>(false); //เลือกรายชื่อ ส่งไปผู้บังคับบัญชา/ผู้มีอำนาจ
const itemState = ref<DataListState[]>([]);
/** ฟังก์ชันเรียกข้อมูล Workflow ทั้งหมด*/
async function fetchData() {
await http
.post(config.API.workflow + `check-state-all`, {
refId: id,
system: sysName,
})
.then(async (res) => {
const data = await res.data.result;
itemState.value = data;
})
.catch((err) => {
messageError($q, err);
});
}
/** ฟังก์ชันเรียกข้อมูล Workflow ที่อยู่ปัจุบัน*/
async function fetchCheckState() {
await http
.post(config.API.workflow + `check-user-now`, {
refId: id,
system: sysName,
})
.then(async (res) => {
const data = await res.data.result;
stateId.value = data.stateId;
state.value = data.stateNo;
isChangeState.value = data.can_change_state;
isOperate.value = data.can_operate;
isView.value = data.can_view;
isUpdate.value = data.can_update;
isDelete.value = data.can_delete;
isCancel.value = data.can_cancel;
})
.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 () => {
await Promise.all([fetchData(), fetchCheckState()]);
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
2024-10-16 09:51:36 +07:00
});
}
2024-10-16 18:10:55 +07:00
/** ฟังก์ชันเรียกใช้งานฟังก์ชัน fetchData, fetchCheckState*/
async function fetchAllFunction() {
await Promise.all([fetchData(), fetchCheckState()]);
}
onMounted(async () => {
await fetchAllFunction();
2024-10-16 09:51:36 +07:00
});
</script>
<template>
<q-card bordered class="row col-12">
<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-16 18:10:55 +07:00
<div class="row q-col-gutter-sm" v-if="state === 1">
2024-10-16 09:51:36 +07:00
<div>
<q-btn
v-if="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-16 18:10:55 +07:00
>{{ item.createdFullName }}
<!-- {{ `(${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-16 18:10:55 +07:00
<div v-if="isOperate">
2024-10-16 09:51:36 +07:00
<q-btn
@click.prevent="modalSelectPerson = true"
label="ส่งไปผู้บังคับบัญชา/ผู้มีอำนาจ"
color="public"
/>
</div>
2024-10-16 18:10:55 +07:00
<div v-if="isChangeState">
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"
:fetch-data="fetchAllFunction"
/>
2024-10-16 09:51:36 +07:00
</template>