77 <h1 >Termine seu registro</h1 >
88
99 <div v-if =" etapa === 1" class =" step" id =" content1" >
10- <h3 >Nascimento</h3 >
10+ <h3 >Dados pessoais</h3 >
11+
12+
1113 <li v-if =" errorMessage" class =" alertBox alertBox-error" >{{ errorMessage }}</li >
1214 <div class =" input-box" :class =" { 'focused': focused.nascimentoFocused }" >
1315 <label for =" nascimento" >Data de nascimento</label >
1416 <input type =" date" id =" nascimento" v-model =" aluno.nascimento"
1517 @focus =" focused.nascimentoFocused = true" @blur =" focused.nascimentoFocused = false"
1618 required >
1719 </div >
18- <span class =" alert" v-show =" alerts.nascimentoAlert" >Por favor, preencha a data de nascimento
19- corretamente.</span >
20+
21+ <div class =" input-box" :class =" { 'focused': focused.telefone }" >
22+ <label for =" telefone" >Telefone ou número de celular</label >
23+ <input type =" text" id =" telefone" v-model =" aluno.telefone" @focus =" focused.telefone = true"
24+ @blur =" focused.telefone = false" @input =" formatTelefone" required >
25+ </div >
26+
27+ <span class =" alert" v-show =" alerts.nascimentoAlert" >Por favor, preencha sua data de nascimento
28+ e número de telefone ou celular corretamente.</span >
2029 <div class =" button-box" >
2130 <button @click =" validateNascimento" type =" button" >Continuar</button >
2231 </div >
2332 </div >
2433
2534 <div v-if =" etapa === 2" class =" step" id =" content2" >
2635 <li v-if =" errorMessage" class =" alertBox alertBox-error" >{{ errorMessage }}</li >
36+
2737 <h3 >Endereço</h3 >
28- <Select :dataSelect =" dataSelectEstado" @input =" $event => updateCidades($event)" />
29- <Select :dataSelect =" dataSelectCidade" @input =" aluno.endereco.cidade = $event" />
38+
39+ <div class =" input-box" :class =" { 'focused': focused.cep }" >
40+ <label for =" cep" >CEP</label >
41+ <input type =" text" id =" cep" v-model =" aluno.endereco.cep" @focus =" focused.cep = true"
42+ @blur =" focused.cep = false" @input =" handleCepInput" required >
43+ </div >
44+
45+ <div class =" input-box" :class =" { 'focused': focused.municipio }" >
46+ <label for =" municipio" >Município</label >
47+ <input type =" text" id =" municipio" :value =" aluno.endereco.municipio? (aluno.endereco.municipio + ', ' + aluno.endereco.estado) : ''"
48+ @focus =" focused.municipio = true" @blur =" focused.municipio = false" readonly >
49+ </div >
50+
51+ <div class =" input-box" :class =" { 'focused': focused.rua }" >
52+ <label for =" rua" >Rua</label >
53+ <input type =" text" id =" rua" v-model =" aluno.endereco.rua" @focus =" focused.rua = true"
54+ @blur =" focused.rua = false" required >
55+ </div >
56+
57+ <div class =" input-box" :class =" { 'focused': aluno.numero }" >
58+ <label for =" numero" >Número</label >
59+ <input type =" text" id =" numero" v-model =" aluno.endereco.numero" @focus =" focused.numero = true"
60+ @blur =" focused.numero = false" required >
61+ </div >
3062
3163 <span class =" alert" v-show =" alerts.enderecoAlert" >Por favor, preencha o endereço corretamente.</span >
3264 <div class =" button-box" >
6092
6193 <div v-if =" etapa === 5" class =" step" id =" content5" >
6294 <li v-if =" errorMessage" class =" alertBox alertBox-error" >{{ errorMessage }}</li >
63- <h3 >RM </h3 >
95+ <h3 >Resgistro de Matrícula </h3 >
6496 <div class =" input-box" :class =" { 'focused': focused.rmFocused }" >
6597 <label for =" rm" >RM</label >
6698 <input type =" text" id =" rm" v-model =" aluno.rm" @focus =" focused.rmFocused = true"
@@ -90,6 +122,8 @@ import Select from '../../components/Select.vue';
90122import { completeRegister , getCursos , getInicios } from ' ../../services/api/aluno' ;
91123import { mixinAluno } from ' ../../util/authMixins' ;
92124
125+ import axios from ' axios' ;
126+
93127export default {
94128 name: ' Complete' ,
95129 components: {
@@ -101,11 +135,15 @@ export default {
101135 return {
102136 aluno: {
103137 email: ' ' ,
138+ telefone: ' ' ,
104139 nascimento: ' ' ,
105140 rm: ' ' ,
106141 endereco: {
107- cidade: ' ' ,
108- estado: ' '
142+ cep: ' ' ,
143+ municipio: ' ' ,
144+ estado: ' ' ,
145+ rua: ' ' ,
146+ numero: ' '
109147 },
110148 curso: {
111149 name: ' ' ,
@@ -114,8 +152,6 @@ export default {
114152 }
115153 },
116154 etapa: 1 ,
117- ufs: [' SP' ],
118- cidades: [],
119155 cursos: [],
120156 inicios: [],
121157 focused: {
@@ -133,16 +169,6 @@ export default {
133169 inicioAlert: false ,
134170 rmAlert: false
135171 },
136- dataSelectEstado: {
137- title: " Selecione o estado" ,
138- description: " UF" ,
139- options: [],
140- },
141- dataSelectCidade: {
142- title: " Selecione sua cidade" ,
143- description: " Município" ,
144- options: [],
145- },
146172 dataSelectTurno: {
147173 title: " Selecione um turno" ,
148174 description: " Turno" ,
@@ -169,14 +195,28 @@ export default {
169195 },
170196 computed: {
171197 allRequirementsMet () {
172- return this .aluno .nascimento && this .aluno .endereco .estado && this .aluno .endereco .cidade &&
173- this .aluno .curso .name && this .aluno .curso .turno && this .aluno .curso .inicio && this .aluno .rm ;
198+ return this .aluno .nascimento &&
199+ this .aluno .endereco .estado !== ' ' &&
200+ this .aluno .endereco .municipio !== ' ' &&
201+ this .aluno .endereco .rua !== ' ' &&
202+ this .aluno .endereco .numero !== ' ' &&
203+ this .aluno .endereco .cep !== ' ' &&
204+ this .aluno .curso .name !== ' ' &&
205+ this .aluno .curso .turno !== ' ' &&
206+ this .aluno .curso .inicio !== ' ' &&
207+ this .aluno .rm !== ' ' &&
208+ this .aluno .telefone !== ' ' ;
174209 },
175210 nascimentoValidated () {
176- return this .aluno .nascimento !== ' ' ;
211+ return this .aluno .nascimento !== ' ' &&
212+ this .aluno .telefone !== ' ' ;
177213 },
178214 enderecoValidated () {
179- return this .aluno .endereco .estado !== ' ' && this .aluno .endereco .cidade !== ' ' ;
215+ return this .aluno .endereco .estado !== ' ' &&
216+ this .aluno .endereco .municipio !== ' ' &&
217+ this .aluno .endereco .rua !== ' ' &&
218+ this .aluno .endereco .numero !== ' ' &&
219+ this .aluno .endereco .cep !== ' ' ;
180220 },
181221 inicioValidated () {
182222 return this .aluno .curso .inicio !== ' ' ;
@@ -187,7 +227,8 @@ export default {
187227 try {
188228 const response = await completeRegister ({
189229 rm: this .aluno .rm ,
190- endereco: this .aluno .endereco .cidade + " , " + this .aluno .endereco .estado ,
230+ telefone: this .aluno .telefone ,
231+ endereco: this .aluno .endereco ,
191232 nascimento: this .aluno .nascimento ,
192233 curso: this .aluno .curso .name ,
193234 inicio: this .aluno .curso .inicio
@@ -259,23 +300,6 @@ export default {
259300 this .alerts .inicioAlert = true ;
260301 }
261302 },
262- async updateEstados () {
263- this .dataSelectEstado .options = this .ufs .map (uf => ({
264- value: uf,
265- description: uf
266- }));
267- },
268- async updateCidades (estadoSeleted ) {
269- this .aluno .endereco .estado = estadoSeleted;
270- const estado = this .aluno .endereco .estado ;
271- if (estado === ' SP' ) {
272- this .cidades = [' São Paulo' , ' Santo André' , ' São Bernardo' , ' São Caetano' , ' Diadema' , ' Mauá' , ' Ribeirão Pires' , ' Rio Grande da Serra' ];
273- this .dataSelectCidade .options = this .cidades .map (cidade => ({
274- value: cidade,
275- description: cidade
276- }))
277- }
278- },
279303 async fetchCursos () {
280304 try {
281305 const response = await getCursos (this .aluno .token );
@@ -292,14 +316,57 @@ export default {
292316 } catch (error) {
293317 this .errorMessage = " Ops.. Algo deu errado ao buscar os cursos. 😕" ;
294318 }
295- }
319+ },
320+ formatTelefone () {
321+ let telefone = this .aluno .telefone .replace (/ \D / g , ' ' );
322+ if (telefone .length > 11 ) {
323+ telefone = telefone .substring (0 , 11 );
324+ }
325+ if (telefone .length > 10 ) {
326+ telefone = telefone .replace (/ ^ (\d {2} )(\d {5} )(\d {4} )/ , ' ($1) $2-$3' );
327+ } else if (telefone .length > 9 ) {
328+ telefone = telefone .replace (/ ^ (\d {2} )(\d {4} )(\d {4} )/ , ' ($1) $2-$3' );
329+ }
330+ this .aluno .telefone = telefone;
331+ },
332+ async loadDataFromCep () {
333+ const cep = this .aluno .endereco .cep .replace (/ \D / g , ' ' );
334+ if (cep .length === 8 ) {
335+ try {
336+ const response = await axios .get (` https://viacep.com.br/ws/${ cep} /json/` );
337+ if (response .data ) {
338+ this .aluno .endereco .municipio = response .data .localidade ;
339+ this .aluno .endereco .estado = response .data .uf ;
340+ this .aluno .endereco .rua = response .data .logradouro ;
341+ }
342+ } catch (error) {
343+ console .error (" Erro ao buscar dados do CEP:" , error);
344+ }
345+ }
346+ },
347+ formatCep (cep ) {
348+ cep = cep .replace (/ \D / g , ' ' );
349+ if (cep .length > 8 ) {
350+ cep = cep .substring (0 , 8 );
351+ }
352+ if (cep .length > 5 ) {
353+ cep = cep .replace (/ ^ (\d {5} )(\d )/ , ' $1-$2' );
354+ }
355+ return cep;
356+ },
357+ handleCepInput (event ) {
358+ const input = event .target .value ;
359+ this .aluno .endereco .cep = this .formatCep (input);
360+ if (input .replace (/ \D / g , ' ' ).length === 8 ) {
361+ this .loadDataFromCep ();
362+ }
363+ },
296364 },
297365 mixins: [mixinAluno],
298366 async created () {
299367 await this .getToken ();
300368 this .aluno .email = Cookies .get (' email-aluno' );
301369 this .fetchCursos ();
302- this .updateEstados ();
303370 }
304371};
305372 </script >
0 commit comments