API workflow

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-10-16 18:10:55 +07:00
parent e9d68b67a4
commit 079a1c1972
5 changed files with 190 additions and 90 deletions

View file

@ -4,6 +4,7 @@ const metadata = `${env.API_URI}/org/metadata/`;
const org = `${env.API_URI}/org`; const org = `${env.API_URI}/org`;
const profileOrg = `${env.API_URI}/org/profile`; const profileOrg = `${env.API_URI}/org/profile`;
const report = `${env.API_URI}/report/profile/`; const report = `${env.API_URI}/report/profile/`;
const workflow = `${env.API_URI}/org/workflow`;
export default { export default {
profilePosition: () => `${org}/profile/keycloak/position`, profilePosition: () => `${org}/profile/keycloak/position`,
@ -82,4 +83,9 @@ export default {
*/ */
requestEdit: `${profileOrg}/edit/`, requestEdit: `${profileOrg}/edit/`,
developmentUser: `${profileOrg}/development/user`, developmentUser: `${profileOrg}/development/user`,
/**
* workflow
*/
workflow: `${workflow}/`,
}; };

View file

@ -3,20 +3,28 @@ import { ref, watch } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import { useCounterMixin } from "@/stores/mixin"; import { useCounterMixin } from "@/stores/mixin";
import http from "@/plugins/http";
import config from "@/app.config";
import type { QTableProps } from "quasar"; import type { QTableProps } from "quasar";
import DialogHeader from "@/components/DialogHeader.vue"; import DialogHeader from "@/components/DialogHeader.vue";
const $q = useQuasar(); const $q = useQuasar();
const { dialogConfirm } = useCounterMixin(); const { dialogConfirm, showLoader, hideLoader, messageError } =
useCounterMixin();
const modal = defineModel<boolean>("modal", { required: true }); const modal = defineModel<boolean>("modal", { required: true });
const { stateId, fetchData } = defineProps({
stateId: { type: String, require: true },
fetchData: { type: Function, require: true },
});
/** table*/ /** table*/
const selected = ref<any[]>([]); const selected = ref<any[]>([]);
const rows = ref<any[]>([ const rows = ref<any[]>([
{ {
id: "1",
fullName: "นายศรัณย์ ศิลาดี", fullName: "นายศรัณย์ ศิลาดี",
position: "นักบริหาร", position: "นักบริหาร",
posType: "บริหาร(สูง)", posType: "บริหาร(สูง)",
@ -62,14 +70,34 @@ const columns = ref<QTableProps["columns"]>([
}, },
]); ]);
const isAcknowledge = ref<boolean>(false); const isAcceptSetting = ref<boolean>(false);
const isConsider = ref<boolean>(false); const isApproveSetting = ref<boolean>(false);
const isComment = ref<boolean>(false); const isReasonSetting = ref<boolean>(false);
function fetchLists() {} function fetchLists() {}
function onSubmit() { function onSubmit() {
dialogConfirm($q, () => {}); dialogConfirm($q, async () => {
showLoader();
await http
.post(config.API.workflow + `add-step`, {
stateId: stateId,
profileId: selected.value[0].id,
isAcceptSetting: isAcceptSetting.value,
isApproveSetting: isApproveSetting.value,
isReasonSetting: isReasonSetting.value,
})
.then(async () => {
await fetchData?.();
onCloseModal();
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
});
} }
function onCloseModal() { function onCloseModal() {
@ -146,26 +174,28 @@ watch(modal, (val) => {
keep-color keep-color
color="primary" color="primary"
dense dense
v-model="isAcknowledge" v-model="isAcceptSetting"
label="ให้เลือกรับทราบ" label="ให้เลือกรับทราบ"
@update:model-value="(isConsider = false), (isComment = false)" @update:model-value="
(isApproveSetting = false), (isReasonSetting = false)
"
/> />
</div> </div>
<div v-if="!isAcknowledge"> <div v-if="!isAcceptSetting">
<q-checkbox <q-checkbox
dense dense
keep-color keep-color
color="primary" color="primary"
v-model="isConsider" v-model="isApproveSetting"
label="ให้เลือกพิจารณา (อนุมัติ/ไม่อนุมัติ)" label="ให้เลือกพิจารณา (อนุมัติ/ไม่อนุมัติ)"
/> />
</div> </div>
<div v-if="!isAcknowledge"> <div v-if="!isAcceptSetting">
<q-checkbox <q-checkbox
dense dense
keep-color keep-color
color="primary" color="primary"
v-model="isComment" v-model="isReasonSetting"
label="ให้แสดงความเห็นในเอกสาร" label="ให้แสดงความเห็นในเอกสาร"
/> />
</div> </div>
@ -181,7 +211,7 @@ watch(modal, (val) => {
type="submit" type="submit"
:disable=" :disable="
selected.length === 0 || selected.length === 0 ||
(!isAcknowledge && !isConsider && !isComment) (!isAcceptSetting && !isApproveSetting && !isReasonSetting)
" "
> >
</q-btn> </q-btn>

View file

@ -3,74 +3,102 @@ import { onMounted, ref } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import { useCounterMixin } from "@/stores/mixin"; import { useCounterMixin } from "@/stores/mixin";
import http from "@/plugins/http";
import config from "@/app.config";
import type { DataListState } from "@/components/Workflow/interface/response/Main";
import DialogSelectPerson from "@/components/Workflow/DialogSelectPerson.vue"; import DialogSelectPerson from "@/components/Workflow/DialogSelectPerson.vue";
import DialogApprove from "@/components/Workflow/DialogApprove.vue";
const $q = useQuasar(); const $q = useQuasar();
const { dialogConfirm } = useCounterMixin(); const { dialogConfirm, showLoader, hideLoader, messageError } =
useCounterMixin();
const { id, sysName } = defineProps({ const { id, sysName } = defineProps({
id: { type: String, require: true }, id: { type: String, require: true },
sysName: { type: String, require: true }, sysName: { type: String, require: true },
}); });
const state = ref<number>(1); const stateId = ref<string>(""); //id state
const isChangeState = ref<boolean>(false); const state = ref<number>(1); //state
const isOperate = ref<boolean>(false);
const rowsOperate = ref<any[]>([ const isChangeState = ref<boolean>(false); ///
{ const isOperate = ref<boolean>(true); // (state)
fullName: "ชื่อนาม - สกุล", const isView = ref<boolean>(true); //
comment: "ความเห็น", const isUpdate = ref<boolean>(true); //
position: " บริหาร - ต้น ", const isDelete = ref<boolean>(true); // ()
status: "อนุมัติ", const isCancel = ref<boolean>(true); // ()
},
]);
const modalSelectPerson = ref<boolean>(false);
const modalApprove = ref<boolean>(false);
const itemState = ref<any[]>([ const modalSelectPerson = ref<boolean>(false); // /
{ const itemState = ref<DataListState[]>([]);
stateNo: 1,
stateName: "Darft",
},
{
stateNo: 2,
stateName: "Operate",
},
{
stateNo: 3,
stateName: "Finish",
},
]);
function fetchData() { /** ฟังก์ชันเรียกข้อมูล Workflow ทั้งหมด*/
console.log(id, sysName); async function fetchData() {
const data = { await http
stateNo: 1, .post(config.API.workflow + `check-state-all`, {
step: 1, refId: id,
can_view: true, system: sysName,
can_update: true, })
can_operate: true, .then(async (res) => {
can_change_state: true, const data = await res.data.result;
can_delete: false, itemState.value = data;
can_cancel: false, })
}; .catch((err) => {
messageError($q, err);
state.value = data.stateNo; });
isChangeState.value = data.can_change_state;
isOperate.value = data.can_operate;
} }
function onConfirmDraft() { /** ฟังก์ชันเรียกข้อมูล Workflow ที่อยู่ปัจุบัน*/
dialogConfirm($q, () => { async function fetchCheckState() {
state.value++; 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);
});
}
/** ฟังก์ชันยืนยันการ 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();
});
}); });
} }
onMounted(() => { /** ฟังก์ชันเรียกใช้งานฟังก์ชัน fetchData, fetchCheckState*/
fetchData(); async function fetchAllFunction() {
await Promise.all([fetchData(), fetchCheckState()]);
}
onMounted(async () => {
await fetchAllFunction();
}); });
</script> </script>
@ -78,12 +106,6 @@ onMounted(() => {
<q-card bordered class="row col-12"> <q-card bordered class="row col-12">
<div class="bg-grey-1 q-pa-sm col-12 row items-center"> <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 class="q-pl-sm text-weight-bold text-dark">Workflow</div>
<q-space />
<!-- <q-btn
@click.prevent="modalApprove = true"
label="DialogApprove"
color="public"
/> -->
</div> </div>
<div class="col-12"><q-separator /></div> <div class="col-12"><q-separator /></div>
<q-card-section> <q-card-section>
@ -103,14 +125,11 @@ onMounted(() => {
:color="state < index + 1 ? 'grey-4' : ''" :color="state < index + 1 ? 'grey-4' : ''"
> >
<!-- Darft --> <!-- Darft -->
<div <div class="row q-col-gutter-sm" v-if="state === 1">
class="row q-col-gutter-sm"
v-if="step.stateName === 'Darft' && state === 1"
>
<div> <div>
<q-btn <q-btn
v-if="isChangeState" v-if="isChangeState"
@click.prevent="onConfirmDraft" @click.prevent="onChangeState"
label="Next Step" label="Next Step"
color="primary" color="primary"
/> />
@ -120,31 +139,44 @@ onMounted(() => {
<!-- Operate --> <!-- Operate -->
<div <div
class="q-col-gutter-sm" class="q-col-gutter-sm"
v-if="step.stateName === 'Operate' && state > 1" v-if="index > 0 && index < itemState.length - 1 && state > index"
> >
<div> <div v-if="step.stateUserComments.length !== 0">
<q-list bordered separator style="min-width: 20vw"> <q-list bordered separator style="min-width: 20vw">
<q-item v-for="(item, index) in rowsOperate" :key="index"> <q-item
v-for="(item, index) in step.stateUserComments"
:key="index"
>
<q-item-section> <q-item-section>
<q-item-label <q-item-label
>{{ item.fullName }} >{{ item.createdFullName }}
{{ `(${item.position})` }}</q-item-label <!-- {{ `(${item.position})` }} -->
> </q-item-label>
<q-item-label caption lines="2">{{ <q-item-label caption lines="2">{{
item.comment item.isReasonSetting ? item.reason : ""
}}</q-item-label> }}</q-item-label>
</q-item-section> </q-item-section>
<q-item-section side top> <q-item-section side top>
<q-item-label class="text-green"> <q-item-label class="text-green">
{{ item.status }}</q-item-label {{
item.isAcceptSetting
? item.isAccept
? "รับทราบ"
: ""
: item.isApproveSetting
? item.isApprove
? "อนุมันติ"
: ""
: ""
}}</q-item-label
> >
</q-item-section> </q-item-section>
</q-item> </q-item>
</q-list> </q-list>
</div> </div>
<div v-if="isOperate && state === 2"> <div v-if="isOperate">
<q-btn <q-btn
@click.prevent="modalSelectPerson = true" @click.prevent="modalSelectPerson = true"
label="ส่งไปผู้บังคับบัญชา/ผู้มีอำนาจ" label="ส่งไปผู้บังคับบัญชา/ผู้มีอำนาจ"
@ -152,9 +184,9 @@ onMounted(() => {
/> />
</div> </div>
<div v-if="isChangeState && state === 2"> <div v-if="isChangeState">
<q-btn <q-btn
@click.prevent="onConfirmDraft" @click.prevent="onChangeState"
label="Next Step" label="Next Step"
color="primary" color="primary"
/> />
@ -166,7 +198,9 @@ onMounted(() => {
</q-card-section> </q-card-section>
</q-card> </q-card>
<DialogSelectPerson v-model:modal="modalSelectPerson" /> <DialogSelectPerson
v-model:modal="modalSelectPerson"
<DialogApprove v-model:modal="modalApprove" /> :state-id="stateId"
:fetch-data="fetchAllFunction"
/>
</template> </template>

View file

@ -0,0 +1,27 @@
interface DataListState {
stateId: string;
stateName: string;
stateNo: number;
stateUserComments: StateUserComments[];
}
interface StateUserComments {
createdAt: string;
createdFullName: string;
createdUserId: string;
id: string;
isAccept: boolean | null;
isAcceptSetting: boolean | null;
isApprove: boolean | null;
isApproveSetting: boolean | null;
isReasonSetting: boolean | null;
lastUpdateFullName: string;
lastUpdateUserId: string;
lastUpdatedAt: string;
order: null;
profileId: string;
reason: string;
stateId: string;
}
export type { DataListState };

View file

@ -17,7 +17,11 @@ const router = useRouter();
const mixin = useCounterMixin(); const mixin = useCounterMixin();
const { success, messageError, showLoader, hideLoader, dialogConfirm } = mixin; const { success, messageError, showLoader, hideLoader, dialogConfirm } = mixin;
const id = ref<string>(""); //id path const id = ref<string>(
router.currentRoute.value.name === "addTransfer"
? ""
: route.params.id.toString()
); //id path
const files = ref<any>(); // const files = ref<any>(); //
const tranferOrg = ref<string>(""); // const tranferOrg = ref<string>(""); //
const noteReason = ref<string>(""); // const noteReason = ref<string>(""); //
@ -91,7 +95,6 @@ function fileOpen(url: string) {
*/ */
onMounted(() => { onMounted(() => {
if (route.params.id !== undefined) { if (route.params.id !== undefined) {
id.value = route.params.id.toString();
fecthDataTransfer(id.value); fecthDataTransfer(id.value);
} }
}); });
@ -199,7 +202,7 @@ onMounted(() => {
<!-- Workflow --> <!-- Workflow -->
<div class="col-12" v-if="routeName != 'addTransfer'"> <div class="col-12" v-if="routeName != 'addTransfer'">
<Workflow :id="id" :sys-name="`transfer`" /> <Workflow :id="id" :sys-name="`PLACEMENT_TRANSFER`" />
</div> </div>
</div> </div>
</div> </div>