12345市长热线标准版-前端

chatSidebar.js 3.7KB

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