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

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

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

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

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

  /**
   * 业务员密码重置
   * @param paramObject 参数
   * @param callBack
   */
  salesmanPwdReset(paramObject: object, callBack) {
    this.http.post(environment.baseUrl + 'tySalesman/salesmanPwdReset', paramObject).subscribe(data => {
      callBack(data);
    });
  }

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

  /**
   * 修改业务员
   * @param paramObject 参数
   * @param callBack
   */
  getDetailByKey(key: string, callBack) {
    this.http.get(environment.baseUrl + 'tySalesman/getDetailByKey?key=' + key).subscribe(data => {
      callBack(data);
    });
  }

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


}
