$(function(){
//雷达图
    var data1=$("#claimbehavior").val();
    colorChange("claim_behavior",data1);
    var data2=$("#medicaltreatment").val();
    colorChange("medical_treatment",data2);
    var data3=$("#diseaseddiagnosis").val();
    colorChange("disease_diagnosis",data3);
    var data4=$("#drugproject").val();
    colorChange("drug_project",data4);
    var data5=$("#diagnosisproject").val();
    colorChange("diagnosis_project",data5);

    var myChart;
    var domMain = document.getElementById('showecharts');
    var option = {
        tooltip: {},
        name: {
            show: true,
            formatter: null,
            textStyle: {
                //设置颜色
                color: '#272923'
            }
        },
        radar: {
            splitNumber: 3,
            indicator: [
                {name: '索赔行为', max: 10},
                {name: '医疗行为', max: 10},
                {name: '疾病诊断', max: 10},
                {name: '药品项目', max: 10},
                {name: '诊疗项目', max: 10}
            ]
        },
        series: [{
            type: 'radar',
            areaStyle: {
                type: 'default'
            },
            data: [
                {
                    value: [data1, data2, data3, data4, data5],
                    name: '风险等级评分',
                    itemStyle: {
                        normal: {
                            color: '#72abe5',
                            areaStyle: {
                                color: '#72abe5'
                            }
                        }
                    }
                }
            ]
        }]
    };
    myChart = echarts.init(domMain);
    myChart.setOption(option, true);
    $("#temperinner").width(Math.ceil($("#score").val()/ 1000 * ($('#temper').width()))+ 'px');

});

$("#pdfbtn").click(
    function(){
        var height = $("#pdfbox").height();
        var width = $("#pdfbox").width();
        html2canvas(document.getElementById("pdfbox"),{
            scale:2,
            height:height*2,
            width:width*2,
            onrendered: function(canvas) {

                var contentWidth = width;
                var contentHeight = height;
                //一页pdf显示html页面生成的canvas高度;
                var pageHeight =1700;
                //未生成pdf的html页面高度
                var leftHeight = contentHeight;
                //页面偏移
                var position = 0;
                //a4纸的尺寸[595.28,841.89]，html页面生成的canvas在pdf中图片的宽高
                var imgWidth = 1200;
                var imgHeight =height;

                var pageData = canvas.toDataURL('image/jpeg', 1.0);

                var pdf = new jsPDF('', 'pt', 'a4');

                //有两个高度需要区分，一个是html页面的实际高度，和生成pdf的页面高度(841.89)
                //当内容未超过pdf一页显示的范围，无需分页
                /*pdf.addImage(pageData, 'JPEG', 0, 0, imgWidth, imgHeight );*/

                if(leftHeight<pageHeight) {
                    pdf.addImage(pageData, 'JPEG', 0, 0, imgWidth,pageHeight);
                } else {
                        while(leftHeight > 0) {
                            //arg3-->距离左边距;arg4-->距离上边距;arg5-->宽度;arg6-->高度
                            pdf.addImage(pageData, 'JPEG', 0, position,imgWidth, imgHeight)
                            leftHeight -= pageHeight;
                            position -= 841.89;
                            //避免添加空白页
                            if(leftHeight > 0) {
                                //注②
                                pdf.addPage();
                            }
                        }
                    }

                var claim=document.getElementsByName("claimNo_one")[0];
                pdf.save(claim.value+'.pdf');

            }
        });
    }
);


$("#ajaxBtn").click(function(){
    var params = $("#myform").serialize();
    $.ajax({
        type: "POST",
        url: "/icc-front/Assessment/insert.do",
        data: params,
        success: function (msg) {
            if(msg.resCode=='1'){
                showPopup(350,130,'反馈成功！');
            }else{
                showPopup(350,130,'反馈失败！');
            }

        }
    });
});

function showPopup(w,h,Msg){
    var popUp = document.getElementById("popupcontent");
    popUp.style.bottom ="400px";
    popUp.style.left ="375px";
    popUp.style.width = w + "px";
    popUp.style.height = h + "px";
    var baseText="";
    baseText+="<div role=\"document\" class=\"feedback-content\">"+Msg+"</div>";
    baseText+="<div role=\"document\" class=\"recharge-feedbackfoot\" onclick=\"hidePopup();\">确定</div>";
    popUp.innerHTML = baseText;
    popUp.style.visibility = "visible";
}
function hidePopup(){
    var popUp = document.getElementById("popupcontent");
    popUp.style.visibility = "hidden";
}

function   colorChange(idname,score){
    var str="";
    var level="";
    var color="";
    if("claim_behavior"==idname){
        str="索赔行为：";
    }else if("medical_treatment"==idname){
        str="医疗行为：";
    }else if("disease_diagnosis"==idname){
        str="疾病诊断：";
    }else if("drug_project"==idname){
        str="药品项目：";
    }else {
        str="诊疗项目：";
    }
    if(score==1){
        level="低";
        color="green";
    }else if(score>1&&score<=5){
        level="中";
        color="blue";
    }
    else{
        level="高";
        color="orange";
    }
    $("#"+idname).attr("class",color);
    $("#"+idname).html(str+level);
}


function hero()
{
    var herowidth=825;//改为你要的网页宽度
    var heroheight=2000;//改为你要的网页高度
    window.resizeTo(herowidth,heroheight);
}
$(window).resize(function() {
    $("#temperinner").width(Math.ceil($("#score").val()/ 1000 * ($('#temper').width()))+ 'px');
});
