12345市长热线标准版-前端

chatSidebar.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. var type=0;
  2. messages(type)
  3. setInterval(messages, 5000,0);//Ajax调用函数
  4. function messages(type){
  5. var html=$('#tab-'+(type+1)).find('.chat_box');
  6. html.html('');
  7. $.ajax({
  8. type:"get",
  9. url:huayi.config.callcenter_url+"Index/GetChatLists",
  10. async:true,
  11. dataType:'json',
  12. data:{
  13. token:$.cookie("token"),
  14. isread:type,
  15. top:50,
  16. fromid:0
  17. },
  18. success:function(data){
  19. $('#tab-1').find('.message_count').html(data.total);
  20. if(type==0){
  21. if(data.total==0){
  22. $('.readed').hide();
  23. $('.chat_count').hide();
  24. }else{
  25. $('.chat_count').show();
  26. $('.chat_count').html(data.total);
  27. $('.readed').show();
  28. }
  29. $('.close_chat').show();
  30. }
  31. $(data.rows).each(function(i,n){
  32. var str='';
  33. str='<div class="sidebar-message">'+
  34. '<a href="#">'+
  35. '<div class="pull-left text-center">'+
  36. '<img alt="image" class="img-circle message-avatar" src="img/chat_pic.jpg">'+
  37. '<div class="m-t-xs">'+ n.F_UserName +'</div>'+
  38. '</div>'+
  39. '<div class="media-body">'+
  40. '<div class="chat_content">'+ GetCont(n.Content) +'</div>'+
  41. '<small class="text-muted">'+ n.CreateDate+'</small>'+
  42. '<span class="reply" data-FromUserId="'+ n.FromUserId+'" data-ToUserId="'+ n.ToUserId+'" data-roleId="'+ n.F_RoleId+'" onclick="resply(this)">回复</span>'
  43. if(n.IsRead!=1){
  44. str +='<span class="reply close_chat" data-index="'+ n.Id+'" onclick="closed(this)">关闭</span>'
  45. }
  46. '</div>'+
  47. '</a>'+
  48. '</div>'
  49. html.append(str);
  50. })
  51. }
  52. });
  53. }
  54. function closed(a){
  55. var id=$(a).attr('data-index');
  56. $.ajax({
  57. type:"post",
  58. url:huayi.config.callcenter_url+"Index/CloseChat",
  59. async:true,
  60. dataType:'json',
  61. data:{
  62. token:$.cookie("token"),
  63. id:id
  64. },
  65. success:function(data){
  66. if(data.total>0){
  67. messages(type)
  68. }else{
  69. layer.msg("关闭消息失败!");
  70. }
  71. }
  72. });
  73. }
  74. $(document).ready(function(){
  75. $('.right-tab li').click(function(){
  76. type=$(this).index();
  77. console.log(type);
  78. messages(type)
  79. })
  80. //全部已读
  81. $('.readed').click(function(){
  82. $.ajax({
  83. type:"get",
  84. url:huayi.config.callcenter_url+"Index/CloseChat",
  85. async:true,
  86. dataType:'json',
  87. data:{
  88. token:$.cookie("token"),
  89. id:0
  90. },
  91. success:function(data){
  92. if(data.total>0){
  93. messages(type)
  94. }else{
  95. layer.msg("设置失败!");
  96. }
  97. }
  98. });
  99. })
  100. })
  101. //回复
  102. function resply(a){
  103. var userId=$(a).attr('data-FromUserId')
  104. var toId=$(a).attr('data-ToUserId')
  105. var roleId=$(a).attr('data-roleId')
  106. layer.open({
  107. type: 2,
  108. content: "replyChat.html?userId="+ userId +"&roleId="+roleId+"&toId="+toId, //iframe的url,no代表不显示滚动条
  109. title: '回复消息',
  110. area: ['50%', '60%'], //宽高
  111. });
  112. }
  113. //主动发消息
  114. $('.sele_send').click(function(){
  115. layer.open({
  116. type: 2,
  117. content: "replyChat.html", //iframe的url,no代表不显示滚动条
  118. title: '发送消息',
  119. area: ['50%', '60%'], //宽高
  120. });
  121. })
  122. //回复
  123. function GetCont(val) {
  124. if(val) {
  125. var str = '<div '
  126. if(val.length > 10) {
  127. str = str + ' title="' + val + '" ';
  128. val = val.substr(0, 25) + "...";
  129. }
  130. return str + '>' + val + '</div>';
  131. } else {
  132. return '';
  133. }
  134. }