customer-auth.js 6.44 KB
import api from '@/api/api'
import {
	httpGet,
	httpPost
} from '@/api/fetch-api.js'
import {
	mapState
} from 'vuex';


import Auth from '@components/auth/auth.vue';
import modalComp from '@/components/modal-comp/modal-comp.vue';
import modalSimpleComp from '@/components/modal-simple-comp/modal-simple-comp.vue';
import DatePicker from '@/components/date-picker/date-picker.vue'
import Vue from 'vue';
import { Loading } from 'vant';
Vue.use(Loading);


export default {
	data() {
		return {
			loading: false,
			showForm: false,
			key: 'value',
			values: {
				// 返回的token,串连整个流程,后台安全校验使用
				vcodeuuid: "",
				token: "",
				deviceId: "",
				imageBase64: "",
				password: "",
				passwordRepeat: ""
			},
			birthDate: "",
			information: {
				firstName: "",
				lastName: "",
				sex: "",
				birthDate: "",
				idNo: "",
				idType: ""
			},
			errorTips: {
				e1: "",
				e2: "",
				e3: "",
				e4: "",
				e5: "",
				// 生日
				e6: "",
			},
			modalSimpleVisiable: false,
			modalVisiable: false,
			targetPath: "",
			modalIcon: "succ",
			modalContent: "",
			errorModel : 1
		}
	},
	components: {
		modalComp,
		DatePicker,
		Auth,
		modalSimpleComp
	},
	computed: {
		...mapState({
			userInfo: state => state.userInfo
		}),
		locale() {
			return this.$i18n.locale || 'tc';
		},
		i18n() {
			return this.$i18n.messages && this.$i18n.locale ? this.$i18n.messages[this.$i18n.locale] : {};
		},
		sexCandidates() {
			let i18n = this.$i18n.messages[this.$i18n.locale];
			return i18n.infomationImprove.candidates.sex;
		},
		idTypeCandidates() {
			let i18n = this.$i18n.messages[this.$i18n.locale];
			return i18n.infomationImprove.candidates.idType;
		},
		submitBtnDisabled() {
			let b1 = !this.information.firstName ? true : false;
			let b2 = !this.information.lastName ? true : false;
			let b3 = !this.information.sex ? true : false;
			let b4 = !this.information.birthDate ? true : false;
			let b5 = !this.information.idNo ? true : false;
			let b6 = !this.information.idType ? true : false;
			return b1 || b2 || b3 || b4 || b5 || b6;
		}
	},
	methods: {
		showModal(content, icon) {
			icon = !icon || typeof icon === "undefined" ? "succ" : icon;
			this.modalIcon = icon;
			this.modalContent = content;
			if (icon == "succ") {
				this.modalVisiable = true;
			} else {
				this.modalSimpleVisiable = true;
			}
		},
		closeModal() {
			this.modalVisiable = false;
			this.modalSimpleVisiable = false;
		},
		initData() {
		},
		onUpdateHandler() {
			if (this.submitBtnDisabled) {
				return;
			}
			let b1 = this.checkCnName();
			let b2 = this.checkIdNo();
			let b3 = this.checkBirthday();
			let b4 = this.checkSex();
			let b5 = this.checkIdType();
			let b = b1 & b2 & b3 & b4 & b5;

			if (b) {
				this.information.birthDate = this.birthDate;
				this.loadIdentify().then(() => {
					if (this.loading) {
						return;
					}
					this.loading = true;
					httpPost({
						url: api.customerAuth,
						data: this.information,
						sid: true
					}).then(response => {
						this.loading = false;
						this.backTargetPath();
					}).catch(err => {
						this.loading = false;
						this.showErrorTips();
						this.errorModel = 2;
					});
				});
			}
		},
		loadIdentify() {
			return new Promise((resolve, reject) => {
				resolve();
			});
		},
		checkCnName() {
			if (!this.information.firstName || !this.information.lastName) {
				let message = this.i18n.infomationImprove.errorTips.e1;
				this.errorTips.e1 = message;
				return false;
			}
			return true;
		},
		checkSex() {
			if (!this.information.sex) {
				let message = this.i18n.infomationImprove.errorTips.e2;
				this.errorTips.e2 = message;
				return false;
			}
			return true;
		},
		backTargetPath(){
			let path = this.$route.query.c;
			if(!path){
				path = "/custom/service?q=m3";
			}
			this.$router.push({
				path: path
			});
		},
		checkBirthday() {
			if (!this.birthDate) {
				let message = this.i18n.infomationImprove.errorTips.e3;
				this.errorTips.e3 = message;
				return false;
			}
			return true;
		},
		checkIdType() {
			if (!this.information.idType) {
				let message = this.i18n.infomationImprove.errorTips.e4;
				this.errorTips.e4 = message;
				return false;
			}
			return true;
		},
		checkIdNo() {
			let message = this.i18n.infomationImprove.errorTips.e5;
			if (!this.information.idNo) {
				this.errorTips.e5 = message;
				return false;
			}
			if (!this.information.idType) {
				return true;
			}
			message = this.i18n.infomationImprove.errorTips.e6;
			let idNo = this.information.idNo + "";
			switch (this.information.idType) {
				// case "1":  // 身份證
				// 	message = idNo.length == 18 ? "" : message;
				// 	break;
				case "2":  // 護照
					message = idNo.length > 3 && idNo.length < 50 ? "" : message;
					break;
				case "3":  // 軍官證或士兵證
					message = idNo.length > 6 && idNo.length < 50 ? "" : message;
					break;
				case "6":  // 港澳通行證/回鄉證或台胞證
					if (idNo.indexOf("81") == 0 || idNo.indexOf("82") == 0) {
						if ((/\\d{15}/.test(idNo) || /\\d{17}/.test(idNo))) {
							message = "";
						}
					}
					break;
				case "V":  // 港澳居民居住證
					if (idNo.indexOf("81") == 0 || idNo.indexOf("82") == 0) {
						if ((/\\d{15}/.test(idNo) || /\\d{17}/.test(idNo))) {
							message = "";
						}
					}
					break;
				case "W":  //台灣居民居住證
					if (idNo.indexOf("83") == 0 || idNo.indexOf("82") == 0) {
						if ((/\\d{15}/.test(idNo) || /\\d{17}/.test(idNo))) {
							message = "";
						}
					}
					break;
				default:
					message = "";
					break;
			}
			return true;
		},
		modalCallback() {
			this.modalVisiable = false;
			if (this.targetPath) {
				this.$router.push({
					"path": this.targetPath
				});
			}
		},
		showErrorTips(content){
			this.errorTips.e1 = "1";
			this.errorTips.e2 = "1";
			this.errorTips.e3 = "1";
			this.errorTips.e4 = "1";
			this.errorTips.e5 = "1";
			this.errorTips.e6 = "1";
		},
		userLogout() {
			this.$router.push({
				path : "/"
			});
		},
		userLogin(data) {
			this.showForm = true;
		}
	},
	mounted() {
		this.initData();
	},
	watch: {
		'information.cnName': function () {
			this.errorTips.e1 = "";
		},
		'information.sex': function () {
			this.errorTips.e2 = "";
		},
		'birthDate': function () {
			this.errorTips.e3 = "";
			this.information.birthDate = this.birthDate;
		},
		'information.idNo': function () {
			this.errorTips.e4 = "";
		},
		'information.idType': function () {
			this.errorTips.e5 = "";
		}
	},
	created() { }
}