海南旅游SAAS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

262 lines
8.9 KiB

4 years ago
4 years ago
4 years ago
4 years ago
  1. <style>
  2. .chat-container { padding: 20px 40px; height: calc(100vh - 160px) }
  3. .msg-chat {
  4. position: relative; background-color: white; padding: 40px 20px 50px 20px;
  5. border-top-right-radius: 8px; border-bottom-right-radius: 8px; height: 100%;
  6. }
  7. .msg-chat-list { height: 100%; overflow-y: auto; overflow-x: hidden; padding-bottom: 20px; }
  8. .msg-user { margin: 5px 0px; line-height: 30px; }
  9. .msg-name { display: inline-block; font-size: 14px; font-weight: bold; padding: 0px 5px; }
  10. .msg-avatar { display: inline-block; }
  11. .msg-avatar img { width: 30px; height: 30px; border-radius: 50%; }
  12. .msg-content { display: inline-block; background-color: #f4f4f4; padding: 20px; border-radius: 10px; }
  13. .msg-content-image { max-width: 120px; max-height: 120px; }
  14. .msg-send { position: absolute; bottom: 0; left: 0; z-index: 999; height: 50px; }
  15. .msg-send .input-group-addon { width: 40px; border: none; line-height: 2.7; background-color: #dbe3e6; cursor: pointer; }
  16. .msg-send .input-group-addon.msg-text { background-color: #586cb1; color: white; padding: 5px 10px; width: 60px; line-height: 2.8; }
  17. .msg-time { padding: 0 5px; color: gray; font-size: 12px; margin: 5px 0; }
  18. .msg-list {
  19. position: relative; background-color: white;
  20. border-top-left-radius: 5px; border-bottom-left-radius: 5px;
  21. height: 100%; border-right: 1px solid #dbe3e6; overflow-y: auto;
  22. padding: 20px 10px;
  23. }
  24. .msg-list-item { position: relative; border: 1px solid #dbe3e6; padding: 10px; border-radius: 5px; margin-bottom: 1px; cursor: pointer; }
  25. .msg-list-item:hover { border-color: green; }
  26. .msg-list-item.active { border: 2px solid green; box-shadow: 0px 0px 4px green; }
  27. .msg-list-title { font-weight: bold; font-size: 14px; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; border-radius: 5px; padding: 2px 5px; overflow: hidden; text-overflow: ellipsis; margin-bottom: 5px; }
  28. .msg-list-content { color: gray; background-color: #f4f4f4; border-radius: 5px; padding: 2px 5px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  29. .msg-list-badge {
  30. position: absolute; right: 5px; top: 5px;
  31. width: 10px; height: 10px; border-radius: 10px;
  32. }
  33. .background-red { background-color: red; }
  34. .background-gray { background-color: gray; }
  35. </style>
  36. <div class="row chat-container">
  37. <div class="col-lg-3 col-md-4 msg-list">
  38. @foreach($user_list as $key => $item)
  39. @if($workorder['workorder_id']==$item['workorder_id'])
  40. <div class="msg-list-item active" onclick="window.location.href = '?workorder_id={{$item['workorder_id']}}'">
  41. @else
  42. <div class="msg-list-item" onclick="window.location.href = '?workorder_id={{$item['workorder_id']}}'">
  43. @endif
  44. <div class="msg-user">
  45. <div class="msg-avatar">
  46. <img src="{{$item['avatar']}}" alt="头像" title="头像" />
  47. </div>
  48. <div class="msg-name">
  49. {{$item['name']}}
  50. </div>
  51. </div>
  52. <div class="msg-list-title">
  53. {{$item['content']}}
  54. </div>
  55. <div class="msg-list-content">
  56. {{$item['last_message']}}
  57. </div>
  58. <div class="msg-time">
  59. {{$item['last_message_time']}}
  60. </div>
  61. {{--@if($item['unread'] == true)--}}
  62. {{--<div class="msg-list-badge background-red"></div>--}}
  63. {{--@else--}}
  64. {{--<div class="msg-list-badge background-gray"></div>--}}
  65. {{--@endif--}}
  66. </div>
  67. @endforeach
  68. </div>
  69. <div class="col-lg-9 col-md-8 msg-chat">
  70. <div class="input-group input-group-lg msg-send">
  71. <input name="msg-input" type="text" class="form-control" style="border-radius: 0; border-color: #dbe3e6; text-align: center;">
  72. <div class="input-group-addon msg-image"><span class="fa fa-picture-o"></span></div>
  73. <div class="input-group-addon msg-text">发送</div>
  74. <input type="file" class="hidden image" name="image">
  75. </div>
  76. <div class="msg-chat-list">
  77. @foreach($msg_list as $key => $item)
  78. @if($item['type'] == 'op')
  79. <div class="row">
  80. <div class="col-lg-11 text-left">
  81. <div class="msg-user">
  82. <div class="msg-avatar">
  83. <img src="{{$item['avatar']}}" alt="头像" title="头像" />
  84. </div>
  85. <div class="msg-name">
  86. {{$item['name']}}
  87. </div>
  88. </div>
  89. <div class="msg-content">
  90. @if($item['it_type'] == 1)
  91. {{$item['content']}}
  92. @elseif($item['it_type'] == 2)
  93. <img class="msg-content-image" onclick="viewImage(this)" src="{{$item['content']}}" alt="图片" title="图片" />
  94. @endif
  95. </div>
  96. <div class="msg-time">
  97. {{$item['created_at_text']}}
  98. </div>
  99. </div>
  100. </div>
  101. @elseif($item['type'] == 'my')
  102. <div class="row">
  103. <div class="col-lg-11 offset-1 text-right">
  104. <div class="msg-user">
  105. <div class="msg-name">
  106. {{$item['name']}}
  107. </div>
  108. <div class="msg-avatar">
  109. <img src="{{$item['avatar']}}" alt="头像" title="头像" />
  110. </div>
  111. </div>
  112. <div class="msg-content text-left">
  113. @if($item['it_type'] == 1)
  114. {{$item['content']}}
  115. @elseif($item['it_type'] == 2)
  116. <img class="msg-content-image" onclick="viewImage(this)" src="{{$item['content']}}" alt="图片" title="图片" />
  117. @endif
  118. </div>
  119. <div class="msg-time">
  120. {{$item['created_at_text']}}
  121. </div>
  122. </div>
  123. </div>
  124. @endif
  125. @endforeach
  126. </div>
  127. </div>
  128. <div class="hidden-forms">
  129. <input type="hidden" name="workorder-id" value="{{$workorder['workorder_id']??1}}">
  130. </div>
  131. </div>
  132. <div class="template-op hidden">
  133. <div class="row">
  134. <div class="col-lg-11 text-left">
  135. <div class="msg-user">
  136. <div class="msg-avatar">
  137. <img src="http://local.base_pro.com/vendor/dcat-admin/images/default-avatar.jpg" alt="头像" title="头像" />
  138. </div>
  139. <div class="msg-name">
  140. 代理商AbcD
  141. </div>
  142. </div>
  143. <div class="msg-content">#contents</div>
  144. <div class="msg-time">#times</div>
  145. </div>
  146. </div>
  147. </div>
  148. <div class="template-my hidden">
  149. <div class="row">
  150. <div class="col-lg-11 offset-1 text-right">
  151. <div class="msg-user">
  152. <div class="msg-name">
  153. {{$user->name}}
  154. </div>
  155. <div class="msg-avatar">
  156. <img src="{{$user->avatar}}" alt="头像" title="头像" />
  157. </div>
  158. </div>
  159. <div class="msg-content text-left">#contents</div>
  160. <div class="msg-time">#times</div>
  161. </div>
  162. </div>
  163. </div>
  164. <div class="modal fade" tabindex="-1" role="dialog" id="viewImage">
  165. <div class="modal-dialog modal-lg" role="document">
  166. <div class="modal-content">
  167. <img src="" style="width: 100%; height: 100%;" />
  168. </div>
  169. </div>
  170. </div>
  171. <script src="js/helper.js" type="application/javascript"></script>
  172. <script>
  173. Dcat.ready(function() {
  174. // 获取元素距离父级元素顶部的距离
  175. let offsetTop = $('.msg-list-item.active').position().top
  176. $(".msg-list").animate({ scrollTop: offsetTop - 20}, 1)
  177. $(".msg-chat-list").animate({ scrollTop: $(".msg-chat-list")[0].scrollHeight - $('.msg-chat-list').height() + 200 }, 1)
  178. $('.msg-image').on('click', function (e) {
  179. $('.image').click();
  180. });
  181. $('.image').on('change', function (e) {
  182. let formData = new FormData()
  183. formData.append("image", $(this)[0].files[0])
  184. formData.append("workorder_id", $('input[name=workorder-id]').val())
  185. $.ajax({
  186. url: '/admin-agent/send_image',
  187. type: 'POST',
  188. data: formData,
  189. processData: false,
  190. contentType: false,
  191. dataType: 'json',
  192. success: function(res) {
  193. let imageUrl = 'https://hainan.lanzulive.com/'+res.data.content
  194. let msgTime = res.data.created_at
  195. let templateHtml = $('.template-my').html()
  196. let imgDoc = '<img class="msg-content-image" onclick="viewImage(this)" src="'+imageUrl+'" alt="图片" title="图片" />'
  197. templateHtml = templateHtml.replace('#contents', imgDoc)
  198. templateHtml = templateHtml.replace('#times', msgTime)
  199. $(".msg-chat-list").append(templateHtml)
  200. $(".msg-chat-list").animate({ scrollTop: $(".msg-chat-list")[0].scrollHeight - $('.msg-chat-list').height() + 200 }, 1)
  201. },
  202. error: function (error) {
  203. console.log(error)
  204. }
  205. });
  206. });
  207. $('input[name=msg-input]').on('keyup', function (e) {
  208. if (e.keyCode == 13) {
  209. $('.msg-text').click()
  210. }
  211. });
  212. $('.msg-text').on('click', function (e) {
  213. let msgText = $('input[name=msg-input]').val()
  214. let workorderId = $('input[name=workorder-id]').val()
  215. $.ajax({
  216. url: '/admin-agent/send_text',
  217. type: 'POST',
  218. data: {content: msgText, workorder_id: workorderId},
  219. dataType: 'json',
  220. success: function(res) {
  221. let msgText = res.data.content
  222. let msgTime = res.data.created_at
  223. let templateHtml = $('.template-my').html()
  224. templateHtml = templateHtml.replace('#contents', msgText)
  225. templateHtml = templateHtml.replace('#times', msgTime)
  226. $(".msg-chat-list").append(templateHtml)
  227. $('input[name=msg-input]').val('')
  228. $(".msg-chat-list").animate({ scrollTop: $(".msg-chat-list")[0].scrollHeight - $('.msg-chat-list').height() }, 1)
  229. },
  230. error: function (error) {
  231. console.log(error)
  232. }
  233. });
  234. });
  235. });
  236. </script>