import { Component, OnInit } from "@angular/core";
import { MainService } from "../../../services/main.service";
import { ToolService } from 'src/app/services/tool.service';
import { NzMessageService } from 'ng-zorro-antd';
import { Subject, forkJoin } from 'rxjs';
import { debounceTime } from 'rxjs/operators';

@Component({
  selector: "app-configuration-specimen",
  templateUrl: "./configuration-specimen.component.html",
  styleUrls: ["./configuration-specimen.component.less"],
})
export class ConfigurationSpecimenComponent implements OnInit {
  loading:boolean = false; //页面加载的loading
  btnLoading:boolean = false; //提交按钮的loading
  tabModalName:string = 'characteristics'; //当前选中的tab
  hosId = this.tool.getCurrentHospital().id; //当前院区

	// tab类型
	dictionaryKeyList:any[] = [
		{
			name:'检验标本',key:'examine'
		},
		{
			name:'病理标本',key:'pathology'
		},
    {
      name:'标本打包',key:'specimenPackage'
    },
    {
      name:'标本退回',key:'specimenReturn'
    },
		{
		  name:'检验项目',key:'checkoutProject'
		}
	];

  spePackageUnionReceive:any = undefined;//是否联合标本收取
  speHandoverTubeType:any = undefined;//标本交接默认界面
  spePackageModel:any = undefined;//工单模式
  drugsCreateSign:any = [{ label:'是否开启', value: 0 }];//支持建单并签到
  drugsReceiveSign:any = [{ label:'是否开启', value: 0 }];//支持接单并签到
  drugsStartCheck:any = [{ label:'是否开启', value: 0 }];//起点科室支持核对
  drugsStartCheckScanIds:any = [];//起点核对方式
  drugsStartManual:any = undefined;//起点科室手动填写
  drugsEndCheck:any = [{ label:'是否开启', value: 1 }];//终点科室支持核对
  drugsEndCheckScanIds:any = [];//终点核对方式
  drugsEndManual:any = undefined;//终点科室手动填写
  spePackageAutoPack:any = [{ label:'是否开启', value: 0 }];//自动打包
  spePackageUrgents:any[] = [{label: '急标', value: 1}, {label: '普标', value: 0}];//自动关联急标普标急标
  spePackageTubeIds:any[] = [];// 自动关联试管类型
  spePackageTubeList:any[] = [];// 自动关联试管类型列表
  spePackageInventoryTypes:any[] = [{label: '患者', value: 1}, {label: '试管', value: 2}];//清点方式
  spePrintPosition:any = undefined;//打印位置
  spePackageCreateOrder:any = [{ label:'是否开启', value: 0 }];//生成配送工单
  spePrintTubeType:any = [{ label:'是否开启', value: 0 }];//是否同时打印试管类型
  spePackageCodeSize:any = undefined;//条码打印尺寸
	// 是否允许转派
	handoverOrder:any[] = [
	  {label:'是否开启',value: 0}
	];

  // 交接是否展示试管类型
	speExpandTube:any[] = [
	  {label:'是否开启',value: 0}
	];

  // 是否默认展开
	speDefaultExpandTube:any[] = [
	  {label:'是否开启',value: 0}
	];

  // 是否空单自动关单
	speAutoCloseEmptyOrder:any[] = [
	  {label:'是否开启',value: 0}
	];

  // 工单模式
  spePackageModelList:any[] = [
    { label: '一单一包', value: 1 },
  ];

  // 手动填写
  drugsManualList:any[] = [];

	// 是否支持根据手术新建申请单
	autoCreate:any[] = [
	  {label:'是否开启',value: 0}
	];

	// 是否是否支持门诊新增申请单
	outpatientCreatePathologyForm:any[] = [
	  {label:'是否开启',value: 0}
	];
	outpatientPathologyLabelSize:any; //门诊病理标签样式
	surgeryPathologyLabelSize:any //手术病理标签样式
	// 门诊支持离体并固定
	outpatientInVitroFixation:any[] = [
	  {label:'是否开启',value: 0}
	];

  // 扫描时指定科室不提醒勾选项
  deptNotAlert:any[] = [
    {label:'是否开启',value: 0}
  ];

  // 收取时需扫描二维码
  arriveScanCode:any[] = [
    {label:'是否开启',value: 0}
  ];

  // 必须扫描动态二维码
  arriveScanDynamicCode:any[] = [
    {label:'是否开启',value: 0}
  ];

	// 必须扫描动态二维码
	enterDynamicDigitalKey:any[] = [
	  {label:'是否开启',value: 0}
	];

  // 退回标本是否填写交接人
  returnSpecimenWhetherHandover:any[] = [
    {label:'是否开启',value: 0}
  ];

  // 显示接单签到按钮
  bigScanShowSignBtn:any[] = [
    {label:'是否开启',value: 0}
  ];

  // 支持待到达非本人
  bigScanArriveNotOwner:any[] = [
    {label:'是否开启',value: 0}
  ];

  // 显示建单并签到按钮
  bigScanShowCreateBtn:any[] = [
    {label:'是否开启',value: 0}
  ];

  // 默认扫描标本进入标本扫描页
  defaultScanSpe:any[] = [
    {label:'是否开启',value: 0}
  ];

	// 是否开通收取限制
	speCollectLimit:any[] = [
    {label:'是否开启',value: 0}
  ];

	// 是否支持非起点科室收取
	speCollectSupportNotStartDept:any[] = [
	  {label:'是否开启',value: 0}
	];

	// 限制标本状态收取
	speCollectLimitState:any = [];

	// 限制终点科室收取
	speCollectLimitEndDept:any = [];

	// 限制普通或紧急收取
	speCollectLimitUrgent:any = [];

	// 是否限制重复收取标本
	speCollectLimitRepeat:any[]= [
	  {label:'是否开启',value: 0}
	];

	// 是否限制试管类型收取标本
	speCollectLimitTubeType:any[];

	// 是否开始收取前进入配置页
	speStartCollectShowConfig:any[] = [
	  {label:'是否开启',value: 0}
	];

	// 速冻标本数量控制
	pathologyFrozenSpecimenNum:any = '0';

	// 提示语
	prompt:any;

	//申请单条码设置
	pathologyBarCode:any;

  // 配置
  configs:any = {};
  // 任务类型
  tasktype:any = {};
	specimenStateData:any = [];
	endDeptData:any = [];
	repetitionData:any = [];
	astrictData:any = [
		{name:'普通',id:'0'},
		{name:'紧急',id:'1'},
	]
  searchTimerSubject = new Subject();
  constructor(private mainService: MainService,private tool: ToolService,private msg: NzMessageService) {}

  ngOnInit():void {
    // todo
    this.searchTimerSubject.pipe(debounceTime(500)).subscribe((v) => {
      let fun = v[0];
      fun.call(this, v[1]);
    });
		this.getDeptDic();
    this.getDeptList();
    this.getTaskType();
  }


	// 获取科室类型
	deptItem:any;
	getDeptDic(e:string = ''){
		this.mainService.getDictionary("list", "speState").subscribe((res) => {
			this.specimenStateData = res
		})
		this.mainService.getDictionary("list", "specimen_tube_type").subscribe((res) => {
			this.repetitionData = res
		})
		this.mainService.getDictionary("list", "dept_type").subscribe((res2) => {
			this.deptItem = res2.find(i=>i.name=='检验科室')
			let data1 = {
			  idx: 0,
			  sum: 9999,
			  department: {
			    hospital: { id: this.hosId || "" },
			    type: { id: this.deptItem.id || "" },
					dept: e,
			  },
			};
			this.mainService
			  .getFetchDataList("data", "department", data1)
			  .subscribe((res) => {
			    this.endDeptData = res.list;
			  });
		})
	}

	getEndDeptData(e){
		let data1 = {
		  idx: 0,
		  sum: 9999,
		  department: {
		    hospital: { id: this.hosId || "" },
		    type: { id: this.deptItem.id || "" },
				dept: e,
		  },
		};
		this.mainService
		  .getFetchDataList("data", "department", data1)
		  .subscribe((res) => {
				 this.isLoading = false;
		    this.endDeptData = res.list;
		  });
	}

	// 搜索起点科室
	changeEndDept(e){
		this.searchTimer(this.getEndDeptData, e);
	}

	// 点击数据字典key
	activeDictionaryKey:any = 'examine';
	clickDictionaryKey(item){
	  this.activeDictionaryKey = item.key;
    this.tabModal('characteristics');
		if(item.key=='examine'){
			this.getDeptList();
			this.getTaskType();
		}else if(item.key=='pathology'){
			this.getLabelDic()
			this.getTaskTypesId()
		}else if(item.key=='specimenPackage'){
      this.getDeptList();
      this.loading = true;
      let drugs_bag_check_scan_type$ = this.mainService.getDictionary('list', 'drugs_bag_check_scan_type', true);
      let drugs_bag_manual_type$ = this.mainService.getDictionary('list', 'drugs_bag_manual_type', true);
      let specimen_tube_type$ = this.mainService.getDictionary('list', 'specimen_tube_type', true);
      forkJoin(drugs_bag_check_scan_type$, drugs_bag_manual_type$, specimen_tube_type$).subscribe((data:any[]) => {
        let drugs_bag_check_scan_type = data[0] || [];
        let drugs_bag_manual_type = data[1] || [];
        let specimen_tube_type = data[2] || [];

        this.drugsStartCheckScanIds = drugs_bag_check_scan_type.map(v => ({ label:v.name, value: v.id }));
        this.drugsEndCheckScanIds = drugs_bag_check_scan_type.map(v => ({ label:v.name, value: v.id }));
        this.drugsManualList = drugs_bag_manual_type.map(v => ({ label:v.name, value: v.id }));

        this.spePackageTubeList = specimen_tube_type.map(v => ({ label:v.name, value: v.id }));

        this.getTaskTypeByOrdinary('specimenPackage')
      })
		}
	}

	changeSpeCollect(e){
		if(!e[0].checked){

		}
	}

  // 扫描时指定科室不提醒勾选项
  changeDeptNotAlert(e){
    console.log(e);
    if(!e[0].checked){
      this.deptNotAlertIds = [];
    }
  }

  // 交接是否展示试管类型
  changeSpeExpandTube(e){
    console.log(e);
    if(!e[0].checked){
      this.speDefaultExpandTube[0].checked = false;
    }
  }
  // 收取时需扫描二维码
  changeArriveScanCode(e){
    console.log(e);
    if(!e[0].checked){
      this.arriveScanDynamicCode[0].checked = false;
			this.enterDynamicDigitalKey[0].checked = false;
    }
  }
  // 用户输入搜索
  isLoading: boolean = false;
  deptNotAlertIds:any[] = [];
  spePackageDeptIds:any[] = [];
  deptList:any[] = [];
  changeDept(e) {
    this.searchTimer(this.getDeptList, e);
  }
  // 边输入边搜索节流阀
  searchTimer(fun, e) {
    this.isLoading = true;
    this.searchTimerSubject.next([fun, e]);
  }
  openDeptList(flag){
    if(flag){
      this.getDeptList();
    }
  }
  //获取科室列表
  getDeptList(e:string = '') {
    let postData:any = {
      idx: 0,
      sum: 20,
      department: {
        searchType: 1,// 简单查询
        hospital: { id: this.hosId },
        dept: e,
      }
    };
    this.isLoading = true;
    this.mainService.getFetchDataList("simple/data", "department", postData)
      .subscribe((result) => {
        this.isLoading = false;
        if (result.status == 200) {
          this.deptList = result.list || [];
        }
      });
  }

  // 切换tab
  tabModal(tabModalName:string){
    this.tabModalName = tabModalName;
  }

	//病理标本保存
	submitPathologyForm(){
		let postData:any = {
		  id: this.configs.id,
		  taskType: this.taskTypeData.id,
		  hosId: this.hosId,
		  autoCreate: this.autoCreate[0].checked ? 1 : 0,
			outpatientCreatePathologyForm: this.outpatientCreatePathologyForm[0].checked ? 1 : 0,
			outpatientInVitroFixation: this.outpatientInVitroFixation[0].checked ? 1 : 0,
			pathologyBarCode : this.pathologyBarCode,
			pathologyFrozenSpecimenNum : this.pathologyFrozenSpecimenNum,
			prompt : this.prompt?this.prompt:undefined,
			outpatientPathologyLabelSize:{
				id:this.outpatientPathologyLabelSize
			},
			surgeryPathologyLabelSize:{
				id:this.surgeryPathologyLabelSize
			},
		};
		this.btnLoading = true;
		this.mainService
		  .simplePost("addData", "taskTypeConfig", postData)
		  .subscribe((result) => {
		    this.btnLoading = false;
		    if (result.status == 200) {
		      this.getConfig();
		    }
		  });
	}

  // 检验标本保存
  submitForm() {
    if(!this.tasktype.id){
      this.msg.create("warning", "请先配置患者陪检任务类型！");
      return;
    }
    if(this.deptNotAlert[0].checked && !this.deptNotAlertIds.length){
      this.msg.create("warning", "请选择科室！");
      return;
    }
    let postData:any = {
      id: this.configs.id,
      taskType: this.tasktype.id,
      hosId: this.hosId,
      speHandoverTubeType: this.speHandoverTubeType,
      deptNotAlert: this.deptNotAlert[0].checked ? 1 : 0,
      arriveScanCode: this.arriveScanCode[0].checked ? 1 : 0,
      arriveScanDynamicCode: this.arriveScanDynamicCode[0].checked ? 1 : 0,
			enterDynamicDigitalKey: this.enterDynamicDigitalKey[0].checked ? 1 : 0,
      returnSpecimenWhetherHandover: this.returnSpecimenWhetherHandover[0].checked ? 1 : 0,
      bigScanShowSignBtn: this.bigScanShowSignBtn[0].checked ? 1 : 0,
      bigScanArriveNotOwner: this.bigScanArriveNotOwner[0].checked ? 1 : 0,
      bigScanShowCreateBtn: this.bigScanShowCreateBtn[0].checked ? 1 : 0,
      defaultScanSpe: this.defaultScanSpe[0].checked ? 1 : 0,
      deptNotAlertIds: this.deptNotAlertIds && this.deptNotAlertIds.length>0 ? this.deptNotAlertIds.toString() : undefined,
			speCollectLimit: this.speCollectLimit[0].checked ? 1 : 0,
			speCollectSupportNotStartDept: null,
			speCollectLimitRepeat: null,
			speCollectLimitTubeType: null,
			speStartCollectShowConfig: null,
			speCollectLimitState: null,
			speCollectLimitEndDept: null,
			speCollectLimitUrgent: null,
			handoverOrder: this.handoverOrder[0].checked ? 1 : 0,
			speExpandTube: this.speExpandTube[0].checked ? 1 : 0,
			speDefaultExpandTube: this.speDefaultExpandTube[0].checked ? 1 : 0,
			speAutoCloseEmptyOrder: this.speAutoCloseEmptyOrder[0].checked ? 1 : 0,
		};
		if(this.speCollectLimit[0].checked){
			postData.speCollectSupportNotStartDept = this.speCollectSupportNotStartDept[0].checked ? 1 : 0;
			postData.speCollectLimitRepeat = this.speCollectLimitRepeat[0].checked ? 1 : 0;
			postData.speCollectLimitTubeType = this.speCollectLimitTubeType && this.speCollectLimitTubeType.length>0 ? this.speCollectLimitTubeType.toString() : undefined;
			postData.speStartCollectShowConfig = this.speStartCollectShowConfig[0].checked ? 1 : 0;
			postData.speCollectLimitState = this.speCollectLimitState && this.speCollectLimitState.length>0 ? this.speCollectLimitState.toString() : undefined;
			postData.speCollectLimitEndDept = this.speCollectLimitEndDept && this.speCollectLimitEndDept.length>0 ? this.speCollectLimitEndDept.toString() : undefined;
			postData.speCollectLimitUrgent = this.speCollectLimitUrgent && this.speCollectLimitUrgent.length>0 ? this.speCollectLimitUrgent.toString() : undefined;
		}else{
			postData.speCollectSupportNotStartDept = undefined;
			postData.speCollectLimitRepeat = undefined;
			postData.speCollectLimitTubeType = undefined;
			postData.speStartCollectShowConfig = undefined;
			postData.speCollectLimitState = undefined;
			postData.speCollectLimitEndDept = undefined;
			postData.speCollectLimitUrgent = undefined;
		}
    this.btnLoading = true;
    this.mainService
      .simplePost("addData", "taskTypeConfig", postData)
      .subscribe((result) => {
        this.btnLoading = false;
        if (result.status == 200) {
          this.getConfig();
        }
      });
  }

  // 标本打包保存
  submitSpecimenPackageForm() {
    if(!this.tasktype.id){
      this.msg.create("warning", "请先配置关联任务类型！");
      return;
    }
    if(!this.spePackageModel){
      this.msg.create("warning", "请选择工单模式！");
      return;
    }

    if(this.drugsStartCheck[0].checked && !this.drugsStartCheckScanIds.filter(v => v.checked).length){
      this.msg.create("warning", "请选择起点科室的核对方式！");
      return;
    }

    if(this.drugsEndCheck[0].checked && !this.drugsEndCheckScanIds.filter(v => v.checked).length){
      this.msg.create("warning", "请选择终点科室的核对方式！");
      return;
    }

    let postData:any = {
      id: this.configs.id,
      taskType: this.tasktype.id,
      hosId: this.hosId,
      spePackageUnionReceive: this.spePackageUnionReceive,
      spePackageModel: this.spePackageModel || undefined,
      drugsCreateSign: this.drugsCreateSign[0].checked ? 1 : 0,
      drugsReceiveSign: this.drugsReceiveSign[0].checked ? 1 : 0,
      drugsStartCheck: this.drugsStartCheck[0].checked ? 1 : 0,
      drugsStartCheckScanIds: this.drugsStartCheckScanIds.filter(v => v.checked).map(v => v.value).toString() || undefined,
      drugsStartManual: this.drugsStartManual ? { id: this.drugsStartManual } : undefined,
      drugsEndCheck: this.drugsEndCheck[0].checked ? 1 : 0,
      drugsEndCheckScanIds: this.drugsEndCheckScanIds.filter(v => v.checked).map(v => v.value).toString() || undefined,
      drugsEndManual: this.drugsEndManual ? { id: this.drugsEndManual } : undefined,
      spePackageAutoPack: this.spePackageAutoPack[0].checked ? 1 : 0,
      spePackageUrgents: this.spePackageUrgents.filter(v => v.checked).map(v => v.value).toString() || undefined,
      spePackageDeptIds: this.spePackageDeptIds.length ? this.spePackageDeptIds.toString() : undefined,
      spePackageTubeIds: this.spePackageTubeIds.length ? this.spePackageTubeIds.toString() : undefined,
      spePackageInventoryTypes: this.spePackageInventoryTypes.filter(v => v.checked).map(v => v.value).toString() || undefined,
      spePrintPosition: this.spePrintPosition,
      spePackageCreateOrder: this.spePackageCreateOrder[0].checked ? 1 : 0,
      spePrintTubeType: this.spePrintTubeType[0].checked ? 1 : 0,
      spePackageCodeSize: this.spePackageCodeSize || undefined,
    };
    this.btnLoading = true;
    this.mainService
      .simplePost("addData", "taskTypeConfig", postData)
      .subscribe((result) => {
        this.btnLoading = false;
        if (result.status == 200) {
          this.getConfig();
        }
      });
  }

	// 获取标本字典
	labelData:any = [];
	getLabelDic(){
		this.mainService.getDictionary("list", "pathology_label_size").subscribe((data) => {
			this.labelData = data
		});
	}

	// 获取任务类型（病理标本）
	taskTypeData:any;
	getTaskTypesId() {
		this.mainService.getDictionary("list", "ordinary_field").subscribe((data) => {
			this.taskTypeData = data.find(i=>i.value=='pathology')
			this.getConfig();
		});
	}

  //获取任务类型
  getTaskType() {
    this.loading = true;
    let postData = {
      idx: 0,
      sum: 10,
      taskType: {
        simpleQuery: true,
        hosId: {
          id: this.hosId
        },
        associationType: {
          key:"association_types",
          value: 'specimen'
        }
      }
    };
    this.mainService
      .getFetchDataList("simple/data", "taskType", postData)
      .subscribe((result) => {
        this.loading = false;
        if (result.status == 200) {
          this.tasktype = result.list[0] || {};
          this.getConfig();
        }
      });
  }

  //获取任务类型
  getTaskTypeByOrdinary(key) {
    this.loading = true;
    let postData = {
      idx: 0,
      sum: 10,
      taskType: {
        simpleQuery: true,
        hosId: {
          id: this.hosId
        },
        ordinaryField: {
          key:"ordinary_field",
          value: key
        }
      }
    };
    this.mainService
      .getFetchDataList("simple/data", "taskType", postData)
      .subscribe((result) => {
        this.loading = false;
        if (result.status == 200) {
          this.tasktype = result.list[0] || {};
          this.getConfig();
        }
      });
  }

  // 获取配置
  taskTypeDTO:any = {};
  getConfig() {
    this.loading = true;
		let postData = null;
		if(this.activeDictionaryKey=='examine'){
			postData = {
			  idx: 0,
			  sum: 10,
			  taskTypeConfig: {
			    taskTypeDTO: {
			      hosId: {
			        id: this.hosId
			      },
			      associationType: this.tasktype.associationType
			    }
			  }
			};
		}else if(this.activeDictionaryKey=='pathology'){
			postData = {
			  idx: 0,
			  sum: 10,
			  taskTypeConfig: {
					hosId:this.hosId,
					taskType:this.taskTypeData.id
			  }
			};
		}else if(this.activeDictionaryKey=='specimenPackage'){
			postData = {
			  idx: 0,
			  sum: 10,
			  taskTypeConfig: {
			    taskTypeDTO: {
			      hosId: {
			        id: this.hosId
			      },
			      ordinaryField: this.tasktype.ordinaryField
			    }
			  }
			};
		}

    this.mainService
      .getFetchDataList("simple/data", "taskTypeConfig", postData)
      .subscribe((result) => {
        this.loading = false;
        if (result.status == 200) {
          this.configs = result.list[0] || {};
          this.taskTypeDTO = this.configs.taskTypeDTO || {};
					if(this.activeDictionaryKey=='examine'){
            // 检验标本
            this.speHandoverTubeType = this.configs.speHandoverTubeType;
						this.deptNotAlert[0].checked = this.configs.deptNotAlert == 1;
						this.arriveScanCode[0].checked = this.configs.arriveScanCode == 1;
						this.arriveScanDynamicCode[0].checked = this.configs.arriveScanDynamicCode == 1;
						this.enterDynamicDigitalKey[0].checked = this.configs.enterDynamicDigitalKey == 1;
						this.returnSpecimenWhetherHandover[0].checked = this.configs.returnSpecimenWhetherHandover == 1;
						this.bigScanShowSignBtn[0].checked = this.configs.bigScanShowSignBtn == 1;
						this.bigScanArriveNotOwner[0].checked = this.configs.bigScanArriveNotOwner == 1;
						this.bigScanShowCreateBtn[0].checked = this.configs.bigScanShowCreateBtn == 1;
						this.defaultScanSpe[0].checked = this.configs.defaultScanSpe == 1;
						this.deptNotAlertIds = this.configs.deptNotAlertIds ? this.configs.deptNotAlertIds.split(',').map(v => +v) : [];
						this.deptList = this.configs.deptNotAlertList || [];
            this.speCollectLimit[0].checked = this.configs.speCollectLimit == 1;
						this.handoverOrder[0].checked = this.configs.handoverOrder == 1;
						this.speExpandTube[0].checked = this.configs.speExpandTube == 1;
						this.speDefaultExpandTube[0].checked = this.configs.speDefaultExpandTube == 1;
						this.speAutoCloseEmptyOrder[0].checked = this.configs.speAutoCloseEmptyOrder == 1;
						if(this.configs.speCollectLimit == 1){
							this.speCollectSupportNotStartDept[0].checked = this.configs.speCollectSupportNotStartDept == 1;
							this.speCollectLimitRepeat[0].checked  = this.configs.speCollectLimitRepeat == 1;
							this.speCollectLimitTubeType = this.configs.speCollectLimitTubeType ? this.configs.speCollectLimitTubeType.split(',').map(v => +v) : [];
							this.speStartCollectShowConfig[0].checked = this.configs.speStartCollectShowConfig == 1;
							this.speCollectLimitState = this.configs.speCollectLimitState ? this.configs.speCollectLimitState.split(',').map(v => +v) : [];
							this.speCollectLimitEndDept = this.configs.speCollectLimitEndDept ? this.configs.speCollectLimitEndDept.split(',').map(v => +v) : [];
							this.speCollectLimitUrgent = this.configs.speCollectLimitUrgent ? this.configs.speCollectLimitUrgent.split(',').map(v => v) : [];
						}
					}else if(this.activeDictionaryKey=='pathology'){
            // 病理标本
						this.autoCreate[0].checked = this.configs.autoCreate == 1;
						this.outpatientCreatePathologyForm[0].checked = this.configs.outpatientCreatePathologyForm == 1;
						this.outpatientInVitroFixation[0].checked = this.configs.outpatientInVitroFixation == 1;
						this.pathologyBarCode = this.configs.pathologyBarCode;
						this.pathologyFrozenSpecimenNum = this.configs.pathologyFrozenSpecimenNum;
						this.prompt = this.configs.prompt || '';
            this.outpatientPathologyLabelSize = this.configs.outpatientPathologyLabelSize.id; //门诊病理标签样式
						this.surgeryPathologyLabelSize = this.configs.surgeryPathologyLabelSize.id //手术病理标签样式
					}else if(this.activeDictionaryKey=='specimenPackage'){
						// 标本打包
						this.spePackageUnionReceive = this.configs.spePackageUnionReceive || 0;
						this.spePackageModel = this.configs.spePackageModel || undefined;
            this.drugsCreateSign[0].checked = this.configs.drugsCreateSign == 1;
            this.drugsReceiveSign[0].checked = this.configs.drugsReceiveSign == 1;

            this.drugsStartCheck[0].checked = this.configs.drugsStartCheck == 1;
            this.drugsStartCheckScanIds = this.drugsStartCheckScanIds.map(v => ({...v, checked: (this.configs.drugsStartCheckScanIds || '').split(',').includes(v.value.toString())}));
            this.drugsStartManual = this.configs.drugsStartManual ? this.configs.drugsStartManual.id : undefined;

            this.drugsEndCheck[0].checked = true;
            this.drugsEndCheckScanIds = this.drugsEndCheckScanIds.map(v => ({...v, checked: (this.configs.drugsEndCheckScanIds || '').split(',').includes(v.value.toString())}));
            this.drugsEndManual = this.configs.drugsEndManual ? this.configs.drugsEndManual.id : undefined;

            this.spePackageAutoPack[0].checked = this.configs.spePackageAutoPack == 1;
            this.spePackageUrgents = this.spePackageUrgents.map(v => ({...v, checked: (this.configs.spePackageUrgents || '').split(',').includes(v.value.toString())}));
            this.spePackageDeptIds = this.configs.spePackageDeptIds ? this.configs.spePackageDeptIds.split(',').map(v => +v) : [];
            this.deptList = this.configs.spePackageDeptList || [];
            this.spePackageTubeIds = this.configs.spePackageTubeIds ? this.configs.spePackageTubeIds.split(',').map(v => +v) : [];
            this.spePackageInventoryTypes = this.spePackageInventoryTypes.map(v => ({...v, checked: (this.configs.spePackageInventoryTypes || '').split(',').includes(v.value.toString())}));
            this.spePackageCreateOrder[0].checked = this.configs.spePackageCreateOrder == 1;
            this.spePrintTubeType[0].checked = this.configs.spePrintTubeType == 1;
            this.spePackageCodeSize = this.configs.spePackageCodeSize || undefined;

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

  // 修改起点科室支持核对
  changeDrugsStartCheck(e){
    console.log(e);
    if(!e[0].checked){
      this.drugsStartCheckScanIds = this.drugsStartCheckScanIds.map(v => ({...v, checked: false}));
      this.drugsStartManual = undefined;
    }
  }

  // 修改终点科室支持核对
  changeDrugsEndCheck(e){
    console.log(e);
    if(!e[0].checked){
      this.drugsEndCheckScanIds = this.drugsEndCheckScanIds.map(v => ({...v, checked: false}));
      this.drugsEndManual = undefined;
    }
  }

  // 修改自动打包
  changeSpePackageAutoPack(e){
    console.log(e);
    if(!e[0].checked){
      this.spePackageUrgents = this.spePackageUrgents.map(v => ({...v, checked: false}));
      this.spePackageDeptIds = [];
      this.spePackageTubeIds = [];
    }
  }
}
