This commit is contained in:
Viet An
2026-06-25 09:14:51 +07:00
parent 66ffa01c57
commit 07151bf78e
4 changed files with 48 additions and 25 deletions

View File

@@ -1,19 +1,19 @@
export default function usePlaceOrder({ activeCart, activeCartItems, orderInfo, getCarts, onSuccess }) {
export default function usePlaceOrder({
activeCart,
activeCartItems,
orderInfo,
fullAddress,
subtotal,
total,
getCarts,
onSuccess,
}) {
const { $dayjs, $id, $getdata, $insertapi, $patchapi, $deleteapi, $snackbar } = useNuxtApp();
const isPending = ref(false);
const paidPaymentStatus = ref();
const invoice = ref();
const showVietQRModal = ref();
const subtotal = computed(() => {
return activeCartItems.value?.reduce((prev, curr) => prev + curr.imei__variant__price, 0);
});
const shipping_address = computed(() => {
if (!orderInfo.value.address) return "";
return `${orderInfo.value.address.address_detail}, ${orderInfo.value.address.ward}, ${orderInfo.value.address.district}, ${orderInfo.value.address.city}`;
});
/**
* Create a record in `invoice` as `pending`
*/
@@ -26,12 +26,12 @@ export default function usePlaceOrder({ activeCart, activeCartItems, orderInfo,
customer_name: activeCart.value.customer__fullname,
customer_phone: activeCart.value.customer__phone,
customer_email: activeCart.value.customer__email,
shipping_address: shipping_address.value,
shipping_address: fullAddress.value,
product_amount: activeCartItems.value.length,
shipping_fee: 0,
shipping_fee: orderInfo.value.shipping_fee,
total_amount: subtotal.value,
discount_amount: 0,
final_amount: subtotal.value,
final_amount: total.value,
order_type: "pos",
status: "pending",
payment_status: 1,
@@ -124,7 +124,7 @@ export default function usePlaceOrder({ activeCart, activeCartItems, orderInfo,
district: orderInfo.value.address.district,
ward: orderInfo.value.address.ward,
address: orderInfo.value.address.address_detail,
shipping_fee: 0,
shipping_fee: orderInfo.value.shipping_fee,
carrier: orderInfo.value.deliveryMethod.id,
tracking_code: $id(),
status: "pending",
@@ -144,8 +144,8 @@ export default function usePlaceOrder({ activeCart, activeCartItems, orderInfo,
data: {
invoice: invoiceId,
payment_method: orderInfo.value.paymentMethod.id,
transfer_amount: orderInfo.value.paymentMethod.code === "CASH" ? undefined : subtotal.value,
cash_amount: orderInfo.value.paymentMethod.code === "CASH" ? subtotal.value : undefined,
transfer_amount: orderInfo.value.paymentMethod.code === "CASH" ? undefined : total.value,
cash_amount: orderInfo.value.paymentMethod.code === "CASH" ? total.value : undefined,
},
notify: false,
});
@@ -232,5 +232,5 @@ export default function usePlaceOrder({ activeCart, activeCartItems, orderInfo,
});
});
return { isPending, subtotal, shipping_address, placeOrder, testReturnPage, showVietQRModal };
return { isPending, placeOrder, testReturnPage, showVietQRModal };
}