policy-change-contact.js
4.33 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import api from '@/api/api'
import {
httpGet,
httpPost
} from '@/api/fetch-api.js'
import Auth from '@components/auth/auth.vue';
import modalComp from '@/components/modal-comp/modal-comp.vue';
import PolicyHeadList from "./policy-head-list.vue";
export default {
data() {
return {
loading: false,
showForm: false,
key: 'value',
checked1: false,
checked2: false,
checked3: false,
dataInit: false,
selectedPolicies: [],
data: {
mobileAreaCode: "",
mobile: "",
email: "",
address: "",
},
errorTips: {
e1: "",
e2: "",
e3: ""
},
modalSimpleVisiable: false,
modalVisiable: false,
targetPath: "",
modalIcon: "succ",
modalContent: "",
}
},
components: {
Auth,
PolicyHeadList,
modalComp
},
computed: {
locale() {
return this.$i18n.locale || 'tc';
},
i18n() {
return this.$i18n.messages && this.$i18n.locale ? this.$i18n.messages[this.$i18n.locale] : {};
},
submitBtnDisabled() {
let b1 = !this.selectedPolicies || this.selectedPolicies.length == 0;
let b2 = !this.data.address && !this.data.email && !this.data.mobile;
return b1 || b2;
}
},
methods: {
showModal(content, icon) {
icon = !icon || typeof icon === "undefined" ? "succ" : icon;
this.modalIcon = icon;
this.modalContent = content;
this.modalVisiable = true;
},
modalCallback() {
this.modalVisiable = false;
},
showSuccess() {
this.showModal(this.i18n.policyChangeContact.success);
},
updateContactsHandler() {
if (this.submitBtnDisabled) {
return;
}
let b1 = this.checkMobile();
let b2 = this.checkEmail();
let b3 = this.checkAddress();
let b = b1 & b2 & b3;
if (b) {
if (this.loading) {
return;
}
let policies = [];
this.selectedPolicies.forEach(element => {
policies.push({ policyId: element.id, policyCode: element.code });
});
let data = {
mobileNo: this.data.mobile,
address: this.data.address,
email: this.data.email,
mobileNoAcceptMsg: this.checked1 ? 1 : 0,
addressAcceptMsg: this.checked2 ? 1 : 0,
emailAcceptMsg: this.checked3 ? 1 : 0,
policies: policies
}
this.loading = true;
httpPost({
url: api.updatePolicyContanct,
data: data,
sid: true
}).then(() => {
this.loading = false;
this.showSuccess();
}).catch(err => {
this.loading = false;
if (err.code == 404) {
this.$refs.auth.noAuth();
}
})
}
},
checkMobile() {
if (this.data.mobile) {
let hkMobile = /^[5689]{1}\d{7}$/.test(this.data.mobile);
let zhMobile = /^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(166)|(17[0-9])|(18[0-9])|(19[0-9]))\d{8}$/.test(this.data.mobile);
if (!hkMobile && !zhMobile) {
this.errorTips.e1 = this.i18n.policyChangeContact.errorTips.e1;
return false;
}
}
return true;
},
checkAddress() {
return true;
},
checkEmail() {
if (this.data.email && !/^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/.test(this.data.email)) {
this.errorTips.e3 = this.i18n.policyChangeContact.errorTips.e3;
return false;
}
return true;
},
initData() {
if (this.dataInit) {
return;
}
if (this.loading) {
return;
}
this.data = null;
this.loading = true;
let param = {
policyId: this.selectedPolicies[0].id,
policyCode: this.selectedPolicies[0].code
};
httpPost({
url: api.policyDetail,
data: param,
sid: true
}).then(response => {
this.data = {};
if (response) {
this.loading = false;
this.dataInit = true;
this.data.mobile = response.clientMobileNo;
this.checked1 = "1" == response.clientMobileAcceptMessage;
this.data.address = response.clientContactAddress;
this.checked2 = "1" == response.clientAddressAcceptMessage;
this.data.email = response.clientEmail;
this.checked3 = "1" == response.clientEmailAcceptMessage;
}
}).catch(res => {
if (res.code == "404") {
this.$refs.auth.noAuth();
}
});
},
handlePolicySelect(data) {
this.selectedPolicies = data;
this.initData();
},
userLogout() {
this.showForm = false;
},
userLogin(data) {
this.showForm = true;
}
},
watch: {
'data.mobile': function () {
this.errorTips.e1 = "";
},
'data.address': function () {
this.errorTips.e2 = "";
},
'data.email': function () {
this.errorTips.e3 = "";
}
},
mounted() {
}
}