clarms-plugins-material.js 7.49 KB
import api from '@/api/api'
import {
	httpGet,
	httpPost,
	formdata
} from '@/api/fetch-api.js'

import DatePicker from '@/components/date-picker/date-picker.vue';
import ClarmsUpload from './clarms-plugins-upload.vue';
import Vue from 'vue';
import {
	Loading
} from 'vant';
import {
	Select,
	Option
} from 'element-ui';

Vue.use(Loading);
Vue.use(Select);
Vue.use(Option);

export default {
	props: {
		// 是否显示组件
		insuredList: {
			type: Array,
			default () {
				return []
			}
		},
		cid: {
			type: String,
			default: ""
		}
	},
	data() {
		return {
			showTips: false,
			// 候选人所购买的保单可选择的类型
			/**
			 * 1 意外医疗
			 * 2 疾病医疗
			 * 3 意外残疾
			 * 4 疾病残疾
			 * 5 意外死亡
			 * 6 疾病死亡
			 * 7 重大疾病
			 */
			typeCandidates: ['1', '2', '5', '6', '7'],
			// 已经选择的类型,
			typeSelected: [],
			images: [],
			agress: false,
			data: {
				insuredIndex: "",
				amount: null,
				contactDate: "",
				// 必传资料
				HT41: null,
				HT26: null,
				// 非必传资料
				HT29: null,
				HT34: null,
				HT16: null,

				// 是否正在上传
				HT41Uploading: false,
				HT26Uploading: false,
				HT29Uploading: false,
				HT34Uploading: false,
				HT16Uploading: false,

			},
			loading: false,
			contactDateError: false,
			// 判断是否有合法的保单
			policyIllegal: true,
		}
	},
	components: {
		DatePicker,
		ClarmsUpload
	},
	computed: {
		lan() {
			return this.$i18n.locale;
		},
		i18n() {
			return this.$i18n.messages && this.$i18n.locale ? this.$i18n.messages[this.$i18n.locale] : {};
		},
		submitBtnDisabled() {
			// 受保人
			let b1 = this.data.insuredIndex ? false : true;
			// 申请类型
			let b2 = this.typeSelected.length > 0 ? false : true;
			// 申请额度
			let b3 = this.data.amount > 0 ? false : true;
			// 日期校验
			let b4 = this.data.contactDate ? false : true;
			let b5 = this.contactDateError;

			// 必传资料
			let b6 = this.data.HT41 && this.data.HT41.length > 0 ? false : true;
			let b7 = this.data.HT26 && this.data.HT26.length > 0 ? false : true;
			// 资料上传中
			let b8 = this.data.HT41Uploading || this.data.HT26Uploading || this.data.HT29Uploading || this.data.HT34Uploading || this.data.HT16Uploading;
			let b9 = !this.agress;

			let b10 = this.policyIllegal;

			return b1 || b2 || b3 || b4 || b5 || b6 || b7 || b8 || b9 || b10;
		}
	},
	methods: {
		initData() {
			// console.log("this.insuredList = ", this.insuredList);
		},
		typeClickHandle(t) {
			let index = this.typeSelected.indexOf(t);
			if (index > -1) {
				this.typeSelected.splice(index, 1);
			} else {
				this.typeSelected.push(t);
			}
		},
		amountCheck() {
			if (this.data.amount) {
				if (this.data.amount < 0) {
					this.data.amount = 0;
				} else if (this.data.amount > 5000) {
					this.data.amount = 5000;
				}
			}
		},
		uploadSuccess(data) {
			// console.log(data);
			switch (data.type) {
				case "HT41":
					this.data.HT41Uploading = false;
					this.data.HT41 = data.list;
					break;
				case "HT26":
					this.data.HT26Uploading = false;
					this.data.HT26 = data.list;
					break;
				case "HT29":
					this.data.HT29Uploading = false;
					this.data.HT29 = data.list;
					break;
				case "HT34":
					this.data.HT34Uploading = false;
					this.data.HT34 = data.list;
					break;
				case "HT16":
					this.data.HT16Uploading = false;
					this.data.HT16 = data.list;
					break;
			}
		},
		beforeUpload(data) {
			// console.log(data);
			switch (data.type) {
				case "HT41":
					this.data.HT41Uploading = true;
					this.data.HT41 = [];
					break;
				case "HT26":
					this.data.HT26Uploading = true;
					this.data.HT26 = [];
					break;
				case "HT29":
					this.data.HT29Uploading = true;
					this.data.HT29 = [];
					break;
				case "HT34":
					this.data.HT34Uploading = true;
					this.data.HT34 = [];
					break;
				case "HT16":
					this.data.HT16Uploading = true;
					this.data.HT16 = [];
					break;
			}
		},
		checkDate(data) {
			this.contactDateError = data.disable;
		},
		toContact() {
			this.$router.push({
				path: "/custom/service?q=m1"
			});
		},
		submitMaterial() {

			if (this.submitBtnDisabled) {
				return;
			}
			if (this.loading) {
				return;
			}
			let policy = this.checkPolicy();
			if (!policy) {
				return;
			}
			let insured = this.insuredList[this.data.insuredIndex - 1];
			this.loading = true;

			let imageList = [];
			imageList = this.data.HT41 && this.data.HT41.length > 0 ? imageList.concat(this.data.HT41) : imageList;
			imageList = this.data.HT26 && this.data.HT26.length > 0 ? imageList.concat(this.data.HT26) : imageList;
			imageList = this.data.HT29 && this.data.HT29.length > 0 ? imageList.concat(this.data.HT29) : imageList;
			imageList = this.data.HT34 && this.data.HT34.length > 0 ? imageList.concat(this.data.HT34) : imageList;
			imageList = this.data.HT16 && this.data.HT16.length > 0 ? imageList.concat(this.data.HT16) : imageList;

			let params = {
				cid: this.cid,
				insuredId: insured.insuredId,
				policyId: policy.policyId,
				accidentTime: this.data.contactDate,
				applyReasonList: this.typeSelected.join(","),
				treatmentAmount: this.data.amount,
				imageList: imageList
			}
			httpPost({
				url: api.clarmsRegisterCase,
				data: params
			}).then(res => {
				this.$emit("showModal", 2);
				this.loading = false;
				this.agress = false;
			}).catch(e => {
				this.loading = false;
				this.showTips = true;
				this.agress = false;
			})
		},
		checkPolicy() {
			// 校验选择的受保人在选择的时间点内是否有保单
			if (this.contactDateError) {
				return false;
			}
			if (!this.data.contactDate || !this.data.insuredIndex) {
				return false;
			}
			let insured = this.insuredList[this.data.insuredIndex - 1];
			if (!insured.policyInfoList || insured.policyInfoList.length <= 0) {
				this.$emit("showModal", 1);
				return false;
			}
			// console.log("insured === ", insured);
			var time = new Date(this.data.contactDate.replace(/\-/g, "/") + " 00:00:00").getTime();
			for (let index = 0; index < insured.policyInfoList.length; index++) {
				let policy = insured.policyInfoList[index];
				// 有效期为生效日至满期日+60天
				if (policy.activeDate <= time && policy.expireDate + 60 * 24 * 60 * 60 * 1000 >= time) {
					return policy;
				}
			}
			this.$emit("showModal", 1);
			return false;
		}
	},
	watch: {
		"data.insuredIndex": function (v, ov) {
			this.typeSelected = [];

			let d = {
				insuredIndex: this.data.insuredIndex,
				amount: null,
				contactDate: "",
				// 必传资料
				HT41: null,
				HT26: null,
				// 非必传资料
				HT29: null,
				HT34: null,
				HT16: null,

				// 是否正在上传
				HT41Uploading: false,
				HT26Uploading: false,
				HT29Uploading: false,
				HT34Uploading: false,
				HT16Uploading: false,
			};
			this.$set(this, "data", d);
			if (this.checkPolicy()) {
				this.policyIllegal = false;
			} else {
				this.policyIllegal = true;
			}
		},
		"data.contactDate": function () {
			if (this.checkPolicy()) {
				this.policyIllegal = false;
			} else {
				this.policyIllegal = true;
			}
		},
		'agree': function () {
			this.showTips = false;
		}
	},
	mounted() {
		this.initData();
	},
	created() {
		try {
			this.$root.eventBus.$off("_evt_to_account_information");
		} catch (e) {}
		this.$root.eventBus.$on("_evt_to_account_information", () => {
			this.$nextTick(() => {
				console.log("ccccc:", document.getElementById("sc"));
				let sc = document.getElementById("sc");
				if (sc) {
					document.getElementById("sc").scrollIntoView();
				}
			})
		});
	}
}