require('../css/index.less');
require('../css/reset.css');
require('../css/popup.css');
require('./popup');
const $ = require("jquery");
const { post,config,getUrlArgObject,openNewWin } = require('./promise.js');

// var msg = {
//   age: getUrlArgObject('age'),
//   sex: getUrlArgObject('sex') == '男'?1:(getUrlArgObject('sex') == '女'?2:(getUrlArgObject('sex') == '通用'?3:getUrlArgObject('sex'))),
//   symptom: getUrlArgObject('symptomJson'),
//   vital: getUrlArgObject('vitalJson'),
//   lis: getUrlArgObject('lisJson')? JSON.parse(getUrlArgObject('lisJson')) : [],
//   pacs: getUrlArgObject('pacsJson'),
//   diag: getUrlArgObject('diagJson'),
//   diseaseName: getUrlArgObject('diagJson'),
//   other: getUrlArgObject('otherJson') + getUrlArgObject('pastJson'),
//   hosCode:getUrlArgObject('hospitalCode') || ''
// }//推送相关信息

var msg = JSON.parse(getUrlArgObject('msg'))
window.msg = msg
window.pushMessage = {}

post(config.pushInner,Object.assign(msg,{featureType: '22',ruleType:config.ruleTypeMap['22']})).then((res)=>{
  var data = res.data
  if(data.code == 0) {
    var result = data.data;
    if (result.medicalIndications && result.medicalIndications.length > 0) {//病情提示
      window.pushMessage = result.medicalIndications;//计算的需要的相关数据
      bqtsFun(result.medicalIndications)
    }
  }
});

function bqtsFun(data){//病情提示
  let tmpBqDetailAllStr = '';
  //let names = [];
  for(var k = 0;k < data.length;k++){
    var tmpBq = data[k]
    let hasSritical = false
        let tmpBqStr;
        if(tmpBq.details) {
            for(let i = 0; i < tmpBq.details.length; i++) {
                if(tmpBq.details[i].type == 4) {
                    hasSritical= true
                }
            }
        }
        if(hasSritical) {
          /*if(names.includes(tmpBq.name)){    //name相同去重
            tmpBqStr='';
          }else{
            names.push(tmpBq.name);*/
            tmpBqStr = `<p class="mayIllness">
            <span class="sriticalNameBox"><span class="sriticalName">${tmpBq.name}</span>
            </span>
        </span></p>`
          //}

        } else {
            tmpBqStr =  '<div class="mayIllness">患者可能有 <span class="diagName" data-name='+tmpBq.name+'>'+tmpBq.name+'<span target="_blank" title="点击该名称可看详细说明" class="infoMsg" href="information.html?type=22&position=2&name='+tmpBq.name+'"></span></span> :';
        }

    var tmpBqDetailStr = ''
    for(var m = 0;m < tmpBq.details.length;m++){
      var tmpBqDetail = tmpBq.details[m]
      if(tmpBqDetail.type == 1){
       
        tmpBqDetailStr+=tmpBqStr+ "<div target='_blank' data-scaleName="+tmpBqDetail.content.name+"  class='illnessTable'>【"+tmpBqDetail.content.name+"】</div>"+
          '</div>';
      }
      if(tmpBqDetail.type == 2){
        var deepDetailName = '<div class="modalTitle">'+tmpBqDetail.content.name+'<i class="closeModal"></i></div>'
        var deepDetailStr = ''
        var deepDetailResultStr = ''
        for(var n = 0;n < tmpBqDetail.content.details.length;n++){
          var deepDetail = tmpBqDetail.content.details[n]
          if(deepDetail.controlType == 2){//0-radio,1-checkbox,2-text,3-dropdownlist
            if(deepDetail.isShow == 0) {
              deepDetailStr+='<li class="radioCheck"><span class="modalMaintltle">'+deepDetail.name+': </span>' + deepDetail.value +' '+ deepDetail.uint+'</li>'
            } else {
              deepDetailStr+='<li class="radioCheck"><span class="modalMaintltle">请输入'+deepDetail.name+': </span><input class="'+ tmpBqDetail.content.name+deepDetail.name+'" type="text" placeholder="请输入"' +(deepDetail.isShow == 0 ? 'readonly':'') + ' value="'+deepDetail.value+'"><i class="uint">'+deepDetail.uint+'</i></li>'
            }
          }
          if(deepDetail.controlType == 0){
            let tooDeepDetailStr = ''
            for(var f = 0;f<deepDetail.details.length;f++){
              var tooDeepDetail = deepDetail.details[f]
              if(deepDetail.isShow == '0'){
                if(tooDeepDetail.state == 1) {
                  // tooDeepDetailStr+='<li><span>'+tooDeepDetail.detailName+'</span></li>'
                  tooDeepDetailStr+='<li class="radioChecks" data-select="'+(tooDeepDetail.state == 1?"select":"")+'"><span>'+tooDeepDetail.detailName+'</span></li>'
                }
              }else{
                tooDeepDetailStr+='<li class="radioChecks"><i></i><span>'+tooDeepDetail.detailName+'</span>'+(tooDeepDetail.state == 1?"<a>（智能推荐）</a>":"")+'</li>'
              }
            }
            deepDetailStr+='<li class="radioCheck"><span class="modalMaintltle">'+deepDetail.name+': </span>'+
              '<ul class="clearfix caculateLis" data-isShow="'+deepDetail.isShow+'">'+
              tooDeepDetailStr+
              '</ul>'+
              '</li>'
          }
        }
        for(var v = 0;v < tmpBqDetail.content.result.length;v++){
          deepDetailResultStr+='<p class="result"><span class="calculateName">'+tmpBqDetail.content.result[v].name+'：</span><span class="calculateResult"></span></p>'
        }
        tmpBqDetailStr+='<div class="mayResult">计算公式结果：<span class="mayResultSelect" data-num="'+k+'">'+
          '<span class="makesureResult">请选择</span>'+
          '<span class="sanjiao"></span>'+
          '<div class="popupModal">'+
          deepDetailName+
          '<div class="modalMainTwo">'+
          '<ul class="clearfix">'+
          deepDetailStr+
          '</ul>'+
          '<div class="calculate" data-num="'+k+'">计算</div>'+
          '<p class="calculateError">请填写计算公式内容</p><div class="resultLis">'+
          deepDetailResultStr+
          '</div></div>'+
          '<div class="btnWrap clearfix">'+
          '<div class="sureScore" data-type="2">关闭</div>'+
          '</div>'+
          '</div>'+
          '</span></div></div>'
      }
      if(tmpBqDetail.type == 3){
        var deepDetailName = '<span class="modalMaintltle">'+tmpBqDetail.content.name+': </span>'
        var deepDetailStr = ''
        for(var n = 0;n < tmpBqDetail.content.details.length;n++){
          var deepDetail = tmpBqDetail.content.details[n]
          deepDetailStr+='<li class="radioChecks"><i></i><span>'+deepDetail.detailName+'</span>'+(deepDetail.state == 1?"<a>（智能推荐）</a>":"")+'</li>'
        }
        tmpBqDetailStr+='<div class="mayResult">可能结果：<span class="mayResultSelect" data-num="'+k+'"><span class="makesureResult">请选择</span><i class="sanjiao"></i>'+
          '<div class="popupModal">'+
          '<div class="modalTitle">结果选择<i class="closeModal"></i></div>'+
          '<div class="modalMainOne">'+
          deepDetailName+
          '<ul class="clearfix">'+
          deepDetailStr+
          '</ul>'+
          '</div>'+
          '<div class="btnWrap clearfix">'+
          '<div class="sureScore" data-type="3" data-num="'+k+'">确定</div>'+
          '</div>'+
          '</div>'+
          '</span></div></div>'
      }
      if(tmpBqDetail.type == 4){
        tmpBqDetailStr+=tmpBqStr + 
        // "<div class='sriticalinfo'>诊断要点："+tmpBqDetail.content.name+"</div>"+
          '</div>';
      }
    }
    /*if(tmpBqStr != '' || tmpBqDetailStr != ''){
      $(".conditionHintTipsNull").css("display","none")
    }*/
    tmpBqDetailAllStr += tmpBqDetailStr
  }
  $(".conditionHintTipsNull").html('<div class=" clearfix">'+'<div class="sriticalinfo">'+tmpBqDetailAllStr+'</div></div>')

  $(".mayIllness .infoMsg").on("click",function(){
    const infoMsgName = $(this).parent().attr('data-name')
    openNewWin(`information.html?type=22&position=2&name=${encodeURIComponent(infoMsgName)}`)
  })
  $(".illnessTable").on('click',function(){
    const msg1 = JSON.parse(JSON.stringify(msg))
    msg1.scaleName = $(this).attr('data-scaleName')
    msg1.featureType = 21
    openNewWin(`scale.html?msg=${encodeURIComponent(JSON.stringify(msg1))}`)
  })
}