steps.blade.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. }).on('leaveStep', function (e, tab, idx, direction) {
  111. @if ($leaving = $steps->getOption('leaving'))
  112. var callbacks = [];
  113. @foreach($leaving as $fun)
  114. callbacks.push({!! $fun !!});
  115. @endforeach
  116. return call_listeners(callbacks, build_args(e, tab, idx, direction));
  117. @endif
  118. }).on('showStep', function (e, tab, idx, direction) {
  119. @if ($shown = $steps->getOption('shown'))
  120. var callbacks = [];
  121. @foreach($shown as $fun)
  122. callbacks.push({!! $fun !!});
  123. @endforeach
  124. return call_listeners(callbacks, build_args(e, tab, idx, direction));
  125. @endif
  126. });
  127. @if ($steps->getOption('leaving') || $steps->getOption('shown'))
  128. // 执行回调函数
  129. function call_listeners(func, args) {
  130. for (var i in func) {
  131. if (func[i](args) === false) {
  132. return false;
  133. }
  134. }
  135. }
  136. // 获取步骤表单
  137. function get_form(idx) {
  138. return box.find('.la-step-form [data-toggle="validator"]').eq(idx);
  139. }
  140. // 构建参数
  141. function build_args(e, tab, idx, direction) {
  142. return {
  143. event: e,
  144. tab: tab,
  145. index: idx,
  146. direction: direction,
  147. form: get_form(idx),
  148. getFrom: function (idx) {
  149. return get_form(idx)
  150. },
  151. formArray: get_form(idx).formToArray(),
  152. getFormArray: function (idx) {
  153. return get_form(idx).formToArray();
  154. }
  155. };
  156. }
  157. @endif
  158. smartWizard = smartWizard.data('smartWizard');
  159. // 上一步
  160. var prev = box.find('.sw-btn-prev').click(function (e) {
  161. e.preventDefault();
  162. if (smartWizard.steps.index(this) !== smartWizard.current_index) {
  163. smartWizard.prev();
  164. }
  165. toggle_btn();
  166. });
  167. // 下一步
  168. var next = box.find('.sw-btn-next').click(function (e) {
  169. e.preventDefault();
  170. if ($(this).hasClass('disabled') || isSubmitting) {
  171. return false;
  172. }
  173. var stepForm = form.find('.sw-container [data-toggle="validator"]').eq(smartWizard.current_index);
  174. stepForm.validator('validate');
  175. if (stepForm.find('.has-error').length > 0) {
  176. return false;
  177. }
  178. var self = this;
  179. $(self).button('loading').removeClass('waves-effect');
  180. isSubmitting = 1;
  181. // 发送表单到服务器进行验证
  182. stepInput.val(smartWizard.current_index);
  183. submit(function (state) {
  184. $(self).button('reset');
  185. isSubmitting = 0;
  186. if (state) {
  187. // 表单验证成功
  188. if (smartWizard.steps.index(self) !== smartWizard.current_index) {
  189. smartWizard.next();
  190. }
  191. toggle_btn();
  192. }
  193. });
  194. });
  195. // 提交表单
  196. function submit(after) {
  197. LA.Form({
  198. $form: form,
  199. after: function (state, b, c, d) {
  200. after(state, b, c, d);
  201. if (state) {
  202. return false;
  203. }
  204. }
  205. });
  206. }
  207. // 按钮显示隐藏切换
  208. function toggle_btn() {
  209. var last = {{ $lastStep->getIndex() }},
  210. sbm = box.find('.step-submit-btn');
  211. if (smartWizard.current_index == last) {
  212. sbm.removeClass('disabled hide');
  213. next.hide();
  214. prev.show();
  215. } else {
  216. sbm.addClass('disabled hide');
  217. if (smartWizard.current_index !== 0) {
  218. prev.show();
  219. } else {
  220. prev.hide();
  221. }
  222. if (smartWizard.current_index != (last + 1)) {
  223. next.show()
  224. }
  225. }
  226. if (smartWizard.current_index == (last + 1)) {
  227. box.find('.sw-btn-group').remove()
  228. }
  229. }
  230. toggle_btn();
  231. });
  232. </script>