Divided the app into components and rewrote JS to TS.
This commit is contained in:
7
src/components/Child.vue
Normal file
7
src/components/Child.vue
Normal file
@@ -0,0 +1,7 @@
|
||||
<script setup>
|
||||
const model = defineModel()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<span>My input</span> <input v-model="model">
|
||||
</template>
|
||||
149
src/components/MainForm.vue
Normal file
149
src/components/MainForm.vue
Normal file
@@ -0,0 +1,149 @@
|
||||
<script setup lang="ts">
|
||||
import VueDatePicker from '@vuepic/vue-datepicker';
|
||||
import type { Category, Contractor, OrderProduct } from '@/main';
|
||||
|
||||
const props = defineProps(['isDarkTheme']);
|
||||
|
||||
const uuid = defineModel<string>('orderUuid');
|
||||
const contractors = defineModel<Array<Contractor>>('contractors');
|
||||
const contractor = defineModel<number>('contractor');
|
||||
const deliveryDate = defineModel<Date>('deliveryDate');
|
||||
const categories = defineModel<Array<Category>>('categories');
|
||||
const showModal = defineModel<boolean>('showModal');
|
||||
|
||||
|
||||
function createJSON(event: Event) {
|
||||
console.log(contractor.value);
|
||||
event.preventDefault();
|
||||
const json = {
|
||||
MZN_UUID: uuid.value,
|
||||
MZN_DataZam: new Date(Date.now()).toISOString(),
|
||||
MZN_DataDos: deliveryDate.value != undefined ? deliveryDate.value.toISOString() : null,
|
||||
MZN_PodID: contractor.value,
|
||||
MZamElem: new Array<OrderProduct>
|
||||
};
|
||||
|
||||
if(categories.value == undefined) return;
|
||||
|
||||
for (let category of categories.value) {
|
||||
for (let product of category.Towary) {
|
||||
if(product.Quantity != null) {
|
||||
const productObject : OrderProduct = {
|
||||
MZE_TwrId: product.Twr_TwrId,
|
||||
MZE_TwrJm: product.ChosenOption,
|
||||
MZE_TwrCena: product.ChosenOption == product.Twr_JMZ ? product.Twr_CenaZ : product.Twr_Cena,
|
||||
MZE_TwrIlosc: product.Quantity.toString(),
|
||||
MZE_TwrNazwa: product.Twr_Nazwa,
|
||||
MZE_MZNID: undefined,
|
||||
MZE_MZEID: undefined,
|
||||
MZE_TwrStawka: undefined
|
||||
};
|
||||
json.MZamElem.push(productObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
fetch('https://zamowienia.mleczarnia-kuzma.pl/api/zamowienie', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(json)
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(response => uuid.value = response.MZN_UUID);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<form class="box" @submit="createJSON">
|
||||
<div class="mb-3">
|
||||
<div class="box">
|
||||
<h1 class="is-large mb-3"><b>ZAMÓWIENIE</b></h1>
|
||||
<h1 class="is-large mb-3" v-if="uuid != null" ><b>{{ uuid }}</b></h1>
|
||||
<div class="field mb-5">
|
||||
<label class="label is-small">NIP</label>
|
||||
<div class="field">
|
||||
<div class="select is-small is-expanded" style="width: 100%">
|
||||
<select v-model="contractor" class="is-expanded" style="width: 100%" required>
|
||||
<option class="is-expanded" v-for="contractor in contractors" :key="contractor.Knt_KntId" :value=contractor.Knt_KntId>{{ contractor.Knt_NipE + ', ' + contractor.Knt_Miasto + ', ' + contractor.Knt_Nazwa1 + ' ' + contractor.Knt_Nazwa2 + ' ' + contractor.Knt_Nazwa3 }}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label is-small">Data dostawy</label>
|
||||
<div class="field is-small">
|
||||
<VueDatePicker class ="bulma-is-small is-static"
|
||||
v-model="deliveryDate"
|
||||
:enable-time-picker="false"
|
||||
:clearable="true"
|
||||
input-class-name="input is-small"
|
||||
v-bind:dark = "isDarkTheme"/>
|
||||
</div>
|
||||
</div>
|
||||
<button class="button is-primary mt-5">Submit</button>
|
||||
<button class="button is-primary mt-5 ml-3" @click="showModal = true">Potwierdź</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-for="category in categories" :key="category.Kod">
|
||||
<div class="box mb-3" >
|
||||
<h1 class="is-large mb-3"><b>{{ category.Kod }}</b></h1>
|
||||
<div class="field" v-for="(product, index) in category.Towary" :key="product.Twr_Nazwa">
|
||||
<label class="label is-small">{{ product.Twr_Nazwa }}</label>
|
||||
<div class="columns is-mobile">
|
||||
<div class="column" v-if="product.ChosenOption == product.Twr_JM">
|
||||
<div class="field">
|
||||
<input
|
||||
class="input is-small"
|
||||
type="text"
|
||||
placeholder="Kwota"
|
||||
v-model="product.Twr_Cena"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column" v-else-if="product.ChosenOption == product.Twr_JMZ">
|
||||
<div class="field">
|
||||
<input
|
||||
class="input is-small"
|
||||
type="text"
|
||||
placeholder="Kwota"
|
||||
v-model="product.Twr_CenaZ"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column">
|
||||
<div class="field has-addons">
|
||||
<p class="control">
|
||||
<span class="select is-small">
|
||||
<select v-model="product.ChosenOption" readonly>
|
||||
<option v-for="option in product.Options" :key="option">{{ option }}</option>
|
||||
</select>
|
||||
</span>
|
||||
</p>
|
||||
<p class="control is-expanded">
|
||||
<input class="input is-small" type="text" placeholder="Ilość" v-model="product.Quantity">
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="!(index == category.Towary.length - 1)"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="columns mt-1 is-variable is-mobile">
|
||||
<div class = "column is-6">
|
||||
<button class="button is-primary is-fullwidth is-large">Submit</button>
|
||||
</div>
|
||||
<div class = "is-large column is-6 ml-3">
|
||||
<button class="button is-primary is-fullwidth is-large" @click="parseOrderJSON">Potwierdź</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.dp__theme_dark {
|
||||
--dp-background-color: rgb(20, 22, 26);
|
||||
}
|
||||
</style>
|
||||
68
src/components/NavBar.vue
Normal file
68
src/components/NavBar.vue
Normal file
@@ -0,0 +1,68 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
|
||||
const emit = defineEmits(['form', 'order']);
|
||||
|
||||
const activator = ref(false);
|
||||
|
||||
function makeBurger() {
|
||||
activator.value = !activator.value
|
||||
return activator
|
||||
}
|
||||
|
||||
function clickForm() {
|
||||
emit('form');
|
||||
if(activator.value) {
|
||||
activator.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function clickOrders() {
|
||||
emit('order');
|
||||
if(activator.value) {
|
||||
activator.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<nav class="navbar" role="navigation" aria-label="main navigation">
|
||||
<div class="navbar-brand">
|
||||
<a class="navbar-item">
|
||||
<h3 class="title is-3">Mleczarnia</h3>
|
||||
</a>
|
||||
<button @click="makeBurger" class="button navbar-burger" data-target="navMenu" v-bind:class="{ 'is-active': activator }">
|
||||
<span aria-hidden="true"></span>
|
||||
<span aria-hidden="true"></span>
|
||||
<span aria-hidden="true"></span>
|
||||
<span aria-hidden="true"></span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="navbar-menu" id="navMenu" v-bind:class="{ 'is-active': activator }">
|
||||
<div class="navbar-start">
|
||||
<a class="navbar-item" @click="clickForm">
|
||||
Formularz
|
||||
</a>
|
||||
|
||||
<a class="navbar-item" @click="clickOrders">
|
||||
Zamówienia
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="navbar-end">
|
||||
<div class="navbar-item">
|
||||
<div class="buttons">
|
||||
<a class="button is-light">
|
||||
Log in
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
149
src/components/OrdersSelector.vue
Normal file
149
src/components/OrdersSelector.vue
Normal file
@@ -0,0 +1,149 @@
|
||||
<script setup lang="ts">
|
||||
import VueDatePicker from '@vuepic/vue-datepicker';
|
||||
import {ref, watch} from 'vue'
|
||||
import type { Category, Order } from '@/main'
|
||||
|
||||
const searchOrderDate = ref<Date>();
|
||||
const isOutOfBufor = ref<boolean>(false);
|
||||
const isInBufor = ref<boolean>(false);
|
||||
const orders = defineModel<Array<Order>>('orders');
|
||||
const uuid = defineModel<string>('uuid');
|
||||
const contractor = defineModel<number>('contractor');
|
||||
const deliveryDate = defineModel<Date>('deliveryDate');
|
||||
const categories = defineModel<Array<Category>>('categories');
|
||||
|
||||
const emit = defineEmits(['order']);
|
||||
|
||||
watch(isInBufor, (val) => {
|
||||
if(val && val == isOutOfBufor.value) {
|
||||
isOutOfBufor.value = false;
|
||||
}
|
||||
},{
|
||||
immediate: true
|
||||
});
|
||||
|
||||
watch(isOutOfBufor, (val) => {
|
||||
if(val && val == isInBufor.value) {
|
||||
isInBufor.value = false;
|
||||
}
|
||||
}, {
|
||||
immediate: true
|
||||
});
|
||||
|
||||
async function viewOrder(event: Event | undefined) {
|
||||
console.log(event?.target?.name);
|
||||
let tempOrder = orders.value?.find(order => (order.MZN_UUID == event?.target?.name));
|
||||
console.log(tempOrder);
|
||||
if (tempOrder == undefined) return;
|
||||
if (categories.value == undefined) return;
|
||||
|
||||
const response = await fetch('https://zamowienia.mleczarnia-kuzma.pl/api/zamowienie/' + tempOrder.MZN_UUID);
|
||||
let order = await response.json();
|
||||
|
||||
uuid.value = "test";
|
||||
contractor.value = order.MZN_PodID;
|
||||
deliveryDate.value = new Date(order.MZN_DataDos);
|
||||
console.log(order);
|
||||
for(let orderProduct of order.MZamElem){
|
||||
for(let category of categories.value) {
|
||||
let product = category.Towary.find(product => (product.Twr_TwrId == orderProduct.MZE_TwrId));
|
||||
if(product != null) {
|
||||
console.log('ten towar ' + product);
|
||||
product.Twr_Cena = orderProduct.MZE_TwrCena.slice(0, -2);
|
||||
product.Quantity = orderProduct.MZE_TwrIlosc.slice(0, -2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
emit('order');
|
||||
window.scrollTo(0, 0);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="box is-shadowless">
|
||||
<form class="mb-3">
|
||||
<div class="box">
|
||||
<h1 class="is-large mb-3"><b>FILTR ZAMÓWIEŃ</b></h1>
|
||||
<div class="field mb-5">
|
||||
<label class="label is-small">Data zamówienia</label>
|
||||
<div class="field is-small">
|
||||
<VueDatePicker v-model="searchOrderDate"
|
||||
:enable-time-picker="false"
|
||||
:clearable="true"
|
||||
input-class-name="input is-small"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field mb-5">
|
||||
<label class="label is-small">Zamówienie potwierdzone?</label>
|
||||
<div class="control">
|
||||
<label class="checkbox mr-5">
|
||||
<input type="checkbox" v-model="isOutOfBufor"/>
|
||||
Tak
|
||||
</label>
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" v-model="isInBufor"/>
|
||||
Nie
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<button class="button is-primary is-small is-expanded" @click="createJSON">Pobierz zamówienia</button>
|
||||
</div>
|
||||
</form>
|
||||
<div class="box">
|
||||
<h1 class="is-large mb-3"><b>ZAMÓWIENIA</b></h1>
|
||||
<div class="columns is-multiline">
|
||||
<div class="column is-4" v-for="order in orders" :key="order.MZN_UUID">
|
||||
<div class="box">
|
||||
<h1 class="mb-3 is-size-7"><b>{{ order.MZN_UUID }}</b></h1>
|
||||
<label class="label is-small">Klient</label>
|
||||
<div class="field is-small mb-3">
|
||||
<input class="input is-small is-static"
|
||||
type="text"
|
||||
:value="order.MZN_PodNazwa1 + order.MZN_PodNazwa2 + order.MZN_PodNazwa3"
|
||||
readonly/>
|
||||
</div>
|
||||
<div class="columns is-mobile field is-small mb-0">
|
||||
<div class="column is-6">
|
||||
<label class="label is-small">Data dostawy</label>
|
||||
<div class="field is-small">
|
||||
<input class="input is-small is-static"
|
||||
type="text"
|
||||
v-model="order.MZN_DataDos"
|
||||
readonly/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column is-6">
|
||||
<label class="label is-small">Data zamówienia</label>
|
||||
<div class="field is-small">
|
||||
<input class="input is-small is-static"
|
||||
type="text"
|
||||
v-model="order.MZN_DataZam.split('T')[0]"
|
||||
readonly/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<label class="label is-small">Zamówienie potwierdzone?</label>
|
||||
<div class="field is-small mb-3" v-if="order.MZN_Bufor==0">
|
||||
<input class="input is-small is-static"
|
||||
type="text"
|
||||
value="Tak"
|
||||
readonly/>
|
||||
</div>
|
||||
<div class="field is-small mb-3" v-else>
|
||||
<input class="input is-small is-static"
|
||||
type="text"
|
||||
value="Nie"
|
||||
readonly/>
|
||||
</div>
|
||||
<button class="button is-primary is-small is-expanded" @click="viewOrder" :name="order.MZN_UUID">Podgląd</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
Reference in New Issue
Block a user