ปรับข้อมูลหลักเครื่องราชฯ

This commit is contained in:
Warunee Tamkoo 2024-01-30 13:43:25 +07:00
parent a7fa6e6cf4
commit f3e2b2c06b
4 changed files with 44 additions and 36 deletions

View file

@ -17,7 +17,6 @@ const router = useRouter();
const route = useRoute(); const route = useRoute();
const $q = useQuasar(); const $q = useQuasar();
const store = useInsigniaDataStore(); const store = useInsigniaDataStore();
const row = ref<DetailRow[]>();
const mixin = useCounterMixin(); const mixin = useCounterMixin();
const { date2Thai, messageError, hideLoader, showLoader } = mixin; const { date2Thai, messageError, hideLoader, showLoader } = mixin;
const id = ref<string>(route.params.id.toString()); const id = ref<string>(route.params.id.toString());
@ -40,7 +39,7 @@ async function fetchData(id: string) {
} }
onMounted(async () => { onMounted(async () => {
fetchData(id.value); await fetchData(id.value);
}); });
</script> </script>
@ -60,7 +59,7 @@ onMounted(async () => {
</div> </div>
<q-card flat bordered> <q-card flat bordered>
<InsigniaList :data="row" /> <InsigniaList :fetchData="fetchData"/>
</q-card> </q-card>
</template> </template>

View file

@ -12,6 +12,13 @@ import config from "@/app.config";
const store = useInsigniaDataStore(); const store = useInsigniaDataStore();
const router = useRouter(); const router = useRouter();
const mixin = useCounterMixin(); const mixin = useCounterMixin();
const props = defineProps({
fetchData: {
type: Function,
default: ()=>"",
}
})
const { const {
date2Thai, date2Thai,
dialogRemove, dialogRemove,
@ -23,17 +30,14 @@ const {
const $q = useQuasar(); const $q = useQuasar();
const columns = ref<QTableProps["columns"]>([ const columns = ref<QTableProps["columns"]>([
{ {
name: "level", name: "no",
align: "left", align: "left",
label: "ลำดับ", label: "ลำดับ",
sortable: true, sortable: false,
field: "level", field: "no",
headerStyle: "font-size: 14px; width:0px", headerStyle: "font-size: 14px; width:0px",
style: "font-size: 14px", style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
}, },
{ {
name: "name", name: "name",
align: "left", align: "left",
@ -144,7 +148,7 @@ const shortNameRef = ref<any>(null);
const dialogStatus = ref<string>(""); const dialogStatus = ref<string>("");
const editId = ref<string>(""); const editId = ref<string>("");
const visibleColumns = ref<string[]>([ const visibleColumns = ref<string[]>([
"level", "no",
"name", "name",
"shortName", "shortName",
"insigniaType", "insigniaType",
@ -165,24 +169,24 @@ function validateForm() {
onSubmit(); onSubmit();
} }
async function fetchData(id: string) { // async function fetchData(id: string) {
showLoader(); // showLoader();
await http // await http
.get(config.API.insigniaTypeNewId(id)) // .get(config.API.insigniaTypeNewId(id))
.then(async (res) => { // .then(async (res) => {
insigniaTypeId.value = res.data.result.name; // insigniaTypeId.value = res.data.result.name;
store.fetchData(res.data.result.insignias, res.data.result.name); // store.fetchData(res.data.result.insignias, res.data.result.name);
}) // })
.catch((err) => { // .catch((err) => {
messageError($q, err); // messageError($q, err);
}) // })
.finally(() => { // .finally(() => {
hideLoader(); // hideLoader();
}); // });
} // }
onMounted(async () => { // onMounted(async () => {
fetchData(id.value); // fetchData(id.value);
}); // });
async function onSubmit() { async function onSubmit() {
if (name.value.length > 0 && shortName.value.length > 0) { if (name.value.length > 0 && shortName.value.length > 0) {
@ -210,7 +214,7 @@ async function addData() {
note: note.value == "" ? "-" : note.value, note: note.value == "" ? "-" : note.value,
insigniaTypeId: id.value, insigniaTypeId: id.value,
}); });
fetchData(id.value); props.fetchData(id.value);
} }
async function editData(idData: string) { async function editData(idData: string) {
@ -221,12 +225,12 @@ async function editData(idData: string) {
note: note.value == "" ? "-" : note.value, note: note.value == "" ? "-" : note.value,
insigniaTypeId: id.value, insigniaTypeId: id.value,
}); });
fetchData(id.value); props.fetchData(id.value);
} }
async function deleteData(idData: string) { async function deleteData(idData: string) {
await http.delete(config.API.insigniaNewId(idData)); await http.delete(config.API.insigniaNewId(idData));
fetchData(id.value); props.fetchData(id.value);
} }
import { defineEmits } from "vue"; import { defineEmits } from "vue";
@ -305,8 +309,11 @@ const dialogOrder = ref<boolean>(false);
</template> </template>
<template v-slot:body="props"> <template v-slot:body="props">
<q-tr :props="props" class="cursor-pointer"> <q-tr :props="props" class="cursor-pointer">
<q-td v-for="col in props.cols" :key="col.id"> <q-td v-for="(col, index) in props.cols" :key="col.id">
<div v-if="col.name == 'isActive'"> <div v-if="col.name == 'no'">
{{ props.rowIndex + 1 }}
</div>
<div v-else-if="col.name == 'isActive'">
<q-icon <q-icon
v-if="col.value == false" v-if="col.value == false"
name="mdi-close" name="mdi-close"

View file

@ -58,6 +58,7 @@ async function save() {
}); });
console.log("post data===>", dataPost); console.log("post data===>", dataPost);
modal.value = false modal.value = false
// showLoader(); // showLoader();
// await http // await http
// .put(config.API.insigniaTypeNewId(id), dataPost) // .put(config.API.insigniaTypeNewId(id), dataPost)
@ -68,6 +69,7 @@ async function save() {
// }) // })
// .finally(() => { // .finally(() => {
// hideLoader(); // hideLoader();
store.row = rows.value
// }); // });
} }

View file

@ -11,9 +11,9 @@ const { date2Thai } = useCounterMixin();
export const useInsigniaDataStore = defineStore("insigniaData", () => { export const useInsigniaDataStore = defineStore("insigniaData", () => {
const row = ref<DataRow[]>([]); const row = ref<DataRow[]>([]);
function fetchData(data: DataResponse[], insigniaType?: string) { function fetchData(data: DataResponse[], insigniaType?: string) {
data.forEach((row, index) => { // data.forEach((row, index) => {
row.level = index + 1; // row.level = index + 1;
}); // });
const list = data.map((e) => ({ const list = data.map((e) => ({
...e, ...e,
insigniaType: insigniaType, insigniaType: insigniaType,