Browse Source

增加help

develop
李可松 4 years ago
parent
commit
33c028488d
  1. 30
      app/AdminSupplier/Controllers/ProductController.php
  2. 110
      resources/views/admin/form/hasmanytable.blade.php

30
app/AdminSupplier/Controllers/ProductController.php

@ -135,9 +135,9 @@ class ProductController extends AdminController
->default(current(Admin::user()->publish_type))
->when(0, function (Form $form) { //旅游线路
$form->table('extends.field_0.project', '包含项目', function (NestedForm $table) {
$table->text('name', '项目名称');
$table->text('num', '数量');
$table->text('price', '费用');
$table->text('name', '');
$table->text('num', '');
$table->text('price', '');
})->help('第一行数据默认是表头,如:项目名称、数量、额外费用');
$form->dateRange('extends.field_0.date.start', 'extends.field_0.date.end', '行程时间');
@ -157,15 +157,15 @@ class ProductController extends AdminController
$form->map('extends.field_1.latitude', 'extends.field_1.longitude', '位置');
})->when(2, function (Form $form) { //景区
$form->table('extends.field_2.open_time', '开放时间', function (NestedForm $table) {
$table->text('node', '节点')->placeholder('如:周一至周五');
$table->text('summer', '夏季')->placeholder('如:08:00~19:00');
$table->text('winter', '冬季')->placeholder('如:08:00~18:00');
$table->text('node', '')->placeholder('如:周一至周五');
$table->text('summer', '')->placeholder('如:08:00~19:00');
$table->text('winter', '')->placeholder('如:08:00~18:00');
})->help('第一行数据默认是表头,如:项目名称、数量、额外费用');
$form->table('extends.field_2.project', '包含项目', function (NestedForm $table) {
$table->text('name', '项目名称');
$table->text('num', '数量');
$table->text('price', '费用');
$table->text('name', '');
$table->text('num', '');
$table->text('price', '');
})->help('第一行数据默认是表头,如:项目名称、数量、额外费用');
$form->text('extends.field_2.name', '景区名');
@ -173,15 +173,15 @@ class ProductController extends AdminController
$form->map('extends.field_2.latitude', 'extends.field_2.longitude', '位置');
})->when(3, function (Form $form) { //餐厅
$form->table('extends.field_3.open_time', '开放时间', function (NestedForm $table) {
$table->text('week', '星期')->placeholder('如:周一至周五');
$table->text('section', '时段')->placeholder('如:上午/下午');
$table->text('time', '时间')->placeholder('如:08:00~18:00');
$table->text('week', '')->placeholder('如:周一至周五');
$table->text('section', '')->placeholder('如:上午/下午');
$table->text('time', '')->placeholder('如:08:00~18:00');
})->help('第一行数据默认是表头,如:项目名称、数量、额外费用');
$form->table('extends.field_3.package', '包含套餐', function (NestedForm $table) {
$table->text('name', '名称')->placeholder('如:清蒸鱿鱼');
$table->text('num', '数量')->placeholder('如:1条');
$table->text('price', '价格')->placeholder('如:99元');
$table->text('name', '')->placeholder('如:清蒸鱿鱼');
$table->text('num', '')->placeholder('如:1条');
$table->text('price', '')->placeholder('如:99元');
})->help('第一行数据默认是表头,如:项目名称、数量、额外费用');
$form->text('extends.field_3.name', '餐厅名');

110
resources/views/admin/form/hasmanytable.blade.php

@ -0,0 +1,110 @@
<style>
.table-has-many .input-group{flex-wrap: nowrap!important}
</style>
<div class="row form-group">
<div class="{{$viewClass['label']}} "><label class="control-label pull-right">{!! $label !!}</label></div>
<div class="{{$viewClass['field']}}">
@include('admin::form.error')
<span name="{{$column}}"></span> {{-- 用于显示错误信息 --}}
<div class="has-many-{{$columnClass}}" >
<table class="table table-has-many has-many-{{$columnClass}}">
<thead>
<tr>
@foreach($headers as $header)
<th>{{ $header }}</th>
@endforeach
<th class="hidden"></th>
@if($options['allowDelete'])
<th></th>
@endif
</tr>
</thead>
<tbody class="has-many-{{$columnClass}}-forms">
@foreach($forms as $pk => $form)
<tr class="has-many-{{$columnClass}}-form fields-group">
<?php $hidden = ''; ?>
@foreach($form->fields() as $field)
@if (is_a($field, Dcat\Admin\Form\Field\Hidden::class))
<?php $hidden .= $field->render(); ?>
@continue
@endif
<td>{!! $field->setLabelClass(['hidden'])->width(12, 0)->render() !!}</td>
@endforeach
<td class="hidden">{!! $hidden !!}</td>
@if($options['allowDelete'])
<td class="form-group">
<div>
<div class="remove btn btn-white btn-sm pull-right"><i class="feather icon-trash"></i></div>
</div>
</td>
@endif
</tr>
@endforeach
</tbody>
</table>
<template class="{{$columnClass}}-tpl">
<tr class="has-many-{{$columnClass}}-form fields-group">
{!! $template !!}
<td class="form-group">
<div>
<div class="remove btn btn-white btn-sm pull-right"><i class="feather icon-trash"></i></div>
</div>
</td>
</tr>
</template>
@if($options['allowCreate'])
<div class="form-group row m-t-10">
<div class="{{$viewClass['field']}}" style="margin-top: 8px">
<div class="add btn btn-primary btn-outline btn-sm"><i class="feather icon-plus"></i>&nbsp;{{ trans('admin.new') }}</div>
</div>
</div>
@endif
@include('admin::form.help-block')
</div>
</div>
</div>
{{--<hr style="margin-top: 0px;">--}}
<script>
var nestedIndex = {!! $count !!},
container = '.has-many-{{ $columnClass }}';
function replaceNestedFormIndex(value) {
return String(value).replace(/{{ Dcat\Admin\Form\NestedForm::DEFAULT_KEY_NAME }}/g, nestedIndex);
}
$(container).on('click', '.add', function () {
var tpl = $('template.{{ $columnClass }}-tpl');
nestedIndex++;
var template = replaceNestedFormIndex(tpl.html());
$('.has-many-{{ $columnClass }}-forms').append(template);
});
$(container).on('click', '.remove', function () {
var $form = $(this).closest('.has-many-{{ $columnClass }}-form');
$form.hide();
$form.find('[required]').prop('required', false);
$form.find('.{{ Dcat\Admin\Form\NestedForm::REMOVE_FLAG_CLASS }}').val(1);
});
</script>
Loading…
Cancel
Save