import { Injectable } from '@angular/core';
import {CommonsService} from './commons.service';
import {environment} from '../../environments/environment';
import {HttpClient} from '@angular/common/http';

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

  constructor(
      private http: HttpClient,
      private commonsService: CommonsService
  ) { }

  /**
   * 增加业务员
   * @param paramObject 参数
   * @param callBack
   */
  insertSalesman(paramObject: object, callBack) {
    this.http.post(environment.baseUrl + 'salesman/insertSalesman', paramObject).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 修改业务员
   * @param paramObject 参数
   * @param callBack
   */
  updateSalesman(paramObject: object, callBack) {
    this.http.post(environment.baseUrl + 'salesman/updateSalesman', paramObject).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 禁用业务员
   * @param paramObject 参数
   * @param callBack
   */
  disableSalesman(paramObject: object, callBack) {
    this.http.post(environment.baseUrl + 'salesman/disableSalesman', paramObject).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 删除业务员
   * @param paramObject 参数
   * @param callBack
   */
  delSalesman(paramObject: object, callBack) {
    this.http.post(environment.baseUrl + 'salesman/delSalesman', paramObject).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 查询业务员
   * @param paramObject 参数
   * @param callBack
   */
  querySalesman(salesmanId: number, callBack) {
    this.http.get(environment.baseUrl + 'salesman/querySalesman?salesmanId=' + salesmanId).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 查询代理商的业务员列表
   * @param paramObject 参数
   * @param callBack
   */
  querySalesmanListByAgent(paramObject: object, callBack) {
    this.http.get(environment.baseUrl + 'salesman/querySalesmanListByAgent?' + this.commonsService.getWhereCondition(paramObject)).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 查询业务员列表
   * @param paramObject 参数
   * @param callBack
   */
  querySalesmanList(paramObject: object, callBack) {
    this.http.get(environment.baseUrl + 'salesman/querySalesmanList?' + this.commonsService.getWhereCondition(paramObject)).subscribe(data => {
      callBack(data);
    });
  }


}
