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

273 lines
9.4 KiB

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