replyTicket.blade.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. @extends('user.layouts')
  2. @section('content')
  3. <div class="page-content">
  4. <div class="panel panel-bordered">
  5. <div class="panel-heading">
  6. <h1 class="panel-title cyan-600"><i class="icon wb-help-circle"></i> {{ $ticket->title }} </h1>
  7. @if ($ticket->status !== 2)
  8. <div class="panel-actions">
  9. <button class="btn btn-danger" onclick="closeTicket()"> {{ trans('common.close') }} </button>
  10. </div>
  11. @endif
  12. </div>
  13. <div class="panel-body">
  14. <div class="chat-box">
  15. <div class="chats">
  16. @php
  17. $currentUser = Auth::user();
  18. @endphp
  19. <x-chat-unit :user="$currentUser" :ticket="$ticket" />
  20. @foreach ($replyList as $reply)
  21. <x-chat-unit :user="$currentUser" :ticket="$reply" />
  22. @endforeach
  23. </div>
  24. </div>
  25. </div>
  26. <div class="panel-footer pb-30">
  27. <form>
  28. <div class="input-group">
  29. <input class="form-control" id="editor" type="text" placeholder="{{ trans('user.ticket.reply_placeholder') }}" />
  30. <span class="input-group-btn">
  31. <button class="btn btn-primary" type="button" onclick="replyTicket()"> {{ trans('common.send') }}</button>
  32. </span>
  33. </div>
  34. </form>
  35. </div>
  36. </div>
  37. </div>
  38. @endsection
  39. @section('javascript')
  40. <script>
  41. //回车检测
  42. $(document).on('keypress', 'input', function(e) {
  43. if (e.which === 13) {
  44. replyTicket();
  45. return false;
  46. }
  47. });
  48. // 关闭工单
  49. function closeTicket() {
  50. swal.fire({
  51. title: '{{ trans('common.close_item', ['attribute' => trans('user.ticket.attribute')]) }}',
  52. text: '{{ trans('user.ticket.close_tips') }}',
  53. icon: 'question',
  54. showCancelButton: true,
  55. cancelButtonText: '{{ trans('common.close') }}',
  56. confirmButtonText: '{{ trans('common.confirm') }}',
  57. }).then((result) => {
  58. if (result.value) {
  59. $.ajax({
  60. method: 'PATCH',
  61. url: '{{ route('ticket.close', $ticket) }}',
  62. async: true,
  63. data: {
  64. _token: '{{ csrf_token() }}',
  65. },
  66. dataType: 'json',
  67. success: function(ret) {
  68. swal.fire({
  69. title: ret.message,
  70. icon: 'success',
  71. timer: 1300,
  72. }).then(() => window.location.href = '{{ route('ticket.index') }}');
  73. },
  74. error: function() {
  75. swal.fire({
  76. title: '{{ trans('user.ticket.error') }}',
  77. icon: 'error'
  78. });
  79. },
  80. });
  81. }
  82. });
  83. }
  84. // 回复工单
  85. function replyTicket() {
  86. const content = document.getElementById('editor').value;
  87. if (content.trim() === '') {
  88. swal.fire({
  89. title: '{{ ucfirst(trans('validation.required', ['attribute' => trans('validation.attributes.content')])) }}!',
  90. icon: 'warning',
  91. timer: 1500,
  92. });
  93. return false;
  94. }
  95. swal.fire({
  96. title: '{{ trans('user.ticket.reply_confirm') }}',
  97. icon: 'question',
  98. allowEnterKey: false,
  99. showCancelButton: true,
  100. cancelButtonText: '{{ trans('common.close') }}',
  101. confirmButtonText: '{{ trans('common.confirm') }}',
  102. }).then((result) => {
  103. if (result.value) {
  104. $.ajax({
  105. method: 'PUT',
  106. url: '{{ route('ticket.reply', $ticket) }}',
  107. async: true,
  108. data: {
  109. _token: '{{ csrf_token() }}',
  110. content: content,
  111. },
  112. dataType: 'json',
  113. success: function(ret) {
  114. if (ret.status === 'success') {
  115. swal.fire({
  116. title: ret.message,
  117. icon: 'success',
  118. timer: 1000,
  119. showConfirmButton: false,
  120. }).then(() => window.location.reload());
  121. } else {
  122. swal.fire({
  123. title: ret.message,
  124. icon: 'error'
  125. }).then(() => window.location.reload());
  126. }
  127. },
  128. error: function() {
  129. swal.fire({
  130. title: '{{ trans('user.ticket.error') }}',
  131. icon: 'error'
  132. });
  133. },
  134. });
  135. }
  136. });
  137. }
  138. </script>
  139. @endsection