import { Component, OnInit, Output, Input } from '@angular/core';
import { EventEmitter } from '@angular/core';
import { ToolService } from 'src/app/services/tool.service';
import { MainService } from 'src/app/services/main.service';

@Component({
  selector: 'app-package-specimen-rule',
  templateUrl: './package-specimen-rule.component.html',
  styleUrls: ['./package-specimen-rule.component.less']
})
export class PackageSpecimenRuleComponent implements OnInit {
  @Output() cancelFlagHand = new EventEmitter();
  constructor(
    private mainService: MainService,
    private tool: ToolService,
  ) { }

  hosId:any = this.tool.getCurrentHospital().id; //当前院区

  ngOnInit() {
    this.getConfig();
  }
  // 隐藏模态框
  hideModal() {
    this.cancelFlagHand.emit(false)
  }

  // 获取配置
  configs:any = {};
  spePackageUrgents = {
    '0': '普标',
    '1': '急标',
  }
  getConfig() {
		let postData = {
      idx: 0,
      sum: 10,
      taskTypeConfig: {
        taskTypeDTO: {
          hosId: {
            id: this.hosId
          },
          ordinaryField: {
            key:"ordinary_field",
            value: 'specimenPackage'
          }
        }
      }
    };

    this.mainService
      .getFetchDataList("simple/data", "taskTypeConfig", postData)
      .subscribe((result) => {
        if (result.status == 200) {
          let configs = result.list[0] || {};

          configs.spePackageDeptList = configs.spePackageDeptList || [];
          configs.spePackageTubeList = configs.spePackageTubeList || [];
          if(configs.spePackageUrgents){
            configs.spePackageUrgentsList = configs.spePackageUrgents.split(',').map(v => ({ name: this.spePackageUrgents[v] }));
          }else{
            configs.spePackageUrgentsList = [];
          }

          this.configs = configs;
        }
      });
  }
}

