ToothLogController.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Models\Student;
  4. use Dcat\Admin\Form;
  5. use Dcat\Admin\Grid;
  6. use Dcat\Admin\Show;
  7. use App\Admin\Controllers\AdminController;
  8. use Dcat\Admin\Layout\Content;
  9. use App\Models\ToothLog;
  10. class ToothLogController extends AdminController
  11. {
  12. public function index($parent, Content $content)
  13. {
  14. $title = '长牙记录';
  15. return $content
  16. ->title($title)
  17. ->description('列表')
  18. // 添加面包屑导航
  19. ->breadcrumb([
  20. 'text' => '返回列表',
  21. 'url' => admin_url('/student'),
  22. 'icon' => 'fa fa-step-backward'
  23. ],['text' => $title]
  24. )
  25. ->body($this->grid($parent));
  26. }
  27. /**
  28. * Make a grid builder.
  29. *
  30. * @return Grid
  31. */
  32. protected function grid($id)
  33. {
  34. return Grid::make(new ToothLog(), function (Grid $grid) use($id) {
  35. //$grid->column('student_id');
  36. $grid->column('student_id','学生信息')->display(function () {
  37. $str = "";
  38. $str .= "<div style='margin-right:10px;display: flex;align-items: center'>";
  39. $str .= '<img data-action="preview-img" src="' . $this->avatar . '" style="height:50px;width:50px;cursor:pointer;margin-right:10px;" class="img img-thumbnail">';
  40. $str .= '<div>';
  41. $str .= '<p style="margin-bottom: 5px">' . $this->username . '</p>';
  42. $str .= '<p style="margin-bottom: 0px">' . $this->mobile . '</p>';
  43. $str .= "</div>";
  44. $str .= "</div>";
  45. return $str;
  46. });
  47. $grid->column('log_time');
  48. $grid->column('desc')->limit(50);
  49. $grid->column('photos')->display(function ($photo_urls){
  50. return json_decode($photo_urls, true);
  51. })->image('', '60', '60');;
  52. $grid->disableActions();
  53. $grid->filter(function (Grid\Filter $filter) {
  54. $filter->panel();
  55. $filter->like('student_id')->width(4);
  56. });
  57. });
  58. }
  59. /**
  60. * Make a show builder.
  61. *
  62. * @param mixed $id
  63. *
  64. * @return Show
  65. */
  66. protected function detail($id)
  67. {
  68. return Show::make($id, new ToothLog(), function (Show $show) {
  69. $show->field('id');
  70. });
  71. }
  72. /**
  73. * Make a form builder.
  74. *
  75. * @return Form
  76. */
  77. protected function form($id)
  78. {
  79. return Form::make(new ToothLog(), function (Form $form) use($id) {
  80. $form->width(6)->datetime('time')->required()->placeholder('时间');
  81. $form->width(6)->textarea('desc')->placeholder('长牙描述');
  82. $form->width(6)->multipleImage('photos')->placeholder('上传照片')->saveAsJson();
  83. });
  84. }
  85. }