HrBindController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. namespace App\Admin\Controllers\Person;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\HrBind;
  5. use Encore\Admin\Controllers\HasResourceActions;
  6. use Encore\Admin\Facades\Admin;
  7. use Encore\Admin\Form;
  8. use Encore\Admin\Grid;
  9. use Encore\Admin\Layout\Content;
  10. use Encore\Admin\Show;
  11. class HrBindController extends Controller
  12. {
  13. use HasResourceActions;
  14. /**
  15. * Index interface.
  16. *
  17. * @param Content $content
  18. * @return Content
  19. */
  20. public function index(Content $content)
  21. {
  22. return $content
  23. ->header('HR列表')
  24. ->description(' ')
  25. ->body($this->grid());
  26. }
  27. /**
  28. * Show interface.
  29. *
  30. * @param mixed $id
  31. * @param Content $content
  32. * @return Content
  33. */
  34. public function show($id, Content $content)
  35. {
  36. return $content
  37. ->header('Detail')
  38. ->description('description')
  39. ->body($this->detail($id));
  40. }
  41. /**
  42. * Edit interface.
  43. *
  44. * @param mixed $id
  45. * @param Content $content
  46. * @return Content
  47. */
  48. public function edit($id, Content $content)
  49. {
  50. return $content
  51. ->header('Edit')
  52. ->description('description')
  53. ->body($this->form()->edit($id));
  54. }
  55. /**
  56. * Create interface.
  57. *
  58. * @param Content $content
  59. * @return Content
  60. */
  61. public function create(Content $content)
  62. {
  63. return $content
  64. ->header('Create')
  65. ->description('description')
  66. ->body($this->form());
  67. }
  68. /**
  69. * Make a grid builder.
  70. *
  71. * @return Grid
  72. */
  73. protected function grid()
  74. {
  75. $grid = new Grid(new HrBind);
  76. $grid->column('memberInfo.username', '用户名')->width(200);
  77. $grid->column('companyInfo.companyname', '所在企业')->width(200);
  78. $grid->column('memberInfo.mobile', '电话')->width(100);
  79. $grid->column('memberInfo.email', '邮箱')->width(150);
  80. $grid->status('绑定状态')->display(function () {
  81. return $this->status?'绑定':'解绑';
  82. });
  83. $grid->binded_at('操作时间');
  84. if (Admin::user()->can('person_hr_delete')) {
  85. $grid->disableActions();
  86. $grid->tools(function (Grid\Tools $tools) {
  87. $tools->batch(function ($batch) {
  88. $batch->disableDelete(false);
  89. });
  90. });
  91. }
  92. $grid->filter(function ($filter) {
  93. $filter->disableIdFilter();
  94. $filter->column(1/2, function ($filter) {
  95. $filter->like('memberInfo.username', '用户名');
  96. $filter->like('companyInfo.companyname', '企业名称');
  97. });
  98. $filter->column(1/2, function ($filter) {
  99. $filter->like('memberInfo.mobile', '电话');
  100. $filter->like('memberInfo.email', 'Email');
  101. });
  102. });
  103. return $grid;
  104. }
  105. /**
  106. * Make a show builder.
  107. *
  108. * @param mixed $id
  109. * @return Show
  110. */
  111. protected function detail($id)
  112. {
  113. $show = new Show(HrBind::findOrFail($id));
  114. $show->id('ID');
  115. $show->created_at('Created at');
  116. $show->updated_at('Updated at');
  117. return $show;
  118. }
  119. /**
  120. * Make a form builder.
  121. *
  122. * @return Form
  123. */
  124. protected function form()
  125. {
  126. $form = new Form(new HrBind);
  127. $form->display('ID');
  128. $form->display('Created at');
  129. $form->display('Updated at');
  130. return $form;
  131. }
  132. }