|
|
@@ -0,0 +1,105 @@
|
|
|
+<template>
|
|
|
+ <q-dialog ref="dialogRef" @hide="onDialogHide">
|
|
|
+ <q-card class="q-dialog-plugin overflow-hidden" style="width: 100%; max-width: 500px">
|
|
|
+ <DefaultDialogHeader
|
|
|
+ :title="() => (item ? 'Editar Faixa de Habitante' : 'Nova Faixa de Habitante')"
|
|
|
+ @close="onDialogCancel"
|
|
|
+ />
|
|
|
+
|
|
|
+ <q-form ref="formRef" @submit="onOKClick">
|
|
|
+ <q-card-section class="row q-col-gutter-sm q-pt-none">
|
|
|
+ <DefaultInput
|
|
|
+ v-model="form.description"
|
|
|
+ v-model:error="validationErrors.description"
|
|
|
+ class="col-12"
|
|
|
+ label="Descrição"
|
|
|
+ :error-message="validationErrors.description"
|
|
|
+ :rules="[inputRules.required]"
|
|
|
+ />
|
|
|
+
|
|
|
+ <DefaultInput
|
|
|
+ v-model="form.acronym"
|
|
|
+ v-model:error="validationErrors.acronym"
|
|
|
+ class="col-12"
|
|
|
+ label="Sigla"
|
|
|
+ maxlength="2"
|
|
|
+ :error-message="validationErrors.acronym"
|
|
|
+ :rules="[inputRules.required]"
|
|
|
+ />
|
|
|
+ </q-card-section>
|
|
|
+
|
|
|
+ <q-card-actions>
|
|
|
+ <q-space />
|
|
|
+
|
|
|
+ <q-btn
|
|
|
+ color="negative"
|
|
|
+ label="Cancelar"
|
|
|
+ outline
|
|
|
+ @click="onDialogCancel"
|
|
|
+ />
|
|
|
+
|
|
|
+ <q-btn
|
|
|
+ color="primary-2"
|
|
|
+ label="Salvar"
|
|
|
+ type="submit"
|
|
|
+ :loading="loading"
|
|
|
+ />
|
|
|
+ </q-card-actions>
|
|
|
+ </q-form>
|
|
|
+ </q-card>
|
|
|
+ </q-dialog>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup>
|
|
|
+import {
|
|
|
+ createInhabitantClassification,
|
|
|
+ updateInhabitantClassification,
|
|
|
+} from "src/api/inhabitant_classification";
|
|
|
+
|
|
|
+import { useDialogPluginComponent } from "quasar";
|
|
|
+import { useFormUpdateTracker } from "src/composables/useFormUpdateTracker";
|
|
|
+import { useInputRules } from "src/composables/useInputRules";
|
|
|
+import { useSubmitHandler } from "src/composables/useSubmitHandler";
|
|
|
+import { useTemplateRef } from "vue";
|
|
|
+
|
|
|
+import DefaultDialogHeader from "src/components/defaults/DefaultDialogHeader.vue";
|
|
|
+import DefaultInput from "src/components/defaults/DefaultInput.vue";
|
|
|
+
|
|
|
+defineEmits([...useDialogPluginComponent.emits]);
|
|
|
+
|
|
|
+const { item } = defineProps({
|
|
|
+ item: {
|
|
|
+ type: Object, default: null,
|
|
|
+ },
|
|
|
+});
|
|
|
+
|
|
|
+const { inputRules } = useInputRules();
|
|
|
+
|
|
|
+const {
|
|
|
+ dialogRef,
|
|
|
+ onDialogCancel,
|
|
|
+ onDialogHide,
|
|
|
+ onDialogOK,
|
|
|
+} = useDialogPluginComponent();
|
|
|
+
|
|
|
+const formRef = useTemplateRef("formRef");
|
|
|
+
|
|
|
+const { form, getUpdatedFields } = useFormUpdateTracker({
|
|
|
+ description: item?.description ?? "", acronym: item?.acronym ?? "",
|
|
|
+});
|
|
|
+
|
|
|
+const { loading, validationErrors, execute } = useSubmitHandler({
|
|
|
+ formRef,
|
|
|
+ onSuccess: () => onDialogOK(true),
|
|
|
+});
|
|
|
+
|
|
|
+const onOKClick = async () => {
|
|
|
+ if (item) {
|
|
|
+ console.log(getUpdatedFields.value);
|
|
|
+
|
|
|
+ await execute(() => updateInhabitantClassification(item.id, getUpdatedFields.value));
|
|
|
+ } else {
|
|
|
+ await execute(() => createInhabitantClassification(form));
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|