changes
This commit is contained in:
@@ -1,21 +1,12 @@
|
||||
import { without } from "es-toolkit";
|
||||
|
||||
export default function useActiveCart({ carts, cartItems, customers }) {
|
||||
const activeCartId = ref();
|
||||
export default function useActiveCart() {
|
||||
const posStore = usePosStore();
|
||||
const { carts, cartItems, customers, activeCartId } = storeToRefs(posStore);
|
||||
|
||||
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);
|
||||
@@ -27,10 +18,5 @@ export default function useActiveCart({ carts, cartItems, customers }) {
|
||||
return activeCartItems.value?.reduce((prev, curr) => prev + curr.imei__variant__price, 0);
|
||||
});
|
||||
|
||||
const invalidCartItems = ref([]);
|
||||
|
||||
watch(activeCartId, () => {
|
||||
invalidCartItems.value = [];
|
||||
});
|
||||
return { activeCartId, activeCart, activeCartItems, customerIdsWithNoCart, subtotal, invalidCartItems };
|
||||
return { activeCart, activeCartItems, customerIdsWithNoCart, subtotal };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user