OfficeController.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace App\Community\Controllers;
  3. use App\Models\Office;
  4. use App\Models\Organization;
  5. use Encore\Admin\Controllers\AdminController;
  6. use Encore\Admin\Facades\Admin;
  7. use Encore\Admin\Form;
  8. use Encore\Admin\Grid;
  9. use Encore\Admin\Show;
  10. class OfficeController extends AdminController
  11. {
  12. /**
  13. * Title for current resource.
  14. *
  15. * @var string
  16. */
  17. protected $title = '科室';
  18. /**
  19. * Make a grid builder.
  20. *
  21. * @return Grid
  22. */
  23. protected function grid()
  24. {
  25. $grid = new Grid(new Office());
  26. $grid->model()->orderByDesc('id');
  27. $is_admin = Admin::user()->isRole('administrator');
  28. if(!$is_admin){
  29. $grid->model()->where(['org_id'=>Admin::user()->org_id]);
  30. } else {
  31. $grid->column('organizations.name','机构名称');
  32. }
  33. $grid->disableCreateButton(false);
  34. $grid->column('id', __('Id'));
  35. $grid->column('name', __('名称'));
  36. $grid->column('created_at', __('创建时间'));
  37. $grid->column('updated_at', __('更新时间'));
  38. return $grid;
  39. }
  40. /**
  41. * Make a show builder.
  42. *
  43. * @param mixed $id
  44. * @return Show
  45. */
  46. protected function detail($id)
  47. {
  48. $show = new Show(Office::findOrFail($id));
  49. $show->field('id', __('Id'));
  50. $show->field('name', __('Name'));
  51. $show->field('created_at', __('Created at'));
  52. $show->field('updated_at', __('Updated at'));
  53. return $show;
  54. }
  55. /**
  56. * Make a form builder.
  57. *
  58. * @return Form
  59. */
  60. protected function form()
  61. {
  62. $form = new Form(new Office());
  63. $org_id = Admin::user()->org_id;
  64. if($org_id){
  65. $form->hidden('org_id', __('名称'))->value(Admin::user()->org_id);
  66. } else {
  67. $orglist = Organization::pluck('name','id');
  68. $form->select('org_id', __('名称'))->options($orglist);
  69. }
  70. $form->text('name', __('名称'));
  71. $form->setWidth(6);
  72. return $form;
  73. }
  74. }