This commit is contained in:
Viet An
2026-06-19 15:55:16 +07:00
parent f491f82f43
commit cb5d63b064
3 changed files with 38 additions and 30 deletions

View File

@@ -17,8 +17,8 @@ const shipping_address = computed(() => {
async function createOrder() {
try {
isPending.value = true;
const invoice = await $insertapi("Invoice", {
data: {
const invoicePayload = {
customer: activeCart.value.customer,
customer_name: activeCart.value.customer__fullname,
customer_phone: activeCart.value.customer__phone,
@@ -31,11 +31,15 @@ async function createOrder() {
final_amount: subtotal.value,
order_type: "pos",
status: "pending",
payment_status: 1,
staff: 1,
ordered_at: new Date(),
paid_at: null,
delivery_method: orderInfo.value.deliveryMethod.id,
},
};
const invoice = await $insertapi("Invoice", {
data: invoicePayload,
notify: false,
});
@@ -68,8 +72,8 @@ async function createOrder() {
if (orderInfo.value.deliveryMethod.code === "HOME_DELIVERY") {
const deliveryInfoPayload = {
invoice: invoice.id,
receiver_name: invoice.customer_name,
receiver_phone: invoice.customer_phone,
receiver_name: orderInfo.value.receiver_name,
receiver_phone: orderInfo.value.receiver_phone,
city: orderInfo.value.address.city,
district: orderInfo.value.address.district,
ward: orderInfo.value.address.ward,
@@ -171,9 +175,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>{{ activeCart.customer__fullname }}</span>
<span>{{ orderInfo.receiver_name }}</span>
<span> </span>
<span>{{ activeCart.customer__phone }}</span>
<span>{{ orderInfo.receiver_phone }}</span>
</p>
</div>
</div>

View File

@@ -215,10 +215,9 @@ provide("pos", {
<p class="control">
<input
class="input is-small"
type="email"
:value="activeCart.customer__fullname"
placeholder="Name"
disabled
type="text"
v-model="orderInfo.receiver_name"
placeholder="Tên"
/>
</p>
</div>
@@ -227,10 +226,9 @@ provide("pos", {
<p class="control">
<input
class="input is-small"
type="email"
:value="activeCart.customer__phone"
placeholder="Phone"
disabled
type="text"
v-model="orderInfo.receiver_phone"
placeholder="SĐT"
/>
</p>
</div>

View File

@@ -1,6 +1,8 @@
export default function useOrderInfo({ activeCartId, activeCart, activeCartItems, addresses, getAddresses }) {
const orderInfo = ref({
address: null,
receiver_name: null,
receiver_phone: null,
deliveryMethod: null,
paymentMethod: null,
});
@@ -18,10 +20,14 @@ export default function useOrderInfo({ activeCartId, activeCart, activeCartItems
if (!oldVal || !oldVal.customer || oldVal.customer !== newVal.customer) {
const defaultAddress = addresses.value.find((add) => add.is_default);
orderInfo.value.address = defaultAddress;
orderInfo.value.receiver_name = newVal.customer__fullname;
orderInfo.value.receiver_phone = newVal.customer__phone;
}
} else {
addresses.value = null;
orderInfo.value.address = null;
orderInfo.value.receiver_name = null;
orderInfo.value.receiver_phone = null;
}
});