DistAdminDistributorController.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Repositories\DistAdminDistributor;
  4. use Dcat\Admin\Form;
  5. use Dcat\Admin\Grid;
  6. use Dcat\Admin\Show;
  7. use Dcat\Admin\Http\Controllers\AdminController;
  8. use Dcat\Admin\Layout\Content;
  9. use Dcat\Admin\Admin;
  10. class DistAdminDistributorController extends AdminController
  11. {
  12. /**
  13. * page index
  14. */
  15. public function index(Content $content)
  16. {
  17. return $content
  18. ->header('Distro Management')
  19. ->description('all')
  20. ->breadcrumb(['text'=>'list','url'=>''])
  21. ->body($this->grid());
  22. }
  23. /**
  24. * Make a grid builder.
  25. *
  26. * @return Grid
  27. */
  28. protected function grid()
  29. {
  30. return Grid::make(new DistAdminDistributor(), function (Grid $grid) {
  31. $grid->column('id')->sortable();
  32. $grid->column('company_name','Company Name');
  33. $grid->column('site_name');
  34. $grid->column('level_domain');
  35. $grid->column('country');
  36. $grid->column('contact_number');
  37. $grid->column('service_hotline');
  38. $grid->column('enabled')->switch();
  39. $grid->column('created_at');
  40. $grid->column('updated_at')->sortable();
  41. // 过滤
  42. $grid->filter(function (Grid\Filter $filter) {
  43. $filter->panel();
  44. $filter->expand();
  45. $filter->equal('company_name', 'company name')->width(2);
  46. $filter->equal('site_name')->width(2);
  47. $filter->equal('level_domain')->width(2);
  48. $filter->equal('enabled', 'enabled')->select(config('dictionary.enabled'))->width(2);
  49. });
  50. // 排序
  51. $grid->model()->orderBy("id",'desc');
  52. //按钮
  53. $grid->showQuickEditButton();
  54. $grid->enableDialogCreate();
  55. $grid->disableEditButton();
  56. $grid->disableDeleteButton();
  57. $grid->disableBatchDelete();
  58. });
  59. }
  60. /**
  61. * Make a show builder.
  62. *
  63. * @param mixed $id
  64. *
  65. * @return Show
  66. */
  67. protected function detail($id)
  68. {
  69. return Show::make($id, new DistAdminDistributor(), function (Show $show) {
  70. $show->field('id');
  71. $show->field('company_name','Company Name');
  72. $show->field('company_address','Company Address');
  73. $show->field('site_name');
  74. $show->field('level_domain');
  75. $show->field('country');
  76. $show->field('contact_number');
  77. $show->field('service_hotline');
  78. $show->field('whats_app');
  79. $show->field('facebook');
  80. $show->field('instagram');
  81. $show->field('youtube');
  82. $show->field('linkedin');
  83. $show->field('tiktok');
  84. $show->field('remark');
  85. $show->width(6)->field('enabled')->using(config('dictionary.enabled'));
  86. $show->field('created_at');
  87. $show->field('updated_at');
  88. // 按钮
  89. $show->disableDeleteButton();
  90. });
  91. }
  92. /**
  93. * Make a form builder.
  94. *
  95. * @return Form
  96. */
  97. protected function form()
  98. {
  99. return Form::make(new DistAdminDistributor(), function (Form $form) {
  100. $form->display('id');
  101. $form->text('company_name', 'Company Name')->required();
  102. $form->text('company_address','Company Address');
  103. $form->text('site_name')->required();
  104. $form->text('level_domain')->required();
  105. $form->text('country')->required();
  106. $form->text('contact_number');
  107. $form->text('service_hotline');
  108. $form->text('whats_app');
  109. $form->text('facebook');
  110. $form->text('instagram');
  111. $form->text('youtube');
  112. $form->text('linkedin');
  113. $form->text('tiktok');
  114. $form->textarea('remark');
  115. $form->switch('enabled')->default(1);
  116. //保存后回调
  117. $form->saved(function (Form $form, $result) {
  118. if ($form->isCreating()) {
  119. $newId = $form->getKey();
  120. $distProductCategory = new DistProductCategory();
  121. $distProductCategory->create([
  122. 'parent_id' => 0,
  123. 'name' => 'Default Category',
  124. 'order' => 0,
  125. 'enabled' => 1,
  126. 'dist_id'=>$newId,
  127. ]);
  128. }
  129. });
  130. });
  131. }
  132. }