todos cruds funcionais e com evidencias

This commit is contained in:
ka-lucas 2025-04-24 12:07:57 -03:00
parent 1d05933646
commit 78b43d8f04
7 changed files with 272 additions and 190 deletions

View File

@ -1,6 +1,6 @@
<template> <template>
<v-dialog v-model="isOpen" max-width="500px" @close="closeModal"> <v-dialog v-model="isOpen" max-width="500px" @close="closeModal">
<v-form> <v-form ref="form" v-model="formValid">
<v-card class="pa-6 rounded-xl elevation-2 card-modal"> <v-card class="pa-6 rounded-xl elevation-2 card-modal">
<v-card-title class="text-h5 font-weight-bold pb-0"> <v-card-title class="text-h5 font-weight-bold pb-0">
<span class="text-h5">Adicionar Nova Empresa</span> <span class="text-h5">Adicionar Nova Empresa</span>
@ -10,104 +10,177 @@
<v-row> <v-row>
<v-text class="text-h7">Dados básicos</v-text> <v-text class="text-h7">Dados básicos</v-text>
<v-col cols="12"> <v-col cols="12">
<v-text-field v-model="localCompany.name" label="Nome da Empresa *" clearable required /> <v-text-field
v-model="localCompany.name"
label="Nome da Empresa *"
clearable
:rules="[rules.required]"
required
/>
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
<v-text-field v-model="localCompany.fantasy_name" label="Nome Fantasia" clearable /> <v-text-field
v-model="localCompany.fantasy_name"
label="Nome Fantasia *"
clearable
:rules="[rules.required]"
required
/>
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
<v-text-field v-model="localCompany.cnpj" label="CNPJ *" clearable required /> <v-text-field
v-model="localCompany.cnpj"
label="CNPJ *"
clearable
:rules="[rules.required]"
required
/>
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
<v-text-field v-model="localCompany.type" label="Tipo" clearable /> <v-text-field
v-model="localCompany.type"
label="Tipo *"
clearable
:rules="[rules.required]"
required
/>
</v-col> </v-col>
<v-text class="text-h7">Contato</v-text> <v-text class="text-h7">Contato</v-text>
<v-col cols="12"> <v-col cols="12">
<v-text-field v-model="localCompany.email" label="Email *" clearable required /> <v-text-field
v-model="localCompany.email"
label="Email *"
clearable
:rules="[rules.required, rules.email]"
required
/>
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
<v-text-field v-model="localCompany.email_sec" label="Email Secundário" clearable /> <v-text-field
</v-col> v-model="localCompany.phone"
<v-col cols="12"> label="Telefone *"
<v-text-field v-model="localCompany.phone" label="Telefone *" clearable required /> clearable
</v-col> :rules="[rules.required]"
<v-col cols="12"> required
<v-text-field v-model="localCompany.phone_sec" label="Telefone Secundário" clearable /> />
</v-col> </v-col>
<v-text class="text-h7">Endereço</v-text> <v-text class="text-h7">Endereço</v-text>
<v-col cols="12"> <v-col cols="12">
<v-text-field v-model="localCompany.cep" label="CEP *" clearable /> <v-text-field
v-model="localCompany.cep"
label="CEP *"
clearable
:rules="[rules.required]"
required
/>
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
<v-text-field v-model="localCompany.rua" label="Rua *" clearable /> <v-text-field
v-model="localCompany.rua"
label="Rua *"
clearable
:rules="[rules.required]"
required
/>
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
<v-text-field v-model="localCompany.numero" label="Número *" clearable /> <v-text-field
v-model="localCompany.numero"
label="Número *"
clearable
:rules="[rules.required]"
required
/>
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
<v-text-field v-model="localCompany.bairro" label="Bairro *" clearable /> <v-text-field
v-model="localCompany.bairro"
label="Bairro *"
clearable
:rules="[rules.required]"
required
/>
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
<v-text-field v-model="localCompany.complemento" label="Complemento" clearable /> <v-text-field
v-model="localCompany.estado"
label="Estado *"
clearable
:rules="[rules.required]"
required
/>
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
<v-text-field v-model="localCompany.estado" label="Estado" clearable /> <v-text-field
</v-col> v-model="localCompany.cidade"
<v-col cols="12"> label="Cidade *"
<v-text-field v-model="localCompany.cidade" label="Cidade" clearable /> clearable
:rules="[rules.required]"
required
/>
</v-col> </v-col>
</v-row> </v-row>
<!--<FormFields :company="localCompany" />-->
</v-container> </v-container>
</v-card-text> </v-card-text>
<v-card-actions> <v-card-actions>
<v-spacer /> <v-spacer />
<v-btn text color="blue-darken-1" @click="closeModal">Cancelar</v-btn> <v-btn text color="blue-darken-1" @click="closeModal">Cancelar</v-btn>
<v-btn text class="text-white salvar-btn" @click="handleSave" :loading="companyStore.loading"> <v-btn
text
class="text-white salvar-btn"
:disabled="!formValid"
@click="validateAndSave"
:loading="companyStore.loading"
>
Salvar Salvar
</v-btn> </v-btn>
</v-card-actions> </v-card-actions>
</v-card> </v-card>
</v-form> </v-form>
</v-dialog> </v-dialog>
</template> </template>
<script setup> <script setup>
import { ref, watch } from 'vue'; import { ref, watch } from 'vue';
import { useCompanyStore } from '../../stores/company'; import { useCompanyStore } from '../../stores/company';
import { useAuthStore } from '../../stores/auth'; import { useAuthStore } from '../../stores/auth';
//import FormFields from './FormFields.vue'; // Campos de formulário extraídos (opcional)
const props = defineProps({ const props = defineProps({
isModalOpen: Boolean isModalOpen: Boolean,
}); });
const emit = defineEmits(['update:isModalOpen', 'company-created']); const emit = defineEmits(['update:isModalOpen', 'company-created']);
const isOpen = ref(false); const isOpen = ref(false);
const companyStore = useCompanyStore(); const companyStore = useCompanyStore();
const authStore = useAuthStore(); const authStore = useAuthStore();
const localCompany = ref({ const localCompany = ref({
name: '', name: '',
fantasy_name: '', fantasy_name: '',
type: '', type: '',
cnpj: '', cnpj: '',
email: '', email: '',
email_sec: '',
phone: '', phone: '',
phone_sec: '',
estado: '', estado: '',
cidade: '', cidade: '',
bairro: '', bairro: '',
rua: '', rua: '',
numero: '', numero: '',
complemento: '',
cep: '', cep: '',
service_instance_id: authStore.service_instance_id || 2, service_instance_id: authStore.service_instance_id || 2,
parent_id: authStore.userId, parent_id: authStore.userId,
}); });
watch(() => props.isModalOpen, (newVal) => { const rules = {
required: (value) => !!value || 'Campo obrigatório',
email: (value) => /.+@.+\..+/.test(value) || 'E-mail inválido',
};
const form = ref(null);
const formValid = ref(false);
watch(() => props.isModalOpen, (newVal) => {
isOpen.value = newVal; isOpen.value = newVal;
if (newVal) { if (newVal) {
Object.assign(localCompany.value, { Object.assign(localCompany.value, {
@ -116,34 +189,31 @@
type: '', type: '',
cnpj: '', cnpj: '',
email: '', email: '',
email_sec: '',
phone: '', phone: '',
phone_sec: '',
estado: '', estado: '',
cidade: '', cidade: '',
bairro: '', bairro: '',
rua: '', rua: '',
numero: '', numero: '',
complemento: '',
cep: '', cep: '',
service_instance_id: authStore.service_instance_id || 2, service_instance_id: authStore.service_instance_id || 2,
parent_id: authStore.userId, parent_id: authStore.userId,
}); });
} }
}); });
watch(isOpen, (newVal) => { watch(isOpen, (newVal) => {
if (!newVal){ if (!newVal) {
emit('update:isModalOpen', false); emit('update:isModalOpen', false);
} }
}); });
const closeModal = () => { const closeModal = () => {
isOpen.value = false; isOpen.value = false;
}; };
const handleSave = async (e) => { const validateAndSave = async () => {
e.preventDefault(); // Impede o comportamento padrão do botão if (form.value.validate()) {
try { try {
await companyStore.createCompany(localCompany.value); await companyStore.createCompany(localCompany.value);
emit('company-created'); emit('company-created');
@ -151,9 +221,11 @@
} catch (error) { } catch (error) {
console.error('Erro ao criar empresa:', error); console.error('Erro ao criar empresa:', error);
} }
}; }
</script> };
<style scoped> </script>
<style scoped>
.card-modal { .card-modal {
background-color: #FFFFFF; background-color: #FFFFFF;
border-radius: 16px; border-radius: 16px;

View File

@ -46,8 +46,8 @@
/>--> />-->
<v-card-actions> <v-card-actions>
<v-spacer /> <v-spacer />
<v-btn text color="blue-darken-1" @click="closeModal">Cancelar</v-btn> <v-btn text color="blue-darken-1" @click="close">Cancelar</v-btn>
<v-btn text class="text-white salvar-btn" @click="handleSave" :loading="companyStore.loading"> <v-btn text class="text-white salvar-btn" @click="submit" :loading="shiftStore.loading">
Salvar Salvar
</v-btn> </v-btn>
</v-card-actions> </v-card-actions>
@ -112,15 +112,6 @@ function submit() {
close() close()
} }
const handleSave = async () => {
try {
await companyStore.createCompany(localCompany.value);
emit('company-created');
closeModal();
} catch (error) {
console.error('Erro ao criar empresa:', error);
}
};
</script> </script>
<style scoped> <style scoped>
.card-modal { .card-modal {

View File

@ -28,7 +28,7 @@
</v-card-text> </v-card-text>
<v-card-actions> <v-card-actions>
<v-spacer></v-spacer> <v-spacer></v-spacer>
<v-btn text color="blue-darken-1" @click="closeModal">Cancelar</v-btn> <v-btn text color="blue-darken-1" @click="$emit('cancel')">Cancelar</v-btn>
<v-btn text class="text-white salvar-btn" @click="handleSave" :loading="holidayStore.loading"> <v-btn text class="text-white salvar-btn" @click="handleSave" :loading="holidayStore.loading">
Salvar Salvar
</v-btn> </v-btn>

View File

@ -1,5 +1,6 @@
<template> <template>
<v-dialog :model-value="modalValue" @update:model-value="updateModalValue" max-width="500px"> <v-dialog :model-value="modalValue" @update:model-value="updateModalValue" max-width="500px">
<v-form ref="form" v-model="formValid">
<v-card class="pa-6 rounded-xl elevation-2 card-modal"> <v-card class="pa-6 rounded-xl elevation-2 card-modal">
<v-card-title class="text-h5 font-weight-bold pb-0"> <v-card-title class="text-h5 font-weight-bold pb-0">
<span class="text-h5">Adicionar Novo Feriado</span> <span class="text-h5">Adicionar Novo Feriado</span>
@ -8,32 +9,34 @@
<v-container> <v-container>
<v-row> <v-row>
<v-col cols="12"> <v-col cols="12">
<v-text-field v-model="localHoliday.name" label="Feriado *" clearable required /> <v-text-field v-model="localHoliday.name" label="Feriado *" clearable :rules="[rules.required]" required />
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
<v-text-field v-model="localHoliday.type" label="Tipo do Feriado *" clearable required /> <v-text-field v-model="localHoliday.type" label="Tipo do Feriado *" clearable :rules="[rules.required]" required />
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
<v-text-field v-model="localHoliday.date" label="Data do feriado *" type="date" clearable <v-text-field v-model="localHoliday.date" label="Data do feriado *" type="date" clearable
:rules="[v => !!v || 'Data é obrigatória']" required /> :rules="[v => !!v || 'Data é obrigatória']" required />
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
<v-text-field v-model="localHoliday.municipio" label="Municipio" type="municipio" clearable /> <v-text-field v-model="localHoliday.municipio" label="Municipio" type="municipio" :rules="[rules.required]" clearable required/>
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
<v-text-field v-model="localHoliday.estado" label="Estado" type="estado" clearable /> <v-text-field v-model="localHoliday.estado" label="Estado" type="estado" clearable :rules="[rules.required]" required/>
</v-col> </v-col>
</v-row> </v-row>
</v-container> </v-container>
</v-card-text> </v-card-text>
<v-card-actions> <v-card-actions>
<v-spacer></v-spacer> <v-spacer></v-spacer>
<v-btn text color="blue-darken-1" @click.prevent.stop="closeModal">Cancelar</v-btn> <v-btn text color="blue-darken-1" @click="$emit('cancel')">Cancelar</v-btn>
<v-btn text class="text-white salvar-btn" @click="handleSave" :loading="holidayStore.loading"> <v-btn text class="text-white salvar-btn" :disabled="!formValid"
@click="handleSave" :loading="holidayStore.loading">
Salvar Salvar
</v-btn> </v-btn>
</v-card-actions> </v-card-actions>
</v-card> </v-card>
</v-form>
</v-dialog> </v-dialog>
</template> </template>
@ -64,6 +67,12 @@ const defaultHoliday = {
parent_id: authStore.userId, parent_id: authStore.userId,
service_instance_id: authStore.service_instance_id || 2 service_instance_id: authStore.service_instance_id || 2
}; };
const rules = {
required: (value) => !!value || 'Campo obrigatório'
};
const form = ref(null);
const formValid = ref(false);
// Estado local do feriado // Estado local do feriado
const localHoliday = ref({...defaultHoliday}); const localHoliday = ref({...defaultHoliday});
@ -107,6 +116,7 @@ const closeModal = () => {
// Salvar o novo feriado // Salvar o novo feriado
const handleSave = async (event) => { const handleSave = async (event) => {
if(form.value.validate()){
event.preventDefault(); // Impede o comportamento padrão do botão event.preventDefault(); // Impede o comportamento padrão do botão
try { try {
const holidayData = { const holidayData = {
@ -124,7 +134,7 @@ const handleSave = async (event) => {
resetLocalHoliday(); resetLocalHoliday();
} catch (error) { } catch (error) {
console.error('Erro ao criar feriado:', error); console.error('Erro ao criar feriado:', error);
} }}
}; };
// Inicialização do componente // Inicialização do componente

View File

@ -68,8 +68,8 @@ export const useCompanyStore = defineStore('company', {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
} }
}); });
print('response.data', response.data); //print('response.data', response.data);
print('compony', companyData); //print('compony', companyData);
this.companys.push(response.data); this.companys.push(response.data);
return response.data; return response.data;
} catch (error) { } catch (error) {

View File

@ -158,7 +158,6 @@ import { useRouter } from 'vue-router';
import cameraModal from '../components/modals/CameraModal.vue'; import cameraModal from '../components/modals/CameraModal.vue';
import ambienteModal from '../components/modals/AmbienteModal.vue'; import ambienteModal from '../components/modals/AmbienteModal.vue';
import {cameraService} from '../services/camera'; import {cameraService} from '../services/camera';
import AmbienteModal from '../components/modals/AmbienteModal.vue';
export default { export default {

View File

@ -79,10 +79,12 @@
:isEditMode="isEditing" :isEditMode="isEditing"
:holiday="forms.holiday" :holiday="forms.holiday"
@save="submitForm" @save="submitForm"
@cancel="closeHolidayModal"
/> />
<CreateHolidayModal <CreateHolidayModal
v-model="dialogs.createholiday" v-model="dialogs.createholiday"
@save="SubmitFormCreate" @save="SubmitFormCreate"
@cancel="closeCreateModal"
/> />
<!-- Diálogo de Confirmação de Exclusão --> <!-- Diálogo de Confirmação de Exclusão -->
<v-dialog v-model="dialogs.delete" max-width="400px"> <v-dialog v-model="dialogs.delete" max-width="400px">
@ -323,6 +325,12 @@
dialogs.value.createholiday = true dialogs.value.createholiday = true
}; };
const closeHolidayModal = () => {
dialogs.value.holiday = false;
};
const closeCreateModal = () => {
dialogs.value.createholiday = false;
};
const openEditPage = (type, item) => { const openEditPage = (type, item) => {
console.log('Feriado que será editado:', item); // Log para depuração console.log('Feriado que será editado:', item); // Log para depuração
@ -495,6 +503,8 @@
deleteItem, deleteItem,
openEditPage, openEditPage,
openCreateModal, openCreateModal,
closeHolidayModal,
closeCreateModal,
// filtercameras, // filtercameras,
//exportToCSV, //exportToCSV,
handleholidayUpdated handleholidayUpdated