|
|
@@ -0,0 +1,109 @@
|
|
|
+<template>
|
|
|
+ <q-dialog ref="dialogRef" @hide="onDialogHide">
|
|
|
+ <q-card class="q-dialog-plugin overflow-hidden" style="width: 1000px; max-width: 90vw">
|
|
|
+ <DefaultDialogHeader :title="title" @close="onDialogCancel" />
|
|
|
+ <q-form ref="formRef" @submit="onOKClick">
|
|
|
+ <q-card-section class="row q-col-gutter-sm">
|
|
|
+ <q-input
|
|
|
+ v-model="form.description"
|
|
|
+ fill-mask
|
|
|
+ unmasked-value
|
|
|
+ :label="$t('improvement_type.fields.description')"
|
|
|
+ :rules="[inputRules.required]"
|
|
|
+ :error="!!serverErrors?.description"
|
|
|
+ :error-message="serverErrors?.description"
|
|
|
+ class="col-12"
|
|
|
+ />
|
|
|
+
|
|
|
+ <q-select
|
|
|
+ v-model="form.improvement_type"
|
|
|
+ :options="improvementTypeOptions"
|
|
|
+ :label="$t('improvement_type.fields.improvement_type')"
|
|
|
+ :rules="[inputRules.required]"
|
|
|
+ :error="!!serverErrors?.improvement_type"
|
|
|
+ :error-message="serverErrors?.improvement_type"
|
|
|
+ emit-value
|
|
|
+ map-options
|
|
|
+ class="col-12"
|
|
|
+ />
|
|
|
+
|
|
|
+ <div class="col-12">
|
|
|
+ <q-checkbox
|
|
|
+ v-model="form.is_active"
|
|
|
+ :label="$t('common.status.active')"
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+
|
|
|
+ </q-card-section>
|
|
|
+ <q-card-actions align="center">
|
|
|
+ <q-btn color="primary" label="Cancel" @click="onDialogCancel" />
|
|
|
+ <q-space />
|
|
|
+ <q-btn color="primary" label="OK" :type="'submit'" :loading="loading" :disable="!hasUpdatedFields" />
|
|
|
+ </q-card-actions>
|
|
|
+ </q-form>
|
|
|
+ </q-card>
|
|
|
+ </q-dialog>
|
|
|
+</template>
|
|
|
+<script setup>
|
|
|
+import { useTemplateRef, computed } from "vue";
|
|
|
+import { useInputRules } from "src/composables/useInputRules";
|
|
|
+import { useDialogPluginComponent } from "quasar";
|
|
|
+import { useI18n } from "vue-i18n";
|
|
|
+import { createImprovementType, updateImprovementType } from "src/api/improvementType";
|
|
|
+import { useFormUpdateTracker } from "src/composables/useFormUpdateTracker";
|
|
|
+import { useSubmitHandler } from "src/composables/useSubmitHandler";
|
|
|
+import DefaultDialogHeader from "src/components/defaults/DefaultDialogHeader.vue";
|
|
|
+
|
|
|
+defineEmits([
|
|
|
+ ...useDialogPluginComponent.emits,
|
|
|
+]);
|
|
|
+
|
|
|
+const { improvementType, title } = defineProps({
|
|
|
+ improvementType: {
|
|
|
+ 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 { form, getUpdatedFields, hasUpdatedFields } = useFormUpdateTracker({
|
|
|
+ description: improvementType ? improvementType?.description : "",
|
|
|
+ improvement_type: improvementType ? improvementType?.improvement_type : "both",
|
|
|
+ is_active: improvementType ? improvementType?.is_active : true,
|
|
|
+});
|
|
|
+
|
|
|
+const improvementTypeOptions = computed(() => [
|
|
|
+ { label: t("improvement_type.types.client"), value: "client" },
|
|
|
+ { label: t("improvement_type.types.provider"), value: "provider" },
|
|
|
+ { label: t("improvement_type.types.both"), value: "both" },
|
|
|
+]);
|
|
|
+
|
|
|
+const {
|
|
|
+ loading,
|
|
|
+ serverErrors,
|
|
|
+ execute: submitForm,
|
|
|
+} = useSubmitHandler({
|
|
|
+ onSuccess: () => onDialogOK(true),
|
|
|
+ formRef: formRef,
|
|
|
+});
|
|
|
+
|
|
|
+
|
|
|
+const onOKClick = async () => {
|
|
|
+ if (improvementType) {
|
|
|
+ await submitForm(() => updateImprovementType(getUpdatedFields.value, improvementType.id));
|
|
|
+ } else {
|
|
|
+ await submitForm(() => createImprovementType({ ...form }));
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+</script>
|