海南旅游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.

268 lines
9.2 KiB

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