
$(document).ready(function(){
    initData();
    bthRight();

});


function initData(){
    var  reportIndex =  $("#reportIndex").val();
    var  operate =  $("#operate").val();
    if(reportIndex == null || reportIndex == ""){
        alertui("数据无对应的理赔分析报告!");
        return false;
    }
    $.ajax({
        type: "POST",
        url: "/claim-risk/LpReport/reportInfo",
        data : {
            reportIndex:reportIndex,
            operate:operate
        },
        success: function (data) {
            var result = data.resCode;
            if(result == "1"){
                var pic = data.mapMsg.sex;
                var html = "";
                if(pic=="女"){
                    html = "<img id='agesvg' src='../compass/app/img/0.svg'>"
                }
                if(pic=="男"){
                    html = "<img id='agesvg' src='../compass/app/img/1.svg'>"
                }

                $("#perPic").html(html);
                $("#perName").html(data.mapMsg.name);
                $("#perSex").html(data.mapMsg.sex);
                $("#perAge").html(data.mapMsg.age);
                $("#claimNoId").html(data.mapMsg.claimNo);
                $("#acctdateId").html(data.mapMsg.acctdate);
                $("#regdateId").html(data.mapMsg.regdate);
                $("#pidId").html(data.mapMsg.pid);
                $("#claimNo").html(data.mapMsg.claimNo);
                $("#reportIndex").html(data.mapMsg.reportIndex);
                $("#otherFeedBack").html(data.mapMsg.othertext);
                showMnameInfo(data.riskHintList);
                initRadar(data.mapradar);
                showMnameDetail(data.ratelist);
                if(operate == "1"){
                    showFreshPopup(540,160,'在初审环节做过任何信息修改的，请点击【重新获取】刷新风险分析报告！');
                }

            }else if(result == "0"){
                showPopup(350,130,'加载数据失败！');
            }else{
                showPopup(350,130,'编码冲突！');
            }
        },
        error :function(data){
            $("#reQueryBtn").attr("disabled", false);
            showPopup(350,130,'重新获取失败！');
        }
    });
}

function  showMnameInfo(mnames) {
    if(mnames != null){
        var mname_context = '';
        for (var i = 0; i < mnames.length; i++) {
            var array_element = mnames[i];
            var mname = array_element.Mname;
            var massage = array_element.massage;
            var hisClaimno = array_element.hisClaimno;
            var mname_ = mname;
            var massage_ = massage;
            var hisClaimno_ = hisClaimno;
            if(mname.length > 18){
                mname_ = mname_.substring(0, 18) + "……";
            }
            if(massage.length > 28){
                massage_ = massage_.substring(0, 28) + "……";
            }
            if(hisClaimno.length > 45){
                hisClaimno_ = hisClaimno_.substring(0, 45) + "……";
            }
            var hisclm = '';
            if(hisClaimno != null && hisClaimno !== ''){
                hisclm += (hisClaimno+"").split(",").join("\n");
            }
            // massage = "4444444444444444444444444:{sssssssssssssssssssssssssssssss}";
            mname_context += "<tr>"+
                "<td style='width: 28%;padding: 5px 5px 5px 5px;' title="+ mname +">"+ mname_ +"</td>"+
                "<td style='text-align: left;width: 36%;padding: 5px 6px 5px 7px;' title='"+ massage +"'>"+ massage_ +"</td>"+
                "<td style='text-align: left;width: 36%;padding: 5px 6px 5px 7px;' title='"+ hisclm +"'>"+ hisClaimno_ +"</td>"+
                "</tr>";
        }
        $("#rate-content").html(mname_context);
    }
}

function  showMnameDetail(mnames) {
    if(mnames != null){
        var mname_context = '';
        for (var i = 0; i < mnames.length; i++) {
            var array_element = mnames[i];
            var mname = array_element.Mname;
            var massage = array_element.massage;
            var radioname = array_element.radioname;
            var textname = array_element.textname;
            var text = array_element.text;
            var radio = array_element.radio;
            var placeText = "请输入反馈说明";

            mname_context += "<tr>"+
                "<td style='width: 28%;padding-top: 5px;padding-bottom: 5px;'>"+mname+"</td>"+
                "<td align='center' style='width: 36%;'>"+
                "<div class='fl radio-box'>"+
                "<input  type='radio'   name='"+radioname+"'   value='1' class='report-td' style='margin-right:5px;'>"+"<span style='font-size: 12px;'>"+"准确"+"</span>"+
                "</div>"+
                "<div class='fl radio-box'>"+
                "<input  type='radio'   name='"+radioname+"'   value='-1' class='report-td' style='margin-right:5px;'>"+"<span style='font-size: 12px;'>"+"不准确"+"</span>"+
                "</div>"+
                "<div class='fl radio-box'>"+
                "<input  type='radio'   name='"+radioname+"'   value='0' class='report-td' style='margin-right:5px;'>"+"<span style='font-size: 12px;'>"+"无法判断"+"</span>"+
                "</div>"+
                "</td>"+
                "<td  style='width: 36%;padding-top: 5px;padding-bottom: 5px;'>"+
                "<input  type='text'  name='"+textname+"'  class='search_showbox search_font'   value='"+ text +"'      placeholder='"+placeText+"'>"+
                "</td>"+
                "</tr>";
        }
        $("#rate-detail").html(mname_context);
        console.log(mnames.length);
        for (var i = 0; i < mnames.length; i++) {
            var array_element = mnames[i];
            var radioname = array_element.radioname;
            var radio = array_element.radio;
            if(radio=="1"){
                document.getElementsByName(radioname)[0].checked=true;
            }
            if(radio=="-1"){
                document.getElementsByName(radioname)[1].checked=true;
            }
            if(radio=="0"){
                document.getElementsByName(radioname)[2].checked=true;
            }
        }
    }
}

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


function initRadar(radar){
    //雷达图
    var data1=radar.pay_behavior;
    colorChange("pay_behavior",data1);
    var data2=radar.cheat_behavior;
    colorChange("cheat_behavior",data2);
    var data3=radar.frequency_behavior;
    colorChange("frequency_behavior",data3);
    var data4=radar.accident_behavior;
    colorChange("accident_behavior",data4);
    var data5=radar.perinfo_behavior;
    colorChange("perinfo_behavior",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');
}
/*
$(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,'反馈失败！');
            }
        },
        error :function(data){
            $("#reQueryBtn").attr("disabled", false);
            showPopup(350,130,'提交反馈失败！');
        }
    });
});

$("#reQueryBtn").click(function(){
    refresh();
});

function  refresh() {
    hidePopup();
    $("#mask").css("z-index", 88);
    $("#mask").css("height", $("#app").css("height"));
    $("#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;
    }
    var operate = $("#operate").val();
    $.ajax({
        type: "POST",
        url: "/claim-risk/LpReport/reRiskScore.do",
        data : {
            reportIndex:reportIndex,
            claimNo:claimNo,
            operate:operate
        },
        success: function (data) {

            var result = data.resCode;
            if(result == "1"){
                var pic = data.mapMsg.sex;
                var html = "";
                if(pic=="女"){
                    html = "<img id='agesvg' src='../compass/app/img/0.svg'>"
                }
                if(pic=="男"){
                    html = "<img id='agesvg' src='../compass/app/img/1.svg'>"
                }

                $("#perPic").html(html);
                $("#perName").html(data.mapMsg.name);
                $("#perSex").html(data.mapMsg.sex);
                $("#perAge").html(data.mapMsg.age);
                $("#claimNoId").html(data.mapMsg.claimNo);
                $("#acctdateId").html(data.mapMsg.acctdate);
                $("#regdateId").html(data.mapMsg.regdate);
                $("#pidId").html(data.mapMsg.pid);
                $("#claimNo").html(data.mapMsg.claimNo);
                $("#reportIndex").html(data.mapMsg.reportIndex);
                $("#otherFeedBack").html(data.mapMsg.othertext);
                showMnameInfo(data.riskHintList);
                initRadar(data.mapradar);
                showMnameDetail(data.ratelist);
                $("#reQueryBtn").attr("disabled", false);
                bthRight();
                showPopup(350,130,'重新获取成功！');

            }else if(result == "0"){
                showPopup(350,130,'加载数据失败！');
            }else{
                showPopup(350,130,'编码冲突！');
            }
        },
        error :function(data){
            $("#reQueryBtn").attr("disabled", false);
            showPopup(350,130,'重新获取失败！');
        }
    });

}




//过长的mname截取 末端用…… 省略  鼠标移上可现实全部
function longMnameSub(mnames) {
    var rObj = /{([^=]+=[^,]+),\s+([^={]+=[^,}]+)*/g
    var m = mnames.match(rObj)
    var rNvp = /([^,={\s]+=[^,]+)/g
    var list = [];
    for(var i=0;i<m.length;i++){
        var m2 = m[i].match(rNvp);
        var o={};
        for(j = 0;j<m2.length;j++){
            var arr = m2[j].split("=");
            o[arr[0]] = arr[1];
        }
        list.push(o);
    }
    var mname_context = '';
    for(var j = 0;j < list.length; j ++){
        var mname = list[j].Mname;
        var massage = list[j].massage;
        var mname_ = mname;
        if(mname.length > 18){
            mname_ = mname.substring(0, 18) + "……";
        }
        mname_context += "<tr>"+
            "<td style='width: 28%;padding: 5px 5px 5px 5px;' title="+ mname +">"+ mname_ +"</td>"+
            "<td style='text-align: left;width: 36%;padding: 5px 6px 5px 7px;'>"+ massage +"</td>"+
            "</tr>";
    }
    $("#rate-content").html(mname_context);
}



function showPopup(w,h,Msg){
    var popUp = document.getElementById("popupcontent");
    popUp.style.bottom ="700px";
    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 showFreshPopup(w,h,Msg){
    var popUp = document.getElementById("popupcontent");
    popUp.style.bottom ="840px";
    popUp.style.left ="375px";
    popUp.style.width = w + "px";
    popUp.style.height = h + "px";
    popUp.style.border;
    var baseText="";
    baseText+="<div role=\"document\" class=\"feedback-content1\">"+Msg+"</div>";
    baseText+="<div>";
    baseText+="<div role=\"document\" class=\"recharge-feedbackfoot1\" onclick=\"refresh();\">重新获取</div>";
    baseText+="<div role=\"document\" class=\"recharge-feedbackfoot2\" onclick=\"hidePopup();\">取消</div>";
    baseText+="</div>";

    popUp.innerHTML = baseText;
    popUp.style.visibility = "visible";
    $("#reQueryBtn").attr("disabled", true);
    $("#ajaxBtn").attr("disabled", true);
    $("#mask").css("z-index", 88);
    $("#mask").css("height", $("#app").css("height"));

}



function hidePopup(){
    var popUp = document.getElementById("popupcontent");
    popUp.style.visibility = "hidden";
    $("#reQueryBtn").attr("disabled", false);
    $("#ajaxBtn").attr("disabled", false);
    $("#mask").css("z-index", -1);
    $("#mask").css("height", "1px");
}

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);
}

$(".mname-hide").each(function(){
    var mname = $(this).html();
    if(mname.length() > 40) {
        $(this).html(mname.substring(0, 40) + "...");
    }
});


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');
})


$("#mask").css("height", "100%");