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

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

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

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

  // 列表-增
  add({name, deptId, placeCode, phones, priority, hosId}) {
    let data = {
      qrCode: {
        name,
        deptId,
        placeCode,
        phones,
				priority,
        hosId,
      }
    };

    return this.mainService.coopData("addData", "qrCode", data);
  }

  // 列表-改
  update({name, deptId, placeCode, phones, priority, coopData}) {
    let data:any = {
      name,
      deptId,
      placeCode,
      phones,
			priority
    };
    data = {
      qrCode: {
        ...coopData,
        ...data,
      }
    };
    return this.mainService.coopData("addData", "qrCode", data);
  }

  // 查询科室
  queryOtherTasktype({hosId, keywords}){
    let postData = {
      department: {
        cascadeHosId: hosId,
        dept: keywords,
        searchType: 1,// 简单查询
      },
      idx: 0,
      sum: 9999,
    };
    return this.mainService.getFetchDataList("data", "department", postData).pipe(map((v:any) => {
      if(Array.isArray(v.list)){
        v.list = v.list.map(vv => ({id: vv.id, dept: vv.dept, pcode: vv.pcode}));
      }else{
        v.list = [];
      }
      return v;
    }));
  }
}
