clarms-plugins-material.js 8.5 KB
import { mapState } from "vuex";
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';

import { ddMMyyyy2yyyyMMdd } from '@utils/utils.js';

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,
			// 1、选择类型;2、时间选择
			modelType: "1"
		}
	},
	components: {
		DatePicker,
		ClarmsUpload
	},
	computed: {
		...mapState({
			userInfo: state => state.userInfo
		}),
		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;

			// console.log("b1:",b1);
			// console.log("b2:",b2);
			// console.log("b3:",b3);
			// console.log("b4:",b4);
			// console.log("b5:",b5);
			// console.log("b6:",b6);
			// console.log("b7:",b7);
			// console.log("b8:",b8);
			// console.log("b9:",b9);
			// console.log("b10:",b10);

			return b1 || b2 || b3 || b4 || b5 || b6 || b7 || b8 || b9 || b10;
		},
		isLogin() {
			if (this.userInfo && this.userInfo.name) {
				return true;
			}
			return false;
		}
	},
	methods: {
		initData() {
			// console.log("this.insuredList = ", this.insuredList);
		},
		datePickCompleteHandler(){
			console.log("datePickCompleteHandler");
		},
		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,
				accidentTime: ddMMyyyy2yyyyMMdd(this.data.contactDate),
				applyReasonList: this.typeSelected.join(","),
				treatmentAmount: this.data.amount,
				imageList: imageList
			}
			httpPost({
				url: api.clarmsRegisterCase,
				data: params
			}).then(res => {
				this.$emit("showModal", { action: 2, type: 1 });
				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) {
				// action1为错误提示,type标记为类型,1是选择类型;2是时间范围
				this.$emit("showModal", { action: 1, type: 1 });
				return false;
			}
			// console.log("insured === ", insured);
			var time = new Date(ddMMyyyy2yyyyMMdd(this.data.contactDate).replace(/\-/g, "/") + " 00:00:00").getTime();
			// 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;
				}
			}
			// 2标记为时间
			this.$emit("showModal", { action: 1, type: 2 });
			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();
				}
			})
		});
	}
}