import { Injectable, Injector } from '@angular/core';
import { BaseService } from '../core/base.service';
import { map } from 'rxjs/operators';

@Injectable({
  providedIn: 'root'
})
export class ShipperBaseService extends BaseService {
  $api_get_carless_carrier = ``; // 获取承运人
  $api_get_enterprise_project = `/api/mdc/cuc/enterpriseProject/getEnterpriseProjectList `; // 所属项目列表
  $api_get_staff_list = `/api/mdc/cuc/userApp/getStaffList`; //查询企业项目员工列表(录单员)
  $api_get_network_freight_forwarder = ``; // 获取网络货运人


  constructor(public injector: Injector) {
    super(injector);
  }

  /**
   * 获取无车承运人
   * @returns
   */
  getCarlessCarrier() {
    return
    const params = {
    };
    return this.request(this.$api_get_carless_carrier, params, 'POST').pipe(
      map((res) => {
        if (res) {
          res.map((m: any) => {
            return { label: m.platformName, value: m.operationId };
          });
        }
      }),
    );
  }


  /**
   * 获取所属项目
   * @returns
   */
  getEnterpriseProject(params = {}) {
    return this.request(this.$api_get_enterprise_project, params).pipe(
      map((res: any) => {
        if (!res) {
          return [];
        }
        const list = res.map(((item: any) => {
          return {
            label: item.projectName,
            value: item.enterpriseId
          }
        }))
        const obj = [{ value: '', label: '全部' }];
        return [...obj, ...list];
      })
    )
  }

  /**
   * 获取录单员
   * @returns
   */
  getStaffList(params = {}) {
    return this.request(this.$api_get_staff_list, params).pipe(
      map((res: any) => {
        if (!res) {
          return [];
        }
        const list = res.map(((item: any) => {
          return {
            label: item.name,
            value: item.userId
          }
        }))
        const obj = [{ value: '', label: '全部' }];
        return [...obj, ...list];
      })
    )
  }

  /**
 * 获取网络货运人
 * @returns
 */
  getNetworkFreightForwarder(params = {}) {
    return this.request(this.$api_get_network_freight_forwarder, params).pipe(
      map((res: any) => {
        if (!res) {
          return [];
        }
        const list = res.map(((item: any) => {
          return {
            label: item.name,
            value: item.userId
          }
        }))
        const obj = [{ value: '', label: '全部' }];
        return [...obj, ...list];
      })
    )
  }

}
