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

281 lines
9.6 KiB

5 years ago
5 years ago
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. </div>
  131. </div>
  132. </div>
  133. @endif
  134. @endforeach
  135. </div>
  136. @endif
  137. </div>
  138. <div class="hidden-forms">
  139. <input type="hidden" name="workorder-id" value="{{$workorder['workorder_id']??1}}">
  140. </div>
  141. </div>
  142. <div class="template-op hidden">
  143. <div class="row">
  144. <div class="col-lg-11 text-left">
  145. <div class="msg-user">
  146. <div class="msg-avatar">
  147. <img src="/vendor/dcat-admin/images/default-avatar.jpg" alt="头像" title="头像" />
  148. </div>
  149. <div class="msg-name">
  150. 代理商AbcD
  151. </div>
  152. </div>
  153. <div class="msg-content">#contents</div>
  154. <div class="msg-time">#times</div>
  155. </div>
  156. </div>
  157. </div>
  158. <div class="template-my hidden">
  159. <div class="row">
  160. <div class="col-lg-11 offset-1 text-right">
  161. <div class="msg-user">
  162. <div class="msg-name">
  163. {{$user->name}}
  164. </div>
  165. <div class="msg-avatar">
  166. <img src="{{\Illuminate\Support\Facades\Storage::url($user->avatar)}}" alt="头像" title="头像" />
  167. </div>
  168. </div>
  169. <div class="msg-content text-left">#contents</div>
  170. <div class="msg-time">#times</div>
  171. </div>
  172. </div>
  173. </div>
  174. <div class="modal fade" tabindex="-1" role="dialog" id="viewImage">
  175. <div class="modal-dialog modal-lg" role="document">
  176. <div class="modal-content">
  177. <img src="" style="width: 100%; height: 100%;" />
  178. </div>
  179. </div>
  180. </div>
  181. <script src="js/helper.js" type="application/javascript"></script>
  182. <script>
  183. $(document).ready(function() {
  184. // 获取元素距离父级元素顶部的距离
  185. let offsetTop = $('.msg-list-item.active').position().top
  186. $(".msg-list").animate({ scrollTop: offsetTop - 20}, 1)
  187. $(".msg-chat-list").animate({ scrollTop: $(".msg-chat-list")[0].scrollHeight - $('.msg-chat-list').height() + 600 }, 1)
  188. $('.msg-image').on('click', function (e) {
  189. $('.image').click();
  190. });
  191. $('.image').on('change', function (e) {
  192. let formData = new FormData()
  193. formData.append("image", $(this)[0].files[0])
  194. formData.append("workorder_id", $('input[name=workorder-id]').val())
  195. $.ajax({
  196. url: '/{{$route}}/send_image',
  197. type: 'POST',
  198. data: formData,
  199. processData: false,
  200. contentType: false,
  201. dataType: 'json',
  202. success: function(res) {
  203. let imageUrl = res.data.content
  204. let msgTime = res.data.created_at
  205. let templateHtml = $('.template-my').html()
  206. let imgDoc = '<img class="msg-content-image" onclick="viewImage(this)" src="'+imageUrl+'" alt="图片" title="图片" />'
  207. templateHtml = templateHtml.replace('#contents', imgDoc)
  208. templateHtml = templateHtml.replace('#times', msgTime)
  209. $(".msg-chat-list").append(templateHtml)
  210. $(".msg-chat-list").animate({ scrollTop: $(".msg-chat-list")[0].scrollHeight - $('.msg-chat-list').height() + 600 }, 1)
  211. },
  212. error: function (error) {
  213. console.log(error)
  214. }
  215. });
  216. });
  217. $('input[name=msg-input]').on('keyup', function (e) {
  218. if (e.keyCode == 13) {
  219. $('.msg-text').click()
  220. }
  221. });
  222. $('.msg-text').on('click', function (e) {
  223. let msgText = $('input[name=msg-input]').val()
  224. let workorderId = $('input[name=workorder-id]').val()
  225. if (msgText == '') {
  226. $('input[name=msg-input]').css('border-color', 'red').focus();
  227. setTimeout(function () {
  228. $('input[name=msg-input]').css('border-color', '#dbe3e6');
  229. }, 3000)
  230. }
  231. $.ajax({
  232. url: '/{{$route}}/send_text',
  233. type: 'POST',
  234. data: {content: msgText, workorder_id: workorderId},
  235. dataType: 'json',
  236. success: function(res) {
  237. if (res.code != 0) {
  238. return false;
  239. }
  240. let msgText = res.data.content
  241. let msgTime = res.data.created_at
  242. let templateHtml = $('.template-my').html()
  243. templateHtml = templateHtml.replace('#contents', msgText)
  244. templateHtml = templateHtml.replace('#times', msgTime)
  245. $(".msg-chat-list").append(templateHtml)
  246. $('input[name=msg-input]').val('')
  247. $(".msg-chat-list").animate({ scrollTop: $(".msg-chat-list")[0].scrollHeight - $('.msg-chat-list').height() }, 1)
  248. },
  249. error: function (error) {
  250. console.log(error)
  251. }
  252. });
  253. });
  254. });
  255. </script>