rukou.js 12.5 KB
Newer Older
1
define(['zepto', 'medtap','mui'], function($, medtap,mui) {
hanpeng committed
2
	var main = {
hanpeng committed
3
		orderSn: medtap.getRequest('orderSn'),
hanpeng committed
4
		userId: '',
hanpeng committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
		relationId: '',
		doctorId: '',
		doctorName: '',
		doctorProfile: '',
		helperName: '',
		helperProfile: '',
		userName: '',
		userProfile: '',
		hasMore: false,
		limit: 50,
		offset: 1,
		minId: 0,
		maxId: 0,
		init: function() {
			main.getOrderDetail();
			main.bindEve();
hanpeng committed
21 22
				var getTalk = setInterval(function() {
					main.getTalkRecord();
hanpeng committed
23 24 25 26 27
					if(document.documentElement.scrollHeight > document.documentElement.clientHeight){
						setTimeout(function(){
							document.documentElement.scrollTop = document.documentElement.scrollHeight;
						})
					}
hanpeng committed
28
				}, 5000)
hanpeng committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42
				$('input').on('focus',function(){
					clearInterval(getTalk);
				});
				$('input').on('blur',function(){
					var getTalk = setInterval(function() {
						main.getTalkRecord();
						if(document.documentElement.scrollHeight > document.documentElement.clientHeight){
						setTimeout(function(){
							document.documentElement.scrollTop = document.documentElement.scrollHeight;
						})
					}
					}, 5000)
				});

hanpeng committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
		},
		bindEve: function() {
			$('.close_info_btn').unbind().bind('click', function() {
				$('.chat_info').hide();
				$(this).hide();
				$('.open_info_btn').show();
			});

			$('.open_info_btn').unbind().bind('click', function() {
				$('.chat_info').show();
				$(this).hide();
				$('.close_info_btn').show();
			});

			$('.send').unbind().bind('click', function() {
				if (!$('#sendMsg').val()) {
					medtap.winPop('消息不能为空')
				} else {
					main.sendMsg();
				}
63
			});
hanpeng committed
64

65
			//接受订单
hanpeng committed
66 67

			$('.accept_btn').unbind().bind('click', function() {
68 69
				main.acceptOrder();
			})
hanpeng committed
70

71
			//取消订单
hanpeng committed
72
			$('.refer_btn').unbind().bind('click', function() {
73
				main.rejectOrder();
hanpeng committed
74
			});
75
			$('.close_consult').unbind().bind('click', function() {
76 77 78
				mui.confirm('确认已给出明确建议,结束本次咨询?','结束提醒',['取消','结束'],function(e){
					if(e.index=='1'){
						$('.footer_tip').hide()
79
						$('.footer').hide()
80 81 82 83 84 85
						main.finishOrder()
						// console.log('确认了')
					}else if(e.index=='0'){
						// console.log('取消了')
					}
				})
86
			});
hanpeng committed
87 88 89
		},
		getOrderDetail: function() {
			$.ajax({
90
				url: 'https://gateway.medtap.cn/trade/order/getOrderByOrderSn',
hanpeng committed
91 92 93 94 95 96
				type: 'get',
				headers: medtap.getHeaders(),
				data: {
					orderSn: main.orderSn
				},
				success: function(res) {
97
					
hanpeng committed
98 99 100 101
					if (res.success == true) {
						var detail = res.content.order;
						$('.user_age').html(detail.imageConsultOrder.age + '岁' + ' ' + detail.imageConsultOrder.diseaseDiagnosisDesc)
						main.talkRelation(detail.clientId);
hanpeng committed
102
						var imgConsultDetail = detail.imageConsultOrder; //图文咨询详情
zujiaozhang committed
103
						if(imgConsultDetail.serviceStatus.key=='3'){
104 105 106
							$('.footer_tip').show()
						}else{
							$('.footer_tip').hide()
107
							$('.footer').hide()
108
						}
hanpeng committed
109 110 111 112 113 114 115
						main.userId = imgConsultDetail.clientId;
						$('.patient_name').html(imgConsultDetail.patientName + ' (' + (imgConsultDetail.sex == 'M' ? '男 ' : '女 ') +
							imgConsultDetail.age + '岁' + ' ' + (imgConsultDetail.hasOwnProperty('areaItem') ? imgConsultDetail.areaItem
								.fullName : '') + ')');
						$('.user_age').html((imgConsultDetail.sex == 'M' ? '男 ' : '女 ') +
							imgConsultDetail.age + '岁' + ' ' + (imgConsultDetail.hasOwnProperty('areaItem') ? imgConsultDetail.areaItem
								.fullName : ''))
116
						$('.patient_disease').html(imgConsultDetail.diseaseDiagnosisDesc);
hanpeng committed
117
						$('.patient_disease_type').html(imgConsultDetail.pathologyTypeDesc);
118 119
						$('.disease_area').val(imgConsultDetail.describe);
						var str = '';
hanpeng committed
120 121
						if (imgConsultDetail.hasOwnProperty('describePic')) {
							for (var i = 0; i < imgConsultDetail.describePic.length; i++) {
122 123
								str += '<img src="' + imgConsultDetail.describePic[i] + '" >'
							}
hanpeng committed
124 125

						} else {
126 127 128
							str = '';
						}
						$('.content_item_imgList').html(str);
hanpeng committed
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
						$('.content_item_imgList img').unbind().bind('click', function() {
							var imgObject = {};
							var imgSelect = $(this).index();
							var imgIndex = 0;
							var urls = [],
								picUrl = "";
							[].forEach.call($('.content_item_imgList img'),function(item,index){
								if($(item).index() == imgSelect){
									imgIndex = index;
								}
								urls.push($(item).attr('src'));
							})
							imgObject.imgList = urls;
							imgObject.imgIndex = imgIndex;
							try {
								if (!WebAPI) {
							
								}
								try {
									WebAPI.showImages(imgObject);
								} catch (e) {
							
								}
							} catch (e) {
							
							}
						})
156
						$('.help_area').val(imgConsultDetail.expectationHelp || '');
hanpeng committed
157

158
						//订单状态判断
hanpeng committed
159
						/* if (detail.status == 0) {
hanpeng committed
160 161

						} else if (detail.status.key == 1) {
hanpeng committed
162 163 164 165 166
							
						} else if (detail.status.key == 3) {
							$('.footer_btn').hide();
							$('.footer').hide();
						} */
zujiaozhang committed
167
						
hanpeng committed
168 169 170 171
						if (imgConsultDetail.serviceStatus.key == 2) {
							$('.footer_btn').show();
							$('.footer').hide();
						} else if (imgConsultDetail.serviceStatus.key == 10) {
hanpeng committed
172 173
							$('.footer_btn').hide();
							$('.footer').hide();
hanpeng committed
174 175 176 177 178 179 180
							main.getTalkRecord(imgConsultDetail.clientId);
							main.getPmdOrderInfo(imgConsultDetail.clientId);
						} else {
							$('.footer_btn').hide();
							$('.footer').show();
							main.getTalkRecord(imgConsultDetail.clientId);
							main.getPmdOrderInfo(imgConsultDetail.clientId);
181
						}
hanpeng committed
182
						var userId = res.content.order.clientId;
hanpeng committed
183
						$('.go_emr').unbind().bind('click', function() {
hanpeng committed
184
							medtap.pushNewWindow('../patientInfoByOrder/myEMR.html?userId=' + userId)
hanpeng committed
185 186 187 188 189 190 191 192
						})
					}
				}
			})
		},
		getPmdOrderInfo: function() {
			medtap.jzz(1);
			$.ajax({
193
				url: 'https://gateway.medtap.cn/trade/pmdConsultOrder/listValidOrder',
hanpeng committed
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
				type: 'post',
				contentType: "application/json",
				async: false,
				headers: medtap.getHeaders(),
				data: JSON.stringify({
					clientId: parseInt(main.userId),
					clientType: 'USER'
				}),
				success: function(res) {
					medtap.jzz(0);
					if (res.success == true) {
						var pmdOrderList = res.content.list;
						if (pmdOrderList.length == 0) {
							$('.service_btn').addClass('service_none');
						} else {
							if (pmdOrderList[0].serviceStatus == 3) {
								$('.pmd').html('私人医生(服务中)');
								$('.img_consult').html('图文咨询(不限次)');
								$('.consult').html('电话咨询(' + pmdOrderList[0].consultCount + ')次')
							}
							//$('.pmd')
						}
hanpeng committed
216 217 218 219 220 221 222 223
					}
				}
			})
		},
		//初始化聊天
		talkRelation: function(userId) {
			medtap.jzz(1);
			$.ajax({
224
				url: 'https://gateway.medtap.cn/operation/talk/talkRelation',
hanpeng committed
225 226 227 228 229
				type: 'post',
				async: false,
				contentType: 'application/json',
				headers: medtap.getHeaders(),
				data: JSON.stringify({
hanpeng committed
230
					userId: userId,
hanpeng committed
231
					orderSn: main.orderSn
hanpeng committed
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
				}),
				success: function(res) {
					medtap.jzz(0);
					if (res.success == true) {
						main.relationId = res.content.talkRealtion.id;
						main.doctorId = res.content.talkRealtion.doctorId;
						main.doctorName = res.content.talkRealtion.doctorName;
						main.doctorProfile = res.content.talkRealtion.doctorProfile;
						main.userName = res.content.talkRealtion.username;
						main.userProfile = res.content.talkRealtion.userProfile;
						main.helperName = res.content.talkRealtion.helperName;
						main.helperProfile = res.content.talkRealtion.helperProfile;
						$('.user_profile').attr('src', res.content.talkRealtion.userProfile);
						$('.user_name').html(res.content.talkRealtion.username);
						document.title = res.content.talkRealtion.username;
						main.relationId = res.content.talkRealtion.id;
					}
				}
			})
		},
		//获取消息列表
		getTalkRecord: function() {
			medtap.jzz(1);
			$.ajax({
256
				url: 'https://gateway.medtap.cn/operation/talk/talkRecord',
hanpeng committed
257 258 259 260 261 262 263 264 265 266
				type: 'get',
				async: false,
				headers: medtap.getHeaders(),
				data: {
					offset: main.offset,
					limit: 50,
					relationId: main.relationId,
					orderSn: main.orderSn,
				},
				success: function(res) {
267
					console.log(res)
hanpeng committed
268 269 270 271 272
					medtap.jzz(0);
					var record = res.content.list;
					var html = '';
					if (record.length == 0) {
						main.hasMore = false;
hanpeng committed
273
						//medtap.winPop('没有更多了')
hanpeng committed
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
					} else {
						main.hasMore = true;
						main.minId = record[0].id;
						main.maxId = record[record.length - 1].id;
						//console.log(chat.minId + ':' + chat.maxId)
						for (var i = 0; i < record.length; i++) {
							var type = record[i].contentType;
							if (type == 0) {
								if (record[i].senderId == main.doctorId) {
									html += '<div class="chat_item chat_item_right">' +
										'<p class="message_time">' + record[i].createTime.substring(5, 16) + '</p>' +
										'<div class="chat_info_warp clearfix">' +
										'<img src="' + main.doctorProfile + '" class="chat_profile send_profile">' +
										'<div class="chat_message_warp">' +
										'<div class="chat_message chat_message_send">' +
										record[i].content +
										'</div>' +
										'</div>' +
										'</div>' +
										'</div>';
								} else if (record[i].senderId == main.userId) {
									html += '<div class="chat_item chat_item_left">' +
										'<p class="message_time">' + record[i].createTime.substring(5, 16) + '</p>' +
										'<div class="chat_info_warp clearfix">' +
										'<img src="' + main.userProfile + '" class="chat_profile from_profile">' +
										'<div class="chat_message_warp">' +
										/* '<p class="chat_from_name">' + chat.doctorName + '医生</p>' + */
										'<div class="chat_message chat_message_from">' +
										record[i].content +
										'</div>' +
										'</div>' +
										'</div>' +
										'</div>';
								}
hanpeng committed
308 309 310 311
							} else if (record[i].contentType == 3) {
								var content = record[i].content;
								content.replace(/\n/g, "<br>");
								html += '<p class="system_msg">' + content.replace(/\n/g, "<br>") + '</p>'
hanpeng committed
312 313 314 315 316
							}
						}
					}
					if (main.offset == 1) {
						$('.chat_list').html(html);
hanpeng committed
317 318 319 320 321
						if (document.documentElement.scrollHeight > document.documentElement.clientHeight) {
							setTimeout(function() {
								document.documentElement.scrollTop = document.documentElement.scrollHeight;
							})
						}
hanpeng committed
322 323
					} else {
						$('.chat_list').prepend(html);
hanpeng committed
324 325 326 327 328
						if (document.documentElement.scrollHeight > document.documentElement.clientHeight) {
							setTimeout(function() {
								document.documentElement.scrollTop = document.documentElement.scrollHeight;
							})
						};
hanpeng committed
329 330 331 332 333 334 335
					}
				}
			})
		},
		sendMsg: function() {
			medtap.jzz(1);
			$.ajax({
336
				url: 'https://gateway.medtap.cn/operation/talk/talk',
hanpeng committed
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
				type: 'post',
				async: false,
				headers: medtap.getHeaders(),
				contentType: 'application/json',
				data: JSON.stringify({
					contentType: 0,
					content: $('#sendMsg').val(),
					orderSn: main.orderSn,
					relationId: main.relationId
				}),
				success: function(res) {
					medtap.jzz(0);
					if (res.success == true) {
						//window.location.reload();
						main.getTalkRecord();
						window.scrollTo(0, document.documentElement.clientHeight);
						$('#sendMsg').val('')
hanpeng committed
354
					} else {
hanpeng committed
355
						medtap.winPop(res.resultDesc)
hanpeng committed
356 357 358 359
					}
				}
			})
		},
360
		//接受订单
hanpeng committed
361
		acceptOrder: function() {
362 363
			medtap.jzz(1);
			$.ajax({
364
				url: 'https://gateway.medtap.cn/trade/imageConsultOrder/affirmOrder/ACCEPT',
hanpeng committed
365
				type: 'post',
366 367 368
				async: false,
				headers: medtap.getHeaders(),
				contentType: 'application/json',
hanpeng committed
369 370
				data: JSON.stringify({
					orderSn: main.orderSn
371
				}),
hanpeng committed
372
				success: function(res) {
373
					medtap.jzz(0);
hanpeng committed
374
					if (res.success == true) {
375
						medtap.winPop('已接受订单');
hanpeng committed
376
						setTimeout(function() {
377 378 379 380 381 382
							window.location.reload();
						}, 2000);
					}
				}
			})
		},
hanpeng committed
383
		rejectOrder: function() {
384 385
			medtap.jzz(1);
			$.ajax({
386
				url: 'https://gateway.medtap.cn/trade/imageConsultOrder/affirmOrder/REJECT',
hanpeng committed
387
				type: 'post',
388 389 390
				async: false,
				headers: medtap.getHeaders(),
				contentType: 'application/json',
hanpeng committed
391 392
				data: JSON.stringify({
					orderSn: main.orderSn
393
				}),
hanpeng committed
394
				success: function(res) {
395
					medtap.jzz(0);
hanpeng committed
396
					if (res.success == true) {
397
						medtap.winPop('已取消订单');
hanpeng committed
398
						setTimeout(function() {
399 400 401 402 403
							window.location.reload();
						}, 2000);
					}
				}
			})
404 405 406
		},
		// 完成订单
		finishOrder:function(){
407
			medtap.jzz(1);
408
			$.ajax({
409
				url: 'https://gateway.medtap.cn/trade/order/completeOrder',
410 411 412 413
				type: 'post',
				async: false,
				headers: medtap.getHeaders(),
				contentType: 'application/json',
414
				data: JSON.stringify({
415 416 417
					orderSn: main.orderSn
				}),
				success: function(res) {
418
					medtap.jzz(0);
419 420
				}
			})
421
		}
hanpeng committed
422 423
	}
	main.init();
hanpeng committed
424
})