123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- <style>
- .dcat-step .dcat-step-item:not(.active) > .dcat-step-item-container[role=button]:hover .dcat-step-icons,
- .done > .dcat-step-item-container > .dcat-step-line:after,
- .done .dcat-step-icons,
- .active .dcat-step-icons {
- border-color: @primary
- }
- .dcat-step .dcat-step-item:not(.active) > .dcat-step-item-container[role=button]:hover .dcat-step-icons .dcat-step-icon,
- .dcat-step .dcat-step-item:not(.active) > .dcat-step-item-container[role=button]:hover .dcat-step-desc .dcat-step .dcat-step-item:not(.active) > .dcat-step-item-container[role=button]:hover .dcat-step-title,
- .active .dcat-step-icons > .dcat-step-icon {
- color: #fff
- }
- .done .dcat-step-icons > .dcat-step-icon {
- color: @primary
- }
- .done > .dcat-step-item-container > .dcat-step-content > .dcat-step-title:after,
- .done .dcat-step-icons > .dcat-step-icon .dcat-step-icon-dot,
- .active .dcat-step-icons,
- .active .dcat-step-icons > .dcat-step-icon .dcat-step-icon-dot {
- background-color: @primary
- }
- </style>
- @if($showHeader)
- <div class="box-header with-border">
- <h3 class="box-title" style="line-height:30px">{!! $form->title() !!}</h3>
- <div class="pull-right">{!! $form->renderTools() !!}</div>
- </div>
- @endif
- <div class="box-body">
- @if($steps->count())
- <div class="fields-group dcat-step-box" style="padding: {{ $steps->getOption('padding') }};max-width: {{ $steps->getOption('width') }}">
- <ul class="dcat-step-horizontal dcat-step-label-horizontal dcat-step ">
- @foreach($steps->all() as $step)
- <li class="dcat-step-item">
- <a href="#{{ $step->getElementId() }}" class="dcat-step-item-container">
- <div class="dcat-step-line"></div>
- <div class="dcat-step-icons">
- <span class="dcat-step-icon" data-index="{{ $step->index() }}">{{ $step->index() + 1 }}</span>
- </div>
- <div class="dcat-step-content">
- <div class="dcat-step-title">{!! $step->title() !!}</div>
- <div class="dcat-step-desc"> {{ $step->description() }} </div>
- </div>
- </a>
- </li>
- @endforeach
- <li class="dcat-step-item">
- <a href="#{{ $steps->done()->getElementId() }}" class="dcat-step-item-container">
- <div class="dcat-step-line"></div>
- <div class="dcat-step-icons">
- <span class="dcat-step-icon" data-index="{{ $steps->count() }}"> {{ $steps->count() + 1 }} </span>
- </div>
- <div class="dcat-step-content">
- <div class="dcat-step-title">{{ $steps->done()->title() }}</div>
- <div class="dcat-step-desc"></div>
- </div>
- </a>
- </li>
- </ul>
- <div class="dcat-step-form">
- {!! $steps->build() !!}
- <div id="{{ $steps->done()->getElementId() }}" class="dcat-done-step" style="display: none;">
- </div>
- </div>
- </div>
- @endif
- </div>
- <input type="hidden" class="current-step-input" name="{{ Dcat\Admin\Form\Steps\Builder::CURRENT_VALIDATION_STEP }}" />
- <input type="hidden" class="all-steps-input" name="{{ Dcat\Admin\Form\Steps\Builder::ALL_STEPS }}" />
- @php
- $lastStep = $step;
- @endphp
- <script>
- Dcat.ready(function () {
- var form = $('#{{ $form->getElementId() }}'),
- box = form.find('.dcat-step-box'),
- stepInput = form.find('.current-step-input'),
- allStepInput = form.find('.all-steps-input'),
- smartWizard,
- isSubmitting;
- var submitBtn = $('<button style="margin-left: 10px"></button>')
- .text('{{ trans('admin.submit') }}')
- .addClass('btn btn-primary step-submit-btn disabled d-none')
- .on('click', function(){
- var $t = $(this);
- if ($t.hasClass('disabled') || isSubmitting) {
- return false;
- }
- form.validator('validate');
- if (form.find('.has-error').length > 0) {
- return false;
- }
- allStepInput.val("1");
- stepInput.val("");
- $t.buttonLoading().removeClass('waves-effect');
- isSubmitting = 1;
- // 提交完整表单
- submit(function (state, data) {
- $t.buttonLoading(false);
- isSubmitting = 0;
-
- if (typeof data.status !== 'undefined' && ! data.status) {
- return Dcat.handleJsonResponse(data)
- }
- if (state) {
- if (data) {
- form.find('.dcat-done-step').html(data);
- }
- smartWizard.next();
- toggleBtn();
- }
- });
- return false;
- });
- smartWizard = box.smartWizard({
- selected: {{ $steps->getOption('selected') }},
- transitionEffect: 'fade',
- useURLhash: false,
- keyNavigation: false,
- showStepURLhash: false,
- autoAdjustHeight: false,
- lang: {
- next: '{!! trans('admin.next_step') !!}',
- previous: '{!! trans('admin.prev_step') !!}'
- },
- toolbarSettings: {
- toolbarPosition: 'bottom',
- toolbarExtraButtons: [submitBtn,],
- toolbarButtonPosition: 'left'
- },
- anchorSettings: {
- removeDoneStepOnNavigateBack: true,
- enableAnchorOnDoneStep: false,
- },
- }).on('leaveStep', function (e, tab, idx, direction) {
- @if ($leaving = $steps->getOption('leaving'))
- var callbacks = [];
- @foreach($leaving as $fun)
- callbacks.push({!! $fun !!});
- @endforeach
- return callListeners(callbacks, buildArgs(e, tab, idx, direction));
- @endif
- }).on('showStep', function (e, tab, idx, direction) {
- @if ($shown = $steps->getOption('shown'))
- var callbacks = [];
- @foreach($shown as $fun)
- callbacks.push({!! $fun !!});
- @endforeach
- return callListeners(callbacks, buildArgs(e, tab, idx, direction));
- @endif
- });
- @if ($steps->getOption('leaving') || $steps->getOption('shown'))
- // 执行回调函数
- function callListeners(func, args) {
- for (var i in func) {
- if (func[i](args) === false) {
- return false;
- }
- }
- }
- // 获取步骤表单
- function getForm(idx) {
- return box.find('.dcat-step-form [data-toggle="validator"]').eq(idx);
- }
- // 构建参数
- function buildArgs(e, tab, idx, direction) {
- return {
- event: e,
- tab: tab,
- index: idx,
- direction: direction,
- form: getForm(idx),
- getFrom: function (idx) {
- return getForm(idx)
- },
- formArray: getForm(idx).formToArray(),
- getFormArray: function (idx) {
- return getForm(idx).formToArray();
- }
- };
- }
- @endif
- smartWizard = smartWizard.data('smartWizard');
- // 上一步
- var prev = box.find('.sw-btn-prev').click(function (e) {
- e.preventDefault();
- if (smartWizard.steps.index(this) !== smartWizard.current_index) {
- smartWizard.prev();
- }
- toggleBtn();
- });
- // 下一步
- var next = box.find('.sw-btn-next').click(function (e) {
- e.preventDefault();
- if ($(this).hasClass('disabled') || isSubmitting) {
- return false;
- }
- var FormStep = form.find('.sw-container [data-toggle="validator"]').eq(smartWizard.current_index);
- FormStep.validator('validate');
- if (FormStep.find('.has-error').length > 0) {
- return false;
- }
- var self = this;
- $(self).buttonLoading().removeClass('waves-effect');
- isSubmitting = 1;
- // 发送表单到服务器进行验证
- stepInput.val(smartWizard.current_index);
- submit(function (state) {
- $(self).buttonLoading(false);
- isSubmitting = 0;
- if (state) {
- // 表单验证成功
- if (smartWizard.steps.index(self) !== smartWizard.current_index) {
- smartWizard.next();
- }
- toggleBtn();
- }
- });
- });
- // 提交表单
- function submit(after) {
- Dcat.Form({
- form: form,
- after: function (state, b, c, d) {
- after(state, b, c, d);
- if (state) {
- return false;
- }
- }
- });
- }
- // 按钮显示隐藏切换
- function toggleBtn() {
- var last = {{ $lastStep->index() }},
- sbm = box.find('.step-submit-btn');
- if (smartWizard.current_index == last) {
- sbm.removeClass('disabled d-none');
- next.hide();
- prev.show();
- } else {
- sbm.addClass('disabled d-none');
- if (smartWizard.current_index !== 0) {
- prev.show();
- } else {
- prev.hide();
- }
- if (smartWizard.current_index != (last + 1)) {
- next.show()
- }
- }
- if (smartWizard.current_index == (last + 1)) {
- box.find('.sw-btn-group').remove()
- }
- }
- toggleBtn();
- });
- </script>
|