ClearBowl/front/components/Products/AddProductModal.vue

130 lines
4.5 KiB
Vue
Raw Normal View History

2019-12-05 11:23:34 +01:00
<template>
<div>
<Button v-if="$auth.loggedIn" type="primary" @click="active = true">Dodaj produkt</Button>
<Modal v-model="active" @on-cancel="cancel">
<p slot="header" style="text-align:center">
<Icon type="ios-pizza"/>
<span>Dodawanie produktu</span>
</p>
<div>
<Form ref="form" :model="form" :rules="rules">
<FormItem label="Nazwa" prop="name">
<Input v-model="form.name" placeholder="Podaj nazwę produktu"/>
</FormItem>
2019-12-09 17:25:25 +01:00
<FormItem label="Kcal" prop="kcal">
2019-12-05 11:23:34 +01:00
<InputNumber class="input" v-model="form.kcal" :min="0" :precision="0"/>
</FormItem>
2019-12-15 22:52:29 +01:00
<FormItem label="Węglowodany (g)" prop="carbohydrates">
2019-12-05 11:23:34 +01:00
<InputNumber class="input" v-model="form.carbohydrates" :min="0"/>
</FormItem>
2019-12-15 22:52:29 +01:00
<FormItem label="Białko (g)" prop="protein">
2019-12-05 11:23:34 +01:00
<InputNumber class="input" v-model="form.protein" :min="0"/>
</FormItem>
2019-12-15 22:52:29 +01:00
<FormItem label="Tłuszcz (g)" prop="fat">
2019-12-05 11:23:34 +01:00
<InputNumber class="input" v-model="form.fat" :min="0"/>
</FormItem>
</Form>
</div>
<div slot="footer">
<Button type="error" @click="cancel">Anuluj</Button>
<Button type="success" :loading="modal_loading" @click="ok">Zatwierdź</Button>
</div>
</Modal>
</div>
</template>
<script>
export default {
name: 'AddProductModal',
data() {
return {
active: false,
modal_loading: false,
form: {
name: null,
kcal: null,
carbohydrates: null,
protein: null,
fat: null
},
rules: {
name: [
{
required: true,
message: 'Proszę podać nazwę produktu',
trigger: 'blur'
}
],
kcal: [
{
2019-12-15 22:52:29 +01:00
required: true,
message: 'Proszę podać wartość kcal',
trigger: 'blur'
2019-12-05 11:23:34 +01:00
}
],
carbohydrates: [
{
2019-12-15 22:52:29 +01:00
required: true,
message: 'Proszę podać ilość węglowodanów',
trigger: 'blur'
2019-12-05 11:23:34 +01:00
}
],
protein: [
{
2019-12-15 22:52:29 +01:00
required: true,
message: 'Proszę podać ilość białka',
trigger: 'blur'
2019-12-05 11:23:34 +01:00
}
],
fat: [
{
2019-12-15 22:52:29 +01:00
required: true,
message: 'Proszę podać ilość tłuszczu',
trigger: 'blur'
2019-12-05 11:23:34 +01:00
}
]
},
};
},
methods: {
cancel() {
this.active = false;
2019-12-15 22:52:29 +01:00
this.resetForm();
2019-12-05 11:23:34 +01:00
this.$Message.error('Anulowano');
},
ok() {
this.$refs.form.validate((valid) => {
if (!valid) {
this.$Message.error('Błąd');
return;
}
this.modal_loading = true;
this.$axios.post('/product', this.form)
.then(() => {
this.$Message.success('Sukces!');
this.active = false;
this.resetForm();
})
.catch(() => {
this.$Message.error('Błąd!');
this.modal_loading = false;
});
});
},
resetForm() {
this.modal_loading = false;
this.$refs.form.resetFields();
}
}
};
</script>
<style scoped>
.input {
width: 15%;
}
</style>