policy-change-contact.js 8.35 KB
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 } from "@/utils/biz.js";

import Auth from "@components/auth/auth.vue";
import modalComp from "@/components/modal-comp/modal-comp.vue";
import PolicyHeadList from "./policy-head-list.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: {
				// 国际号码区号列表
				mobileAreaCode: "",
				// 电话
				mobile: "",
				// 国际地区区号
				countryId: "",
				// 省
				provinceId: "",
				// 市
				cityId: "",
				// 地址
				address: "",
				// 同意接收宣传信息 1:同意 0:不同意
				acceptMessage: 1,

				// 上传信息
				iobsKey: "a",
				fileFormat: "xlsx",
				fileSize: 123,
				fileContentType: "mp4"
			},
			errorTips: {
				e1: "",
				e2: "",
				e3: ""
			},

			modalSimpleVisiable: false,
			modalVisiable: false,
			targetPath: "",
			modalIcon: "succ",
			modalContent: "",

			// 国际号码区号列表
			nationsPhoneCodeList: [],
			// 国际地区区号
			nationsList: []
		};
	},
	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
				};
				console.log("data:", JSON.stringify(data));
				return;
				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 = 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() {
			return true;
		},
		checkEmail() {
			if (this.data.email && !contactMethodCheck("email", this.data.email)) {
				this.errorTips.e3 = this.i18n.policyChangeContact.errorTips.e3;
				return false;
			}
			return true;
		},
		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);

			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;
			console.log("this.selectedPolicies:", this.selectedPolicies);
			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);
			}
		},
		updatePolicyContact() {
<<<<<<< HEAD
			let param = {
				policyContactCode: "",
				policyId: "4655100",
				policyCode: "P000200000000009",
				mobileAreaCode: "0668",
				mobile: "13727826666",
				countryId: "156",
				provinceId: "1",
				cityId: "304",
				address: "上海迪士尼乐园",
				acceptMessage: 1,
				iobsKey: "a",
				fileFormat: "xlsx",
				fileSize: 123,
				fileContentType: "mp4/"
			};
=======
			let param={
				"policyContactCode":"",
				"policies":[{
					"policyId":"4655100",
					"policyCode":"P000200000000009"}],
				"mobileAreaCode":"0668",
				"mobile":"13727826666",
				"countryId":"156",
				"provinceId":"1",
				"cityId":"304",
				"address":"上海迪士尼乐园123213123",
				"acceptMessage":1,
				"iobsKey":"a",
				"fileFormat":"xlsx",
				"fileSize":123,
				"fileContentType":"mp4/"
			}
>>>>>>> 1af854e069546774dda5b13dbb28fa154cacd45d
			httpPost({
				url: api.policyContactApi,
				data: param,
				sid: true
			})
				.then(response => {
					console.log("response:", response);
				})
				.catch(res => {});
		},
<<<<<<< HEAD
		uploadExcel() {}
=======
		uploadExcel(){

		},
		queryPolicyContact(){
			let param ={policyId:'4655100',policyCode:'P000200000000009'}
			httpPost({
				url: api.policyContactDetailApi,
				data: param,
				sid: true
			}).then(response => {
				console.log("response:", response)
			}).catch(res => {

			});
		}
>>>>>>> 1af854e069546774dda5b13dbb28fa154cacd45d
	},
	watch: {
		"data.mobileAreaCode": function() {
			this.errorTips.e1 = "";
		},
		"data.mobile": function() {
			this.errorTips.e2 = "";
		},
		"data.countryId": function() {
			this.errorTips.e3 = "";
		},
		"data.provinceId": function() {
			this.errorTips.e4 = "";
		},
		"data.cityId": function() {
			this.errorTips.e5 = "";
		},
		"data.address": function() {
			this.errorTips.e6 = "";
		},
	},
	mounted() {
		this.initTitle();
	},
	created() {
		// this.loading = true;
		this.$root.eventBus.$on("langChange", () => {
			try {
				this.initData();
			} catch (e) {}
		});
	}
};

// var ttt = {
// 	areaCode:"",
// 	mobileNo: "1232321",
// 	address: "CHINA, GuangdongShenzhen咯农户心情来来来",
// 	email: "zhangwenjun110@ocft.com",
// 	mobileNoAcceptMsg: 0,
// 	addressAcceptMsg: 0,
// 	emailAcceptMsg: 0,
// 	policies: [{ policyId: "4661690", policyCode: "P000200000000458" }]
// };

var tttt2 = {
	policyContactCode: "",
	policyId: "4655100",
	policyCode: "P000200000000009",
	mobileAreaCode: "0668",
	mobile: "13727826666",
	countryId: "156",
	provinceId: "1",
	cityId: "304",
	address: "上海迪士尼乐园",
	acceptMessage: 1,
	iobsKey: "a",
	fileFormat: "xlsx",
	fileSize: 123,
	fileContentType: "mp4"
};