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

View File

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

View File

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