import { Injectable } from '@angular/core';
import { MainService } from 'src/app/services/main.service';
import { map } from 'rxjs/operators';

@Injectable({
  providedIn: 'root'
})
export class DepartmentDistanceService {
  constructor(
    private mainService: MainService,
  ) { }

  // 列表-查
  query({pageIndex, pageSize, hosId}) {
    let data = {
      idx: pageIndex - 1,
      sum: pageSize,
      workOrderGradeDept: {
        hosId,
      },
    };
    return this.mainService.getFetchDataList("simple/data", "workOrderGradeDept", data);
  }

  // 列表-删
  delete({id}) {
    return this.mainService.simplePost("rmvData", "workOrderGradeDept", [id]);
  }

  // 列表-增
  add(postData) {
    return this.mainService.simplePost("addData", "workOrderGradeDept", postData);
  }

  // 列表-改
  update(postData) {
    return this.mainService.simplePost("addData", "workOrderGradeDept", postData);
  }

  // 查询任务类型
  queryOtherTasktype({hosId, keywords}){
    let postData = {
      taskType: {
        simpleQuery: true,
        hosId: {id: hosId},
        taskName: keywords,
      },
      idx: 0,
      sum: 9999,
    };
    return this.mainService.getFetchDataList("configuration", "taskType", postData).pipe(map((v:any) => {
      if(Array.isArray(v.list)){
        v.list = v.list.map(vv => ({id: vv.id, name: vv.taskName}));
      }else{
        v.list = [];
      }
      return v;
    }));
  }

  // 获取科室列表
  getDepartments(postData) {
    return this.mainService.getFetchDataList("simple/data", "department", postData).pipe(map((v:any) => {
      if(Array.isArray(v.list)){
        v.list = v.list.map(vv => ({id: vv.id, dept: vv.dept}));
      }else{
        v.list = [];
      }
      return v;
    }));
  }

}


