DiseaseCategoryPropertiesController.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Http\Controllers\Controller;
  4. use App\Model\DiseaseCategoryProperties;
  5. use App\Model\DiseaseProperties;
  6. use Encore\Admin\Form;
  7. use Encore\Admin\Grid;
  8. use Encore\Admin\Facades\Admin;
  9. use Encore\Admin\Layout\Content;
  10. use Encore\Admin\Controllers\ModelForm;
  11. class DiseaseCategoryPropertiesController extends Controller
  12. {
  13. use ModelForm;
  14. public function index()
  15. {
  16. return Admin::content(function (Content $content) {
  17. $content->header('疾病属性分类');
  18. $content->description('列表');
  19. $content->body($this->grid());
  20. });
  21. }
  22. public function create()
  23. {
  24. return Admin::content(function (Content $content) {
  25. $content->header('疾病属性分类');
  26. $content->description('新增');
  27. $content->body($this->form());
  28. });
  29. }
  30. public function edit($id)
  31. {
  32. return Admin::content(function (Content $content) use ($id) {
  33. $content->header('疾病属性分类');
  34. $content->description('列表');
  35. $content->body($this->form($id)->edit($id));
  36. });
  37. }
  38. protected function form($id = '')
  39. {
  40. return Admin::form(DiseaseCategoryProperties::class, function (Form $form) {
  41. $form->display('id' , '序号');
  42. $form->text( 'name' , '属性分类名称')->required();
  43. $form->select( 'tag' , '分类')->options([1 => '西医' , 2 => '中医'])->required();
  44. $form->select( 'label' , '所属标签')->options(DiseaseProperties::getLables())->required();
  45. });
  46. }
  47. // Grid
  48. protected function grid()
  49. {
  50. return Admin::grid(DiseaseCategoryProperties::class, function (Grid $grid) {
  51. $grid->id('编号')->sortable();
  52. $grid->name('属性分类名称');
  53. $grid->label('所属标签')->display(function($label) {
  54. return DiseaseProperties::getLables($label) ?? '---';
  55. });
  56. $grid->tag('分类')->display(function($tag){
  57. return 1 == $tag ? '西医' : '中医';
  58. });
  59. $grid->created_at('创建时间');
  60. $grid->updated_at('更新时间');
  61. // 禁用导出数据按钮
  62. $grid->actions(function ($actions) {
  63. $actions->disableView();
  64. //$actions->disableEdit();
  65. });
  66. $grid->filter(function($filter){
  67. // 去掉默认的id过滤器
  68. $filter->disableIdFilter();
  69. // 在这里添加字段过滤器
  70. $filter->equal('tag' , '选择分类')->select([1 => '西医' , 2 => '中医']);
  71. });
  72. });
  73. }
  74. }