changes
This commit is contained in:
31
app/components/pos/composables/useActiveCart.js
Normal file
31
app/components/pos/composables/useActiveCart.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import { without } from "es-toolkit";
|
||||
|
||||
export default function useActiveCart({ carts, cartItems, customers }) {
|
||||
const activeCartId = ref();
|
||||
|
||||
const activeCart = computed(() => carts.value.find((c) => c.id === activeCartId.value));
|
||||
const activeCartItems = computed(() => cartItems.value.filter((ci) => ci.cart === activeCartId.value));
|
||||
|
||||
watch(
|
||||
carts,
|
||||
(newVal) => {
|
||||
if (!activeCartId.value && newVal.length) {
|
||||
activeCartId.value = newVal[0].id;
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
const customerIdsWithNoCart = computed(() => {
|
||||
const cusIds = customers.value.map((c) => c.id);
|
||||
const cusIdsWithCart = carts.value.filter((c) => c.customer).map((c) => c.customer);
|
||||
const cusIdsWithNoCart = without(cusIds, ...cusIdsWithCart);
|
||||
return cusIdsWithNoCart;
|
||||
});
|
||||
|
||||
const subtotal = computed(() => {
|
||||
return activeCartItems.value?.reduce((prev, curr) => prev + curr.imei__variant__price, 0);
|
||||
});
|
||||
|
||||
return { activeCartId, activeCart, activeCartItems, customerIdsWithNoCart, subtotal };
|
||||
}
|
||||
Reference in New Issue
Block a user