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

292 lines
10 KiB

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