| xqd
@@ -0,0 +1,114 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Admin\Controllers;
|
|
|
+
|
|
|
+use App\Models\Vaccines;
|
|
|
+use Encore\Admin\Controllers\AdminController;
|
|
|
+use Encore\Admin\Form;
|
|
|
+use Encore\Admin\Grid;
|
|
|
+use Encore\Admin\Show;
|
|
|
+
|
|
|
+class VaccinesController extends AdminController
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * Title for current resource.
|
|
|
+ *
|
|
|
+ * @var string
|
|
|
+ */
|
|
|
+ protected $title = 'Vaccines';
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Make a grid builder.
|
|
|
+ *
|
|
|
+ * @return Grid
|
|
|
+ */
|
|
|
+ protected function grid()
|
|
|
+ {
|
|
|
+ $grid = new Grid(new Vaccines());
|
|
|
+
|
|
|
+ $grid->column('id', __('Id'));
|
|
|
+ $grid->column('type', __('类型'))->using([1=>'Ⅰ类疫苗',2=>'Ⅱ类疫苗']);
|
|
|
+ $grid->column('name', __('名称'));
|
|
|
+ $grid->column('price', __('价钱'));
|
|
|
+ $grid->column('remark', __('备注'));
|
|
|
+ $grid->column('supplier', __('厂家'));
|
|
|
+ $states = [
|
|
|
+ 'on' => ['value' => 1, 'text' => '启用', 'color' => 'success'],
|
|
|
+ 'off' => ['value' => 0, 'text' => '禁用', 'color' => 'danger'],
|
|
|
+ ];
|
|
|
+ $grid->column('states','状态')->switch($states);
|
|
|
+ $grid->column('created_at', __('创建时间'));
|
|
|
+ $grid->column('updated_at', __('更新时间'));
|
|
|
+
|
|
|
+ $grid->filter(function($filter){
|
|
|
+ /*
|
|
|
+ 搜索:按关键字、ID搜索
|
|
|
+ 筛选:类别筛选
|
|
|
+ 导入、导出
|
|
|
+ */
|
|
|
+ // 在这里添加字段过滤器
|
|
|
+ $filter->column(1/2, function ($filter) {
|
|
|
+ $filter->equal('type', '类型')->select(Vaccines::$_post_type);
|
|
|
+ });
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ //按关键字查询
|
|
|
+ $grid->quickSearch(function ($model, $query) {
|
|
|
+ //$model->whereHas('Vaccines',function ($model) use ($query) {
|
|
|
+ $model->where('type', 'like', "%{$query}%")
|
|
|
+ ->orWhere('name', 'like', "%{$query}%")
|
|
|
+ ->orWhere('id',$query)
|
|
|
+ ->orwhere('supplier','like',"%{$query}%")
|
|
|
+ ->orwhere('remark','like',"{$query}");
|
|
|
+ //});
|
|
|
+ })->placeholder('请输入疫苗id/名称/厂家/备注');
|
|
|
+
|
|
|
+ return $grid;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Make a show builder.
|
|
|
+ *
|
|
|
+ * @param mixed $id
|
|
|
+ * @return Show
|
|
|
+ */
|
|
|
+ protected function detail($id)
|
|
|
+ {
|
|
|
+ $show = new Show(Vaccines::findOrFail($id));
|
|
|
+
|
|
|
+ $show->field('id', __('Id'));
|
|
|
+ $show->field('type', __('分类'))->using([1=>'Ⅰ类疫苗',2=>'Ⅱ类疫苗']);
|
|
|
+ $show->field('price', __('价钱'));
|
|
|
+ $show->field('name', __('名称'));
|
|
|
+ $show->field('remark', __('备注'));
|
|
|
+ $show->field('supplier', __('厂家'));
|
|
|
+ $show->field('created_at', __('创建时间'));
|
|
|
+ $show->field('updated_at', __('更新时间'));
|
|
|
+
|
|
|
+ return $show;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Make a form builder.
|
|
|
+ *
|
|
|
+ * @return Form
|
|
|
+ */
|
|
|
+ protected function form()
|
|
|
+ {
|
|
|
+ $form = new Form(new Vaccines());
|
|
|
+
|
|
|
+ $form->select('type', __('分类'))->options(Vaccines::$_post_type)->default('1');
|
|
|
+ $form->text('name', __('名称'))->rules('required|min:3|max:255',['required'=>'请填写名称','min'=>'名称不能少于3个字符!','max'=>'名称长度过长!']);
|
|
|
+ $form->currency('price', __('价格'))->symbol('分');
|
|
|
+ $form->text('remark', __('备注'))->rules('required',['required'=>'请填写备注!']);;
|
|
|
+ $form->text('supplier', __('厂家'))->rules('required',['required'=>'请填写厂家!']);
|
|
|
+ $states = [
|
|
|
+ 'off' => ['value' => 0, 'text' => '禁用', 'color' => 'danger'],
|
|
|
+ 'on' => ['value' => 1, 'text' => '启用', 'color' => 'success'],
|
|
|
+ ];
|
|
|
+ $form->switch('states','状态')->states($states);
|
|
|
+
|
|
|
+ return $form;
|
|
|
+ }
|
|
|
+}
|