const $ = require("jquery");
require("babel-polyfill");
const echarts = require("echarts");
require("./../css/knowledgeTree.less");
require("./../css/common.less");
// require("ztree");
require('./../resources/images/icon.png');
require('./../resources/images/iconOpen.png');
require('./../resources/images/iconClose.png');
require('./../resources/images/node.png');
require('./../resources/images/radioUnSelect.png');
require('./../resources/images/radioSelect.png');
require('./../resources/images/iconSlideUp.png');
require('./../resources/images/iconSlideDown.png');
require('./../resources/images/iconSelect.png');
require('./../resources/images/syflogo.png');
require('./../resources/images/logo.png');
require('./../resources/zTree/js/jquery.ztree.core.min.js');
require('./../resources/zTree/js/jquery.ztree.excheck.min.js')
require('./../resources/zTree/css/zTreeStyle/zTreeStyle.css');
const iconUp = require('./../resources/images/iconUp.png');
const iconDown = require('./../resources/images/iconDown.png');
// document.write("aaaa");
const {getSchema,getTree,getNode,getTab,renderTab,setTabBottomHei,setSelectName,hideSlide} = require('./schemaMap.js');
const {ifHideLogo} = require("./api.js");

window.select_type="疾病";
window.select_type_noSearch="疾病";
window.refreshTree = true


 setHei()
ifHideLogo()
 function setHei(){
    const clientHei = $(window).height()
    const contentHei = 580
    $(".left").css("height",contentHei+'px')
    $(".right").css("height",contentHei+'px')
    console.log('select_type',select_type)
    if(select_type=="疾病"){
        setTabBottomHei(1)
    }else{
        setTabBottomHei(2)
    }
    $("#main").css("height",contentHei-20-20+'px')
 }



 $(window).resize(function(){
    setHei()
    // getSchema(graphTxt,select_type);
 })
//关系图
getSchema("胆囊炎",select_type);
getTree(1,1,"胆囊炎");
$('#searchInp').val("胆囊炎")


//选择类型
$('.select').click(function(e){
    e.stopPropagation();
    hideSlide('selectList')
    const selectListShow = $('.selectList').css('display')
    if(selectListShow == 'none'){
        $('.iconSlide').attr('src','./images/iconSlideUp.png')
    } else{
        $('.iconSlide').attr('src','./images/iconSlideDown.png')
    }
    $('.selectList').fadeToggle()
   
})
$('.selectList .selectItem').click(function(){
    select_type_noSearch = $(this).attr('data-id')
    const txt =  $(this).text()
    const oldTxt = $(".selectedName").html()
    setSelectName(txt)
    $("#searchInp").attr("placeholder",`请输入${txt}名称`)
    if(txt != oldTxt){
        $('#searchInp').val("")
    }
    
})

//搜索节点名
$("#searchInp").bind("input propertychange",function(event){
    const val = $("#searchInp").val().trim()
    if(val){
        getNode(val,select_type_noSearch)
    }else{
        $(".tabNameList").hide()
    }
});

//切换条目
$('.radioItem').click(function(e){
    const initDiag = "胆囊炎"
    const type = $(this).attr('data-type')
    // $(this).children('img').attr('src')
    $('.iconRadio').attr('src','/images/radioUnSelect.png')
    $(this).children('img').attr('src','/images/radioSelect.png')
     $('#searchInp').val(initDiag)
    getTree(type,1,initDiag);
    getSchema(initDiag,select_type);
    // updateTree(initDiag)
})
//搜索
$('#searchBtn').click(function(e){
    e.stopPropagation()
    const val = $('#searchInp').val().trim()
    if(val){
        const clientHei = $(window).height()
        const contentHei = clientHei - 80
        $(".tabNameList").hide()
        getSchema(val,select_type_noSearch).then(()=>{
            if(!window.refreshTree){
                return
            }
                select_type = select_type_noSearch
                
                if(select_type == '疾病'){
                    // $('#searchInp').val("高血压3级")
                    getTree(1,1,val);
                }else if(select_type == '药品通用名'){
                    getTree(0,2,val);
                }else if(select_type == '症状'){
                    getTree(0,3,val);
                }else if(select_type == '手术和操作'){
                    getTree(0,4,val);
                }else if(select_type == '实验室检查'){
                    getTree(0,5,val);
                }else if(select_type == '辅助检查'){
                    getTree(0,6,val);
                }
                if(select_type == '疾病'){
                    $('.iconRadio').attr('src','/images/radioUnSelect.png')
                    $('.ICD10 img').attr('src','/images/radioSelect.png')
                    $(".radioList").show()
                    setTabBottomHei(1)
                }else{
                    $(".radioList").hide()
                    setTabBottomHei(2)
                }
                let renderTabInfo = getTab(select_type) 
                renderTab(renderTabInfo)
           
        })
    }else{
       $('.tabNameListNoSearch').show()
    }
})
let renderTabInfo = getTab("疾病") 
renderTab(renderTabInfo)


$(".tabList").click(function(e){
    e.stopPropagation()
    hideSlide()
})
$(".hideTabList").click(function(e){
    e.stopPropagation()
    hideSlide()
})

//点击页面其他地方关闭下拉
$('html').click(function(){
    hideSlide()
})
		
		
	





