OrganizationController.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Actions\Cdmuser;
  4. use App\Admin\Actions\UpdateCdms;
  5. use App\Models\Area;
  6. use App\Models\Organization;
  7. use Encore\Admin\Controllers\AdminController;
  8. use Encore\Admin\Form;
  9. use Encore\Admin\Grid;
  10. use Encore\Admin\Show;
  11. class OrganizationController extends AdminController
  12. {
  13. /**
  14. * Title for current resource.
  15. *
  16. * @var string
  17. */
  18. protected $title = '机构列表';
  19. /**
  20. * Make a grid builder.
  21. *
  22. * @return Grid
  23. */
  24. protected function grid()
  25. {
  26. $grid = new Grid(new Organization());
  27. $grid->column('id', __('Id'));
  28. $grid->column('type', __('类型'));
  29. $grid->column('name', __('名称'));
  30. $grid->column('province_id', __('省份'))->display(function ($id){
  31. return Area::where('id',$id)->value('name');
  32. });
  33. $grid->column('city_id', __('城市'))->display(function ($id){
  34. return Area::where('id',$id)->value('name');
  35. });
  36. $grid->column('area_id', __('地区'))->display(function ($id){
  37. return Area::where('id',$id)->value('name');
  38. });
  39. $grid->column('address', __('详细地址'));
  40. $grid->column('latitude', __('经度'));
  41. $grid->column('longitude', __('纬度'));
  42. $grid->column('created_at', __('创建时间'));
  43. $grid->column('updated_at', __('更新时间'));
  44. $grid->actions(function ($actions){
  45. if($actions->row->cdms_id){
  46. $actions->add(new UpdateCdms());
  47. } else {
  48. $actions->add(new Cdmuser());
  49. }
  50. });
  51. return $grid;
  52. }
  53. /**
  54. * Make a show builder.
  55. *
  56. * @param mixed $id
  57. * @return Show
  58. */
  59. protected function detail($id)
  60. {
  61. $show = new Show(Organization::findOrFail($id));
  62. $show->field('id', __('Id'));
  63. $show->field('type', __('Type'));
  64. $show->field('name', __('Name'));
  65. $show->field('province_id', __('Province id'));
  66. $show->field('city_id', __('City id'));
  67. $show->field('area_id', __('Area id'));
  68. $show->field('address', __('Address'));
  69. $show->field('latitude', __('Latitude'));
  70. $show->field('longitude', __('Longitude'));
  71. $show->field('created_at', __('Created at'));
  72. $show->field('updated_at', __('Updated at'));
  73. return $show;
  74. }
  75. /**
  76. * Make a form builder.
  77. *
  78. * @return Form
  79. */
  80. protected function form()
  81. {
  82. $form = new Form(new Organization());
  83. $form->select('type', __('类型'))->options(Organization::getType());
  84. $form->text('name', __('名称'));
  85. $form->select('province_id', __('省份'))->options(function (){
  86. return Area::where('level',1)->pluck('name','id');
  87. })->load('city_id','/admin/api/getCity');
  88. $form->select('city_id', __('城市'))->options(function (){
  89. return Area::where('level',2)->pluck('name','id');
  90. })->load('area_id','/admin/api/getArea');;
  91. $form->select('area_id', __('地区'));
  92. $form->text('address', __('详细地址'));
  93. $form->latlong('latitude', 'longitude','经纬度');
  94. return $form;
  95. }
  96. }