Няма описание

chatSidebar.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. function messages(type) {
  2. if (!type) {
  3. type = $('.right-tab li.active').index();
  4. }
  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()
  70. } else {
  71. layer.msg("关闭消息失败!");
  72. }
  73. }
  74. });
  75. }
  76. $(document).ready(function(){
  77. $('.right-tab li').click(function(){
  78. messages($(this).index());
  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()
  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. }