OrganizationController.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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', __('省份'));
  31. $grid->column('city_id', __('城市'));
  32. $grid->column('area_id', __('地区'));
  33. $grid->column('address', __('详细地址'));
  34. $grid->column('latitude', __('经度'));
  35. $grid->column('longitude', __('纬度'));
  36. $grid->column('created_at', __('创建时间'));
  37. $grid->column('updated_at', __('更新时间'));
  38. $grid->actions(function ($actions){
  39. if($actions->row->cdms_id){
  40. $actions->add(new UpdateCdms());
  41. } else {
  42. $actions->add(new Cdmuser());
  43. }
  44. });
  45. return $grid;
  46. }
  47. /**
  48. * Make a show builder.
  49. *
  50. * @param mixed $id
  51. * @return Show
  52. */
  53. protected function detail($id)
  54. {
  55. $show = new Show(Organization::findOrFail($id));
  56. $show->field('id', __('Id'));
  57. $show->field('type', __('Type'));
  58. $show->field('name', __('Name'));
  59. $show->field('province_id', __('Province id'));
  60. $show->field('city_id', __('City id'));
  61. $show->field('area_id', __('Area id'));
  62. $show->field('address', __('Address'));
  63. $show->field('latitude', __('Latitude'));
  64. $show->field('longitude', __('Longitude'));
  65. $show->field('created_at', __('Created at'));
  66. $show->field('updated_at', __('Updated at'));
  67. return $show;
  68. }
  69. /**
  70. * Make a form builder.
  71. *
  72. * @return Form
  73. */
  74. protected function form()
  75. {
  76. $form = new Form(new Organization());
  77. $form->select('type', __('类型'))->options(Organization::getType());
  78. $form->text('name', __('名称'));
  79. $form->select('province_id', __('省份'))->options(function (){
  80. return Area::where('level',1)->pluck('name','id');
  81. })->load('city_id','/admin/api/getCity');
  82. $form->select('city_id', __('城市'))->options(function (){
  83. return Area::where('level',2)->pluck('name','id');
  84. })->load('area_id','/admin/api/getArea');;
  85. $form->select('area_id', __('地区'));
  86. $form->text('address', __('详细地址'));
  87. $form->decimal('latitude', __('经度'));
  88. $form->decimal('longitude', __('纬度'));
  89. return $form;
  90. }
  91. }