steps.blade.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. @if($showHeader)
  2. <div class="box-header with-border">
  3. <h3 class="box-title" style="line-height:30px">{!! $form->title() !!}</h3>
  4. <div class="pull-right">{!! $form->renderTools() !!}</div>
  5. </div>
  6. @endif
  7. <div class="box-body" style="padding:18px 18px 30px">
  8. @if($steps)
  9. <div class="fields-group la-step-box" style="padding:18px;max-width: 1000px">
  10. <ul class="la-step-horizontal la-step-label-horizontal la-step ">
  11. @foreach($steps as $step)
  12. <li class="la-step-item">
  13. <a href="#{{ $step->getFormId() }}" class="la-step-item-container">
  14. <div class="la-step-line"></div>
  15. <div class="la-step-icons">
  16. <span class="la-step-icon" data-index="{{ $step->getIndex() }}">{{ $step->getIndex() + 1 }}</span>
  17. </div>
  18. <div class="la-step-content">
  19. <div class="la-step-title">{!! $step->getTitle() !!}</div>
  20. <div class="la-step-desc"> {{ $step->getDescription() }} </div>
  21. </div>
  22. </a>
  23. </li>
  24. @endforeach
  25. <li class="la-step-item">
  26. <a href="#{{ $doneStep->getElementId() }}" class="la-step-item-container">
  27. <div class="la-step-line"></div>
  28. <div class="la-step-icons">
  29. <span class="la-step-icon" data-index="{{ count($steps) }}"> {{ count($steps) + 1 }} </span>
  30. </div>
  31. <div class="la-step-content">
  32. <div class="la-step-title">{{ $doneStep->title() }}</div>
  33. <div class="la-step-desc"></div>
  34. </div>
  35. </a>
  36. </li>
  37. </ul>
  38. <div class="la-step-form">
  39. @foreach($steps as $step)
  40. {!! $step->render() !!}
  41. @endforeach
  42. <div id="{{ $doneStep->getElementId() }}" class="la-done-step" style="display: none;">
  43. </div>
  44. </div>
  45. </div>
  46. @endif
  47. </div>
  48. @foreach($form->getHiddenFields() as $field)
  49. {!! $field->render() !!}
  50. @endforeach
  51. <input type="hidden" class="current-step-input" name="{{ Dcat\Admin\Form\StepForm::CURRENT_VALIDATION_STEP }}" />
  52. <input type="hidden" class="all-steps-input" name="{{ Dcat\Admin\Form\StepForm::ALL_STEPS }}" />
  53. <input type="hidden" name="_token" value="{{ csrf_token() }}">
  54. @php
  55. $lastStep = $step;
  56. @endphp
  57. <script>
  58. LA.ready(function () {
  59. var form = $('#{{ $form->getFormId() }}'),
  60. box = form.find('.la-step-box'),
  61. stepInput = form.find('.current-step-input'),
  62. allStepInput = form.find('.all-steps-input'),
  63. smartWizard,
  64. isSubmitting;
  65. var submitBtn = $('<button style="margin-left: 10px"></button>')
  66. .text('{{ trans('admin.submit') }}')
  67. .addClass('btn btn-primary step-submit-btn disabled hide')
  68. .on('click', function(){
  69. var $t = $(this);
  70. if ($t.hasClass('disabled') || isSubmitting) {
  71. return false;
  72. }
  73. form.validator('validate');
  74. if (form.find('.has-error').length > 0) {
  75. return false;
  76. }
  77. allStepInput.val("1");
  78. stepInput.val("");
  79. $t.button('loading').removeClass('waves-effect');
  80. isSubmitting = 1;
  81. // 提交完整表单
  82. submit(function (state, data) {
  83. $t.button('reset');
  84. isSubmitting = 0;
  85. if (state) {
  86. if (data) {
  87. form.find('.la-done-step').html(data);
  88. }
  89. smartWizard.next();
  90. toggle_btn();
  91. }
  92. });
  93. return false;
  94. });
  95. smartWizard = box.smartWizard({
  96. transitionEffect: 'fade',
  97. useURLhash: false,
  98. lang: {
  99. next: '{{ trans('admin.next_step') }}',
  100. previous: '{{ trans('admin.prev_step') }}'
  101. },
  102. toolbarSettings: {
  103. toolbarPosition: 'bottom',
  104. toolbarExtraButtons: [submitBtn,],
  105. toolbarButtonPosition: 'left'
  106. },
  107. anchorSettings: {
  108. enableAnchorOnDoneStep: false,
  109. },
  110. });
  111. smartWizard = smartWizard.data('smartWizard');
  112. var prev = box.find('.sw-btn-prev').click(function (e) {
  113. e.preventDefault();
  114. if (smartWizard.steps.index(this) !== smartWizard.current_index) {
  115. smartWizard.prev();
  116. }
  117. toggle_btn();
  118. });
  119. var next = box.find('.sw-btn-next');
  120. next.click(function (e) {
  121. e.preventDefault();
  122. if ($(this).hasClass('disabled') || isSubmitting) {
  123. return false;
  124. }
  125. var stepForm = form.find('.sw-container [data-toggle="validator"]').eq(smartWizard.current_index);
  126. stepForm.validator('validate');
  127. if (stepForm.find('.has-error').length > 0) {
  128. return false;
  129. }
  130. var self = this;
  131. $(self).button('loading').removeClass('waves-effect');
  132. isSubmitting = 1;
  133. // 发送表单到服务器进行验证
  134. stepInput.val(smartWizard.current_index);
  135. submit(function (state) {
  136. $(self).button('reset');
  137. isSubmitting = 0;
  138. if (state) {
  139. // 表单验证成功
  140. if (smartWizard.steps.index(self) !== smartWizard.current_index) {
  141. smartWizard.next();
  142. }
  143. toggle_btn();
  144. }
  145. });
  146. });
  147. function submit(after) {
  148. LA.Form({
  149. $form: form,
  150. after: function (state, b, c, d) {
  151. after(state, b, c, d);
  152. if (state) {
  153. return false;
  154. }
  155. }
  156. });
  157. }
  158. function toggle_btn() {
  159. var last = {{ $lastStep->getIndex() }},
  160. sbm = box.find('.step-submit-btn');
  161. if (smartWizard.current_index == last) {
  162. sbm.removeClass('disabled hide');
  163. next.hide();
  164. prev.show();
  165. } else {
  166. sbm.addClass('disabled hide');
  167. if (smartWizard.current_index !== 0) {
  168. prev.show();
  169. } else {
  170. prev.hide();
  171. }
  172. if (smartWizard.current_index != (last + 1)) {
  173. next.show()
  174. }
  175. }
  176. if (smartWizard.current_index == (last + 1)) {
  177. box.find('.sw-btn-group').remove()
  178. }
  179. }
  180. toggle_btn();
  181. });
  182. </script>