changes
This commit is contained in:
@@ -8,8 +8,11 @@ const props = defineProps({
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<h1 class="subtitle">Sản phẩm</h1>
|
||||
<ProductForm :variantId="variant.id" />
|
||||
<hr />
|
||||
<h1 class="subtitle">Phiên bản</h1>
|
||||
<ProductVariantForm :variantId="variant.id" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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", {
|
||||
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) {
|
||||
|
||||
@@ -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" },
|
||||
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 = `<p>Đã xảy ra lỗi, xóa dữ liệu không thành công.</p>`;
|
||||
if (err.response.data)
|
||||
content += `<p class="mt-2 has-text-grey-dark">
|
||||
<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="mt-2 has-text-grey-dark">${JSON.stringify(err.response.data)}</p>`;
|
||||
if (err.response.data) {
|
||||
content += `
|
||||
<p class="block">
|
||||
<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");
|
||||
}
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user