
var httpData=GetRequest(),
	doctorInfo = JSON.parse(window.localStorage.getItem('wlyyAgent'))

function showSuccessMessage(msg) {
	layer.msg(msg, {
		icon: 1
	})
}

function showErrorMessage(msg) {
	layer.msg(msg, {
		icon: 5
	})
}

function showWarningMessage(msg) {
	layer.msg(msg, {
		icon: 2
	})
}

function showInfoMessage(msg) {
	layer.msg(msg, {
		icon: 6
	})
}

new Vue({
    el: "#app",
    data: {
    	isLeader: null,
    	isShowList1: false,
    	isShowList2: false,
    	isShowList3: false,
    	isJudgeHealthDoctor: null,
    	isJudgeDoctor: null,
    	isJudgeExpense: null,
    	isSaveBtn: false,
    	isSaveBtn1: false,
    	isSaveBtn2: false,
    	patientInfo: null,
    	doctorTeam: null,
    	doctorList: null,
    	memberList: null,
    	dictList: null,
    	adminTeamCode: null,
    	fileList: null,
    	serverName: null
    },
    mounted: function() {
    	this.patientSign();
    	this.patientTeam();
    	this.getDictByDictName();
    	this.findPatientSignServerBySignCode()
    },
    methods: {
    	patientSign: function() {
    		var vm = this,
    			loadding = layer.load(0, {shade: false}),
    			params = {
    				code: httpData.patientCode
    			}
			signAPI.patientSign(params).then(function(res) {
				layer.close(loadding)
				if(res.status == 200) {
					vm.patientInfo = res.data
					vm.jsJudgeExpense = res.data.jtSign.expensesType
				} else {
					showErrorMessage(res.msg);
				}
			})
    	},
    	patientTeam: function() {
    		var vm = this,
    			loadding = layer.load(0, {shade: false}),
    			params = {
    				code: httpData.patientCode
    			}
			signAPI.patientTeam(params).then(function(res) {
				layer.close(loadding)
				if(res.status == 200) {
					vm.doctorTeam = res.data
					vm.isJudgeHealthDoctor = vm.doctorTeam.healthDoctorCode
					vm.isJudgeDoctor = vm.doctorTeam.doctorCode
					vm.isLeader = vm.doctorTeam.isLeader
					if(vm.isLeader) {
						vm.teamMember()
					}
				} else {
					showErrorMessage(res.msg);
				}
			})
    	},
    	getDictByDictName: function() {
    		var vm =this,
    			loadding = layer.load(0, {shade: false}),
    			params = {
    				name: "SIGN_EXPENSES"
    			}
			signAPI.getDictByDictName(params).then(function(res) {
				layer.close(loadding)
				if(res.status == 200) {
					vm.dictList = res.list
				} else {
					showErrorMessage(res.msg);
				}
			})
    	},
    	findPatientSignServerBySignCode: function() {
    		var vm =this,
    			loadding = layer.load(0, {shade: false}),
    			params = {
					signCode: httpData.signCode
    			};
			signAPI.findPatientSignServerBySignCode(params).then(function(res) {
				layer.close(loadding)
				if(res.status == 200) {
					vm.fileList = [];
					var len = res.data.length;
					if(res.data.length > 0) {
						vm.serverName = "";
						for(var i = 0; i < len; i++) {
							if(i == 0) {
								vm.serverName += res.data[i].serverTypeName
							} else {
								vm.serverName += ', ' + res.data[i].serverTypeName
							}
						}
					}
					$.each(res.data, function(i, v) {
		                if(v.serverType == 8 || v.serverType == 9 || v.serverType == 11) {
		                    vm.fileList.push(v);
		                }
		            });
				} else {
					showErrorMessage(res.msg);
				}
			})
    	},
    	teamMember: function() {
    		var vm = this,
    			loadding = layer.load(0, {shade: false}),
    			params = {
    				teamId: vm.doctorTeam.teamId
    			}
			signAPI.teamMember(params).then(function(res) {
				layer.close(loadding)
				vm.memberList = []
				vm.doctorList = []
				if(res.status == 200) {
					$.each(res.data, function(i, v) {
		                if(v.available && (v.level == 3 || v.level == 2)) {vm.memberList.push(v);}
		                if(v.available && v.level == 2) {vm.doctorList.push(v);}
		            });
				} else {
					showErrorMessage(res.msg);
				}
			})
   		},
    	selectStatus: function(num) {
    		if (num == 1) {
    			this.isShowList3 = false;
    			this.isShowList2 = false;
    			this.isShowList1 = !this.isShowList1;
    		} else if (num == 2) {
    			this.isShowList3 = false;
    			this.isShowList1 = false;
    			this.isShowList2 = !this.isShowList2;
    		} else {
    			this.isShowList1 = false;
    			this.isShowList2 = false;
    			this.isShowList3 = !this.isShowList3;
    		}
            
        },
        selectLi: function(num, data) {
        	if(num == 1) {
        		this.isShowList1 = false;
        		if(data.code == this.isJudgeDoctor) {
        			this.isSaveBtn = false
        		} else {
        			this.isSaveBtn = true
        		}
        		this.doctorTeam.doctorCode = data.code;
    			this.doctorTeam.doctorName = data.name;
        	}
        	if(num == 2) {
        		this.isShowList2 = false;
        		if(data.code == this.isJudgeHealthDoctor) {
        			this.isSaveBtn1 = false
        		} else {
        			this.isSaveBtn1 = true
        		}
        		this.doctorTeam.healthDoctorCode = data.code;
    			this.doctorTeam.healthDoctorName = data.name;
        	}
			if(num == 3) {
				this.isShowList3 = false;
				if(data.code == this.jsJudgeExpense) {
					this.isSaveBtn2 = false
				} else {
					this.isSaveBtn2 = true
				}
				this.patientInfo.jtSign.expensesType = data.code
			}
        },
        showExpensesName: function(code) {
        	var expensesName;
        	if(!this.dictList) {
        		return "请选择补贴类型";
        	}
        	for(var i = 0, len = this.dictList.length; i < len; i++) {
        		if(code == this.dictList[i].code) {
        			expensesName = this.dictList[i].value;
        		}
        	}
        	return expensesName
        },
        handleExpensesStatus: function(status) {
        	if(status == 0) return "&emsp;未缴费";
        	if(status == 1) return "&emsp;已缴费";
        	if(status == 2) return "&emsp;已退费";
        	if(!status) return "";
        },
        setPatImg: function(str) {
        	var imgStr = httpRequest.getImgUrl(str);
        	if (imgStr == "") {
        		return '../../../images/p-female.png';
        	} else {
        		return imgStr;
        	}
        },
        lookPhoto: function(data) {
        	layer.open({
        		type: 2,
        		area: ['100%', '100%'],
        		title: "凭证预览",
        		shade: 0.5,
        		shadeClose: true,
        		content: '../html/photo_show.html?serverType=' + data.serverType + '&patientCode=' + httpData.patientCode
        	})
        },
        saveChange: function() {
        	if(!this.isSaveBtn && !this.isSaveBtn1 && !this.isSaveBtn2) {
        		return false;
        	}
        	var vm = this,
    			loadding = layer.load(0, {shade: false}),
    			params = {
    				patient: httpData.patientCode
    			}
    		if(this.isSaveBtn) {
    			params.doctor = this.doctorTeam.doctorCode
    		}
    		if(this.isSaveBtn1) {
    			params.healthDoctor = this.doctorTeam.healthDoctorCode
    		}
    		if(this.isSaveBtn2) {
    			params.expensesType = this.patientInfo.jtSign.expensesType
    		}
			signAPI.saveChange(params).then(function(res) {
				layer.close(loadding)
				if(res.status == 200) {
					showSuccessMessage(res.msg);
					vm.patientSign();
					vm.patientTeam();
					vm.isSaveBtn = false
					vm.isSaveBtn1 = false
					vm.isSaveBtn2 = false
				} else {
					showErrorMessage(res.msg);
				}
			})
       	},
       	showProject: function() {
       		layer.open({
				type: 1,
				area: ['400px', '600px'],
				shade: 0.5,
				title: '个性化服务项目',
				shift: 2,
				closeBtn: 1,
				shadeClose: true, //点击遮罩关闭层
				content: '<div class="p20 pb0">'+
			'<h4><b>1、基本医疗服务</b></h4>'+
			'<div class="pb15">'+
				'<div class="pl20 pt5">'+
					'<div class="pb5">1.1 提供一般常见病、多发病、诊断明确的慢性病VIP诊疗服务（相对独立就诊服务区，每次诊疗时间不低于10分钟，个性化健康指导）。 </div>'+
				'</div>'+

			'</div>'+
			'<h4><b>2、免费提供以下基本公共卫生服务</b></h4>'+
			'<div class="pb15">'+
				'<ol class="pl20 pt5">'+
					'<div class="pb5">2.1 居民健康档案的建立和维护；</div>'+
					'<div class="pb5">2.2 健康评估、健康促进、健康干预；</div>'+
					'<div class="pb5">2.3 0~6岁儿童健康管理；</div>'+
					'<div class="pb5">2.4 孕产妇健康管理；</div>'+
					'<div class="pb5">2.5 老年人健康管理服务；</div>'+
					'<div class="pb5">2.6 预防接种服务；</div>'+
					'<div class="pb5">2.7 传染病报告和处理；</div>'+
					'<div class="pb5">2.8 高血压患者健康管理；</div>'+
					'<div class="pb5">2.9 Ⅱ型糖尿病患者健康管理；</div>'+
					'<div class="pb5">2.10 重性精神疾病患者管理；</div>'+
					'<div class="pb5">2.11 中医药健康管理。</div>'+
				'</ol>'+
			'</div>'+
			'<h4><b>3、免费提供以下个性化服务</b></h4>'+
			'<div class="pb15">'+
				'<div class="pl20 pt5">'+
					'<div class="pb5">3.1 由专科医师个性化技术指导。根据病情需求，由家庭医生预约，接受三级医院专科医师技术指导。 </div>'+
					'<div class="pb5">3.2 由“家庭医生服务团队”提供个性化健康管理、健康评估、健康咨询服务。协助签约居民参与社区自我健康管理团体活动，开展自我健康管理。利用手机APP、或微信公众号服务平台，提供便捷的健康咨询服务。</div>'+
					'<div class="pb5">3.3 上级医院专家预约服务及转诊服务。优先提供上级医院专家门诊预约（根据病情优先享受名院、名科、名医预约服务）、大型仪器设备检查预约及根据病情需要的转诊服务。</div>'+
					'<div class="pb5">3.4社区门诊预约服务。家庭医生会根据病情有针对性的为签约居民办理下次门诊预约服务。</div>'+
					'<div class="pb5">3.5为高血压、糖尿病等慢性病签约对象提供“三师共管”慢病精细化管理服务。重点为高血压、糖尿病等慢性病人提供日常随访、定期检查及全程健康管理等服务。根据病情发展及控制情况提供适时动态转库服务。病情不稳定期纳入强化管理库，由三师提供强化管理服务；病情稳定期纳入常规管理库，在专科医师指导下由全科医生团队提供常规管理服务；强化管理库及常规管理库病人依据病情实行动态流动，需转专科医师时优先及时安排。</div>'+
					'<div class="pb5">3.6为65岁以上老人提供日常随访、定期检查及全程健康管理等服务。为80岁以上老年人及失能半失能老人免费提供每年不少于一次上门出诊服务。签约老人可享受包括测血压、体格检查、用药指导、健康咨询等服务。</div>'+
				'</div>'+
			'</div>'+
			'<h4><b>4、参加厦门市基本医疗保险的本市户籍人员可享受以下医保优惠政策：</b></h4>'+
			'<div class="pb15">'+
				'<div class="pl20 pt5">'+
					'<div class="pb5">4.1 根据上级医院用药长期医嘱，向慢性病患者开具4-8周(含慢性病相关辅助用药)的门诊用药处方。</div>'+
					'<div class="pb5">4.2 在基层医疗卫生机构或医保定点门诊部就医，门诊医疗费不设起付标准，即参保职工个人医疗账户用完后直接进入社会统筹医疗基金支付段，参保居民直接进入社会统筹医疗基金支付段。</div>'+
					'<div class="pb5">4.3 住院医疗费不设二次及以上起付标准。</div>'+
				'</div>'+
			'</div>'+
			'<h4><b>5、签约对象在享受上述签约服务外，还可享受以下服务项目：</b></h4>'+
			'<div class="pb15">'+
				'<div class="pl20 pt5">'+
					'<div class="pb5">5.1 为有康复需求的康复患者免费建立康复、训练档案。提供针对性康复训练和康复治疗服务，相关服务按物价部门制定的标准收取服务费。</div>'+
					'<div class="pb5">5.2 为有需要的签约居民提供建立家庭病床、导尿、换药、上门测血糖、上门抽血检验等有偿上门服务。乙方需要甲方提供出诊等上门适宜医疗服务（不提供院外静脉输液），须先通过甲方的医学安全性评估，并签订相关免责申明。</div>'+
					'<div class="pb5">5.3优先安排彩超、肿瘤标志物检查、眼底筛查、24小时动态血压监测、糖尿病足筛查、尿微量蛋白检测等基本医疗收费项目及慢性疾病筛查服务项目。</div>'+
				'</div>'+
			'</div>'+
		'</div>',
			});
       	}
    }
})
