const $ = require("jquery");
const { post,config,getUrlArgObject } = require('./promise.js');
let mrId = getUrlArgObject('mrId')
let hospitalIdUrl = getUrlArgObject('hospitalId') || ''
const codes = getUrlArgObject('codes') || ''
let msg
$(function(){
  function getMRInfo() {
    return post(config.getMr2,{mrId:mrId})
  }
  function getPusgWarning(){
    return  post(config.indicationPush,Object.assign({},msg,{ruleType: '1,2,3,4',hospitalId:hospitalIdUrl||msg.hospitalId}))
  }
  getMRInfo().then(res =>{
    msg = res.data.data ||{}
    getPusgWarning().then(res =>{
      if(res.data.code == '0'){
        const result = res.data.data
        let billMsgList = result.billMsgList || []  //开单合理性提醒
        let highRiskList = result.highRiskList || []  //高危药品、手术
        let criticalValList = result.criticalValList || []  //危急值提醒
        let noteList = result.noteList || []  //检查内容注意事项
        let dubugStr = result.dubugStr || []  //注意调试信息
        let otherList = result.otherList || []  //其他提醒
        codes.indexOf("rationali")>-1&&renderBillingPush(billMsgList,'开单合理性')
        codes.indexOf("highrisk")>-1&&renderBillingPush(highRiskList,'高风险提示')
        codes.indexOf("crivalue")>-1&&renderBillingPush(criticalValList,'危急值提醒')
        //renderBillingPush(noteList,'检查注意事项')
        codes.indexOf("otherremind")>-1&&renderBillingPush(otherList,'其他提醒')
        // renderBillingPush(dubugStr,'注意调试信息')
       
      }

    })
  })
  function renderBillingPush(list,name){
    if(list.length === 0){
      return
    }
    let str = `<p class="contentTitle"><span>${name}</span></p>`
    let infoStr = ""
    for(let i = 0; i < list.length; i++){
      infoStr+= `<li class="contentItem">${list[i].msg}</li>`
    }
    str += `<ul class="contentBox">${infoStr}</ul>`
    $(".content").append(str)
  }
})