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 RoleService {

  constructor(private http: HttpClient) { }

  /**
   * 编辑角色
   * @param params
   * @param callBack
   */
  public editRole(params: any, callBack:any) {
    params.time = new Date().getTime();
    this.http.post(environment.baseUrl + 'secRole/editRole', params).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 删除角色
   * @param params
   * @param callBack
   */
  public delRole(params: any, callBack:any) {
    params.time = new Date().getTime();
    this.http.post(environment.baseUrl + 'secRole/delRole', params).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 查询详情
   * @param roleId
   * @param callBack
   */
  public queryDetail(roleId: number, callBack:any) {
    this.http.get(environment.baseUrl + 'secRole/queryDetail?roleId='+roleId).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 查询列表
   * @param params
   * @param callBack
   */
  public queryList(params: any, callBack:any) {
    params.time = new Date().getTime();
    this.http.get(environment.baseUrl + 'secRole/queryList?'+ObjectData.objectByString(params)).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 查询全部角色
   * @param callBack
   */
  public queryAllRole(callBack:any) {
    let params = {
      time: new Date().getTime()
    };
    this.http.get(environment.baseUrl + 'secRole/queryAllRole?'+ObjectData.objectByString(params)).subscribe(data => {
      callBack(data);
    });
  }

}
