This commit is contained in:
Viet An
2026-06-30 15:12:04 +07:00
parent 8b3da71895
commit e9e4fbe24f
18 changed files with 149 additions and 158 deletions

View File

@@ -1,12 +1,9 @@
export default function useOrderInfo({ activeCartId, activeCart, activeCartItems, addresses, getAddresses, subtotal }) {
const orderInfo = ref({
address: null,
receiver_name: null,
receiver_phone: null,
shipping_fee: null,
deliveryMethod: null,
paymentMethod: null,
});
import useActiveCart from "~/components/pos/composables/useActiveCart";
export default function useOrderInfo() {
const posStore = usePosStore();
const { activeCartId, addresses, orderInfo } = storeToRefs(posStore);
const { activeCart, activeCartItems, subtotal } = useActiveCart();
const total = computed(() => subtotal.value + orderInfo.value.shipping_fee);
@@ -19,7 +16,7 @@ export default function useOrderInfo({ activeCartId, activeCart, activeCartItems
watch(activeCart, async (newVal, oldVal) => {
// set order info
if (newVal?.customer) {
await getAddresses();
await posStore.getAddresses(newVal.customer);
if (!oldVal || !oldVal.customer || oldVal.customer !== newVal.customer) {
const defaultAddress = addresses.value.find((add) => add.is_default);
orderInfo.value.address = defaultAddress;
@@ -59,5 +56,5 @@ export default function useOrderInfo({ activeCartId, activeCart, activeCartItems
return `${orderInfo.value.address.address_detail}, ${orderInfo.value.address.ward}, ${orderInfo.value.address.district}, ${orderInfo.value.address.city}`;
});
return { orderInfo, isOrderValid, fullAddress, total };
return { isOrderValid, fullAddress, total };
}