if(!Promise){
  var Promise = require("bluebird");
  Promise.config({
    longStackTraces: true,
    warnings: true
  })
}

const $ = require("jquery");
const { post,config,getUrlArgObject } = require('./promise.js');
let mrId = getUrlArgObject('mrId')
let hospitalIdUrl = getUrlArgObject('hospitalId') || ''
let msg;

function getMRInfo() {
   return post(config.getMr2,{mrId:mrId})
}
$('.empty').css("display","none")
if(mrId){
  getMRInfo().then(res =>{
    if(res.data.code == '0'){
        msg = res.data.data ||{}
        window.msg = msg
        renderPushData()
    }
  }).catch(function (err) {
      console.log(err);
  })
} else{

}



let disName=""
function handleShow(){
  const newinConf = {
    width: '600',   //窗口的文档显示区的宽度。以像素计。
    height: '826',  //窗口文档显示区的高度。以像素计。
    left: '0',  //窗口的 x 坐标。以像素计。
    top: '0',    //窗口的 y 坐标。以像素计。
    openMode: "_blank"  //每次都是新窗口打开为_blank,打开同一窗口填写任意字符串
  }
  const newWindowLocation = `width=${newinConf.width}, height=${newinConf.height}, left=${newinConf.left}, top=${newinConf.top} scrollbars=yes`
  window.open('./emergency.html?disName='+disName, newinConf.openMode, newWindowLocation)
}
$(document).on('click',".allDis .allName",function(){
  handleShow()
})
$(document).on('click',".singleDis",function(){
  $(this).next().css("display","block")
  $(this).css("display","none")
})
$(document).on('click',".allDis .right,.allDis .secDis",function(){
  $(".allDis").css("display","none")
  $(".singleDis").css("display","block")
})


function renderPushData(){
  return getPushInfo().then(res =>{
    if(res.data.code == "0"){
      const result = res.data.data.debug['数据']
      let allData = {}
      allData.chiefLabel = result.chiefLabel //主诉
      allData.presentLabel = result.presentLabel //现病史
      allData.pastLabel = result.pastLabel //既往史
      allData.personalLabel = result.personalLabel //个人史
      allData.familyLabel = result.familyLabel //家族史
      allData.maritalLabel = result.maritalLabel //婚育史
      allData.menstrualLabel = result.menstrualLabel //月经史
      allData.vitalLabel = result.vitalLabel //体格
      console.log(allData)
      
    }
  })
}

function getPushInfo() {
  return  post(config.pushInner,Object.assign({},msg,{featureType: '1,4,5,6,7,8,9,10',hospitalId:hospitalIdUrl||msg.hospitalId,ruleType:config.ruleTypeMap['22']}))
}