|
@@ -9,10 +9,18 @@
|
|
|
<div class="text-h6 q-mb-sm">Produto</div>
|
|
<div class="text-h6 q-mb-sm">Produto</div>
|
|
|
|
|
|
|
|
<div class="row q-col-gutter-sm">
|
|
<div class="row q-col-gutter-sm">
|
|
|
|
|
+ <DefaultInput
|
|
|
|
|
+ v-model="form.name"
|
|
|
|
|
+ label="Nome do Produto"
|
|
|
|
|
+ class="col-12"
|
|
|
|
|
+ />
|
|
|
|
|
+
|
|
|
<DefaultInput
|
|
<DefaultInput
|
|
|
v-model="form.description"
|
|
v-model="form.description"
|
|
|
- label="Descrição do Produto"
|
|
|
|
|
|
|
+ label="Descrição"
|
|
|
class="col-12"
|
|
class="col-12"
|
|
|
|
|
+ type="textarea"
|
|
|
|
|
+ autogrow
|
|
|
/>
|
|
/>
|
|
|
|
|
|
|
|
<DefaultCurrencyInput
|
|
<DefaultCurrencyInput
|
|
@@ -29,11 +37,12 @@
|
|
|
min="0"
|
|
min="0"
|
|
|
/>
|
|
/>
|
|
|
|
|
|
|
|
- <DefaultCurrencyInput
|
|
|
|
|
- :model-value="totalValue"
|
|
|
|
|
|
|
+ <DefaultInput
|
|
|
|
|
+ :model-value="totalValueFormatted"
|
|
|
label="Valor Total do Produto"
|
|
label="Valor Total do Produto"
|
|
|
class="col-4"
|
|
class="col-4"
|
|
|
- disabled
|
|
|
|
|
|
|
+ disable
|
|
|
|
|
+ readonly
|
|
|
/>
|
|
/>
|
|
|
</div>
|
|
</div>
|
|
|
</q-card-section>
|
|
</q-card-section>
|
|
@@ -49,6 +58,7 @@
|
|
|
label="Cadastrar Produto"
|
|
label="Cadastrar Produto"
|
|
|
color="primary-2"
|
|
color="primary-2"
|
|
|
type="submit"
|
|
type="submit"
|
|
|
|
|
+ :loading="loading"
|
|
|
/>
|
|
/>
|
|
|
</q-card-actions>
|
|
</q-card-actions>
|
|
|
</q-form>
|
|
</q-form>
|
|
@@ -59,7 +69,9 @@
|
|
|
|
|
|
|
|
<script setup>
|
|
<script setup>
|
|
|
import { ref, computed } from "vue";
|
|
import { ref, computed } from "vue";
|
|
|
-import { useDialogPluginComponent } from "quasar";
|
|
|
|
|
|
|
+import { useDialogPluginComponent, useQuasar } from "quasar";
|
|
|
|
|
+import { createProduct } from "src/api/product";
|
|
|
|
|
+import { formatToBRLCurrency } from "src/helpers/utils";
|
|
|
|
|
|
|
|
import DefaultDialogHeader from "src/components/defaults/DefaultDialogHeader.vue";
|
|
import DefaultDialogHeader from "src/components/defaults/DefaultDialogHeader.vue";
|
|
|
import DefaultInput from "src/components/defaults/DefaultInput.vue";
|
|
import DefaultInput from "src/components/defaults/DefaultInput.vue";
|
|
@@ -67,20 +79,37 @@ import DefaultCurrencyInput from "src/components/defaults/DefaultCurrencyInput.v
|
|
|
|
|
|
|
|
defineEmits([...useDialogPluginComponent.emits]);
|
|
defineEmits([...useDialogPluginComponent.emits]);
|
|
|
|
|
|
|
|
|
|
+const $q = useQuasar();
|
|
|
|
|
+
|
|
|
const { dialogRef, onDialogHide, onDialogOK, onDialogCancel } =
|
|
const { dialogRef, onDialogHide, onDialogOK, onDialogCancel } =
|
|
|
useDialogPluginComponent();
|
|
useDialogPluginComponent();
|
|
|
|
|
|
|
|
const formRef = ref(null);
|
|
const formRef = ref(null);
|
|
|
|
|
+const loading = ref(false);
|
|
|
|
|
|
|
|
const form = ref({
|
|
const form = ref({
|
|
|
|
|
+ name: "",
|
|
|
description: "",
|
|
description: "",
|
|
|
unitPrice: 0,
|
|
unitPrice: 0,
|
|
|
quantity: 0,
|
|
quantity: 0,
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
const totalValue = computed(() => form.value.unitPrice * form.value.quantity);
|
|
const totalValue = computed(() => form.value.unitPrice * form.value.quantity);
|
|
|
|
|
+const totalValueFormatted = computed(() => formatToBRLCurrency(totalValue.value));
|
|
|
|
|
|
|
|
const onOKClick = async () => {
|
|
const onOKClick = async () => {
|
|
|
- onDialogOK({ ...form.value, totalValue: totalValue.value });
|
|
|
|
|
|
|
+ loading.value = true;
|
|
|
|
|
+ try {
|
|
|
|
|
+ const product = await createProduct({
|
|
|
|
|
+ name: form.value.name,
|
|
|
|
|
+ description: form.value.description,
|
|
|
|
|
+ price_sale: form.value.unitPrice,
|
|
|
|
|
+ });
|
|
|
|
|
+ onDialogOK(product);
|
|
|
|
|
+ } catch {
|
|
|
|
|
+ $q.notify({ type: "negative", message: "Erro ao cadastrar produto." });
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ loading.value = false;
|
|
|
|
|
+ }
|
|
|
};
|
|
};
|
|
|
</script>
|
|
</script>
|