OfficeController.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. $is_admin = Admin::user()->isRole('administrator');
  27. if(!$is_admin){
  28. $grid->model()->where(['org_id'=>Admin::user()->org_id]);
  29. } else {
  30. $grid->column('organizations.name','机构名称');
  31. }
  32. $grid->disableCreateButton(false);
  33. $grid->column('id', __('Id'));
  34. $grid->column('name', __('名称'));
  35. $grid->column('created_at', __('创建时间'));
  36. $grid->column('updated_at', __('更新时间'));
  37. return $grid;
  38. }
  39. /**
  40. * Make a show builder.
  41. *
  42. * @param mixed $id
  43. * @return Show
  44. */
  45. protected function detail($id)
  46. {
  47. $show = new Show(Office::findOrFail($id));
  48. $show->field('id', __('Id'));
  49. $show->field('name', __('Name'));
  50. $show->field('created_at', __('Created at'));
  51. $show->field('updated_at', __('Updated at'));
  52. return $show;
  53. }
  54. /**
  55. * Make a form builder.
  56. *
  57. * @return Form
  58. */
  59. protected function form()
  60. {
  61. $form = new Form(new Office());
  62. $org_id = Admin::user()->org_id;
  63. if($org_id){
  64. $form->hidden('org_id', __('名称'))->value(Admin::user()->org_id);
  65. } else {
  66. $orglist = Organization::pluck('name','id');
  67. $form->select('org_id', __('名称'))->options($orglist);
  68. }
  69. $form->text('name', __('名称'));
  70. $form->setWidth(6);
  71. return $form;
  72. }
  73. }