infomation-improve.js 5.63 KB
import api from '@/api/api'
import {
	httpGet,
	httpPost
} from '@/api/fetch-api.js'

import modalComp from '@/components/modal-comp/modal-comp.vue';
import DatePicker from '@/components/date-picker/date-picker.vue'

export default {
	data() {
		return {
			key: 'value',
			values: {
				// 返回的token,串连整个流程,后台安全校验使用
				vcodeuuid: "",
				token: "",
				deviceId: "",
				imageBase64: "",
				password: "",
				passwordRepeat: ""
			},
			birthDate: "",
			information: {
				cnName: "",
				sex: "",
				birthDate: "",
				idNo: "",
				idType: ""
			},
			errorTips: {
				e1: "",
				e2: "",
				e3: "",
				e4: "",
				e5: "",
			},
			modalVisiable: false,
			targetPath: "",
			modalIcon: "succ",
			modalContent: ""
		}
	},
	components: {
		modalComp,
		DatePicker
	},
	computed: {
		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;
		}
	},
	methods: {
		showModal(content, icon) {
			icon = !icon || typeof icon === "undefined" ? "succ" : "succ";
			this.modalIcon = icon;
			this.modalContent = content;
			this.modalVisiable = true;
		},
		initData() {},
		onUpdateHandler() {
			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) {
				// console.log(this.birthDate);
				// let y = this.birthDate.getFullYear();
				// let m = this.birthDate.getMonth() + 1;
				// let d = this.birthDate.getDate();
				// let day = y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d);
				this.information.birthDate = this.birthDate;
				this.loadIdentify().then(() => {
					httpPost({
						url: api.updateInformation,
						data: this.information,
						sid: true
					}).then(response => {
						let message = "";
						switch (response.returnCode) {
							case "GS_MODIFYFIVEKEYS_ERROR_IDNOERROR":
								message = this.i18n.infomationImprove.errorTips.e6;
								this.errorTips.e5 = message;
								break;
							case "COMMON_ERROR_036":
								this.showModal(this.i18n.infomationImprove.errorTips.e7, "info");
								this.errorTips.e5 = message;
								break;
							case "0":
								message = this.i18n.infomationImprove.successMsg;
								this.showModal(message, "succ");
								let path = this.$route.query.callback || "/index";
								this.targetPath = path;
								break;
						}
					});
				});
			}
		},
		loadIdentify() {
			return new Promise((resolve, reject) => {
				httpPost({
					url: api.load,
					data: {
						clientNo: "501381573194155227"
					}
				}).then(response => {
					this.$store.commit("SET_USER_INFO", response.data);
					resolve();
				})
			});
		},
		checkCnName() {
			if (!this.information.cnName) {
				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;
		},
		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 "0": // 外國人永久居留身份證
					// if (/[a-z][A-Z]{3}[0-9]{12}/.test(idNo)) {
					// 	message = "";
					// }
					message = "";
					break;
				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": // 港澳通行證/回鄉證或台胞證
					message = idNo.length > 5 && idNo.length < 50 ? "" : message;
					break;
				case "V": // 港澳台居民居住證
					// if ((/8[1|2]0000\\d{11}/.text(idNo) && (/\\d{15}/.test(idNo) || /\\d{17}/.test(idNo)))) {
					message = "";
					// }
					break;
				case "W": //台灣居民居住證
					// if ((/830000\\d{11}/.text(idNo) && (/\\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
				});
			}
		}
	},
	mounted() {
		this.initData();
	},
	watch: {
		'information.cnName': function () {
			this.errorTips.e1 = "";
		},
		'information.sex': function () {
			this.errorTips.e2 = "";
		},
		'birthDate': function () {
			this.errorTips.e3 = "";
		},
		'information.idNo': function () {
			this.errorTips.e4 = "";
		},
		'information.idType': function () {
			this.errorTips.e5 = "";
		}
	},
	created() {}
}