HTML
xxxxxxxxxx
1
<template>
2
<form>
3
<section class="d-flex flex-column justify-content-between h-100 setup-content animated">
4
<div class="d-flex flex-column">
5
<div class="d-flex flex-column justify-content-around px-2">
6
<mdb-input id="contact_name"
7
:customValidation="true"
8
v-model="name"
9
:isValid="!$v.name.$invalid"
10
:label="trans('marketplaces.checkout.identification.name.label')"
11
icon="user">
12
</mdb-input>
13
14
<mdb-input id="contact_email"
15
:customValidation="true"
16
v-model="email"
17
:isValid="!$v.email.$invalid"
18
:label="trans('marketplaces.checkout.identification.email.label')"
19
icon="envelope">
20
</mdb-input>
21
</div>
22
23
<div class="d-flex flex-column justify-content-around px-2">
24
<mdb-input id="contact_phone_number"
25
:customValidation="true"
26
v-model="phoneNumber"
27
type="tel"
28
:isValid="!$v.phoneNumber.$invalid"
29
:label="trans('marketplaces.checkout.identification.phone_number.label')"
30
icon="phone"
31
v-mask="['(##) ####-####','(##) #####-####']">
32
</mdb-input>
33
<mdb-input id="contact_doc"
34
:customValidation="true"
35
v-model="document"
36
type="tel"
37
:isValid="!$v.document.$invalid"
38
:label="trans(`marketplaces.checkout.identification.${settings.document_type}.label`)"
39
icon="id-card"
40
v-mask="documentMask">
41
</mdb-input>
42
</div>
43
</div>
44
<div class="d-flex step-buttons">
45
<button
46
type="button"
47
class="btn btn-guru btn-guru--next btn-guru--step-1 btn-rounded w-100"
48
@click.prevent="submit"
49
>
50
<span class="d-flex align-items-center justify-content-center">
51
{{trans('marketplaces.checkout.next')}}
52
<i class="uil uil-angle-right"></i>
53
</span>
54
</button>
55
</div>
56
</section>
57
</form>
58
</template>
SCSS
1
1
JS
xxxxxxxxxx
1
2
import { mdbInput } from "mdbvue";
3
import { required, email } from "vuelidate/lib/validators";
4
import {
5
brDocumentIsValid,
6
brPhoneNumberIsValid
7
} from "../../../../common/brValidators";
8
import { emailValidator, fullNameValidator } from "../../../../common/globalValidators";
9
10
export default {
11
name: "brContact",
12
components: {
13
mdbInput
14
},
15
props: ["contact", "settings"],
16
data() {
17
return {
18
name: this.contact.name + "",
19
email: this.contact.email + "",
20
phoneNumber: this.contact.phone.number + "",
21
document: this.contact.document + "",
22
submitting: false
23
};
24
},
25
computed: {
26
documentMask() {
27
switch (this.settings.document_type) {
28
case "cpf":
29
return "###.###.###-##";
30
case "cnpj":
31
return "##.###.###/####-##";
32
case "cpfcnpj":
33
return "###.###.###-##,##.###.###/####-##";
34
default:
35
return "###.###.###-##";
36
}
37
}
38
},
39
validations() {
40
return {
41
name: {
42
required,
43
fullNameValidator
44
},
45
email: {
46
required,
47
email,
48
emailValidator: emailValidator(this.settings.transactionId)
49
},
50
phoneNumber: {
51
required,
52
brPhoneNumberIsValid
53
},
54
document: {
55
required,
56
brDocumentIsValid: brDocumentIsValid(this.settings.document_type)
57
}
58
}
59
},
60
mounted() {
61
if (this.name) {
62
this.$v.name.$touch();
63
}
64
if (this.email) {
65
this.$v.email.$touch();
66
}
67
if (this.phoneNumber) {
68
this.$v.phoneNumber.$touch();
69
}
70
if (this.document) {
71
this.$v.document.$touch();
72
}
73
},
74
methods: {
75
submit() {
76
if (this.$v.$invalid) {
77
console.log("inválido");
78
return;
79
}
80
81
let contact = {
82
email: this.email,
83
name: this.name,
84
phone: {
85
country_code: '+55',
86
number: this.phoneNumber
87
},
88
document: this.document
89
};
90
91
this.$emit("validated", contact);
92
93
console.log("válido");
94
}
95
}
96
};
Console errors: 0