policy-change-information.js 3.96 KB
import api from '@/api/api'
import {
	httpGet,
	httpPost
} from '@/api/fetch-api.js'

import Auth from '@components/auth/auth.vue';
import PolicyHeadList from "./policy-head-list.vue";
import DatePicker from '@/components/date-picker/date-picker.vue'
import modalComp from '@/components/modal-comp/modal-comp.vue';
import modalUploadCardComp from '@/components/modal-upload-card-comp/modal-upload-card-comp.vue';

export default {
	data() {
		return {
			loading: false,
			showForm: false,
			key: 'value',
			isOwner: true,
			checked: false,
			modalUploadCardVisiable: false,
			selectedPolicies: [],
			data: null,
			// 保单信息
			policy: null,

			// 模态窗
			modalSimpleVisiable: false,
			modalVisiable: false,
			targetPath: "",
			modalIcon: "succ",
			modalContent: "",
		}
	},
	components: {
		modalUploadCardComp,
		PolicyHeadList,
		Auth,
		DatePicker,
		modalComp
	},
	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" : icon;
			this.modalIcon = icon;
			this.modalContent = content;
			this.modalVisiable = true;
		},
		modalCallback() {
			this.modalVisiable = false;
		},
		loadData() {
			if (this.loading) {
				return;
			}
			this.loading = true;
			this.data = null;
			let param = {
				policyId: this.selectedPolicies[0].id,
				policyCode: this.selectedPolicies[0].code
			};
			httpPost({
				url: api.policyDetail,
				data: param,
				sid: true
			}).then(response => {
				this.loading = false;
				if (response) {
					this.policy = response;
					this.initData();
				}
			}).catch(res => {
				this.loading = false;
				if (res.code == "404") {
					this.$refs.auth.noAuth();
				}
			});
		},
		initData() {
			let res = this.policy;
			let name = "";
			let isOwner = this.isOwner;
			if (isOwner) {
				name = res.clientNameCn ? res.clientNameCn : res.clientNameEn;
			} else {
				name = res.insuredNameCn ? res.insuredNameCn : res.insuredNameEn;
			}
			let data = {
				name: name,
				idType: isOwner ? res.clientIdType : res.insuredIdType,
				idNumber: isOwner ? res.clientIdNumber : res.insuredIdNumber,
				idExpireAt: isOwner ? res.clientExpireAt : res.insurantExpireAt,
				nature: isOwner ? res.clientNationality : res.insurantNationality,
				company: isOwner ? res.clientCompany : res.insurantCompany,
				marriage: isOwner ? res.clientMarriage : res.insurantMarriage,
				sex: isOwner ? res.clientSex : res.insuredSex,
				birthday: isOwner ? res.clientBirthday : res.insuredBirthday
			};
			data.sex = data.sex ? data.sex : "M";
			console.log("data ===", data);
			this.$set(this, 'data', data);
		},
		handlePolicySelect(data) {
			this.selectedPolicies = data;
			this.loadData();
		},
		updatePolicyInfo() {
			console.log(1, this.loading);
			if (this.loading) {
				return;
			}
			this.loading = true;
			let param = JSON.parse(JSON.stringify(this.data));
			delete param.birthday;
			delete param.sex;
			param.modifyObj = this.isOwner ? 1 : 2;
			param.policyId = this.selectedPolicies[0].id;
			param.policyCode = this.selectedPolicies[0].code;

			console.log("2,", param);
			httpPost({ url: api.updatePolicyInfo, data: param, sid: true }).then(res => {
				console.log("3,", res);
				this.loading = false;
				this.showModal(this.i18n.policyChangeInformation.success);
			}).catch(err => {
				this.loading = false;
				if (err.code == 404) {
					this.$refs.auth.noAuth();
				}
			});

		},
		userLogout() {
			this.showForm = false;
		},
		userLogin(data) {
			this.showForm = true;
		}
	},
	mounted() {
		this.isOwner = this.$route.query.u == 1 ? true : false;
	},
	created() { }
}