policy-change-contact.js
9.36 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
import api from "@/api/api";
import { httpGet, httpPost } from "@/api/fetch-api.js";
import { contactMethodCheck } from "@utils/utils.js";
import { setTitle, ascSort } from "@/utils/utils.js";
import {
getNationsList,
getNationsPhoneCodeList,
getCnProvinceList,
getCityList
} from "@/utils/biz.js";
import Auth from "@components/auth/auth.vue";
import UsTaxFormUploadComp from "./us-tax-form-upload-comp.vue";
import PolicyHeadList from "./policy-head-list.vue";
import modalComp from "@/components/modal-comp/modal-comp.vue";
import Modal2Comp from "@/components/modal2-comp/modal2-comp.vue";
import Vue from "vue";
import { Loading } from "vant";
Vue.use(Loading);
export default {
data() {
return {
loading: false,
showForm: false,
key: "value",
checked1: false,
checked2: false,
checked3: false,
dataInit: false,
selectedPolicies: [],
data: {
policyContactCode: "",
// 国际号码区号列表
mobileAreaCode: "",
// 电话
mobile: "",
// 国际地区区号
countryId: "",
// 省
provinceId: "",
// 市
cityId: "",
// 地址
address: "",
// 同意接收宣传信息 1:同意 0:不同意
acceptMessage: 1,
// 上传信息
iobsKey: "",
fileFormat: "",
fileSize: 0,
fileContentType: ""
},
errorTips: {
e1: "", // 电话号码
e2: "", // 地址
e3: "", // email
e4: "", // 国际地区取号
e5: "", // 电话区号
e6: "", // 省 中国大陆需要判断
e7: "", // 市 中国大陆需要判断
},
modalSimpleVisiable: false,
modalVisiable: false,
modalVisiableTimeoutIndex: 0, //定时隐藏索引
usTaxFormUploadCompVisible: false,
uploadErrorVisible: false,
targetPath: "",
modalIcon: "succ",
modalContent: "",
// 国际号码区号列表
nationsPhoneCodeList: [],
// 国际地区区号
nationsList: [],
provinceList: [],
cityList: []
};
},
components: {
Auth,
PolicyHeadList,
modalComp,
UsTaxFormUploadComp,
Modal2Comp
},
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;
let b1 = !this.selectedPolicies || this.selectedPolicies.length == 0;
let b2 =
!this.data.address ||
!this.data.email ||
!this.data.mobile ||
!this.data.mobileAreaCode ||
!this.data.countryId;
let b3 = false;
if (this.isChina) {
if (!this.data.provinceId || !this.data.cityId) {
b3 = true;
}
}
return b1 || b2 || b3;
},
isChina() {
let result = this.data.countryId == "28";
return result;
},
isUSA() {
let result = this.data.countryId == "225";
// return true;
return result;
}
},
methods: {
showModal(content, icon) {
icon = !icon || typeof icon === "undefined" ? "succ" : icon;
this.modalIcon = icon;
this.modalContent = content;
this.modalVisiable = true;
},
modalCallback() {
clearTimeout(this.modalVisiableTimeoutIndex);
this.modalVisiable = false;
},
showSuccess() {
this.showModal(this.i18n.policyChangeContact.success);
},
showUploadSuccess() {
this.showModal(this.i18n.policyChangeContact.uploadSuccess);
this.modalVisiableTimeoutIndex = setTimeout(() => {
this.modalVisiable = false;
}, 3000);
},
// 提交前准备
updateContactsHandler() {
if (this.submitBtnDisabled) {
return;
}
this.errorTips = {
e1: "",
e2: "",
e3: "",
e4: "",
e5: "",
e6: "",
e7: ""
};
let b1 = this.checkMobile();
let b2 = this.checkEmail();
let b3 = this.checkAddress();
let b4 = this.checkNationsPhoneCode();
let b5 = this.checkNations();
let b6 = this.checkProvince();
let b7 = this.checkCity();
let b = b1 && b2 && b3 && b4 && b5 && b6 && b7;
if (b) {
// 判断是否美国 出
if (this.isUSA) {
this.usTaxFormUploadCompVisible = true;
} else {
this.doSubmit();
}
}
},
/**
* 提交表单
*/
doSubmit(val = {}) {
// this.usTaxFormUploadCompVisible = false;
if (this.loading) {
return;
}
let policies = [];
this.selectedPolicies.forEach(element => {
policies.push({ policyId: element.id, policyCode: element.code });
});
let data = Object.assign(this.data, val);
data.policies = policies;
if (!this.isChina) {
data.provinceId = "";
data.cityId = "";
}
data.policyContactCode = "";
data.policyId = "";
data.policyCode = "";
this.loading = true;
httpPost({
url: api.policyContactApi,
data: data,
sid: true
})
.then(() => {
this.loading = false;
this.usTaxFormUploadCompVisible = false;
this.showSuccess();
})
.catch(err => {
this.loading = false;
if (err.code == 404) {
this.$refs.auth.noAuth();
}
});
},
/**
* 从美国税务表单组件提交
*/
onUsTaxSubmit(val) {
this.doSubmit(val);
},
checkMobile() {
if (this.data.mobile) {
let hkMobile = contactMethodCheck("hkmobile", this.data.mobile);
let zhMobile = contactMethodCheck("mobile", this.data.mobile);
if (!hkMobile && !zhMobile) {
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 true;
},
checkEmail() {
if (this.data.email && !contactMethodCheck("email", this.data.email)) {
this.errorTips.e3 = this.i18n.policyChangeContact.errorTips.e3;
return false;
}
return true;
},
checkNationsPhoneCode() {
if (!this.data.mobileAreaCode) {
this.errorTips.e4 = this.i18n.policyChangeContact.errorTips.e4;
return false;
}
return true;
},
checkNations() {
if (!this.data.countryId) {
this.errorTips.e5 = this.i18n.policyChangeContact.errorTips.e5;
return false;
}
return true;
},
checkProvince() {
if (this.isChina) {
if (!this.data.provinceId) {
this.errorTips.e6 = this.i18n.policyChangeContact.errorTips.e6;
return false;
}
return true;
}
return true;
},
checkCity() {
if (this.isChina) {
if (!this.data.cityId) {
this.errorTips.e7 = this.i18n.policyChangeContact.errorTips.e7;
return false;
}
return true;
}
return true;
},
/**
* 选择国家
*/
onChangeNations() {
// this.checkProvince();
},
/**
* 选择省份
*/
onChangeProvince() {
this.$set(this.data, "cityId", "");
this.cityList = getCityList(this.$i18n.locale, this.data.provinceId);
this.data.cityId = this.cityList[0].v;
},
onAgreeHandler() {
let acceptMessage = !this.data.acceptMessage;
this.$set(this.data, "acceptMessage", acceptMessage);
},
initData() {
// 获取国际电话区号
let nationsPhoneCodeListTemp = getNationsPhoneCodeList();
// 去重
let obj = {};
let nationsPhoneCodeList = nationsPhoneCodeListTemp.reduce(
(cur, next) => {
//设置cur默认类型为数组,并且初始值为空的数组
obj[next.n] ? "" : (obj[next.n] = true && cur.push(next));
return cur;
},
[]
);
// // 加数字属性标号用于排序
// nationsPhoneCodeList.forEach(element => {
// element.num = parseInt(element.n);
// });
// // 排序
// nationsPhoneCodeList = nationsPhoneCodeList.sort(ascSort("num", ""));
this.nationsPhoneCodeList = nationsPhoneCodeList;
// 获取国际区号
this.nationsList = getNationsList(this.$i18n.locale);
// 获取省份
this.provinceList = getCnProvinceList(this.$i18n.locale);
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.policyContactDetailApi,
data: param,
sid: true
})
.then(response => {
this.loading = false;
this.dataInit = true;
if (response) {
this.data = Object.assign(this.data, response);
if (response.provinceId) {
this.cityList = getCityList(
this.$i18n.locale,
this.data.provinceId
);
}
}
})
.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;
},
initTitle() {
try {
let title = this.i18n.customService.menu42;
setTitle(title);
} catch (e) {
console.error(e);
}
},
},
watch: {
"data.mobile": function() {
this.errorTips.e1 = "";
},
"data.address": function() {
this.errorTips.e2 = "";
},
"data.email": function() {
this.errorTips.e3 = "";
},
"data.mobileAreaCode": function() {
this.errorTips.e4 = "";
},
"data.countryId": function() {
this.errorTips.e5 = "";
},
"data.provinceId": function() {
this.errorTips.e6 = "";
},
"data.cityId": function() {
this.errorTips.e7 = "";
}
},
mounted() {
this.initTitle();
},
created() {
this.$root.eventBus.$on("langChange", () => {
try {
this.initData();
} catch (e) {}
});
}
};