steps.blade.php 6.8 KB

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