hrms-mgt/src/modules/12_evaluatePersonal/components/Detail/viewTab2/DialogDirector.vue
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 1b42277dcb fix .prevent
2025-05-23 11:47:17 +07:00

268 lines
6.4 KiB
Vue

<script setup lang="ts">
import { ref, watchEffect, watch, type PropType } from "vue";
import { useCounterMixin } from "@/stores/mixin";
/** importType*/
import type { QTableProps } from "quasar";
import type { directorType } from "@/modules/11_discipline/interface/index/Main";
import type { Directors } from "@/modules/12_evaluatePersonal/interface/response/Main";
/** importComponents*/
import DialogHeader from "@/components/DialogHeader.vue";
const mixin = useCounterMixin();
const { onSearchDataTable } = mixin;
const selected = ref<directorType[]>([]);
const rows = defineModel<Directors[]>("rows", { required: true });
const rowsData = defineModel<Directors[]>("rowsData", { required: true });
const filterKeyword2 = defineModel<string>("filterKeyword2", {
required: true,
});
/** รับ props มาจากหน้าหลัก */
const props = defineProps({
Modal: Boolean,
clickClose: Function,
getData: Function,
filterTable: {
type: String,
default: "",
},
maxPage: {
type: Number,
require: true,
},
rowsPerPage: {
type: Number,
require: true,
},
page: {
type: Number,
require: true,
},
getList: {
type: Function,
default: () => "",
},
selectedRow: {
type: Array as PropType<directorType[]>,
required: true,
},
});
const currentPage = ref<number>(1); //หน้าปัจจุบัน
/** ค้นหาคอลัม */
const visibleColumns2 = ref<string[]>([
"no",
"name",
"position",
"email",
"phone",
]);
// หัวตาราง
const columns2 = ref<QTableProps["columns"]>([
{
name: "no",
align: "left",
label: "ลำดับ",
sortable: false,
field: "no",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "name",
align: "left",
label: "ชื่อ-นามสกุล",
sortable: true,
field: "name",
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",
},
{
name: "email",
align: "left",
label: "อีเมล",
sortable: true,
field: "email",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "phone",
align: "left",
label: "เบอร์โทรศัพท์",
sortable: true,
field: "phone",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
]);
/** แสดงจำนวนในตาราง */
const pagination = ref({
descending: true,
page: Number(props.page),
rowsPerPage: props.rowsPerPage,
});
const emit = defineEmits([
"update:filterKeyword2",
"update:selected",
"update:pagination",
"returnDirector",
]);
/** เลือกกรรมการ */
async function directorSave() {
emit("returnDirector", selected.value);
}
/**
* ฟังก์ชันอัปเดทคำค้นหา
* @param value คำค้นหา
*/
function updateInput(value: any) {
emit("update:filterKeyword2", value);
}
/**
* รีเซ็ตค่าในช่องค้นหา
*/
function Reset() {
emit("update:filterKeyword2", "");
}
/**
*
* @param newPagination
* @param page
*/
function updateProp(newPagination: number, page: number) {
// ส่ง event ไปยัง parent component เพื่ออัพเดทค่า props
emit("update:pagination", newPagination, page);
}
function onSearch() {
rows.value = onSearchDataTable(
filterKeyword2.value,
rowsData.value,
columns2.value ? columns2.value : []
);
}
/**
* เช็คค่า props.Modal === true
*/
watchEffect(() => {
if (props.Modal === true) {
selected.value = props.selectedRow;
filterKeyword2.value = "";
}
});
watch(
() => currentPage.value,
() => {
if (pagination.value.rowsPerPage) {
updateProp(pagination.value.rowsPerPage, currentPage.value);
}
}
);
watch(
() => pagination.value.rowsPerPage,
() => {
currentPage.value = 1;
if (pagination.value.rowsPerPage) {
updateProp(pagination.value.rowsPerPage, currentPage.value);
}
}
);
</script>
<template>
<q-dialog v-model="props.Modal" persistent>
<q-card style="width: 1200px; max-width: 80vw">
<DialogHeader tittle="เลือกรายชื่อกรรมการ" :close="clickClose" />
<q-separator />
<q-card-section>
<q-input
borderless
outlined
dense
class="col-12 q-mb-sm"
v-model="filterKeyword2"
placeholder="ค้นหารายชื่อ"
style="max-width: 100%"
@keydown.enter.prevent="onSearch"
>
<template v-slot:append>
<q-icon name="search" />
</template>
</q-input>
<d-table
:columns="columns2"
:rows="rows"
row-key="id"
:visible-columns="visibleColumns2"
selection="multiple"
v-model:selected="selected"
:rows-per-page-options="[10, 25, 50, 100]"
v-model:pagination="pagination"
>
<template v-slot:header-selection="scope">
<q-checkbox
keep-color
color="primary"
dense
v-model="scope.selected"
/>
</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 v-if="col.name == 'no'">
{{ props.rowIndex + 1 }}
</div>
<div v-else>
{{ col.value }}
</div>
</q-td>
</q-tr>
</template>
</d-table>
</q-card-section>
<q-separator />
<q-card-actions align="right" class="bg-white text-teal">
<q-btn
label="เพิ่มรายชื่อกรรมการ"
@click="directorSave"
:disable="selected.length === 0"
color="public"
/>
</q-card-actions>
</q-card>
</q-dialog>
</template>