rukou.js 11.6 KB
Newer Older
hanpeng committed
1
define(['zepto', 'medtap'], function($, medtap) {
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

hanpeng committed
22 23
				var getTalk = setInterval(function() {
					main.getTalkRecord();
hanpeng committed
24 25 26 27 28
					if(document.documentElement.scrollHeight > document.documentElement.clientHeight){
						setTimeout(function(){
							document.documentElement.scrollTop = document.documentElement.scrollHeight;
						})
					}
hanpeng committed
29
				}, 5000)
hanpeng committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43
				$('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
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
		},
		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();
				}
64
			});
hanpeng committed
65

66
			//接受订单
hanpeng committed
67 68

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

72
			//取消订单
hanpeng committed
73
			$('.refer_btn').unbind().bind('click', function() {
74
				main.rejectOrder();
hanpeng committed
75 76 77
			});
			
			
hanpeng committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91
		},
		getOrderDetail: function() {
			$.ajax({
				url: 'https://testdevgw.medtap.cn/trade/order/getOrderByOrderSn',
				type: 'get',
				headers: medtap.getHeaders(),
				data: {
					orderSn: main.orderSn
				},
				success: function(res) {
					if (res.success == true) {
						var detail = res.content.order;
						$('.user_age').html(detail.imageConsultOrder.age + '岁' + ' ' + detail.imageConsultOrder.diseaseDiagnosisDesc)
						main.talkRelation(detail.clientId);
hanpeng committed
92 93 94 95 96 97 98 99
						var imgConsultDetail = detail.imageConsultOrder; //图文咨询详情
						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 : ''))
100
						$('.patient_disease').html(imgConsultDetail.diseaseDiagnosisDesc);
hanpeng committed
101
						$('.patient_disease_type').html(imgConsultDetail.pathologyTypeDesc);
102 103
						$('.disease_area').val(imgConsultDetail.describe);
						var str = '';
hanpeng committed
104 105
						if (imgConsultDetail.hasOwnProperty('describePic')) {
							for (var i = 0; i < imgConsultDetail.describePic.length; i++) {
106 107
								str += '<img src="' + imgConsultDetail.describePic[i] + '" >'
							}
hanpeng committed
108 109

						} else {
110 111 112
							str = '';
						}
						$('.content_item_imgList').html(str);
hanpeng committed
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
						$('.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) {
							
							}
						})
140
						$('.help_area').val(imgConsultDetail.expectationHelp || '');
hanpeng committed
141

142
						//订单状态判断
hanpeng committed
143
						/* if (detail.status == 0) {
hanpeng committed
144 145

						} else if (detail.status.key == 1) {
hanpeng committed
146 147 148 149 150 151 152 153 154
							
						} else if (detail.status.key == 3) {
							$('.footer_btn').hide();
							$('.footer').hide();
						} */
						if (imgConsultDetail.serviceStatus.key == 2) {
							$('.footer_btn').show();
							$('.footer').hide();
						} else if (imgConsultDetail.serviceStatus.key == 10) {
hanpeng committed
155 156
							$('.footer_btn').hide();
							$('.footer').hide();
hanpeng committed
157 158 159 160 161 162 163
							main.getTalkRecord(imgConsultDetail.clientId);
							main.getPmdOrderInfo(imgConsultDetail.clientId);
						} else {
							$('.footer_btn').hide();
							$('.footer').show();
							main.getTalkRecord(imgConsultDetail.clientId);
							main.getPmdOrderInfo(imgConsultDetail.clientId);
164
						}
hanpeng committed
165
						var userId = res.content.order.clientId;
hanpeng committed
166
						$('.go_emr').unbind().bind('click', function() {
hanpeng committed
167
							medtap.pushNewWindow('../patientInfoByOrder/myEMR.html?userId=' + userId)
hanpeng committed
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
						})
					}
				}
			})
		},
		getPmdOrderInfo: function() {
			medtap.jzz(1);
			$.ajax({
				url: 'https://testdevgw.medtap.cn/trade/pmdConsultOrder/listValidOrder',
				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
199 200 201 202 203 204 205 206 207 208 209 210 211 212
					}
				}
			})
		},
		//初始化聊天
		talkRelation: function(userId) {
			medtap.jzz(1);
			$.ajax({
				url: 'https://testdevgw.medtap.cn/operation/talk/talkRelation',
				type: 'post',
				async: false,
				contentType: 'application/json',
				headers: medtap.getHeaders(),
				data: JSON.stringify({
hanpeng committed
213
					userId: userId,
hanpeng committed
214
					orderSn: main.orderSn
hanpeng committed
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
				}),
				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({
				url: 'https://testdevgw.medtap.cn/operation/talk/talkRecord',
				type: 'get',
				async: false,
				headers: medtap.getHeaders(),
				data: {
					offset: main.offset,
					limit: 50,
					relationId: main.relationId,
					orderSn: main.orderSn,
				},
				success: function(res) {
					medtap.jzz(0);
					var record = res.content.list;
					var html = '';
					if (record.length == 0) {
						main.hasMore = false;
hanpeng committed
255
						//medtap.winPop('没有更多了')
hanpeng committed
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
					} 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
290 291 292 293
							} 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
294 295 296 297 298
							}
						}
					}
					if (main.offset == 1) {
						$('.chat_list').html(html);
hanpeng committed
299 300 301 302 303
						if (document.documentElement.scrollHeight > document.documentElement.clientHeight) {
							setTimeout(function() {
								document.documentElement.scrollTop = document.documentElement.scrollHeight;
							})
						}
hanpeng committed
304 305
					} else {
						$('.chat_list').prepend(html);
hanpeng committed
306 307 308 309 310
						if (document.documentElement.scrollHeight > document.documentElement.clientHeight) {
							setTimeout(function() {
								document.documentElement.scrollTop = document.documentElement.scrollHeight;
							})
						};
hanpeng committed
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
					}
				}
			})
		},
		sendMsg: function() {
			medtap.jzz(1);
			$.ajax({
				url: 'https://testdevgw.medtap.cn/operation/talk/talk',
				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
336
					} else {
hanpeng committed
337
						medtap.winPop(res.resultDesc)
hanpeng committed
338 339 340 341
					}
				}
			})
		},
342
		//接受订单
hanpeng committed
343
		acceptOrder: function() {
344 345
			medtap.jzz(1);
			$.ajax({
hanpeng committed
346
				url: 'https://testdevgw.medtap.cn/trade/imageConsultOrder/affirmOrder/ACCEPT',
hanpeng committed
347
				type: 'post',
348 349 350
				async: false,
				headers: medtap.getHeaders(),
				contentType: 'application/json',
hanpeng committed
351 352
				data: JSON.stringify({
					orderSn: main.orderSn
353
				}),
hanpeng committed
354
				success: function(res) {
355
					medtap.jzz(0);
hanpeng committed
356
					if (res.success == true) {
357
						medtap.winPop('已接受订单');
hanpeng committed
358
						setTimeout(function() {
359 360 361 362 363 364
							window.location.reload();
						}, 2000);
					}
				}
			})
		},
hanpeng committed
365
		rejectOrder: function() {
366 367
			medtap.jzz(1);
			$.ajax({
hanpeng committed
368
				url: 'https://testdevgw.medtap.cn/trade/imageConsultOrder/affirmOrder/REJECT',
hanpeng committed
369
				type: 'post',
370 371 372
				async: false,
				headers: medtap.getHeaders(),
				contentType: 'application/json',
hanpeng committed
373 374
				data: JSON.stringify({
					orderSn: main.orderSn
375
				}),
hanpeng committed
376
				success: function(res) {
377
					medtap.jzz(0);
hanpeng committed
378
					if (res.success == true) {
379
						medtap.winPop('已取消订单');
hanpeng committed
380
						setTimeout(function() {
381 382 383 384 385 386
							window.location.reload();
						}, 2000);
					}
				}
			})
		}
hanpeng committed
387 388
	}
	main.init();
hanpeng committed
389
})