// require('../css/index.less');
require('../css/reset.css');
require('../css/common.less');
// require('../css/popup.css');
// require('../js/popup');
require('../css/treatPlan.less');
const $ = require("jquery");
const { post,config,getUrlArgObject,openNewWin, isIe8 } = require('../js/promise.js');
let generalImg = require('./../images/general.png');
let drugImg = require('./../images/drug.png');
let slideUpImg = require('./../images/slide-up.png');
let slideDownImg = require('./../images/slide-down.png');


const is8Ie = isIe8() //判断是否为IE8
if(is8Ie) {
  let reg = /undefined/g
  generalImg = generalImg.replace(reg, '')
  drugImg = drugImg.replace(reg, '')
  slideUpImg = slideUpImg.replace(reg, '')
  slideDownImg = slideDownImg.replace(reg, '')
}

// 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('diseaseName'),
//   other: getUrlArgObject('otherJson') + getUrlArgObject('pastJson'),
//   hosCode:getUrlArgObject('hospitalCode') || ''
// }//推送相关信息
var msg = JSON.parse(getUrlArgObject('msg'))
window.msg = msg
window.pushMessage = {}
post(config.pushInner,Object.assign({featureType: '8',ruleType:config.ruleTypeMap['8']},msg)).then((res)=>{
  var data = res.data
  if(data.code == 0){
    var result = data.data.treat;
    var num = 0;
    if(result.commonTreatment && result.commonTreatment.content){
      $(".treatPlanNullWrap").css("display","none")
      ++num
      ybzlFun(result.commonTreatment.content)//一般治疗
    }
    if(result.treatmentPlan && result.treatmentPlan.length>0){
      $(".treatMedicineNullText").css("display","none")
      ++num
      cyywFun(result.treatmentPlan)//常用药物
    } 
    
  }else{
    $(".conditionHintZhiliaoNull").css("display","block")
    $(".treatMedicine").css("display","none")
  }
})

function ybzlFun(data){//一般治疗
  $(".conditionHintZhiliaoAp").prepend(`<div class="treatPlanWrap clearfix"><div class="treatPlan"><p class="treatPlanBg"></p><p class="treatPlanTitle clearfix"><img src=${generalImg} title="一般治疗" class="icon"/><img src=${slideUpImg} title="收起" class="slideImg"/>一般治疗</p></div><div class="commonTreat clearfix">${data}</div></div>`)
  $(".diseaseName").html(' ( '+msg.diseaseName.uniqueName+' )')
  $(document).on('click','.treatPlanTitle', function(){
    if($('.slideImg').attr('src') === slideDownImg) {
      $('.slideImg').attr('src', slideUpImg)
    } else {
      $('.slideImg').attr('src', slideDownImg)
    }
    $(".commonTreat").slideToggle(500);
  })
}
function cyywFun(data){//常用药物
  for(let i = 0; i < data.length; i++) {

    let str = `<div class = "diagBox">
      <p class="diagTitle"><i></i>${data[i].title}</p>`
      for(let j = 0; j < data[i].meditionDetails.length; j++) {
        const meditionDetailsItem = data[i].meditionDetails[j]
        if(meditionDetailsItem.description) {
          str += `<p class="diagDescription">${meditionDetailsItem.description}</p>`
        }
        for(let k = 0; k < meditionDetailsItem.treatment.length; k++) {

          const treatmentItem = meditionDetailsItem.treatment[k]
          str += `<p class="drugCategoryBox">${k+1+'. '+treatmentItem.subdrugsName}: `
          for(let l = 0; l < treatmentItem.medicitionsList.length; l++) {
            const medicitionsListItem = treatmentItem.medicitionsList[l]
            str += `<span class="drugNameBox" data-name=${medicitionsListItem.medicitionName}>
              <span class="drugName ${medicitionsListItem.forbidden == 2 ? 'disUse' : ''}">${medicitionsListItem.medicitionName}</span>
              ${medicitionsListItem.forbidden == 1 ? '<span class="infoFlag cautious">慎用</span>': medicitionsListItem.forbidden == 2 ? '<span class="infoFlag disUse">禁用</span>':''}
              ${l === treatmentItem.medicitionsList.length - 1 ? '' :', '}
              <span class="infoMsg" target="_blank"  title="点击该名称可看详细说明"></span>
            </span>`
          }
          str +=`</p>`
        }
      }

      str += `</div>`
    $(".drugWarp").append(`<div>${str}</div>`)
    // $(".drugWarp").append('<div class="medicinePart clearfix">'+str+'<div class="drugCont">'+strPart+'</div></div>')

    
  }
 
  $(".infoMsg").on("click",function(){
    const infoMsgName = $(this).parent().attr('data-name')
    openNewWin(`information.html?type=8&position=5&name=${encodeURIComponent(infoMsgName)}`)
  })
  // for(var i = 0;i < data.length;i++){
  //   var tmpVal = data[i];
  //   var str = '<div class="drugType">'+(i+1)+'. '+tmpVal.bigdrugsName
  //   if(tmpVal.subdrugsName) {
  //     str += '<p>('+tmpVal.subdrugsName+')</p>';
  //   }
  //   str +='</div>'
  //   var strPart = '';
  //   for(var j = 0;j < tmpVal.medicitionsList.length;j++){
  //     var tmpPart = tmpVal.medicitionsList[j]
  //     strPart += '<div class="drug"><span  class="'+(tmpPart.forbidden == 2?'medicine medicineDis':'medicine')+'" data-name='+tmpPart.medicitionName+'>'+tmpPart.medicitionName+(tmpPart.forbidden==0?'':'<span class="'+(tmpPart.forbidden == 1?'medicineWaring':tmpPart.forbidden == 2?'medicineWaringDis':'')+'">'+(tmpPart.forbidden == 1?'慎用':tmpPart.forbidden == 2?'禁用':'')+'</span>') +'<span class="infoMsg" target="_blank" href="drugInfo.html?type=8&position=5&name='+tmpPart.medicitionName+'" title="点击该名称可看详细说明"></span></span> ' +
  //       //隐藏使用率
  //       // '<p class="'+(tmpPart.forbidden == 2?"medicineWaringDisMsg":"")+'"><i>'+tmpPart.rate+'</i> 使用率</p>' +
  //       '</div>'
  //   }
  //   $(".drugWarp").append('<div class="medicinePart clearfix">'+str+'<div class="drugCont">'+strPart+'</div></div>')
  // }
  
}