createTreatmentInfo.js 15.4 KB
Newer Older
1 2 3 4 5 6
define(['zepto', 'medtap'], function($, medtap) {
	var treatment = {
		pointList: '',
		localIds: [],
		serverId: "",
		imgList: [],
hanpeng committed
7 8 9
		treatmentList: '',
		treatmentHistory: '',
		emrId: medtap.getRequest('emrId'),
10 11 12
		init: function() {
			treatment.bindEve();
			treatment.getWechatTicket();
hanpeng committed
13
			treatment.getEmrInfo();
14 15
		},
		bindEve: function() {
hanpeng committed
16
			$('.next').on('click', function() {
17
				treatment.postData();
hanpeng committed
18 19 20 21
			});

			$('.pre').unbind().bind('click', function() {
				window.history.go(-1)
22
			})
hanpeng committed
23

24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
			$('#hasPoint').on('click', function() {
				$('.select_btn_warp').show();
				$('.content_mod').show();

				$('.select_item').on('click', function() {
					$(this).children('img').attr('src', '../images/pop_select_active@2x.png');
					$(this).siblings('.select_item').children('img').attr('src', '../images/pop_select_default@2x.png');
					$(this).attr('data-select', 'yes');
					$(this).siblings('.select_item').attr('data-select', 'no');
					if ($('.yes').attr('data-select') == 'yes') {
						$('.select_btn_list .select_btn_item').removeAttr('disabled');
						$('.select_btn_list .select_btn_item').removeClass('dis');

					} else if ($('.no').attr('data-select') == 'yes') {
						$('.select_btn_list .select_btn_item').addClass('dis');
						$('.select_btn_list .select_btn_item').removeClass('selectOn');
						$('.select_btn_list .select_btn_item').attr('disabled', 'disabled');
					}
				})
				$('.select_btn_list .select_btn_item').unbind().bind('click', function() {

					if ($('.yes').attr('data-select') == 'yes') {
						$(this).toggleClass('selectOn');

					} else if ($('.no').attr('data-select') == 'yes') {

					}
				})

			});
			$('.content_mod').on('click', function() {
				$('.select_btn_warp').hide();
				$('.content_mod').hide();
			});
			$('.select_btn_confirm').on('click', function() {
				treatment.pointList = '';
				$('.select_btn_warp').hide();
				$('.content_mod').hide();
				var str = [];
				var str2 = [];
				if ($('.yes').attr('data-select') == 'yes') {
					$('.select_btn_list .select_btn_item').each(function(index, el) {
						var selectValue = $(this).attr('sendkey');
						var showText = $(this).text()
						if ($(this).hasClass('selectOn')) {
							str.push(selectValue);
							str2.push(showText);
							str2.join(',');
							treatment.pointList = str.join(',');
						} else {

						}
					});
				} else if ($('.no').attr('data-select') == 'yes') {

				}

				if (str.length == 0) {
hanpeng committed
82
					$('.hasPoint').text('无').css('color', '#000');
83
				} else {
hanpeng committed
84
					$('.hasPoint').text(str2).css('color', '#000');
85 86 87 88 89 90
				}

			});

			$('.treatWay_btn').unbind().bind('click', function() {
				$('#content').hide();
hanpeng committed
91
				$('.hasPre').hide();
92 93 94 95 96
				$('.content_2').show();
			})

			$('#treat_confirm').unbind().bind('click', function() {
				var str = '';
hanpeng committed
97
				if ($('.content_2 .has').hasClass('select')) {
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
					var str1 = []
					var str2 = [];
					var str3 = [];
					var str4 = [];
					$('.content_2 .common_btn .btn_icon').each(function(index, el) {
						var selectValue = $(this).siblings('.btn_name').attr('sendkey');
						var showText = $(this).siblings('.btn_name').text();
						if ($(this).hasClass('btnSelect')) {
							str1.push(selectValue);
							str1.join(',');
							str3.push(showText);
							str3.join(',');
						} else {
							//str1 = [];
						}
					});
hanpeng committed
114
					$('.content_2 .common_btn .more_way_btn').each(function(index, el) {
115 116
						var selectValue = $(this).attr('sendkey');
						var showText = $(this).text();
hanpeng committed
117
						if ($(this).hasClass('btnOn')) {
118 119 120 121
							str2.push(selectValue);
							str2.join(',');
							str4.push(showText);
							str4.join(',');
hanpeng committed
122
						} else {
123 124 125
							//str2 = []
						}
					});
hanpeng committed
126
					treatment.treatmentList = str1 + ',' + str2;
hanpeng committed
127
					console.log(treatment.treatmentList)
128
					str = str3 + ',' + str4;
hanpeng committed
129
				} else {
130 131 132
					treatment.treatmentList = '';
				}
				/* $('.treating').text(str.slice(0,str.length-1)).css('color','#333') */
hanpeng committed
133 134 135 136
				if (str == '') {
					$('.treating').text('无').css('color', '#333');
				} else {
					$('.treating').text(str.slice(0, str.length - 1)).css('color', '#333')
137 138 139
				}
				$('.content_2').hide();
				$('#content').show();
hanpeng committed
140
				$('.hasPre').show();
141 142 143 144
			});

			$('.add_btn').unbind().bind('click', function() {
				$('#content').hide();
hanpeng committed
145
				$('.hasPre').hide();
146 147 148 149
				$('.content_3').show();
			});
			$('#treat_confirm_history').unbind().bind('click', function() {
				var str = '';
hanpeng committed
150
				if ($('.content_3 .has').hasClass('select')) {
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
					var str1 = []
					var str2 = [];
					var str3 = [];
					var str4 = [];
					$('.content_3 .common_btn .btn_icon').each(function(index, el) {
						var selectValue = $(this).siblings('.btn_name').attr('sendkey');
						var showText = $(this).siblings('.btn_name').text();
						if ($(this).hasClass('btnSelect')) {
							str1.push(selectValue);
							str1.join(',');
							str3.push(showText);
							str3.join(',');
						} else {
							//str1 = [];
						}
					});
hanpeng committed
167
					$('.content_3 .common_btn .more_way_btn').each(function(index, el) {
168 169
						var selectValue = $(this).attr('sendkey');
						var showText = $(this).text();
hanpeng committed
170
						if ($(this).hasClass('btnOn')) {
171 172 173 174
							str2.push(selectValue);
							str2.join(',');
							str4.push(showText);
							str4.join(',');
hanpeng committed
175
						} else {
176 177 178
							//str2 = []
						}
					});
hanpeng committed
179
					treatment.treatmentHistory = str1 + ',' + str2;
180
					str = str3 + ',' + str4;
hanpeng committed
181
				} else {
182 183
					treatment.treatmentHistory = '';
				}
hanpeng committed
184
				if (str == '') {
185
					$('.treated').text('无')
hanpeng committed
186 187
				} else {
					$('.treated').text(str.slice(0, str.length - 1));
188 189 190
				}
				$('.content_3').hide();
				$('#content').show();
hanpeng committed
191
				$('.hasPre').show();
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
			});

			//content_2事件定义
			$('.content_2 .select_item').unbind().bind('click', function() {
				$(this).addClass('select');
				$(this).siblings('.select_item').removeClass('select');

				if ($(this).hasClass('has')) {
					$('.content_2 .common_btn').show();
				} else if ($(this).hasClass('no')) {
					$('.content_2 .common_btn').hide();
				}
			});

			$('.content_2 .btn_icon').unbind().bind('click', function() {
				$(this).toggleClass('btnSelect');
				if ($(this).hasClass('btnSelect')) {
					$(this).attr('select', 'yes')
				} else {
					$(this).attr('select', 'no')
				}
			});

			$('.content_2 .more_way_btn').unbind().bind('click', function() {
				$(this).toggleClass('btnOn');
				if ($(this).hasClass('btnOn')) {
					$(this).attr('select', 'yes')
				} else {
					$(this).attr('select', 'no')
				}
			});

			//content_3事件定义
			$('.content_3 .select_item').unbind().bind('click', function() {
				$(this).addClass('select');
				$(this).siblings('.select_item').removeClass('select');

				if ($(this).hasClass('has')) {
					$('.content_3 .common_btn').show();
				} else if ($(this).hasClass('no')) {
					$('.content_3 .common_btn').hide();
				}
			});

			$('.content_3 .btn_icon').unbind().bind('click', function() {
				$(this).toggleClass('btnSelect');
				if ($(this).hasClass('btnSelect')) {
					$(this).attr('select', 'yes')
				} else {
					$(this).attr('select', 'no')
				}
			});

			$('.content_3 .more_way_btn').unbind().bind('click', function() {
				$(this).toggleClass('btnOn');
				if ($(this).hasClass('btnOn')) {
					$(this).attr('select', 'yes')
				} else {
					$(this).attr('select', 'no')
				}
			});
		},
		//获取微信票据
		getWechatTicket: function() {
			medtap.submitAjax({
				url: 'https://testdevgw.medtap.cn/wechat/lung/fetchWechatTicket',
				type: 'GET',
				async: false,
				data: {
					url: window.location.href
				},
				success: function(res) {
					var data = res.content;
					wx.config({
						debug: false,
						appId: data.appId, // 必填,公众号的唯一标识
						timestamp: data.timestamp, // 必填,生成签名的时间戳
						nonceStr: data.nonceStr, // 必填,生成签名的随机串
						signature: data.signature, // 必填,签名,见附录1
						jsApiList: [
							'chooseImage',
							'previewImage',
							'uploadImage'
						]
					})
				}
			})
		}, //选择图片
		choseImage: function() {
			$('#upload').on('click', function() {
				var html = '';
				wx.ready(function() {
					var syncUpload = function(localIds) {
						localId = localIds[0];
						localIds = localIds.length > 1 ? localIds.slice(1) : localIds[0];
						wx.uploadImage({
							localId: localId,
							isShowProgressTips: 1,
							success: function(res) {
								var serverId = res.serverId; // 返回图片的服务器端ID
								//其他对serverId做处理的代码
								treatment.upLoadImg(serverId, localId);
								if (localIds.length > 0) {
									syncUpload(localIds);
								}
							}
						});
					};
					wx.chooseImage({
						count: 9,
						sizeType: ['original', 'compressed'],
						sourceType: ['album', 'camera'],
						success: function(res) {
							treatment.localIds = res.localIds;
							//所有需要上传到图片预览
							syncUpload(treatment.localIds);
						}
					})
				})
			})
		},
		//图片预览
		previewImage: function() {
			$('#ImgUp').on('click', '.image_files_img', function() {
				var imgArray = [];
				var curImageSrc = $(this).attr('src');
				if (curImageSrc) {
					$('#ImgUp .image_files_img').each(function(index, el) {
						var itemSrc = $(this).attr('src');
						imgArray.push(itemSrc);
					});
					wx.previewImage({
						current: curImageSrc,
						urls: imgArray
					});
				}
			});
			$('#ImgUp').on('click', '.image_del', function() {
				if (confirm('确定要删除图片吗?')) {
					$(this).parent().remove();
				}
			});
		},
		//上传图片
		upLoadImg: function(serverId, localId) {
			$.ajax({
				url: 'https://testdevgw.medtap.cn/common/uploadWechatFile',
				type: 'POST',
				async: false,
hanpeng committed
341 342 343
				headers: {
					'apptype': 'wechat_lung',
					'user-os': 'wechat'
hanpeng committed
344
				},
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
				data: {
					bizType: "3",
					folder: 'patientInfo',
					mediaId: serverId,
					ext: 'jpg'
				},
				success: function(data) {
					if (data.success == true) {
						var res = data.content;
						var imgKey = res.ossKey;
						treatment.imgList.push(imgKey);
						var html = '<div class="image_files_item">' +
							'<img src="' + localId + '" class="image_files_img" imgkey="' + imgKey + '">' +
							'<img src="../images/post_delete_btn@2x.png" class="image_del" >' +
							'</div>';
						$('#ImgUp').append(html);
					}
				}

			})
		},
		postData: function() {
			var urls = [],
				picUrl = "";
			[].forEach.call($('#ImgUp .image_files_img'), function(item) {
				urls.push($(item).attr('imgkey'));
			});
			var picUrl = urls.join(',');
			var pointList = ''
hanpeng committed
374
			if ($('.hasPoint').text() == '请选择' || $('.hasPoint').text() == '') {
375
				pointList = '';
hanpeng committed
376
			} else {
377 378 379 380 381 382 383 384
				pointList = $('.hasPoint').text();
			}
			medtap.loading(1);
			medtap.submitAjax({
				url: 'https://testdevgw.medtap.cn/user/patientEMR/createPatientEMR',
				type: 'post',
				contentType: 'application/json',
				data: {
hanpeng committed
385
					targetedMutations: treatment.pointList,
hanpeng committed
386 387
					acceptingCure: treatment.treatmentList, //当前正在接受的治疗
					acceptedCure: treatment.treatmentHistory, //既往接受过的治疗
388
					curePic: picUrl, //选择的图片
hanpeng committed
389 390
					infoStep: 2,
					emrId: treatment.emrId
391 392 393 394 395 396 397 398 399 400
				},
				success: function(res) {
					medtap.loading(0);
					if (res.success == true) {
						setTimeout(function() {
							medtap.toast({
								message: '保存成功',
								time: 1500
							});
							setTimeout(function() {
hanpeng committed
401
								window.location.replace('myEMR.html'); //跳转至医生主页
402 403 404 405 406
							}, 1500)
						}, 2000)
					}
				}
			})
hanpeng committed
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
		},
		getEmrInfo: function() {
			medtap.loading(1);
			medtap.submitAjax({
				url: 'https://testdevgw.medtap.cn/user/patientEMR/getPatientEMRInfo',
				type: 'post',
				async: false,
				contentType: 'application/json',
				data: {

				},
				success: function(res) {
					medtap.loading(0);
					//var emrInfo = res.content.emr;
					if (res.success == true) {
						var emrInfo = res.content.emr;
						//$('.hasPoint').text()
						if (emrInfo.hasOwnProperty('targetedMutationsItem')) {
							var str = [];
hanpeng committed
426
							var str2 = [];
hanpeng committed
427 428
							for (var i = 0; i < emrInfo.targetedMutationsItem.length; i++) {
								str.push(emrInfo.targetedMutationsItem[i].value);
hanpeng committed
429 430 431 432 433 434 435
								$('.select_btn_list .select_btn_item').each(function(index, el) {
									var selectValue = $(this).attr('sendkey');
									if(emrInfo.targetedMutationsItem[i].child == selectValue){
										$(this).addClass('selectOn');
										str2.push(emrInfo.targetedMutationsItem[i].child);
									}
								});
hanpeng committed
436 437
							}
							str.join(',');
hanpeng committed
438 439
							treatment.pointList = str2.join(',');
							console.log(treatment.pointList)
hanpeng committed
440 441 442
							$('.hasPoint').text(str).css('color','#000');
						}else{
							$('.hasPoint').text('无').css('color','#000');
hanpeng committed
443
							treatment.pointList = '';
hanpeng committed
444 445 446
						}
						if(emrInfo.hasOwnProperty('acceptingCureItem')){
							var str = [];
hanpeng committed
447 448
							var str2 = [];
							var str3 = [];
hanpeng committed
449 450
							for(var i = 0; i < emrInfo.acceptingCureItem.length;i++){
								str.push(emrInfo.acceptingCureItem[i].value);
hanpeng committed
451 452 453 454 455 456 457 458 459 460 461 462 463 464
								$('.content_2 .common_btn .btn_icon').each(function(index, el) {
									var selectValue = $(this).siblings('.btn_name').attr('sendkey');
									if(emrInfo.acceptingCureItem[i].child == selectValue){
										str2.push(emrInfo.acceptingCureItem[i].child);
										$(this).addClass('btnSelect');
									}
								});
								$('.content_2 .common_btn .more_way_btn').each(function(index, el) {
									var selectValue = $(this).attr('sendkey');
									if(emrInfo.acceptingCureItem[i].child == selectValue){
										str3.push(emrInfo.acceptingCureItem[i].child);
										$(this).addClass('btnOn')
									}
								});
hanpeng committed
465 466
							}
							str.join(',');
hanpeng committed
467
							treatment.treatmentList = str2 + ',' + str3;
hanpeng committed
468 469 470
							$('.treating').text(str).css('color','#000');
						}else{
							$('.treating').text('无').css('color','#000');
hanpeng committed
471
							treatment.treatmentList = ''
hanpeng committed
472 473 474
						}
						if(emrInfo.hasOwnProperty('acceptedCureItem')){
							var str = [];
hanpeng committed
475 476
							var str2 = [];
							var str3 = [];
hanpeng committed
477 478
							for(var i = 0; i < emrInfo.acceptedCureItem.length;i++){
								str.push(emrInfo.acceptedCureItem[i].value);
hanpeng committed
479 480 481 482 483 484 485 486 487 488 489 490 491 492
								$('.content_3 .common_btn .btn_icon').each(function(index, el) {
									var selectValue = $(this).siblings('.btn_name').attr('sendkey');
									if(emrInfo.acceptedCureItem[i].child == selectValue){
										str2.push(emrInfo.acceptedCureItem[i].child);
										$(this).addClass('btnSelect');
									}
								});
								$('.content_3 .common_btn .more_way_btn').each(function(index, el) {
									var selectValue = $(this).attr('sendkey');
									if(emrInfo.acceptedCureItem[i].child == selectValue){
										str3.push(emrInfo.acceptedCureItem[i].child);
										$(this).addClass('btnOn')
									}
								});
hanpeng committed
493 494
							}
							str.join(',');
hanpeng committed
495 496
							treatment.treatmentHistory = str2 + ',' + str3;
							console.log(treatment.treatmentHistory);
hanpeng committed
497 498 499
							$('.treated').text(str).css('color','#000');
						}else{
							$('.treated').text('无').css('color','#000');
hanpeng committed
500
							treatment.treatmentHistory = '';
hanpeng committed
501 502 503 504
						}
						if(emrInfo.curePicList == ''){
								
						}else{
hanpeng committed
505 506 507 508 509 510 511 512
							var html = '';
							for(var i = 0;i < emrInfo.curePicList.length;i++){
								html += '<div class="image_files_item">' +
											'<img src="' + emrInfo.curePicList[i] + '" class="image_files_img" imgkey="'+ emrInfo.curePicList[i] +'">' +
											'<img src="../images/post_delete_btn@2x.png" class="image_del" >' +
										'</div>';
							}
							$('#ImgUp').append(html);
hanpeng committed
513 514 515 516
						}
					}
				}
			})
517 518 519 520 521 522
		}
	}
	treatment.init();
	treatment.choseImage();
	treatment.previewImage();
})