|
|
@@ -1,158 +0,0 @@
|
|
|
-<template>
|
|
|
- <q-dialog ref="dialogRef" @hide="onDialogHide">
|
|
|
- <q-card class="q-dialog-plugin overflow-hidden" style="width: 800px">
|
|
|
- <DefaultDialogHeader :title="title" @close="onDialogCancel" />
|
|
|
- <q-form ref="formRef" @submit="onOKClick">
|
|
|
- <q-card-section class="row q-col-gutter-sm q-pt-none">
|
|
|
- <DefaultInput
|
|
|
- v-model="form.name"
|
|
|
- v-model:error="validationErrors.name"
|
|
|
- :rules="[inputRules.required]"
|
|
|
- :label="$t('common.terms.name')"
|
|
|
- :placeholder="'Nome completo da cidade'"
|
|
|
- class="col-md-6 col-12"
|
|
|
- />
|
|
|
- <CountrySelect
|
|
|
- v-model="selectedCountry"
|
|
|
- v-model:error="validationErrors.country_id"
|
|
|
- :placeholder="'Selecione o pais desse estado'"
|
|
|
- :rules="[inputRules.required]"
|
|
|
- :initial-id="form.country_id"
|
|
|
- class="col-md-6 col-12"
|
|
|
- />
|
|
|
- <StateSelect
|
|
|
- v-model="selectedState"
|
|
|
- v-model:error="validationErrors.state_id"
|
|
|
- :country="selectedCountry"
|
|
|
- :initial-id="form.state_id"
|
|
|
- :placeholder="'Selecione o estado dessa cidade'"
|
|
|
- :rules="[inputRules.required]"
|
|
|
- class="col-md-6 col-12"
|
|
|
- @selected-country-id="countrySelectRef?.selectCountryById($event)"
|
|
|
- />
|
|
|
- <DefaultSelect
|
|
|
- v-model="selectedStatus"
|
|
|
- v-model:error="validationErrors.status"
|
|
|
- :options="statusOptions"
|
|
|
- :rules="[inputRules.required]"
|
|
|
- :label="$t('common.terms.status')"
|
|
|
- :placeholder="$t('common.terms.status')"
|
|
|
- class="col-md-6 col-12"
|
|
|
- />
|
|
|
- </q-card-section>
|
|
|
- <q-card-actions>
|
|
|
- <q-space />
|
|
|
- <q-btn
|
|
|
- outline
|
|
|
- color="negative"
|
|
|
- :label="$t('common.actions.cancel')"
|
|
|
- @click="onDialogCancel"
|
|
|
- />
|
|
|
- <q-btn
|
|
|
- color="primary"
|
|
|
- :label="city ? $t('common.actions.save') : $t('common.actions.add')"
|
|
|
- :type="'submit'"
|
|
|
- :loading="loading"
|
|
|
- :disable="!hasUpdatedFields"
|
|
|
- />
|
|
|
- </q-card-actions>
|
|
|
- </q-form>
|
|
|
- </q-card>
|
|
|
- </q-dialog>
|
|
|
-</template>
|
|
|
-<script setup>
|
|
|
-import { ref, useTemplateRef, onMounted, watch } from "vue";
|
|
|
-import { useInputRules } from "src/composables/useInputRules";
|
|
|
-import { useDialogPluginComponent } from "quasar";
|
|
|
-import { useI18n } from "vue-i18n";
|
|
|
-import { createCity, updateCity } from "src/api/city";
|
|
|
-import { useFormUpdateTracker } from "src/composables/useFormUpdateTracker";
|
|
|
-import { useSubmitHandler } from "src/composables/useSubmitHandler";
|
|
|
-
|
|
|
-import DefaultDialogHeader from "src/components/defaults/DefaultDialogHeader.vue";
|
|
|
-import DefaultInput from "src/components/defaults/DefaultInput.vue";
|
|
|
-import CountrySelect from "src/components/selects/CountrySelect.vue";
|
|
|
-import StateSelect from "src/components/selects/StateSelect.vue";
|
|
|
-import DefaultSelect from "src/components/defaults/DefaultSelect.vue";
|
|
|
-
|
|
|
-defineEmits([
|
|
|
- // REQUIRED; need to specify some events that your
|
|
|
- // component will emit through useDialogPluginComponent()
|
|
|
- ...useDialogPluginComponent.emits,
|
|
|
-]);
|
|
|
-
|
|
|
-const { city, title } = defineProps({
|
|
|
- city: {
|
|
|
- type: Object,
|
|
|
- default: null,
|
|
|
- },
|
|
|
- title: {
|
|
|
- type: Function,
|
|
|
- default: () => useI18n().t("common.terms.title"),
|
|
|
- },
|
|
|
-});
|
|
|
-
|
|
|
-const { t } = useI18n();
|
|
|
-const { inputRules } = useInputRules();
|
|
|
-
|
|
|
-const { dialogRef, onDialogHide, onDialogOK, onDialogCancel } =
|
|
|
- useDialogPluginComponent();
|
|
|
-
|
|
|
-const formRef = useTemplateRef("formRef");
|
|
|
-const countrySelectRef = useTemplateRef("countrySelectRef");
|
|
|
-
|
|
|
-const { form, getUpdatedFields, hasUpdatedFields } = useFormUpdateTracker({
|
|
|
- name: city ? city?.name : "",
|
|
|
- country_id: city ? city?.country_id : null,
|
|
|
- state_id: city ? city?.state_id : null,
|
|
|
- status: city ? city?.status : "ACTIVE",
|
|
|
-});
|
|
|
-
|
|
|
-const {
|
|
|
- loading,
|
|
|
- validationErrors,
|
|
|
- execute: submitForm,
|
|
|
-} = useSubmitHandler({
|
|
|
- onSuccess: () => onDialogOK(true),
|
|
|
- formRef: formRef,
|
|
|
-});
|
|
|
-
|
|
|
-const selectedCountry = ref(null);
|
|
|
-const selectedState = ref(null);
|
|
|
-const selectedStatus = ref({
|
|
|
- label: t("common.status.active"),
|
|
|
- value: "ACTIVE",
|
|
|
-});
|
|
|
-const statusOptions = ref([
|
|
|
- { label: t("common.status.active"), value: "ACTIVE" },
|
|
|
- { label: t("common.status.inactive"), value: "INACTIVE" },
|
|
|
-]);
|
|
|
-
|
|
|
-const onOKClick = async () => {
|
|
|
- if (city) {
|
|
|
- await submitForm(() => updateCity(getUpdatedFields.value, city.id));
|
|
|
- } else {
|
|
|
- await submitForm(() => createCity({ ...form }));
|
|
|
- }
|
|
|
-};
|
|
|
-
|
|
|
-watch(selectedStatus, () => {
|
|
|
- form.status = selectedStatus.value?.value;
|
|
|
-});
|
|
|
-
|
|
|
-watch(selectedCountry, () => {
|
|
|
- form.country_id = selectedCountry.value?.value;
|
|
|
-});
|
|
|
-
|
|
|
-watch(selectedState, () => {
|
|
|
- form.state_id = selectedState.value?.value;
|
|
|
-});
|
|
|
-
|
|
|
-onMounted(async () => {
|
|
|
- if (city) {
|
|
|
- selectedStatus.value = statusOptions.value.find(
|
|
|
- (status) => status.value === city.status,
|
|
|
- );
|
|
|
- }
|
|
|
-});
|
|
|
-</script>
|