|
@@ -0,0 +1,275 @@
|
|
|
|
|
+<template>
|
|
|
|
|
+ <q-dialog ref="dialogRef" persistent maximized transition-show="slide-left" transition-hide="slide-right">
|
|
|
|
|
+ <div class="bg-page full-height no-shadow">
|
|
|
|
|
+ <div class="row items-center q-px-md q-pt-md q-pb-sm bg-white shadow-profile bg-surface">
|
|
|
|
|
+ <q-btn v-close-popup icon="mdi-chevron-left" flat round dense color="primary" />
|
|
|
|
|
+ <q-space />
|
|
|
|
|
+ <span class="text-subtitle1 text-weight-bold text-primary">{{ $t('profile.bank_data.title') }}</span>
|
|
|
|
|
+ <q-space />
|
|
|
|
|
+ <div style="width: 32px"></div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <q-card-section class="col">
|
|
|
|
|
+ <div class="q-px-md q-pt-lg text-text">
|
|
|
|
|
+ <div class="text-h6 text-weight-bold gradient-diarista">{{ $t('profile.bank_data.my_bank_data_title') }}</div>
|
|
|
|
|
+ <div class="text-caption text-grey-7 q-mb-md">{{ $t('profile.bank_data.subtitle') }}</div>
|
|
|
|
|
+
|
|
|
|
|
+ <div class="pix-warning q-pa-md q-mb-lg row items-start q-col-gutter-sm">
|
|
|
|
|
+ <q-icon name="mdi-alert-outline" color="warning" size="20px" class="q-mt-xs" />
|
|
|
|
|
+ <div class="col text-caption">
|
|
|
|
|
+ <span class="text-weight-bold">{{ $t('profile.bank_data.warning_title') }}</span>
|
|
|
|
|
+ {{ $t('profile.bank_data.warning_message') }}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <div class="text-subtitle1 text-weight-bold text-center text-text q-mb-md">
|
|
|
|
|
+ {{ $t('profile.bank_data.pix_title') }}
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <q-card class="q-pa-lg bg-white shadow-card q-mb-lg" style="border-radius: 25px;" :flat="false">
|
|
|
|
|
+ <div class="text-weight-bold q-mb-xs text-text">{{ $t('profile.bank_data.pix_key') }}</div>
|
|
|
|
|
+ <q-input
|
|
|
|
|
+ v-model="pixForm.pix_key"
|
|
|
|
|
+ outlined
|
|
|
|
|
+ dense
|
|
|
|
|
+ input-class="text-text"
|
|
|
|
|
+ :placeholder="$t('profile.bank_data.pix_key_placeholder')"
|
|
|
|
|
+ class="q-mb-md"
|
|
|
|
|
+ />
|
|
|
|
|
+
|
|
|
|
|
+ <q-btn
|
|
|
|
|
+ unelevated
|
|
|
|
|
+ rounded
|
|
|
|
|
+ no-caps
|
|
|
|
|
+ color="primary"
|
|
|
|
|
+ class="full-width q-py-md text-weight-bold"
|
|
|
|
|
+ style="font-size: 1.1rem;"
|
|
|
|
|
+ :label="$t('profile.bank_data.save_pix')"
|
|
|
|
|
+ :loading="savingPix"
|
|
|
|
|
+ :disable="!hasPixUpdatedFields"
|
|
|
|
|
+ @click="savePix"
|
|
|
|
|
+ />
|
|
|
|
|
+ </q-card>
|
|
|
|
|
+
|
|
|
|
|
+ <div class="text-subtitle1 text-weight-bold text-center text-text q-mb-md">
|
|
|
|
|
+ {{ $t('profile.bank_data.bank_account_title') }}
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <q-card class="q-pa-lg bg-white shadow-card q-mb-lg" style="border-radius: 25px;" :flat="false">
|
|
|
|
|
+ <div class="text-weight-bold q-mb-sm text-text">{{ $t('profile.bank_data.account_type') }}</div>
|
|
|
|
|
+ <div class="row q-mb-md">
|
|
|
|
|
+ <q-radio
|
|
|
|
|
+ v-model="bankForm.bank_account_type"
|
|
|
|
|
+ val="checking"
|
|
|
|
|
+ :label="$t('profile.bank_data.checking')"
|
|
|
|
|
+ color="primary"
|
|
|
|
|
+ class="q-mr-lg text-text"
|
|
|
|
|
+ />
|
|
|
|
|
+ <q-radio
|
|
|
|
|
+ v-model="bankForm.bank_account_type"
|
|
|
|
|
+ val="savings"
|
|
|
|
|
+ :label="$t('profile.bank_data.savings')"
|
|
|
|
|
+ color="primary"
|
|
|
|
|
+ class="text-text"
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <div class="row q-col-gutter-sm q-mb-sm">
|
|
|
|
|
+ <div class="col-5">
|
|
|
|
|
+ <div class="text-weight-bold q-mb-xs text-text">{{ $t('profile.bank_data.agency') }}</div>
|
|
|
|
|
+ <q-input
|
|
|
|
|
+ v-model="bankForm.agency"
|
|
|
|
|
+ outlined
|
|
|
|
|
+ dense
|
|
|
|
|
+ input-class="text-text"
|
|
|
|
|
+ placeholder="0001"
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div class="col-7">
|
|
|
|
|
+ <div class="text-weight-bold q-mb-xs text-text">{{ $t('profile.bank_data.account') }}</div>
|
|
|
|
|
+ <q-input
|
|
|
|
|
+ v-model="bankForm.account"
|
|
|
|
|
+ outlined
|
|
|
|
|
+ dense
|
|
|
|
|
+ input-class="text-text"
|
|
|
|
|
+ placeholder="Ex: 0000000-0"
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <div class="row q-mb-md">
|
|
|
|
|
+ <div class="col-4">
|
|
|
|
|
+ <div class="text-weight-bold q-mb-xs text-text">{{ $t('profile.bank_data.digit') }}</div>
|
|
|
|
|
+ <q-input
|
|
|
|
|
+ v-model="bankForm.digit"
|
|
|
|
|
+ outlined
|
|
|
|
|
+ dense
|
|
|
|
|
+ input-class="text-text"
|
|
|
|
|
+ :placeholder="$t('profile.bank_data.digit')"
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <q-btn
|
|
|
|
|
+ unelevated
|
|
|
|
|
+ rounded
|
|
|
|
|
+ no-caps
|
|
|
|
|
+ color="primary"
|
|
|
|
|
+ class="full-width q-py-md text-weight-bold"
|
|
|
|
|
+ style="font-size: 1.1rem;"
|
|
|
|
|
+ :label="$t('profile.bank_data.save_account')"
|
|
|
|
|
+ :loading="savingBank"
|
|
|
|
|
+ :disable="!hasBankUpdatedFields"
|
|
|
|
|
+ @click="saveBank"
|
|
|
|
|
+ />
|
|
|
|
|
+ </q-card>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div class="q-pb-xl"></div>
|
|
|
|
|
+ </q-card-section>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </q-dialog>
|
|
|
|
|
+</template>
|
|
|
|
|
+
|
|
|
|
|
+<script setup>
|
|
|
|
|
+import { ref, onMounted } from 'vue';
|
|
|
|
|
+import { useDialogPluginComponent, useQuasar } from 'quasar';
|
|
|
|
|
+import {
|
|
|
|
|
+ getProviderPaymentMethods,
|
|
|
|
|
+ createProviderPaymentMethod,
|
|
|
|
|
+ updateProviderPaymentMethod,
|
|
|
|
|
+} from 'src/api/providerPaymentMethod';
|
|
|
|
|
+import { userStore } from 'src/stores/user';
|
|
|
|
|
+import { useFormUpdateTracker } from 'src/composables/useFormUpdateTracker';
|
|
|
|
|
+import { useI18n } from 'vue-i18n';
|
|
|
|
|
+
|
|
|
|
|
+defineEmits([...useDialogPluginComponent.emits]);
|
|
|
|
|
+
|
|
|
|
|
+const { dialogRef } = useDialogPluginComponent();
|
|
|
|
|
+const $q = useQuasar();
|
|
|
|
|
+const { t } = useI18n();
|
|
|
|
|
+const user = userStore();
|
|
|
|
|
+
|
|
|
|
|
+const pixId = ref(null);
|
|
|
|
|
+const bankId = ref(null);
|
|
|
|
|
+const savingPix = ref(false);
|
|
|
|
|
+const savingBank = ref(false);
|
|
|
|
|
+
|
|
|
|
|
+const {
|
|
|
|
|
+ form: pixForm,
|
|
|
|
|
+ hasUpdatedFields: hasPixUpdatedFields,
|
|
|
|
|
+ getUpdatedFields: getPixUpdatedFields,
|
|
|
|
|
+ setUpdateFormAsOriginal: setPixOriginal,
|
|
|
|
|
+} = useFormUpdateTracker({
|
|
|
|
|
+ pix_key: '',
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
|
|
+const {
|
|
|
|
|
+ form: bankForm,
|
|
|
|
|
+ hasUpdatedFields: hasBankUpdatedFields,
|
|
|
|
|
+ getUpdatedFields: getBankUpdatedFields,
|
|
|
|
|
+ setUpdateFormAsOriginal: setBankOriginal,
|
|
|
|
|
+} = useFormUpdateTracker({
|
|
|
|
|
+ bank_account_type: 'checking',
|
|
|
|
|
+ agency: '',
|
|
|
|
|
+ account: '',
|
|
|
|
|
+ digit: '',
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
|
|
+const savePix = async () => {
|
|
|
|
|
+ if (!pixForm.pix_key) {
|
|
|
|
|
+ $q.notify({ type: 'negative', message: t('profile.bank_data.pix_key_required') });
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ savingPix.value = true;
|
|
|
|
|
+ try {
|
|
|
|
|
+ const payload = {
|
|
|
|
|
+ provider_id: user.user.id,
|
|
|
|
|
+ account_type: 'pix',
|
|
|
|
|
+ pix_key: pixForm.pix_key,
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ if (pixId.value) {
|
|
|
|
|
+ await updateProviderPaymentMethod(pixId.value, getPixUpdatedFields.value);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const created = await createProviderPaymentMethod(payload);
|
|
|
|
|
+ pixId.value = created.id;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ setPixOriginal();
|
|
|
|
|
+ $q.notify({ type: 'positive', message: t('profile.bank_data.pix_saved') });
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ $q.notify({ type: 'negative', message: t('profile.bank_data.save_error') });
|
|
|
|
|
+ console.log(error);
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ savingPix.value = false;
|
|
|
|
|
+ }
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+const saveBank = async () => {
|
|
|
|
|
+ if (!bankForm.agency || !bankForm.account) {
|
|
|
|
|
+ $q.notify({ type: 'negative', message: t('profile.bank_data.bank_fields_required') });
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ savingBank.value = true;
|
|
|
|
|
+ try {
|
|
|
|
|
+ const payload = {
|
|
|
|
|
+ provider_id: user.user.id,
|
|
|
|
|
+ account_type: 'bank_account',
|
|
|
|
|
+ bank_account_type: bankForm.bank_account_type,
|
|
|
|
|
+ agency: bankForm.agency,
|
|
|
|
|
+ account: bankForm.account,
|
|
|
|
|
+ digit: bankForm.digit,
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ if (bankId.value) {
|
|
|
|
|
+ await updateProviderPaymentMethod(bankId.value, getBankUpdatedFields.value);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const created = await createProviderPaymentMethod(payload);
|
|
|
|
|
+ bankId.value = created.id;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ setBankOriginal();
|
|
|
|
|
+ $q.notify({ type: 'positive', message: t('profile.bank_data.account_saved') });
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ $q.notify({ type: 'negative', message: t('profile.bank_data.save_error') });
|
|
|
|
|
+ console.log(error);
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ savingBank.value = false;
|
|
|
|
|
+ }
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+onMounted(async () => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const methods = await getProviderPaymentMethods(user.user.id);
|
|
|
|
|
+ if (!methods) return;
|
|
|
|
|
+
|
|
|
|
|
+ const pix = methods.find((m) => m.account_type === 'pix');
|
|
|
|
|
+ if (pix) {
|
|
|
|
|
+ pixId.value = pix.id;
|
|
|
|
|
+ pixForm.pix_key = pix.pix_key || '';
|
|
|
|
|
+ setPixOriginal();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const bank = methods.find((m) => m.account_type === 'bank_account');
|
|
|
|
|
+ if (bank) {
|
|
|
|
|
+ bankId.value = bank.id;
|
|
|
|
|
+ bankForm.bank_account_type = bank.bank_account_type || 'checking';
|
|
|
|
|
+ bankForm.agency = bank.agency || '';
|
|
|
|
|
+ bankForm.account = bank.account || '';
|
|
|
|
|
+ bankForm.digit = bank.digit || '';
|
|
|
|
|
+ setBankOriginal();
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error('Erro ao carregar dados bancários:', error);
|
|
|
|
|
+ }
|
|
|
|
|
+});
|
|
|
|
|
+</script>
|
|
|
|
|
+
|
|
|
|
|
+<style scoped>
|
|
|
|
|
+.pix-warning {
|
|
|
|
|
+ background-color: #EEF0FF;
|
|
|
|
|
+ border-radius: 12px;
|
|
|
|
|
+}
|
|
|
|
|
+</style>
|