jack 7 years ago
parent
commit
fd7757e87c
1 changed files with 93 additions and 79 deletions
  1. 93 79
      js/tidings.js

+ 93 - 79
js/tidings.js

8
	$(".chat_body.clearfix").niceScroll({
8
	$(".chat_body.clearfix").niceScroll({
9
		cursorcolor: "#999999"
9
		cursorcolor: "#999999"
10
	});
10
	});
11
	
11

12
	var userid = $.cookie("userid");
12
	var userid = $.cookie("userid");
13
	var ws = new WebSocket("ws://192.168.3.233:8081/portal/websocket/msg?id=" + userid + "&pm=www");
14
	ws.onopen = function() {
15
		console.log(userid);
16
	};
17
	ws.onmessage = function(a) {
18
		var fol = true;
19
		var $info = JSON.parse(a.data);
20
		for(var i = 0; i < $(".list_body").find('.list_item').length; i++) {
21
			if($(".list_body").find('.list_item').eq(i).attr('data-id') == $info.sender) {
22
				fol = false;
23
				$(".list_body").find('.list_item .last_news').eq(i).text($info.cnt);
24
				$(".list_body").find('.list_item .time').eq(i).text(commenTime($info.sendTime));
25
				if($('.chat_content_nodata').css('display') == "none") {
26
					if($(".list_body").find('.list_item .user_name').eq(i).text() == $(".usepro .user_name").text()) {
27
						setRead($info.sender, $info.sendTime);
28
						var time1 = $(".chat_body_list").find(".time").last().attr("data-createtime");
29
						if(time1) {
30
							var str1 = '<span class="time" data-msgid="98690056999993345" data-createtime="' + $info.sendTime + '" style="">' + compareTime(time1, $info.sendTime) + '</span>'
13

14
	function websocrket() {
15
		var ws = new WebSocket("ws://192.168.3.233:8081/portal/websocket/msg?id=" + userid + "&pm=www");
16
		ws.onopen = function() {
17
			console.log(userid);
18
		};
19
		ws.onmessage = function(a) {
20
			var fol = true;
21
			var $info = JSON.parse(a.data);
22
			for(var i = 0; i < $(".list_body").find('.list_item').length; i++) {
23
				if($(".list_body").find('.list_item').eq(i).attr('data-id') == $info.sender) {
24
					fol = false;
25
					$(".list_body").find('.list_item .last_news').eq(i).text($info.cnt);
26
					$(".list_body").find('.list_item .time').eq(i).text(commenTime($info.sendTime));
27
					if($('.chat_content_nodata').css('display') == "none") {
28
						if($(".list_body").find('.list_item .user_name').eq(i).text() == $(".usepro .user_name").text()) {
29
							setRead($info.sender, $info.sendTime);
30
							var time1 = $(".chat_body_list").find(".time").last().attr("data-createtime");
31
							if(time1) {
32
								var str1 = '<span class="time" data-msgid="98690056999993345" data-createtime="' + $info.sendTime + '" style="">' + compareTime(time1, $info.sendTime) + '</span>'
33
							} else {
34
								var str1 = '<span class="time" data-msgid="98690056999993345" data-createtime="' + $info.sendTime + '" style="">' + anTime($info.sendTime) + '</span>'
35
							}
36

37
							var oStr1 = '<div id="chat-msg-98684419470524420" class="chat_item ">' +
38
								'<div class="clearfix">' +
39
								'<div class="item_avatar fl">' +
40
								'<a href="###"><img src="/images/head/' + $info.sender + '_l.jpg"></a>' +
41
								'</div>' +
42
								'<div class="item_content fl">' +
43
								'<em class="is_readed"></em>' +
44
								'<div class="bubble message C_end">' + $info.cnt + '</div>' +
45
								'</div>' +
46
								'</div>' +
47
								'</div>'
48
							$(".chat_body_list").append(str1 + oStr1);
49
							$(".chat_body.clearfix").getNiceScroll().hide().show().resize();
50
							$(".chat_body.clearfix").getNiceScroll(0).doScrollTop($(".chat_body_list").height(), 100)
31
						} else {
51
						} else {
32
							var str1 = '<span class="time" data-msgid="98690056999993345" data-createtime="' + $info.sendTime + '" style="">' + anTime($info.sendTime) + '</span>'
52
							var oNu = Number($(".list_body").find('.list_item .tips_num').eq(i).text()) + 1;
53
							$(".list_body").find('.list_item .tips_num').eq(i).text(oNu).show();
33
						}
54
						}
34

35
						var oStr1 = '<div id="chat-msg-98684419470524420" class="chat_item ">' +
36
							'<div class="clearfix">' +
37
							'<div class="item_avatar fl">' +
38
							'<a href="/im/chat/client_user_info/8108417.htm?outerPositionId=3488230" target="_blank"><img src="/images/head/' + $info.sender + '_l.jpg"></a>' +
39
							'</div>' +
40
							'<div class="item_content fl">' +
41
							'<em class="is_readed"></em>' +
42
							'<div class="bubble message C_end">' + $info.cnt + '</div>' +
43
							'</div>' +
44
							'</div>' +
45
							'</div>'
46
						$(".chat_body_list").append(str1 + oStr1);
47
						$(".chat_body.clearfix").getNiceScroll().hide().show().resize();
48
						$(".chat_body.clearfix").getNiceScroll(0).doScrollTop($(".chat_body_list").height(), 100)
49
					} else {
55
					} else {
50
						var oNu = Number($(".list_body").find('.list_item .tips_num').eq(i).text()) + 1;
56
						var oNu = Number($(".list_body").find('.list_item .tips_num').eq(i).text()) + 1;
51
						$(".list_body").find('.list_item .tips_num').eq(i).text(oNu).show();
57
						$(".list_body").find('.list_item .tips_num').eq(i).text(oNu).show();
52
					}
58
					}
59
					if(i > 0)
60
						$(".list_body").find('.list_item').eq(i).remove().clone().prependTo($(".list_body"));
61

53
				} else {
62
				} else {
54
					var oNu = Number($(".list_body").find('.list_item .tips_num').eq(i).text()) + 1;
55
					$(".list_body").find('.list_item .tips_num').eq(i).text(oNu).show();
56
				}
57
				if(i > 0)
58
					$(".list_body").find('.list_item').eq(i).remove().clone().prependTo($(".list_body"));
59

63

60
			} else {
64
				}
61

65

62
			}
66
			}
67
			if(fol) {
68
				var ostr = '<div class="list_item clearfix active" data-id="' + $info.sender + '">' +
69
					'<i class="close_icon"></i>' +
70
					'<div class="avatar fl">' +
71
					'<img src="images/default-photo.jpg" alt="李朋涛">' +
72
					'<span class="tips_num" >1</span>' +
73
					'</div>' +
74
					'<div class="list_item_info fl">' +
75
					'<div class="user_infos">' +
76
					'<span class="user_name"> </span><em class="authiconNew"></em>' +
77
					'</div>' +
78
					'<span class="time">' + commenTime($info.sendTime) + '</span><span class="last_news">' + $info.cnt + '</span>' +
79
					'</div>' +
80
					'</div>'
81
				var $str = $(ostr);
82
				$(".list_body").prepend($str);
83
				personMess($info.sender, $str.find('img'), $str.find(".user_name"), $str.find(".authiconNew"));
84
			}
85
		};
86
		ws.onclose = function() {
63

87

64
		}
88
		}
65
		if(fol) {
66
			var ostr = '<div class="list_item clearfix active" data-id="' + $info.sender + '">' +
67
				'<i class="close_icon"></i>' +
68
				'<div class="avatar fl">' +
69
				'<img src="images/default-photo.jpg" alt="李朋涛">' +
70
				'<span class="tips_num" >1</span>' +
71
				'</div>' +
72
				'<div class="list_item_info fl">' +
73
				'<div class="user_infos">' +
74
				'<span class="user_name"> </span><em class="authiconNew"></em>' +
75
				'</div>' +
76
				'<span class="time">' + commenTime($info.sendTime) + '</span><span class="last_news">' + $info.cnt + '</span>' +
77
				'</div>' +
78
				'</div>'
79
			var $str = $(ostr);
80
			$(".list_body").prepend($str);
81
			personMess($info.sender, $str.find('img'), $str.find(".user_name"), $str.find(".authiconNew"));
82
		}
83
	};
84
	ws.onclose = function() {
85

86
	}
89
	}
87
	myMessageList(1);
90
	myMessageList();
88
	if(professorId) {
91
	if(professorId) {
89
		firstFlag = 1;
92
		firstFlag = 1;
90
		$(".chat_content_nodata").hide();
93
		$(".chat_content_nodata").hide();
123
								le = "me";
126
								le = "me";
124
								flo = "fr";
127
								flo = "fr";
125
								if($data[i].readed) {
128
								if($data[i].readed) {
126
									wei = '<em class="is_readed">已读</em>';
129
									wei = '<em class="is_readed"></em>';
127
								} else {
130
								} else {
128
									wei = '<em class="is_readed"></em>';
131
									wei = '<em class="is_readed"></em>';
129
								}
132
								}
139
								'<div id="chat-msg-98684419470524420" class="chat_item ' + le + '">' +
142
								'<div id="chat-msg-98684419470524420" class="chat_item ' + le + '">' +
140
								'<div class="clearfix">' +
143
								'<div class="clearfix">' +
141
								'<div class="item_avatar fl">' +
144
								'<div class="item_avatar fl">' +
142
								'<a href="/im/chat/client_user_info/8108417.htm?outerPositionId=3488230" target="_blank"><img src="/images/head/' + $data[i].sender + '_l.jpg"></a>' +
145
								'<a href="###" ><img src="/images/head/' + $data[i].sender + '_l.jpg"></a>' +
143
								'</div>' +
146
								'</div>' +
144
								'<div class="item_content ' + flo + '">' +
147
								'<div class="item_content ' + flo + '">' +
145
								wei +
148
								wei +
245
			} else {
248
			} else {
246
				$(".list_body").append($str);
249
				$(".list_body").append($str);
247
			}
250
			}
248

251
		
249
			personMess($data[i].id, $str.find('img'), $str.find(".user_name"), $str.find(".authiconNew"));
252
			personMess($data[i].id, $str.find('img'), $str.find(".user_name"), $str.find(".authiconNew"));
250
		}
253
		}
251
		$(".list_body").getNiceScroll().hide().show().resize();
254
		$(".list_body").getNiceScroll().hide().show().resize();
255
		websocrket();
252
	}
256
	}
253
	//专家信息
257
	//专家信息
254
	function personMess(id, pImg, pName, pTitle) {
258
	function personMess(id, pImg, pName, pTitle) {
323
					var userType = autho($data.authType, $data.orgAuth, $data.authStatus);
327
					var userType = autho($data.authType, $data.orgAuth, $data.authStatus);
324
					$(".usepro").find('.authiconNew').attr("title", userType.title).addClass(userType.sty);
328
					$(".usepro").find('.authiconNew').attr("title", userType.title).addClass(userType.sty);
325
					$(".usepro").find('.user_name').text($data.name);
329
					$(".usepro").find('.user_name').text($data.name);
326
					$("#cUserPage").attr("href","userInforShow.html?professorId="+$data.id)
330
					$("#cUserPage").attr("href", "userInforShow.html?professorId=" + $data.id)
327
					var str = '';
331
					var str = '';
328
					if($data.title) {
332
					if($data.title) {
329
						if($data.orgName) {
333
						if($data.orgName) {
353
						}
357
						}
354
					}
358
					}
355
					$('.chating_resume_status').text(str);
359
					$('.chating_resume_status').text(str);
356
					
360

357
				}
361
				}
358
			},
362
			},
359
			"error": function() {
363
			"error": function() {
379
					$(".btnModel").attr("disabled", "disabled");
383
					$(".btnModel").attr("disabled", "disabled");
380
					var time1 = $(".chat_body_list").find(".time").last().attr("data-createtime");
384
					var time1 = $(".chat_body_list").find(".time").last().attr("data-createtime");
381
					if(time1) {
385
					if(time1) {
382
						var str1 = '<span class="time" data-msgid="98690056999993345" data-createtime="' + data.data.sendTime + '" style="">' + compareTime(time1, data.data) + '</span>'
386
						var str1 = '<span class="time" data-msgid="98690056999993345" data-createtime="' + data.data + '" style="">' + compareTime(time1, data.data) + '</span>'
383
					} else {
387
					} else {
384
						var str1 = '<span class="time" data-msgid="98690056999993345" data-createtime="' + data.data.sendTime + '" style="">' + anTime(data.data) + '</span>'
388
						var str1 = '<span class="time" data-msgid="98690056999993345" data-createtime="' + data.data + '" style="">' + anTime(data.data) + '</span>'
385
					}
389
					}
386

390

387
					var oStr = '<div id="chat-msg-98684419470524420" class="chat_item me">' +
391
					var oStr = '<div id="chat-msg-98684419470524420" class="chat_item me">' +
388
						'<div class="clearfix">' +
392
						'<div class="clearfix">' +
389
						'<div class="item_avatar fl">' +
393
						'<div class="item_avatar fl">' +
390
						'<a href="/im/chat/client_user_info/8108417.htm?outerPositionId=3488230" target="_blank"><img src="/images/head/' + userid + '_l.jpg"></a>' +
394
						'<a href="#" ><img src="/images/head/' + userid + '_l.jpg"></a>' +
391
						'</div>' +
395
						'</div>' +
392
						'<div class="item_content fr">' +
396
						'<div class="item_content fr">' +
393
						'<em class="is_readed"></em>' +
397
						'<em class="is_readed"></em>' +
396
						'</div>' +
400
						'</div>' +
397
						'</div>'
401
						'</div>'
398
					$(".chat_body_list").append(str1 + oStr);
402
					$(".chat_body_list").append(str1 + oStr);
399
					$(".messContent").val("");
403

400
					$(".chat_body.clearfix").getNiceScroll().hide().show().resize();
404
					$(".chat_body.clearfix").getNiceScroll().hide().show().resize();
401
					$(".chat_body.clearfix").getNiceScroll(0).doScrollTop($(".chat_body_list").height(), 100)
405
					$(".chat_body.clearfix").getNiceScroll(0).doScrollTop($(".chat_body_list").height(), 100)
406
					for(var i = 0; i < $(".list_body").find('.list_item').length; i++) {
407
						if($(".list_body").find('.list_item .user_name').eq(i).text() == $(".usepro .user_name").text()) {
408
							$(".list_body").find('.list_item .last_news').eq(i).text($(".messContent").val());
409
							$(".list_body").find('.list_item .time').eq(i).text(commenTime(data.data));
410
							if(i != 0) {
411
								$(".list_body").find('.list_item').eq(i).remove().clone().prependTo($(".list_body"))
412
							}
413
						}
414
					}
415
					$(".messContent").val("");
402
				}
416
				}
403
			},
417
			},
404
			"error": function() {
418
			"error": function() {
426
		$(".chat_content_nodata").hide();
440
		$(".chat_content_nodata").hide();
427
		$(".chat_content").show();
441
		$(".chat_content").show();
428
		var pro = JSON.parse($(this).attr("data"));
442
		var pro = JSON.parse($(this).attr("data"));
429
		$("#cUserPage").attr("href","userInforShow.html?professorId="+pro.id)
443
		$("#cUserPage").attr("href", "userInforShow.html?professorId=" + pro.id)
430
		$(".usepro").find(".user_name").text(pro.name).siblings(".authiconNew").addClass(pro.idf.sty).attr("title", pro.idf.title).parent().siblings(".chating_resume_status").text(pro.duties);
444
		$(".usepro").find(".user_name").text(pro.name).siblings(".authiconNew").addClass(pro.idf.sty).attr("title", pro.idf.title).parent().siblings(".chating_resume_status").text(pro.duties);
431
		professorId = pro.id;
445
		professorId = pro.id;
432
		if(Number($(this).find(".tips_num").text())) {
446
		if(Number($(this).find(".tips_num").text())) {
515
	});*/
529
	});*/
516
	/*删除会话*/
530
	/*删除会话*/
517
	var $that;
531
	var $that;
518
	$(".list_body").on("click",".close_icon",function() {
519
		$that=$(this)
532
	$(".list_body").on("click", ".close_icon", function() {
533
		$that = $(this)
520
		$.MsgBox.Confirm("提示", "确定删除?", deleChat);
534
		$.MsgBox.Confirm("提示", "确定删除?", deleChat);
521
		return false;
535
		return false;
522
	})
536
	})
527
			"type": "POST",
541
			"type": "POST",
528
			"traditional": true,
542
			"traditional": true,
529
			"data": {
543
			"data": {
530
				owner:userid,
531
				actor:$that.parents(".list_item").attr('data-id')
544
				owner: userid,
545
				actor: $that.parents(".list_item").attr('data-id')
532
			},
546
			},
533
			"context":$that.parents(".list_item"),
547
			"context": $that.parents(".list_item"),
534
			"dataType": "json",
548
			"dataType": "json",
535
			"success": function(data) {
549
			"success": function(data) {
536
				if(data.success) {
550
				if(data.success) {
537
						$(this).remove();
551
					$(this).remove();
538
				}
552
				}
539
			},
553
			},
540
			"error": function() {
554
			"error": function() {