changes
This commit is contained in:
@@ -5,10 +5,10 @@ const emit = defineEmits(["close"]);
|
||||
const { $patchapi, $deleteapi, $insertapi, $dayjs, $snackbar } = useNuxtApp();
|
||||
const id = "confirmOrder";
|
||||
const isPending = ref(false);
|
||||
const { cartItems, orderInfo, getCart } = inject("pos");
|
||||
const { activeCart, activeCartItems, orderInfo, getCarts } = inject("pos");
|
||||
|
||||
const subtotal = computed(() => {
|
||||
return cartItems.value?.reduce((prev, curr) => prev + curr.imei__variant__price, 0);
|
||||
return activeCartItems.value?.reduce((prev, curr) => prev + curr.imei__variant__price, 0);
|
||||
});
|
||||
const shipping_address = computed(() => {
|
||||
return `${orderInfo.value.address.address_detail}, ${orderInfo.value.address.ward}, ${orderInfo.value.address.district}, ${orderInfo.value.address.city}`;
|
||||
@@ -19,12 +19,12 @@ async function createOrder() {
|
||||
isPending.value = true;
|
||||
const invoice = await $insertapi("Invoice", {
|
||||
data: {
|
||||
customer: orderInfo.value.customer.id,
|
||||
customer_name: orderInfo.value.customer.fullname,
|
||||
customer_phone: orderInfo.value.customer.phone,
|
||||
customer_email: orderInfo.value.customer.email,
|
||||
customer: "",
|
||||
customer_name: "",
|
||||
customer_phone: "",
|
||||
customer_email: "",
|
||||
shipping_address: shipping_address.value,
|
||||
product_amount: cartItems.value.length,
|
||||
product_amount: activeCartItems.value.length,
|
||||
shipping_fee: 0,
|
||||
total_amount: subtotal.value,
|
||||
discount_amount: 0,
|
||||
@@ -38,7 +38,7 @@ async function createOrder() {
|
||||
notify: false,
|
||||
});
|
||||
|
||||
const imeisSoldPayload = cartItems.value.map((cartItem) => ({
|
||||
const imeisSoldPayload = activeCartItems.value.map((cartItem) => ({
|
||||
imei: cartItem.imei__imei,
|
||||
variant: cartItem.imei__variant,
|
||||
sold_date: $dayjs().format("YYYY-MM-DD"),
|
||||
@@ -49,7 +49,7 @@ async function createOrder() {
|
||||
notify: false,
|
||||
});
|
||||
|
||||
const invoiceDetailPayload = cartItems.value.map((cartItem) => {
|
||||
const invoiceDetailPayload = activeCartItems.value.map((cartItem) => {
|
||||
const imeiSold = imeisSold.find((imeiSold) => imeiSold.imei === cartItem.imei__imei);
|
||||
return {
|
||||
invoice: invoice.id,
|
||||
@@ -69,14 +69,14 @@ async function createOrder() {
|
||||
await Promise.all([
|
||||
$deleteapi(
|
||||
"Cart_Item",
|
||||
cartItems.value.map((c) => c.id),
|
||||
activeCartItems.value.map((c) => c.id),
|
||||
),
|
||||
$patchapi("Cart", {
|
||||
id: cartItems.value[0].cart,
|
||||
id: activeCartItems.value[0].cart,
|
||||
customer: null,
|
||||
}),
|
||||
]);
|
||||
getCart();
|
||||
getCarts();
|
||||
emit("close");
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@@ -101,11 +101,11 @@ async function createOrder() {
|
||||
<span>Khách hàng</span>
|
||||
</p>
|
||||
<div>
|
||||
<p>{{ orderInfo.customer.fullname }}</p>
|
||||
<p>{{ activeCart.customer__fullname }}</p>
|
||||
<p class="is-size-7 has-text-grey">
|
||||
{{ orderInfo.customer.phone }}
|
||||
{{ activeCart.customer__phone }}
|
||||
•
|
||||
{{ orderInfo.customer.email }}
|
||||
{{ activeCart.customer__email }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -119,11 +119,11 @@ async function createOrder() {
|
||||
:size="18"
|
||||
/>
|
||||
</span>
|
||||
<span>{{ cartItems.length }} sản phẩm</span>
|
||||
<span>{{ activeCartItems.length }} sản phẩm</span>
|
||||
</p>
|
||||
<div class="is-flex is-flex-direction-column is-gap-1">
|
||||
<CartItem
|
||||
v-for="cartItem in cartItems"
|
||||
v-for="cartItem in activeCartItems"
|
||||
:key="cartItem.id"
|
||||
:cartItem="cartItem"
|
||||
/>
|
||||
@@ -148,9 +148,9 @@ async function createOrder() {
|
||||
<div v-else>
|
||||
<p class="font-medium fs-16 mb-0.5">{{ shipping_address }}</p>
|
||||
<p class="has-text-grey">
|
||||
<span>{{ orderInfo.customer.fullname }}</span>
|
||||
<span>{{ activeCart.customer__fullname }}</span>
|
||||
<span> • </span>
|
||||
<span>{{ orderInfo.customer.phone }}</span>
|
||||
<span>{{ activeCart.customer__phone }}</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -177,7 +177,7 @@ async function createOrder() {
|
||||
<tr>
|
||||
<td>
|
||||
<span>Tạm tính</span>
|
||||
<span> ({{ cartItems.length }} sản phẩm)</span>
|
||||
<span> ({{ activeCartItems.length }} sản phẩm)</span>
|
||||
</td>
|
||||
<td class="has-text-right">{{ $numtoString(subtotal, { hasUnit: true }) }}</td>
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user