policy-change-contact.js
3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import api from '@/api/api'
import {
httpGet,
httpPost
} from '@/api/fetch-api.js'
export default {
data() {
return {
key: 'value',
checked1: false,
checked2: false,
checked3: false,
data: {
mobileAreaCode: "",
mobile: "",
mobileAcceptMessage: 0,
email: "",
emailAcceptMessage: 0,
address: "",
addressAcceptMessage: 0
},
errorTips: {
e1: "",
e2: "",
e3: ""
},
}
},
components: {},
computed: {
locale() {
return this.$i18n.locale || 'tc';
},
i18n() {
return this.$i18n.messages && this.$i18n.locale ? this.$i18n.messages[this.$i18n.locale] : {};
}
},
methods: {
modalCallback() {
this.modalVisiable = false;
},
sessionLost() {
// let message = this.i18n.glbalTips.sessionLost;
// alert(message);
// let targetPath = "/login?callback=" + this.buildCallbackPath();
// this.$router.push({
// path: targetPath
// });
},
showSuccess() {
alert("更新成功")
},
updateContactsHandler() {
let b1 = this.checkMobile();
let b2 = this.checkEmail();
let b3 = this.checkAddress();
let b = b1 & b2 & b3;
if (b) {
this.data.mobileAcceptMessage = this.checked1 ? 1 : 0;
this.data.addressAcceptMessage = this.checked2 ? 1 : 0;
this.data.emailAcceptMessage = this.checked3 ? 1 : 0;
httpPost({
url: api.updateContacts,
data: this.data,
sid: true
}).then(() => {
this.showSuccess();
}).catch(() => {
this.sessionLost();
})
}
},
checkMobile() {
if (!this.data.mobile) {
this.errorTips.e1 = this.i18n.policyChangeContact.errorTips.e1;
return false;
} else {
if (this.data.mobile.length != 8 && this.data.mobile.length != 11) {
this.errorTips.e1 = this.i18n.policyChangeContact.errorTips.e1;
return false;
}
}
return true;
},
checkAddress() {
if (!this.data.address) {
this.errorTips.e2 = this.i18n.policyChangeContact.errorTips.e2;
return false;
}
return true;
},
checkEmail() {
if (!/^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/.test(this.data.email)) {
this.errorTips.e3 = this.i18n.policyChangeContact.errorTips.e3;
return false;
}
return true;
},
initData() {
httpPost({
url: api.getContacts,
sid: true
}).then(response => {
if (response) {
this.data.mobile = response.mobile;
this.data.mobileAcceptMessage = response.mobileAcceptMessage;
this.data.email = response.email;
this.data.emailAcceptMessage = response.emailAcceptMessage;
this.data.address = response.address;
this.data.addressAcceptMessage = response.addressAcceptMessage;
}
this.checked1 = this.data.mobileAcceptMessage == 1 ? true : false;
this.checked2 = this.data.addressAcceptMessage == 1 ? true : false;
this.checked3 = this.data.emailAcceptMessage == 1 ? true : false;
}).catch(res => {
if (res.code == "404") {
this.sessionLost();
}
});
},
buildCallbackPath() {
let path = this.$route.path;
let sep = "?"
for (let key in this.$route.query) {
path += sep + key + "=" + this.$route.query[key];
sep = "&";
}
return path;
}
},
watch: {
'data.mobile': function () {
this.errorTips.e1 = "";
},
'data.address': function () {
this.errorTips.e2 = "";
},
'data.email': function () {
this.errorTips.e3 = "";
}
},
mounted() {
this.initData();
},
created() {}
}