From f78d8547ce2a32367e9bc89c18228ab1749e3d20 Mon Sep 17 00:00:00 2001 From: oat_dev Date: Fri, 15 Mar 2024 10:27:53 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=81=E0=B8=B2?= =?UTF-8?q?=E0=B8=A3=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B9=80=E0=B8=A0=E0=B8=97?= =?UTF-8?q?=E0=B8=95=E0=B8=B3=E0=B9=81=E0=B8=AB=E0=B8=99=E0=B9=88=E0=B8=87?= =?UTF-8?q?:=20=E0=B8=9B=E0=B8=A3=E0=B8=B1=E0=B8=9A=E0=B8=AA=E0=B9=84?= =?UTF-8?q?=E0=B8=95=E0=B8=A5=E0=B9=8C/validate/=E0=B9=83=E0=B8=AA?= =?UTF-8?q?=E0=B9=88catch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/position/02ListType.vue | 124 +++++++++++------- .../components/position/05ListLevelDetail.vue | 53 +++++--- 2 files changed, 108 insertions(+), 69 deletions(-) diff --git a/src/modules/01_metadataNew/components/position/02ListType.vue b/src/modules/01_metadataNew/components/position/02ListType.vue index a07693bdf..c5caec7ef 100644 --- a/src/modules/01_metadataNew/components/position/02ListType.vue +++ b/src/modules/01_metadataNew/components/position/02ListType.vue @@ -85,16 +85,10 @@ const filterKeyword = ref(""); const dialog = ref(false); const posTypeName = ref(""); const posTypeNameRef = ref(null); -const posTypeRank = ref(); +const posTypeRank = ref(null); const posTypeRankRef = ref(null); const dialogStatus = ref(""); -const visibleColumns = ref([ - "posTypeName", - "posTypeRank", - // "createdAt", - // "lastUpdatedAt", - // "lastUpdateFullName", -]); +const visibleColumns = ref(["posTypeName", "posTypeRank"]); async function fetchData() { showLoader(); @@ -112,24 +106,53 @@ async function fetchData() { } async function addData() { - await http.post(config.API.orgPosType, { - posTypeName: posTypeName.value, - posTypeRank: posTypeRank.value, - }); - fetchData(); + await http + .post(config.API.orgPosType, { + posTypeName: posTypeName.value, + posTypeRank: posTypeRank.value, + }) + .then(() => { + fetchData(); + success($q, "บันทึกข้อมูลสำเร็จ"); + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); } async function editData(id: string) { - await http.put(config.API.orgPosTypeId(id), { - posTypeName: posTypeName.value, - posTypeRank: posTypeRank.value, - }); - fetchData(); + await http + .put(config.API.orgPosTypeId(id), { + posTypeName: posTypeName.value, + posTypeRank: posTypeRank.value, + }) + .then(() => { + fetchData(); + success($q, "บันทึกข้อมูลสำเร็จ"); + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); } async function deleteData(id: string) { - await http.delete(config.API.orgPosTypeId(id)); - fetchData(); + await http + .delete(config.API.orgPosTypeId(id)) + .then(() => { + fetchData(); + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); } onMounted(async () => { @@ -151,14 +174,15 @@ function validateForm() { } async function onSubmit() { - if (posTypeName.value.length > 0) { + console.log(posTypeRank.value); + if (posTypeName.value.length > 0 && posTypeRank.value !== null) { dialogConfirm( $q, async () => { dialogStatus.value === "create" ? addData() : editData(editId.value); closeDialog(); posTypeName.value = ""; - posTypeRank.value = undefined; + posTypeRank.value = null; }, "ยืนยันการบันทึกข้อมูล", "ต้องการยืนยันการบันทึกข้อมูลนี้หรือไม่ ?" @@ -276,7 +300,7 @@ async function onSubmit() { - +
- - +
+ +
+
+ +
diff --git a/src/modules/01_metadataNew/components/position/05ListLevelDetail.vue b/src/modules/01_metadataNew/components/position/05ListLevelDetail.vue index b4f7a0f34..4980d5974 100644 --- a/src/modules/01_metadataNew/components/position/05ListLevelDetail.vue +++ b/src/modules/01_metadataNew/components/position/05ListLevelDetail.vue @@ -13,16 +13,23 @@ import config from "@/app.config"; const store = usePositionDataStore(); const storeOption = useMainOptionDataStore(); const storeName = usePositionTypeDataStore(); -const router = useRouter(); + const mixin = useCounterMixin(); const posName = defineModel("posName", { required: true, }); -const { dialogRemove, dialogConfirm, showLoader, hideLoader, messageError } = - mixin; +const { + dialogRemove, + dialogConfirm, + showLoader, + hideLoader, + messageError, + success, +} = mixin; const $q = useQuasar(); + const columns = [ { name: "no", @@ -123,20 +130,15 @@ const editId = ref(""); const posLevelName = ref(""); const posLevelRank = ref(); const posLevelAuthority = ref(""); -const posTypeId = ref(); const posLevelNameRef = ref(null); const posLevelRankRef = ref(null); const posTypeIdRef = ref(null); -const name = ref(""); const visibleColumns = ref([ "no", "posTypeName", "posLevelName", "posLevelRank", "posLevelAuthority", - // "createdAt", - // "lastUpdatedAt", - // "lastUpdateFullName", ]); async function fetchData() { @@ -165,9 +167,13 @@ async function addData() { }) .then(() => { fetchData(); + success($q, "บันทึกข้อมูลสำเร็จ"); }) .catch((err) => { messageError($q, err); + }) + .finally(() => { + hideLoader(); }); } @@ -182,9 +188,13 @@ async function editData(editId: string) { }) .then(() => { fetchData(); + success($q, "บันทึกข้อมูลสำเร็จ"); }) .catch((err) => { messageError($q, err); + }) + .finally(() => { + hideLoader(); }); } @@ -196,19 +206,12 @@ async function deleteData(id: string) { }) .catch((err) => { messageError($q, err); + }) + .finally(() => { + hideLoader(); }); } -onMounted(async () => { - fetchName(); - storeName.row.forEach((e) => { - if (e.id === id.value) { - posName.value = e.posTypeName ? e.posTypeName : ""; - } - }); - fetchData(); -}); - function closeDialog() { dialog.value = false; } @@ -240,6 +243,11 @@ async function fetchName() { .get(config.API.orgPosType) .then(async (res) => { storeName.save(res.data.result); + storeName.row.forEach((e) => { + if (e.id === id.value) { + posName.value = e.posTypeName ? e.posTypeName : ""; + } + }); }) .catch((err) => { messageError($q, err); @@ -248,6 +256,11 @@ async function fetchName() { hideLoader(); }); } + +onMounted(async () => { + fetchName(); + fetchData(); +});