<?php

namespace App\Http\Controllers\API\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Services\Admin\MenuService;
use Yz;

class MenuController extends Controller
{
    //获取全部菜单
    public function GetList(){
        $type =request('type');
        $page =request('page');
        $pagesize =request('pagesize');
        $s=app()->make(MenuService::class);
        return $s->GetList(['type'=>$type,'page'=>$page,'pagesize'=>$pagesize]);
    }
    //获取可用的一级菜单
    public function GetFatherMenuList(){
        $s=app()->make(MenuService::class);
        return $s->GetFatherMenuList();
    }
    public function AddMenu(){
        $menuInfo =request('menuInfo');
        if($menuInfo['id']){
            if(!($menuInfo['name'] and $menuInfo['pid'] and $menuInfo['url'])){
                return  Yz::echoError('请填写全部信息');
            }
        }else{
            if(!($menuInfo['name'])){
               return Yz::echoError('请填写全部信息');
            }
        }
        $s=app()->make(MenuService::class);
        return $s->AddMenu(['info'=>$menuInfo]);
    }
    public function EditMenu(){
        $menuInfo =request('menuInfo');
        $s=app()->make(MenuService::class);
        return $s->EditMenu(['info'=>$menuInfo]);
    }

}
