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

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

  constructor(
    private mainService: MainService,
  ) { }

  // 字典
  getDictionary(type) {
    return this.mainService.getDictionary("list", type);
  }

  // 获取配置列表
  getConfig(postData) {
    return this.mainService.getFetchDataList("simple/data", "taskTypeConfig", postData);
  }

  // 获取其他临床服务任务类型列表
  getTaskTypes(postData) {
    return this.mainService.getFetchDataList("simple/data", "taskType", postData).pipe(map((v:any) => {
      if(Array.isArray(v.list)){
        v.list = v.list.map(vv => ({id: vv.id, taskName: vv.taskName}));
      }else{
        v.list = [];
      }
      return v;
    }));
  }

  // 获取科室列表
  getDepts(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;
    }));
  }

  // simple增删改
  simplePost(type, model, postData) {
    return this.mainService.simplePost(type, model, postData);
  }
}
