| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 | 
							- <?php
 
- namespace App\Admin\Controllers\Content;
 
- use App\Models\Category;
 
- use App\Models\PolicyProperty;
 
- use App\Models\Treat;
 
- use App\Http\Controllers\Controller;
 
- use Encore\Admin\Controllers\HasResourceActions;
 
- use Encore\Admin\Facades\Admin;
 
- use Encore\Admin\Form;
 
- use Encore\Admin\Grid;
 
- use Encore\Admin\Layout\Content;
 
- use Encore\Admin\Show;
 
- use Illuminate\Http\Request;
 
- class TreatController extends Controller
 
- {
 
-     use HasResourceActions;
 
-     /**
 
-      * Index interface.
 
-      *
 
-      * @param Content $content
 
-      * @return Content
 
-      */
 
-     public function index(Content $content)
 
-     {
 
-         return $content
 
-             ->header('待遇分类')
 
-             ->description(' ')
 
-             ->body($this->grid());
 
-     }
 
-     /**
 
-      * Show interface.
 
-      *
 
-      * @param mixed $id
 
-      * @param Content $content
 
-      * @return Content
 
-      */
 
-     public function show($id, Content $content)
 
-     {
 
-         return $content
 
-             ->header('待遇分类')
 
-             ->description(' ')
 
-             ->body($this->detail($id));
 
-     }
 
-     /**
 
-      * Edit interface.
 
-      *
 
-      * @param mixed $id
 
-      * @param Content $content
 
-      * @return Content
 
-      */
 
-     public function edit($id, Content $content)
 
-     {
 
-         return $content
 
-             ->header('待遇分类')
 
-             ->description(' ')
 
-             ->body($this->editForm($id)->edit($id));
 
-     }
 
-     /**
 
-      * Create interface.
 
-      *
 
-      * @param Content $content
 
-      * @return Content
 
-      */
 
-     public function create(Content $content)
 
-     {
 
-         return $content
 
-             ->header('待遇分类')
 
-             ->description(' ')
 
-             ->body($this->form());
 
-     }
 
-     /**
 
-      * Make a grid builder.
 
-      *
 
-      * @return Grid
 
-      */
 
-     protected function grid()
 
-     {
 
-         $grid = new Grid(new Treat);
 
-         $grid->id('id');
 
-         $grid->categorys()->demand('面向人才');
 
-         $grid->title('分类名称');
 
-         $grid->intro('简介');
 
-         $grid->policyproperty()->categoryname('政策层级');
 
-         $grid->sort('排序');
 
-         $grid->disableCreateButton(false);
 
-         $grid->actions(function ($actions) {
 
-             $actions->disableEdit(false);
 
-             $actions->disableDelete(false);
 
-         });
 
-         $grid->filter(function ($filter) {
 
-             $filter->like('categorys.demand', '面向人才');
 
-             $filter->like('title', '分类名称');
 
-         });
 
-         return $grid;
 
-     }
 
-     /**
 
-      * Make a show builder.
 
-      *
 
-      * @param mixed $id
 
-      * @return Show
 
-      */
 
-     protected function detail($id)
 
-     {
 
-         $show = new Show(Treat::findOrFail($id));
 
-         $show->id('ID');
 
-         $show->created_at('Created at');
 
-         $show->updated_at('Updated at');
 
-         return $show;
 
-     }
 
-     /**
 
-      * Make a form builder.
 
-      *
 
-      * @return Form
 
-      */
 
-     protected function form()
 
-     {
 
-         $form = new Form(new Treat);
 
-         $form->text('title', '待遇名称')->rules(['required'], ['required'=>'请填写待遇名称'])->setMustMark();
 
-         $policyProperty = PolicyProperty::select()->pluck('categoryname', 'id');
 
- //        $policyProperty[0] ='不限';
 
-         $form->select('property_id', '政策层次')->options($policyProperty)->load('c_id', admin_base_path('/content/policys/treats/category'))->rules("required")->setMustMark();
 
-         $form->select('c_id', '面向人才')->rules(['required'], ['required'=>'请填写面向人才'])->setMustMark();
 
-         $form->text('intro', '待遇简介')->rules(['required'], ['required'=>'请填写待遇简介'])->setMustMark();
 
-         $form->number('sort', '排序')->default(0)->min(0);
 
-         $form->text('content', '待遇内容')->rules(['required'], ['required'=>'请填写待遇内容'])->setMustMark();
 
-         return $form;
 
-     }
 
-     protected function editForm($id)
 
-     {
 
-         $form = new Form(new Treat);
 
-         $treatData = Treat::where('id', $id)->select('property_id')->first()->toArray();
 
-         $form->text('title', '待遇名称')->rules(['required'], ['required'=>'请填写待遇名称'])->setMustMark();
 
-         $policyProperty = PolicyProperty::select()->pluck('categoryname', 'id');
 
- //        $policyProperty[0] ='不限';
 
-         $arr = array(
 
-             '1' => 'RC_category_fj',
 
-             '2' => 'RC_category_qz',
 
-             '7' => '',
 
-             '8' => 'RC_category'
 
-         );
 
-         $form->select('property_id', '政策层次')->options($policyProperty)->load('c_id', admin_base_path('/content/policys/treats/category'))->rules("required")->setMustMark();
 
-         $form->select('c_id', '面向人才')->options(Category::categoryType($arr[$treatData['property_id']]))->rules(['required'], ['required'=>'请填写面向人才'])->setMustMark();
 
-         $form->text('intro', '待遇简介')->rules(['required'], ['required'=>'请填写待遇简介'])->setMustMark();
 
-         $form->number('sort', '排序')->default(0)->min(0);
 
-         $form->text('content', '待遇内容')->rules(['required'], ['required'=>'请填写待遇内容'])->setMustMark();
 
-         return $form;
 
-     }
 
-     public function category(Request $request)
 
-     {
 
-         $q = $request->get('q');
 
-         $arr = array(
 
-             '1' => 'RC_category_fj',
 
-             '2' => 'RC_category_qz',
 
-             '7' => 'RC_category_jj',
 
-             '8' => 'RC_category'
 
-         );
 
-         return Category::where('alias', $arr[$q])->get(['id',"demand as text"]);
 
-     }
 
-     public function update($id)
 
-     {
 
-         return $this->editForm($id)->update($id);
 
-     }
 
- }
 
 
  |