123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <?php
- namespace App\Admin\Controllers;
- use App\Models\Activity;
- use App\Models\ActivityRange;
- use App\Models\ActivityWorkStation;
- use Encore\Admin\Controllers\AdminController;
- use Encore\Admin\Facades\Admin;
- use Encore\Admin\Form;
- use Encore\Admin\Grid;
- use Encore\Admin\Show;
- class ActivityController extends AdminController
- {
- /**
- * Title for current resource.
- *
- * @var string
- */
- protected $title = '六进活动';
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- $grid = new Grid(new Activity());
- //权限
- $grid->actions(function ($actions) {
- // 没有`delete-image`权限的角色不显示删除按钮
- if (!Admin::user()->can('delete-activite')) {
- $actions->disableDelete();
- }
- });
- $grid->filter(function($filter){
- $filter->disableIdFilter();
- // $filter->where(function($query){
- // $query->where('activity_range_id=' . $_GET['activity_range_id']);
- // },'hidden');
- // 在这里添加字段过滤器
- $filter->like('title', '活动标题');
- $filter->equal('organiz_type', '机关类型')->select([1=>'党政机关', 2=>'学校', 3=>'企业', 4=>'公共场所', 5=>'社区', 6=>'农村']);
- $filter->expand();
- // $filter->equal('activity_range_id', '活动区域');
- });
- //单个区域查询条件
- if(isset($_GET['belong'])) {
- $grid->model()->where('belong', '=', $_GET['belong']);
- }
- $grid->column('id', __('Id'));
- $grid->column('workstation.name', __('开展单位'));
- $grid->column('organiz_type', __('单位类型'))->using([1=>'党政机关', 2=>'学校', 3=>'企业', 4=>'公共场所', 5=>'社区', 6=>'农村']);
- $grid->column('range.name', __('活动区域'));
- $grid->column('title', __('活动标题'));
- $grid->column('organiz_name', __('单位名称'));
- $grid->column('member_num', __('参加人数'));
- // $grid->column('content', __('活动内容'));
- // $grid->column('ext', __('附件资料'));
- $grid->column('active_time', __('活动时间'));
- $grid->column('creater.name', __('创建者'));
- $grid->column('updater.name', __('修改者'));
- // $grid->column('created_at', __('创建时间'));
- // $grid->column('updated_at', __('修改时间'));
- return $grid;
- }
- /**
- * Make a show builder.
- *
- * @param mixed $id
- * @return Show
- */
- protected function detail($id)
- {
- $show = new Show(Activity::findOrFail($id));
- $show->field('id', __('Id'));
- $show->field('workstation.name', __('开展单位'));
- $show->field('organiz_type', __('单位类型'))->using([1=>'党政机关', 2=>'学校', 3=>'企业', 4=>'公共场所', 5=>'社区', 6=>'农村']);
- $show->field('range.name', __('开展区域'));
- $show->field('title', __('活动标题'));
- $show->field('active_time', __('活动时间'));
- $show->field('organiz_name', __('单位名称'));
- $show->field('member_num', __('参加人数'));
- $show->field('content', __('活动内容'));
- $show->field('ext', __('附件资料'));
- $show->field('creater.name', __('创建者'));
- $show->field('updator.name', __('更新者'));
- // $show->field('created_at', __('Created at'));
- // $show->field('updated_at', __('Updated at'));
- return $show;
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function form()
- {
-
- $form = new Form(new Activity());
- $form->tools(function (Form\Tools $tools) {
- // 去掉`列表`按钮
- $tools->disableList();
-
- // // 去掉`删除`按钮
- // $tools->disableDelete();
-
- // // 去掉`查看`按钮
- // $tools->disableView();
-
-
- });
- $form->select('belong', __('开展单位'))->options(function(){
- $ret = [];
- $stations = ActivityWorkStation::select(['work_station_id as id', 'name'])->get();
- if($stations){
- foreach($stations as $v){
- $ret[$v->id] = $v->name;
- }
- }
- return $ret;
- })->required();
- $form->select('organiz_type', __('被开展单位类型'))->options([1=>'党政机关', 2=>'学校', 3=>'企事业单位', 4=>'公共场所', 5=>'社区', 6=>'农村'])->required();
- $form->select('activity_range_id', __('活动区域'))->options(function(){
- $ret = [];
- $range = ActivityRange::select(['id', 'name'])->get();
- if($range){
- foreach($range as $v){
- $ret[$v->id] = $v->name;
- }
- }
- return $ret;
- })->required();
- $form->datetime('active_time', __('活动时间'))->required();
- $form->text('title', __('活动标题'))->required();
- $form->text('organiz_name', __('单位名称'))->required();
- $form->text('member_num', __('参加人数'))->required();
- $form->text('member', __('主要参加人员'))->required();
- $form->textarea('content', __('活动内容'));
-
- // 多文件
- $form->multipleFile('ext', __('附件资料'))->removable();
- // $form->number('creater', __('Creater'));
- // $form->number('updator', __('Updator'));
- return $form;
- }
- }
|