$(function(){
//雷达图
    var data1=$("#paybehavior").val();
    colorChange("pay_behavior",data1);
    var data2=$("#cheatbehavior").val();
    colorChange("cheat_behavior",data2);
    var data3=$("#frequencybehavior").val();
    colorChange("frequency_behavior",data3);
    var data4=$("#accidentbehavior").val();
    colorChange("accident_behavior",data4);
    var data5=$("#perinfobehavior").val();
    colorChange("perinfo_behavior",data5);

    var operate = $("#operate").val();
    if("1" == operate){
        $("#reQueryBtn").attr("disabled", false);
        $("#ajaxBtn").attr("disabled", false);
    }else{
        $("#reQueryBtn").attr("disabled", true);
        $("#ajaxBtn").attr("disabled", true);
    }

    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(){
    $("#ajaxBtn").attr("disabled", true);
    var params = $("#myform").serialize();
    $.ajax({
        type: "POST",
        url: "/claim-risk/LpReport/insertFeedBack.do",
        data: params,
        success: function (msg) {
            $("#ajaxBtn").attr("disabled", false);
            if(msg.resCode=='3'){
                showPopup(350,130,'提示反馈不可以为空！');
            }else if(msg.resCode=='2'){
                showPopup(350,130,'不可以多次反馈！');
            }else if(msg.resCode=='1'){
                showPopup(350,130,'反馈成功！');
            }else{
                showPopup(350,130,'反馈失败！');
            }
        }
    });
});


$("#reQueryBtn").click(function(){
    $("#reQueryBtn").attr("disabled", true);
    var  reportIndex =  $("#reportIndex").val();
    var  claimNo =  $("#claimNo").val();
    if(reportIndex == null || reportIndex == ""){
        alertui("数据无对应的理赔分析报告!");
        return false;
    }
    if(claimNo == null || claimNo == ""){
        alertui("数据无对应的理赔分析报告!");
        return false;
    }
    $.ajax({
        type: "POST",
        url: "/claim-risk/LpReport/reRiskScore.do",
        data : {
            reportIndex:reportIndex,
            claimNo:claimNo
        },
        success: function (data) {
            $("#reQueryBtn").attr("disabled", false);
            var result = data.result;
            if(result == "success"){
                window.location.reload();
                $(".report-td").prop('checked',false);
                $(".search_showbox").val("");
                showPopup(350,130,'重新获取成功！');
            }else if(result == "failure"){
                showPopup(350,130,'重新获取失败！');
            }else{
                showPopup(350,130,'编码冲突！');
            }
        },
        error :function(data){
             $("#reQueryBtn").attr("disabled", false);
            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("pay_behavior"==idname){
        str="支付对象：";
    }else if("perinfo_behavior"==idname){
        str="身份信息：";
    }else if("accident_behavior"==idname){
        str="出险事故：";
    }else if("frequency_behavior"==idname){
        str="高频案件：";
    }else {
        str="团伙骗赔：";
    }
    if(score==3){
        level="低";
        color="green";
    }else if(score>1&&score<=6){
        level="中";
        color="blue";
    } else if(score>=9){
        level="高";
        color="orange";
    }else{
        level="无";
        color="black";
    }

    $("#"+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');
})