changes
This commit is contained in:
@@ -8,8 +8,11 @@ const props = defineProps({
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
<div>
|
||||||
<h1 class="subtitle">Sản phẩm</h1>
|
<h1 class="subtitle">Sản phẩm</h1>
|
||||||
<ProductForm :variantId="variant.id" />
|
<ProductForm :variantId="variant.id" />
|
||||||
|
<hr />
|
||||||
<h1 class="subtitle">Phiên bản</h1>
|
<h1 class="subtitle">Phiên bản</h1>
|
||||||
<ProductVariantForm :variantId="variant.id" />
|
<ProductVariantForm :variantId="variant.id" />
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -24,10 +24,10 @@ function toggleSelected(imeiRec) {
|
|||||||
|
|
||||||
const { cartItems, getCart } = inject("pos");
|
const { cartItems, getCart } = inject("pos");
|
||||||
const isAdding = ref(false);
|
const isAdding = ref(false);
|
||||||
|
|
||||||
async function addToCart() {
|
async function addToCart() {
|
||||||
try {
|
try {
|
||||||
isAdding.value = true;
|
isAdding.value = true;
|
||||||
console.log("store.customer", store.customer);
|
|
||||||
let cart = await $getdata("Cart", {
|
let cart = await $getdata("Cart", {
|
||||||
filter: { customer: store.customer },
|
filter: { customer: store.customer },
|
||||||
first: true,
|
first: true,
|
||||||
|
|||||||
@@ -66,11 +66,16 @@ async function createOrder() {
|
|||||||
|
|
||||||
$snackbar("Tạo đơn hàng thành công", "Success");
|
$snackbar("Tạo đơn hàng thành công", "Success");
|
||||||
|
|
||||||
await Promise.all(cartItems.value.map(({ id }) => $deleteapi("Cart_Item", id)));
|
await Promise.all([
|
||||||
await $patchapi("Cart", {
|
$deleteapi(
|
||||||
|
"Cart_Item",
|
||||||
|
cartItems.value.map((c) => c.id),
|
||||||
|
),
|
||||||
|
$patchapi("Cart", {
|
||||||
id: cartItems.value[0].cart,
|
id: cartItems.value[0].cart,
|
||||||
customer: null,
|
customer: null,
|
||||||
});
|
}),
|
||||||
|
]);
|
||||||
getCart();
|
getCart();
|
||||||
emit("close");
|
emit("close");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -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}`;
|
window.location.href = `https://${mode === "dev" ? "dev." : ""}login.utopia.com.vn/signin?module=${module}&link=${window.location.origin}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getpath = function (name) {
|
const getpath = function (name = mode) {
|
||||||
return name ? paths.find((v) => v.name === name).url : path;
|
return paths.find((v) => v.name === name).url;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -56,23 +56,23 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|||||||
const getapi = async function (list) {
|
const getapi = async function (list) {
|
||||||
try {
|
try {
|
||||||
const arr = list.map((v) => {
|
const arr = list.map((v) => {
|
||||||
const found = apis.find((api) => api.name === v.name);
|
const api = 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);
|
const url = (v.path ? paths.find((x) => x.name === v.path).url : path) + (v.url || api.url);
|
||||||
let params = v.params ? v.params : found.params === undefined ? {} : found.params;
|
const params = v.params || api.params || {};
|
||||||
params.login = $store.login ? $store.login.id : undefined;
|
params.login = $store.login?.id;
|
||||||
return { url, params };
|
return { url, params };
|
||||||
});
|
});
|
||||||
let data = await Promise.all(arr.map((v) => $fetch(v.url, { params: v.params })));
|
const data = await Promise.all(arr.map(({ url, params }) => $fetch(url, { params })));
|
||||||
data.map((v, i) => {
|
data.forEach((v, i) => {
|
||||||
list[i].data = v;
|
list[i].data = v;
|
||||||
if (list[i].commit) {
|
if (list[i].commit) {
|
||||||
let data = v.rows ? v.rows : v;
|
const data = v.rows ? v.rows : v;
|
||||||
$store.commit(list[i].commit, data);
|
$store.commit(list[i].commit, data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return list;
|
return list;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.error(err);
|
||||||
return "error";
|
return "error";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -323,27 +323,25 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|||||||
const deleteapi = async function (name, id) {
|
const deleteapi = async function (name, id) {
|
||||||
try {
|
try {
|
||||||
const api = findapi(name);
|
const api = findapi(name);
|
||||||
let rs;
|
const rs = Array.isArray(id)
|
||||||
if (!Array.isArray(id)) {
|
? await $fetch(`${path}delete-data/${api.url.slice(5)}`, {
|
||||||
rs = await $fetch(`${path}${api.url_detail}${id}`, {
|
method: "POST",
|
||||||
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 })),
|
body: id.map((id) => ({ id })),
|
||||||
|
})
|
||||||
|
: await $fetch(`${path}${api.url_detail}${id}`, {
|
||||||
|
method: "DELETE",
|
||||||
});
|
});
|
||||||
}
|
|
||||||
if (api.commit) {
|
if (api.commit) {
|
||||||
const copy = $copy($store[api.commit]);
|
const copy = $copy($store[api.commit]);
|
||||||
if (!Array.isArray(id)) {
|
if (Array.isArray(id)) {
|
||||||
const index = copy.findIndex((v) => v.id === id);
|
|
||||||
if (index >= 0) $remove(copy, index);
|
|
||||||
} else {
|
|
||||||
rs.forEach((element) => {
|
rs.forEach((element) => {
|
||||||
const index = copy.findIndex((v) => v.id === element.id);
|
const index = copy.findIndex((v) => v.id === element.id);
|
||||||
if (index >= 0) $remove(copy, index);
|
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);
|
$store.commit(api.name, copy);
|
||||||
}
|
}
|
||||||
@@ -352,21 +350,31 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|||||||
console.error(err);
|
console.error(err);
|
||||||
if (err.response) {
|
if (err.response) {
|
||||||
let content = `<p>Đã xảy ra lỗi, xóa dữ liệu không thành công.</p>`;
|
let content = `<p>Đã xảy ra lỗi, xóa dữ liệu không thành công.</p>`;
|
||||||
if (err.response.data)
|
if (err.response.data) {
|
||||||
content += `<p class="mt-2 has-text-grey-dark">
|
content += `
|
||||||
<sapn class="icon-text">Chi tiết<SvgIcon class="ml-1" v-bind="{name: 'right.svg', type: 'dark', size: 20}"></SvgIcon></span></p>
|
<p class="block">
|
||||||
<p class="mt-2 has-text-grey-dark">${JSON.stringify(err.response.data)}</p>`;
|
<span class="icon-text">
|
||||||
|
<span>Chi tiết</span>
|
||||||
|
<span class="icon">
|
||||||
|
<Icon
|
||||||
|
name="material-symbols:arrow-forward-ios-rounded"
|
||||||
|
:size="18"
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
<pre>${JSON.stringify(err.response.data, null, 2)}</pre>`;
|
||||||
|
}
|
||||||
$dialog(content, "Lỗi", "Error");
|
$dialog(content, "Lỗi", "Error");
|
||||||
}
|
}
|
||||||
return "error";
|
return "error";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// delete row
|
|
||||||
const deleterow = async function (name, id, pagename) {
|
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;
|
if (result === "error" || !pagename || !$store[pagename]) return result;
|
||||||
let copy = $clone($store[pagename]);
|
const copy = $clone($store[pagename]);
|
||||||
copy.update = { refresh: true };
|
copy.update = { refresh: true };
|
||||||
$store.commit(pagename, copy);
|
$store.commit(pagename, copy);
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
Reference in New Issue
Block a user