164 lines
6.2 KiB
JavaScript
164 lines
6.2 KiB
JavaScript
/// <reference types="../../node_modules/.vue-global-types/vue_3.5_0_0_0.d.ts" />
|
|
import { onMounted, reactive, ref } from 'vue';
|
|
import { useRouter } from 'vue-router';
|
|
import { api } from '../api/client';
|
|
import { useSessionStore } from '../stores/session';
|
|
const session = useSessionStore();
|
|
const router = useRouter();
|
|
const products = ref([]);
|
|
const items = reactive([
|
|
{ productVariantId: '', quantity: 1, wagePercent: 7, discountPercent: 0, flatRialCharge: 0 },
|
|
]);
|
|
const submitting = ref(false);
|
|
const error = ref(null);
|
|
onMounted(async () => {
|
|
products.value = await api.listProducts();
|
|
});
|
|
function addItem() {
|
|
items.push({ productVariantId: '', quantity: 1, wagePercent: 7, discountPercent: 0, flatRialCharge: 0 });
|
|
}
|
|
function removeItem(index) {
|
|
items.splice(index, 1);
|
|
}
|
|
async function submit() {
|
|
if (!session.selectedCustomerId) {
|
|
error.value = 'Select a customer from the dashboard first.';
|
|
return;
|
|
}
|
|
submitting.value = true;
|
|
error.value = null;
|
|
try {
|
|
const order = await api.createOrder({
|
|
customerId: session.selectedCustomerId,
|
|
items: items.map((i) => ({ ...i })),
|
|
});
|
|
router.push({ name: 'order-detail', params: { id: order.id } });
|
|
}
|
|
catch (e) {
|
|
error.value = e.message;
|
|
}
|
|
finally {
|
|
submitting.value = false;
|
|
}
|
|
}
|
|
debugger; /* PartiallyEnd: #3632/scriptSetup.vue */
|
|
const __VLS_ctx = {};
|
|
let __VLS_components;
|
|
let __VLS_directives;
|
|
// CSS variable injection
|
|
// CSS variable injection end
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.section, __VLS_intrinsicElements.section)({});
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.h1, __VLS_intrinsicElements.h1)({});
|
|
if (!__VLS_ctx.session.selectedCustomerId) {
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.p, __VLS_intrinsicElements.p)({
|
|
...{ class: "error" },
|
|
});
|
|
}
|
|
else {
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.p, __VLS_intrinsicElements.p)({});
|
|
(__VLS_ctx.session.selectedCustomerId);
|
|
}
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.table, __VLS_intrinsicElements.table)({});
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.thead, __VLS_intrinsicElements.thead)({});
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.tr, __VLS_intrinsicElements.tr)({});
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.th, __VLS_intrinsicElements.th)({});
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.th, __VLS_intrinsicElements.th)({});
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.th, __VLS_intrinsicElements.th)({});
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.th, __VLS_intrinsicElements.th)({});
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.th, __VLS_intrinsicElements.th)({});
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.th, __VLS_intrinsicElements.th)({});
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.tbody, __VLS_intrinsicElements.tbody)({});
|
|
for (const [item, idx] of __VLS_getVForSourceType((__VLS_ctx.items))) {
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.tr, __VLS_intrinsicElements.tr)({
|
|
key: (idx),
|
|
});
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.td, __VLS_intrinsicElements.td)({});
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.select, __VLS_intrinsicElements.select)({
|
|
value: (item.productVariantId),
|
|
});
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.option, __VLS_intrinsicElements.option)({
|
|
value: "",
|
|
disabled: true,
|
|
});
|
|
for (const [p] of __VLS_getVForSourceType((__VLS_ctx.products))) {
|
|
(p.id);
|
|
for (const [v] of __VLS_getVForSourceType((p.variants))) {
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.option, __VLS_intrinsicElements.option)({
|
|
key: (v.id),
|
|
value: (v.id),
|
|
});
|
|
(p.title);
|
|
(v.title);
|
|
(v.rashWeightGrams);
|
|
}
|
|
}
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.td, __VLS_intrinsicElements.td)({});
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.input)({
|
|
type: "number",
|
|
min: "1",
|
|
});
|
|
(item.quantity);
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.td, __VLS_intrinsicElements.td)({});
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.input)({
|
|
type: "number",
|
|
step: "0.1",
|
|
});
|
|
(item.wagePercent);
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.td, __VLS_intrinsicElements.td)({});
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.input)({
|
|
type: "number",
|
|
step: "0.1",
|
|
});
|
|
(item.discountPercent);
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.td, __VLS_intrinsicElements.td)({});
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.input)({
|
|
type: "number",
|
|
step: "1000",
|
|
});
|
|
(item.flatRialCharge);
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.td, __VLS_intrinsicElements.td)({});
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.button, __VLS_intrinsicElements.button)({
|
|
...{ onClick: (...[$event]) => {
|
|
__VLS_ctx.removeItem(idx);
|
|
} },
|
|
});
|
|
}
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.button, __VLS_intrinsicElements.button)({
|
|
...{ onClick: (__VLS_ctx.addItem) },
|
|
});
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.br)({});
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.br)({});
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.button, __VLS_intrinsicElements.button)({
|
|
...{ onClick: (__VLS_ctx.submit) },
|
|
disabled: (__VLS_ctx.submitting),
|
|
});
|
|
if (__VLS_ctx.error) {
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.p, __VLS_intrinsicElements.p)({
|
|
...{ class: "error" },
|
|
});
|
|
(__VLS_ctx.error);
|
|
}
|
|
/** @type {__VLS_StyleScopedClasses['error']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['error']} */ ;
|
|
var __VLS_dollars;
|
|
const __VLS_self = (await import('vue')).defineComponent({
|
|
setup() {
|
|
return {
|
|
session: session,
|
|
products: products,
|
|
items: items,
|
|
submitting: submitting,
|
|
error: error,
|
|
addItem: addItem,
|
|
removeItem: removeItem,
|
|
submit: submit,
|
|
};
|
|
},
|
|
});
|
|
export default (await import('vue')).defineComponent({
|
|
setup() {
|
|
return {};
|
|
},
|
|
});
|
|
; /* PartiallyEnd: #4569/main.vue */
|