define(['zepto', 'medtap'], function($, medtap) {
	var detail = {
		emrId: medtap.getRequest('emrId'),
		init: function() {
			detail.bindEve();
			detail.getEmrDetail();
		},
		bindEve: function() {
			$('.tab_item').unbind().bind('click', function() {
				$(this).addClass('tabOn');
				$(this).siblings('.tab_item').removeClass('tabOn');
				if ($('.basic').hasClass('tabOn')) {
					$('.basicInfo').show();
					$('.treatwayInfo').hide();
				} else if ($('.treatway').hasClass('tabOn')) {
					$('.basicInfo').hide();
					$('.treatwayInfo').show();
				}
			})
		},
		getEmrDetail: function() {
			medtap.jzz(1);
			$.ajax({
				url: 'https://testdevgw.medtap.cn/user/patientEMR/getPatientEMRInfo',
				type: 'post',
				async: false,
				contentType: 'application/json',
				headers: medtap.getHeaders(),
				data: JSON.stringify({
					emrId: detail.emrId
				}),
				success: function(res) {
					medtap.jzz(0);
					if (res.success == true) {
						var info = res.content.emr;
						//基本信息
						var sex = '';
						var diseaseDiagnosis = '';
						$('#username').val(info.patientName);
						document.title = info.patientName;
						if (info.sex == 'M') {
							sex = '男';
						} else {
							sex = '女';
						}
						$('#sex').val(sex).attr('sendkey', info.sex);
						$('#birth').val(info.birthday);
						if (info.diseaseDiagnosis == 'lung') {
							diseaseDiagnosis = '肺癌';
							$('#disease').val(diseaseDiagnosis).attr('sendkey', 'lung');
						} else {
							diseaseDiagnosis = '其他';
							$('#disease').val(diseaseDiagnosis).attr('sendkey', ' ');
						}
						
						if(info.hasOwnProperty('pathologyTypeItem')){
							$('#pathology').val(info.pathologyTypeItem.value).attr('sendkey', info.pathologyTypeItem.child);
						}else{
							$('#pathology').val(info.pathologyTypeName);
						}
						$('#height').val(info.hasOwnProperty('height') ? info.height : '');
						$('#stages').val(info.hasOwnProperty('tumorStageItem') ? info.tumorStageItem.value : '');
						$('#stages_TNM').val(info.hasOwnProperty('tnmStage') ? info.tnmStage : '');
						$('#transfer').val(info.hasOwnProperty('transferNidusItem') ? info.transferNidusItem.value : '');
						if (info.hasOwnProperty('smokingFlg') && info.smokingFlg == true) {
							$('#somke').val(info.smokingYear + '年' + info.smokingDailyNum + '支/天');
						} else if (info.hasOwnProperty('smokingFlg') && info.smokingFlg == false) {
							$('#somke').val('无');
						}
						$('#ECOG').val(info.hasOwnProperty('ecogGradeItem') ? info.ecogGradeItem.value : '');
						$('#idCard').val(info.hasOwnProperty('patientHospitalIdNum') ? info.patientHospitalIdNum : '');
						$('#location').val(info.hasOwnProperty('areaItem') ? info.areaItem.fullName : '');
						//治疗信息
						//$('.hasPoint').text(info.hasOwnProperty('targetedMutationsItem') ? info.targetedMutationsItem.value : "");
						if (info.hasOwnProperty('targetedMutationsItem') && info.targetedMutationsItem.length != 0) {
							var strTargetedMutations = [];
							for (var i = 0; i < info.targetedMutationsItem.length; i++) {
								strTargetedMutations.push(info.targetedMutationsItem[i].value);

							}
							strTargetedMutations.join(',')
							$('.hasPoint').text(strTargetedMutations).css('color', '#333');
						} else {
							$('.hasPoint').text('无');
						}
						if (info.hasOwnProperty('acceptingCureItem') && info.acceptingCureItem.length != 0) {
							var strAccepting = [];
							for (var i = 0; i < info.acceptingCureItem.length; i++) {
								strAccepting.push(info.acceptingCureItem[i].value);
							}
							strAccepting.join(',');
							$('.treating').text(strAccepting).css('color', '#333');
						} else {
							$('.treating').text('无');
						}
						if (info.hasOwnProperty('acceptedCureItem') && info.acceptedCureItem.length != 0) {
							var strAccepted = [];
							for (var i = 0; i < info.acceptedCureItem.length; i++) {
								strAccepted.push(info.acceptedCureItem[i].value);
							}
							strAccepted.join(',');
							$('.treated').text(strAccepted);
						} else {
							$('.treated').text('无');
						}
						//图片
						/* var picUrl = */
						if (info.hasOwnProperty('curePicList') && info.curePicList.length != 0) {
							var picUrl = '';
							for (var i = 0; i < info.curePicList.length; i++) {
								picUrl += '<img src="' + info.curePicList[i] + '" >';
								'<div class="image_files_item">' +
								'<img src="' + info.curePicList[i] + '" class="image_files_img" imgkey="' + info.curePicList[i] + '">' +
									'<img src="images/post_delete_btn@2x.png" class="image_del" >' +
									'</div>';
							}
							$('#ImgUp').html(picUrl);
						}
					}
				}
			})
		}
	}
	detail.init();
})
