From 8ba1a0b5cfbfb4e148961fe60c8d8b193bd0926e Mon Sep 17 00:00:00 2001 From: Viet An Date: Wed, 10 Jun 2026 19:48:58 +0700 Subject: [PATCH] changes --- app/components/imports/EditProduct.vue | 11 ++-- app/components/pos/ChooseIMEIModal.vue | 2 +- app/components/pos/ConfirmOrder.vue | 15 ++++-- app/plugins/02-connection.js | 72 ++++++++++++++------------ 4 files changed, 58 insertions(+), 42 deletions(-) diff --git a/app/components/imports/EditProduct.vue b/app/components/imports/EditProduct.vue index 1bb5d0d..2e6e2b9 100644 --- a/app/components/imports/EditProduct.vue +++ b/app/components/imports/EditProduct.vue @@ -8,8 +8,11 @@ const props = defineProps({ diff --git a/app/components/pos/ChooseIMEIModal.vue b/app/components/pos/ChooseIMEIModal.vue index 380793d..f58bf52 100644 --- a/app/components/pos/ChooseIMEIModal.vue +++ b/app/components/pos/ChooseIMEIModal.vue @@ -24,10 +24,10 @@ function toggleSelected(imeiRec) { const { cartItems, getCart } = inject("pos"); const isAdding = ref(false); + async function addToCart() { try { isAdding.value = true; - console.log("store.customer", store.customer); let cart = await $getdata("Cart", { filter: { customer: store.customer }, first: true, diff --git a/app/components/pos/ConfirmOrder.vue b/app/components/pos/ConfirmOrder.vue index 2cd83b8..0a5de17 100644 --- a/app/components/pos/ConfirmOrder.vue +++ b/app/components/pos/ConfirmOrder.vue @@ -66,11 +66,16 @@ async function createOrder() { $snackbar("Tạo đơn hàng thành công", "Success"); - await Promise.all(cartItems.value.map(({ id }) => $deleteapi("Cart_Item", id))); - await $patchapi("Cart", { - id: cartItems.value[0].cart, - customer: null, - }); + await Promise.all([ + $deleteapi( + "Cart_Item", + cartItems.value.map((c) => c.id), + ), + $patchapi("Cart", { + id: cartItems.value[0].cart, + customer: null, + }), + ]); getCart(); emit("close"); } catch (error) { diff --git a/app/plugins/02-connection.js b/app/plugins/02-connection.js index eb27c64..9d432ed 100644 --- a/app/plugins/02-connection.js +++ b/app/plugins/02-connection.js @@ -16,8 +16,8 @@ export default defineNuxtPlugin((nuxtApp) => { window.location.href = `https://${mode === "dev" ? "dev." : ""}login.utopia.com.vn/signin?module=${module}&link=${window.location.origin}`; }; - const getpath = function (name) { - return name ? paths.find((v) => v.name === name).url : path; + const getpath = function (name = mode) { + return paths.find((v) => v.name === name).url; }; /** @@ -56,23 +56,23 @@ export default defineNuxtPlugin((nuxtApp) => { const getapi = async function (list) { try { const arr = list.map((v) => { - const found = apis.find((api) => api.name === v.name); - const url = (v.path ? paths.find((x) => x.name === v.path).url : path) + (v.url ? v.url : found.url); - let params = v.params ? v.params : found.params === undefined ? {} : found.params; - params.login = $store.login ? $store.login.id : undefined; + const api = apis.find((api) => api.name === v.name); + const url = (v.path ? paths.find((x) => x.name === v.path).url : path) + (v.url || api.url); + const params = v.params || api.params || {}; + params.login = $store.login?.id; return { url, params }; }); - let data = await Promise.all(arr.map((v) => $fetch(v.url, { params: v.params }))); - data.map((v, i) => { + const data = await Promise.all(arr.map(({ url, params }) => $fetch(url, { params }))); + data.forEach((v, i) => { list[i].data = v; if (list[i].commit) { - let data = v.rows ? v.rows : v; + const data = v.rows ? v.rows : v; $store.commit(list[i].commit, data); } }); return list; } catch (err) { - console.log(err); + console.error(err); return "error"; } }; @@ -323,27 +323,25 @@ export default defineNuxtPlugin((nuxtApp) => { const deleteapi = async function (name, id) { try { const api = findapi(name); - let rs; - if (!Array.isArray(id)) { - rs = await $fetch(`${path}${api.url_detail}${id}`, { - method: "delete", - }); - } else { - rs = await $fetch(`${path}import-data/${api.url.substring(5, api.url.length - 1)}/`, { - params: { action: "delete" }, - body: id.map((id) => ({ id })), - }); - } + const rs = Array.isArray(id) + ? await $fetch(`${path}delete-data/${api.url.slice(5)}`, { + method: "POST", + body: id.map((id) => ({ id })), + }) + : await $fetch(`${path}${api.url_detail}${id}`, { + method: "DELETE", + }); + if (api.commit) { const copy = $copy($store[api.commit]); - if (!Array.isArray(id)) { - const index = copy.findIndex((v) => v.id === id); - if (index >= 0) $remove(copy, index); - } else { + if (Array.isArray(id)) { rs.forEach((element) => { const index = copy.findIndex((v) => v.id === element.id); if (index >= 0) $remove(copy, index); }); + } else { + const index = copy.findIndex((v) => v.id === id); + if (index >= 0) $remove(copy, index); } $store.commit(api.name, copy); } @@ -352,21 +350,31 @@ export default defineNuxtPlugin((nuxtApp) => { console.error(err); if (err.response) { let content = `

Đã xảy ra lỗi, xóa dữ liệu không thành công.

`; - if (err.response.data) - content += `

- Chi tiết

-

${JSON.stringify(err.response.data)}

`; + if (err.response.data) { + content += ` +

+ + Chi tiết + + + + +

+
${JSON.stringify(err.response.data, null, 2)}
`; + } $dialog(content, "Lỗi", "Error"); } return "error"; } }; - // delete row const deleterow = async function (name, id, pagename) { - let result = await deleteapi(name, id); + const result = await deleteapi(name, id); if (result === "error" || !pagename || !$store[pagename]) return result; - let copy = $clone($store[pagename]); + const copy = $clone($store[pagename]); copy.update = { refresh: true }; $store.commit(pagename, copy); return result;