comment code ส่วนเครื่องราช
This commit is contained in:
parent
e9b7cddf09
commit
7371689594
7 changed files with 745 additions and 766 deletions
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue