changes
This commit is contained in:
@@ -22,28 +22,15 @@ function toggleSelected(imeiRec) {
|
||||
}
|
||||
}
|
||||
|
||||
const { cartItems, getCart } = inject("pos");
|
||||
const { activeCart, activeCartItems, getCarts } = inject("pos");
|
||||
const isAdding = ref(false);
|
||||
|
||||
async function addToCart() {
|
||||
try {
|
||||
isAdding.value = true;
|
||||
let cart = await $getdata("Cart", {
|
||||
filter: { customer: store.customer },
|
||||
first: true,
|
||||
});
|
||||
|
||||
if (!cart) {
|
||||
const newCart = await $insertapi("Cart", {
|
||||
data: { customer: store.customer },
|
||||
notify: false,
|
||||
});
|
||||
|
||||
cart = newCart;
|
||||
}
|
||||
|
||||
const cartItemsPayload = selectedImeis.value.map((imeiRec) => ({
|
||||
cart: cart.id,
|
||||
cart: activeCart.value.id,
|
||||
imei: imeiRec.id,
|
||||
quantity: 1,
|
||||
total_price: imeiRec.variant__price,
|
||||
@@ -54,7 +41,7 @@ async function addToCart() {
|
||||
});
|
||||
|
||||
$snackbar(`Đã thêm ${newCartItems.length} sản phẩm vào giỏ hàng`, "Success");
|
||||
getCart();
|
||||
getCarts();
|
||||
emit("close");
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@@ -72,7 +59,7 @@ async function fetchImeis() {
|
||||
const imeisSoldFetched = await $getdata("IMEI_Sold");
|
||||
|
||||
imeis.value = imeisFetched.filter((imeiRec) => {
|
||||
const inCart = cartItems.value.find((cartItem) => cartItem.imei === imeiRec.id);
|
||||
const inCart = activeCartItems.value.find((cartItem) => cartItem.imei === imeiRec.id);
|
||||
const sold = imeisSoldFetched.find((imeiSold) => imeiSold.imei === imeiRec.imei);
|
||||
return !inCart && !sold;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user