comment code ส่วนเครื่องราช

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2023-11-16 11:29:56 +07:00
parent e9b7cddf09
commit 7371689594
7 changed files with 745 additions and 766 deletions

View file

@ -1,124 +1,52 @@
<script setup lang="ts">
import { ref, onMounted, watch, useAttrs } from "vue";
import { useCounterMixin } from "@/stores/mixin";
import http from "@/plugins/http";
import config from "@/app.config";
import { useAllocateDataStore } from "@/modules/07_insignia/storeAllocate";
import router from "@/router";
import { useQuasar } from "quasar";
/** impotrType */
import type { OptionDataYear } from "@/modules/07_insignia/interface/index/Main";
import type { QTableProps, QInput } from "quasar";
/** impotrComponents */
import DialogForm from "@/modules/07_insignia/components/4_Allocate/DialogForm.vue";
import DialogEdit from "@/modules/07_insignia/components/4_Allocate/DialogEdit.vue";
import type { OptionDataYear } from "@/modules/07_insignia/interface/index/Main";
import type { QTableProps, QInput } from "quasar";
import { useQuasar } from "quasar";
/** impotrStores */
import { useCounterMixin } from "@/stores/mixin";
import { useAllocateDataStore } from "@/modules/07_insignia/storeAllocate";
const DataStore = useAllocateDataStore();
const mixin = useCounterMixin();
const { showLoader, hideLoader, messageError, dialogRemove, success } = mixin;
const redirectToPage = (id: string, name: string) => {
DataStore.insigniaName = name;
router.push(`/insignia/allocate/org/${id}`);
};
const paging = ref<boolean>(true);
const paginationLabel = (start: string, end: string, total: string) => {
if (paging.value == true) return " " + start + "-" + end + " ใน " + total;
else return start + "-" + end + " ใน " + total;
};
const pagination = ref({
sortBy: "desc",
descending: false,
page: 1,
rowsPerPage: 10,
});
const $q = useQuasar();
const tab = ref<string>("");
const attrs = ref<any>(useAttrs());
const tab = ref<string>("");
const selectRound = ref<string>();
const selectRoundOption = ref<OptionDataYear[]>([]);
const modal = ref<boolean>(false);
const action = ref<string>("");
const roundYear = ref<number>();
const insigniaOp = ref<any>([]);
const filterInsigniaOp = ref<any>({insigniaOp:[]})
const filterInsigniaOp = ref<any>({ insigniaOp: [] });
const loadView = ref<boolean>(false);
onMounted(async () => {
await fecthRound();
const pagination = ref({
sortBy: "desc",
descending: false,
page: 1,
rowsPerPage: 10,
});
//
const fecthRound = async () => {
await http
.get(config.API.noteround())
.then(async (res) => {
let data = res.data.result;
if (data.length !== 0) {
selectRoundOption.value = data.map((e: any) => ({
id: e.id,
name: "รอบการเสนอขอพระราชทานเครื่องราชฯ ปี" + " " + (e.year + 543),
year: e.year,
}));
if (DataStore.roundId && DataStore.roundYear) {
selectRound.value = DataStore.roundId;
roundYear.value = DataStore.roundYear;
} else {
selectRound.value = data[0].id;
roundYear.value = data[0].year;
}
if (selectRound.value) {
DataStore.roundId = selectRound.value;
}
if (roundYear.value) {
await fecthInsigniaType();
}
}
})
.catch((err) => {
messageError($q, err);
});
};
//
const fecthInsignia = async () => {
await http
.get(config.API.insignia)
.then((res) => {
let data = res.data.result;
DataStore.fetchDatainsignia(data);
})
.catch((err) => {
messageError($q, err);
})
.finally(async () => {
insigniaOp.value = await DataStore.insigniaOp.filter(
(x: any) => x.type == tab.value || x.type === ""
);
});
};
// tab
const fecthInsigniaType = async () => {
await http(config.API.insigniaType)
.then((res) => {
let data = res.data.result;
DataStore.fetchDatainsigniaType(data);
if (DataStore.mainTab) {
tab.value = DataStore.mainTab;
} else tab.value = DataStore.insigniaType[0].name;
loadView.value = true;
fecthInsignia();
})
.catch((err) => {
messageError($q, err);
});
};
/** ข้อมูล Table*/
const visibleColumns = ref<string[]>([
"no",
"insignia",
"total",
"allocate",
"remain",
]); //
]);
const columns = ref<QTableProps["columns"]>([
{
name: "no",
@ -167,21 +95,79 @@ const columns = ref<QTableProps["columns"]>([
style: "font-size: 14px",
},
]);
// tab
watch(tab, () => {
insigniaOp.value = DataStore.insigniaOp.filter(
(x: any) => x.type == tab.value || x.type === ""
);
let a = insigniaOp.value.find((e: any) => e.id == DataStore.insignia);
if (!a) {
DataStore.insignia = "";
}
filterInsigniaOp.value = insigniaOp.value
fecthlistInsignia();
});
const filterRef = ref<QInput>();
const filter = ref<string>("");
const rowData = ref<any>([]);
//
const selectorRound = (round: string | undefined) => {
/** function เรียกรอบการเสนอขอ*/
async function fecthRound() {
await http
.get(config.API.noteround())
.then(async (res) => {
let data = res.data.result;
if (data.length !== 0) {
selectRoundOption.value = data.map((e: any) => ({
id: e.id,
name: "รอบการเสนอขอพระราชทานเครื่องราชฯ ปี" + " " + (e.year + 543),
year: e.year,
}));
if (DataStore.roundId && DataStore.roundYear) {
selectRound.value = DataStore.roundId;
roundYear.value = DataStore.roundYear;
} else {
selectRound.value = data[0].id;
roundYear.value = data[0].year;
}
if (selectRound.value) {
DataStore.roundId = selectRound.value;
}
if (roundYear.value) {
await fecthInsigniaType();
}
}
})
.catch((err) => {
messageError($q, err);
});
}
/** function เรียกประเภทเครื่องราช*/
async function fecthInsignia() {
await http
.get(config.API.insignia)
.then((res) => {
let data = res.data.result;
DataStore.fetchDatainsignia(data);
})
.catch((err) => {
messageError($q, err);
})
.finally(async () => {
insigniaOp.value = await DataStore.insigniaOp.filter(
(x: any) => x.type == tab.value || x.type === ""
);
});
}
/** function เรียก Tab*/
const fecthInsigniaType = async () => {
await http(config.API.insigniaType)
.then((res) => {
let data = res.data.result;
DataStore.fetchDatainsigniaType(data);
if (DataStore.mainTab) {
tab.value = DataStore.mainTab;
} else tab.value = DataStore.insigniaType[0].name;
loadView.value = true;
fecthInsignia();
})
.catch((err) => {
messageError($q, err);
});
};
/** function เลือกรอบการเสนขอ*/
async function selectorRound(round: string | undefined) {
selectRound.value = round;
if (selectRound.value) {
DataStore.roundId = selectRound.value;
@ -189,10 +175,11 @@ const selectorRound = (round: string | undefined) => {
const yearFilter = selectRoundOption.value.find((x: any) => x.id == round); //
roundYear.value = yearFilter?.year;
DataStore.roundYear = roundYear.value;
fecthlistInsignia();
};
//
const fecthlistInsignia = async () => {
await fecthlistInsignia();
}
/** function เรียกรายการเครืองราชฯ */
async function fecthlistInsignia() {
DataStore.mainTab = tab.value;
showLoader();
await http
@ -207,24 +194,34 @@ const fecthlistInsignia = async () => {
.finally(() => {
hideLoader();
});
};
}
const filterRef = ref<QInput>();
const filter = ref<string>("");
/**
* function reDirectToPage หนวยงานจดสรรเครองราชอสรยาภรณ
* @param id ดสรรเครองราชอสรยาภรณ
* @param name อเครองราช
*/
function redirectToPage(id: string, name: string) {
DataStore.insigniaName = name;
router.push(`/insignia/allocate/org/${id}`);
}
const close = () => {
/** ตัวแปร popup*/
const modalEdit = ref<boolean>(false);
const actionType = ref<string>("");
/** function closePopup*/
function close() {
modal.value = false;
modalEdit.value = false;
};
// popup
}
/** function openPopup การเพิ่มการจัดสรรเครื่องราชฯ*/
const addData = () => {
modal.value = true;
action.value = "addData";
};
const modalEdit = ref<boolean>(false);
const rowData = ref<any>([]);
const actionType = ref<string>("");
/** function openPopup การแกไขการจัดสรรเครื่องราชฯ*/
const clickEditrow = (data: any) => {
rowData.value = data;
modalEdit.value = true;
@ -251,13 +248,21 @@ const save = async (insigniaId: string, total: string) => {
close();
});
};
//
const saveEdit = async (
//
/**
* function ททกการแกไขการจดสรรเครองราชฯ
* @param id รอบการเสนอ
* @param insigniaId การจดสรรเครองราชฯ
* @param total จำนวน
* @param year
*/
async function saveEdit(
id: string,
insigniaId: string,
total: Number,
year: Number
) => {
) {
showLoader();
let body = {
insignia: insigniaId,
@ -277,9 +282,13 @@ const saveEdit = async (
hideLoader();
close();
});
};
//
const clickDelete = async (insigniaId: string) => {
}
/**
* function ลบการจดสรรเครองราชฯ
* @param insigniaId การจดสรรเครองราชฯ
*/
async function clickDelete(insigniaId: string) {
dialogRemove($q, async () => {
showLoader();
await http
@ -295,33 +304,61 @@ const clickDelete = async (insigniaId: string) => {
hideLoader();
});
});
};
}
const resetFilter = () => {
function resetFilter() {
// reset X
filter.value = "";
filterRef.value!.focus();
};
const filterSelector = (val: any, update: Function, name: any) => {
}
/**
* function นหาขอมลใน option
* @param val คำคนหา
* @param update function
* @param name Selec
*/
function filterSelector(val: any, update: Function, name: any) {
update(() => {
const needle = val.toLowerCase();
if (name === 'filterInsigniaOp') {
DataStore.insignia = undefined as any
if (name === "filterInsigniaOp") {
DataStore.insignia = undefined as any;
filterInsigniaOp.value = insigniaOp.value.filter(
(v: any) => v.name.toLowerCase().indexOf(needle) > -1
);
(v: any) => v.name.toLowerCase().indexOf(needle) > -1
);
}
}
)
});
}
/**
* function เคลยร filter
* @param name filter
*/
const clearInsigniaFilters = (name: string) => {
console.log(insigniaOp.value)
console.log(insigniaOp.value);
if (name === "filterInsigniaOp") {
DataStore.insignia = '';
DataStore.insignia = "";
filterInsigniaOp.value = insigniaOp.value;
}
};
/** function callback ทำงานเมื่อ Tab มีการเปลี่ยน*/
watch(tab, () => {
insigniaOp.value = DataStore.insigniaOp.filter(
(x: any) => x.type == tab.value || x.type === ""
);
let a = insigniaOp.value.find((e: any) => e.id == DataStore.insignia);
if (!a) {
DataStore.insignia = "";
}
filterInsigniaOp.value = insigniaOp.value;
fecthlistInsignia();
});
/** Hook*/
onMounted(async () => {
await fecthRound();
});
</script>
<template>
@ -353,13 +390,11 @@ const clearInsigniaFilters = (name: string) => {
input-class="text-bold text-grey"
@update:model-value="selectorRound(selectRound)"
>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
ไมอม
</q-item-section>
</q-item>
</template>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey"> ไมอม </q-item-section>
</q-item>
</template>
</q-select>
</div>
<q-separator />
@ -406,28 +441,34 @@ const clearInsigniaFilters = (name: string) => {
@update:model-value="
DataStore.selectInsignia(DataStore.insignia)
"
@filter="(inputValue:any,
@filter="(inputValue:any,
doneFn:Function) => filterSelector(inputValue, doneFn,'filterInsigniaOp'
) "
>
<template v-if="DataStore.insignia !== undefined && DataStore.insignia !== ''" v-slot:append>
<q-icon
name="cancel"
@click.stop.prevent="
clearInsigniaFilters('filterInsigniaOp'),
DataStore.selectInsignia(DataStore.insignia)
"
class="cursor-pointer"
/>
</template>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
ไมอม
</q-item-section>
</q-item>
</template>
</q-select>
>
<template
v-if="
DataStore.insignia !== undefined &&
DataStore.insignia !== ''
"
v-slot:append
>
<q-icon
name="cancel"
@click.stop.prevent="
clearInsigniaFilters('filterInsigniaOp'),
DataStore.selectInsignia(DataStore.insignia)
"
class="cursor-pointer"
/>
</template>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
ไมอม
</q-item-section>
</q-item>
</template>
</q-select>
</div>
<div>
@ -496,7 +537,6 @@ const clearInsigniaFilters = (name: string) => {
class="custom-header-table"
v-bind="attrs"
:visible-columns="visibleColumns"
:pagination-label="paginationLabel"
v-model:pagination="pagination"
>
<template v-slot:header="props">
@ -602,18 +642,6 @@ const clearInsigniaFilters = (name: string) => {
</q-td>
</q-tr>
</template>
<template v-slot:pagination="scope">
<q-pagination
v-model="pagination.page"
active-color="primary"
color="dark"
:max="scope.pagesNumber"
:max-pages="5"
size="sm"
boundary-links
direction-links
></q-pagination>
</template>
</d-table>
</div>
</q-tab-panel>