hrms-mgt/src/components/Workflow/DialogSelectPerson.vue

236 lines
6.4 KiB
Vue
Raw Normal View History

2024-10-08 17:29:26 +07:00
<script setup lang="ts">
import { ref, watch } from "vue";
import { useQuasar } from "quasar";
import { useCounterMixin } from "@/stores/mixin";
2024-10-16 18:11:38 +07:00
import http from "@/plugins/http";
import config from "@/app.config";
2024-10-08 17:29:26 +07:00
import type { QTableProps } from "quasar";
import DialogHeader from "@/components/DialogHeader.vue";
const $q = useQuasar();
2024-10-16 18:11:38 +07:00
const { dialogConfirm, showLoader, hideLoader, messageError } =
useCounterMixin();
2024-10-08 17:29:26 +07:00
const modal = defineModel<boolean>("modal", { required: true });
2024-10-18 12:06:01 +07:00
const props = defineProps({
2024-10-16 18:11:38 +07:00
stateId: { type: String, require: true },
fetchData: { type: Function, require: true },
});
2024-10-08 17:29:26 +07:00
/** table*/
2024-10-15 16:16:59 +07:00
const selected = ref<any[]>([]);
2024-10-17 11:23:28 +07:00
const rows = ref<any[]>([]);
2024-10-08 17:29:26 +07:00
const columns = ref<QTableProps["columns"]>([
{
name: "fullName",
align: "left",
label: "ชื่อ-นามสกุล",
sortable: true,
field: "fullName",
2024-10-17 11:23:28 +07:00
format(val, row) {
return `${row.prefix}${row.firstName} ${row.lastName}`;
},
2024-10-08 17:29:26 +07:00
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "position",
align: "left",
label: "ตำแหน่งในสายงาน",
sortable: true,
field: "position",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
2024-10-17 11:23:28 +07:00
// {
// name: "posType",
// align: "left",
// label: "ประเภทตำแหน่ง",
// sortable: true,
// field: "posType",
// headerStyle: "font-size: 14px",
// style: "font-size: 14px",
// },
2024-10-08 17:29:26 +07:00
{
name: "organization",
align: "left",
label: "สังกัด",
field: "organization",
sortable: true,
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
]);
2024-10-16 18:11:38 +07:00
const isAcceptSetting = ref<boolean>(false);
const isApproveSetting = ref<boolean>(false);
const isReasonSetting = ref<boolean>(false);
2024-10-15 16:16:59 +07:00
2024-10-17 11:23:28 +07:00
async function fetchLists() {
showLoader();
await http
.get(config.API.workflow + `commander`)
.then(async (res) => {
rows.value = res.data.result;
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
2024-10-08 17:29:26 +07:00
function onSubmit() {
2024-10-16 18:11:38 +07:00
dialogConfirm($q, async () => {
showLoader();
await http
.post(config.API.workflow + `add-step`, {
2024-10-18 12:06:01 +07:00
stateId: props.stateId,
2024-10-16 18:11:38 +07:00
profileId: selected.value[0].id,
isAcceptSetting: isAcceptSetting.value,
isApproveSetting: isApproveSetting.value,
isReasonSetting: isReasonSetting.value,
})
.then(async () => {
2024-10-18 12:06:01 +07:00
await props.fetchData?.();
2024-10-16 18:11:38 +07:00
onCloseModal();
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
});
2024-10-08 17:29:26 +07:00
}
function onCloseModal() {
modal.value = false;
selected.value = [];
rows.value = [];
2024-10-18 12:06:01 +07:00
isAcceptSetting.value = false;
isApproveSetting.value = false;
isReasonSetting.value = false;
2024-10-08 17:29:26 +07:00
}
watch(modal, (val) => {
if (val) {
fetchLists();
}
});
</script>
<template>
<q-dialog v-model="modal" persistent>
<q-card style="min-width: 700px">
<q-form q-form greedy @submit.prevent @validation-success="onSubmit">
<DialogHeader :tittle="`เลือกรายชื่อ`" :close="onCloseModal" />
<q-separator />
<q-card-section>
<d-table
ref="table"
:columns="columns"
:rows="rows"
row-key="id"
flat
bordered
:paging="true"
dense
:rows-per-page-options="[10, 25, 50, 100]"
selection="single"
v-model:selected="selected"
>
<template v-slot:header-selection="scope">
<q-checkbox
keep-color
color="primary"
dense
v-model="scope.checkBox"
/>
</template>
<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" class="cursor-pointer">
<q-td>
<q-checkbox
keep-color
color="primary"
dense
v-model="props.selected"
/>
</q-td>
<q-td v-for="col in props.cols" :key="col.name" :props="props">
<div>
{{ col.value ? col.value : "-" }}
</div>
</q-td>
</q-tr>
</template>
2024-10-15 16:16:59 +07:00
</d-table>
<div class="q-gutter-xs q-pt-sm">
<div>
<q-checkbox
keep-color
color="primary"
dense
2024-10-16 18:11:38 +07:00
v-model="isAcceptSetting"
2024-10-15 16:16:59 +07:00
label="ให้เลือกรับทราบ"
2024-10-16 18:11:38 +07:00
@update:model-value="
(isApproveSetting = false), (isReasonSetting = false)
"
2024-10-15 16:16:59 +07:00
/>
</div>
2024-10-16 18:11:38 +07:00
<div v-if="!isAcceptSetting">
2024-10-15 16:16:59 +07:00
<q-checkbox
dense
keep-color
color="primary"
2024-10-16 18:11:38 +07:00
v-model="isApproveSetting"
2024-10-15 16:16:59 +07:00
label="ให้เลือกพิจารณา (อนุมัติ/ไม่อนุมัติ)"
/>
</div>
2024-10-16 18:11:38 +07:00
<div v-if="!isAcceptSetting">
2024-10-15 16:16:59 +07:00
<q-checkbox
dense
keep-color
color="primary"
2024-10-16 18:11:38 +07:00
v-model="isReasonSetting"
2024-10-15 16:16:59 +07:00
label="ให้แสดงความเห็นในเอกสาร"
/>
</div>
</div>
</q-card-section>
2024-10-08 17:29:26 +07:00
<q-separator />
<q-card-actions align="right">
<q-btn
2024-10-15 16:16:59 +07:00
label="ส่งไปยังผู้บังคับบัญชา/ผู้มีอำนาจ"
2024-10-08 17:29:26 +07:00
color="public"
type="submit"
2024-10-15 16:16:59 +07:00
:disable="
selected.length === 0 ||
2024-10-16 18:11:38 +07:00
(!isAcceptSetting && !isApproveSetting && !isReasonSetting)
2024-10-15 16:16:59 +07:00
"
2024-10-08 17:29:26 +07:00
>
</q-btn>
</q-card-actions>
</q-form>
</q-card>
</q-dialog>
</template>
<style scoped></style>