import { Injectable } from '@angular/core';
import {HttpClient} from "@angular/common/http";
import {environment} from "../../../environments/environment";
import {ObjectData} from "../../utils/objectData.service";

@Injectable({
  providedIn: 'root'
})
export class MenuService {

  constructor(private http: HttpClient) { }

  /**
   * 分盘菜单
   * @param params
   * @param callBack
   */
  public assignMenu(params: object, callBack:any) {
    this.http.post(environment.userUrl + 'secMenu/assignMenu', params).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 分盘菜单
   * @param roleId
   * @param callBack
   */
  public queryRoleMenuTree(roleId: string, callBack:any) {
    const param = {
      roleId: roleId
    }
    this.http.get(environment.userUrl + 'secMenu/queryRoleMenuTree?' + ObjectData.objectByString(param)).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 编辑菜单
   * @param params
   * @param callBack
   */
  public editMenu(params: object, callBack:any) {
    this.http.post(environment.userUrl + 'secMenu/editMenu', params).subscribe(data => {
      callBack(data);
    });
  }

}
