/**
 * Created by sff on 2018/1/3.
 */

$(function(){
    //设置尺寸
    function setRem ()// 绑定到窗口的这个事件中
    {
        var whdef = 100/1920;// 表示1920的设计图,使用100PX的默认值
        var wH = window.innerHeight;// 当前窗口的高度
        var wW = window.innerWidth<=1920?1920:window.innerWidth;// 当前窗口的宽度
        var rem = wW * whdef;// 以默认比例值乘以当前窗口宽度,得到该宽度下的相应FONT-SIZE值
        $('html').css('font-size', rem + "px");
    }
    setRem ();
   $(window).resize(function(){
       setRem ();
       window.location.reload();
   });
    // 右上角时间显示
    $("#Timer").text(new Date().toLocaleString());
    setInterval(function(){
        $("#Timer").text(new Date().toLocaleString());
    },1000);
    //首次进入大屏
    cusRateWeek();
    cusRateMonth();
    orderRateMonth();
    orderRateWeek();
    order();
    fact();

    //大屏1分钟刷新一次
    setTimeout(function () {
        cusRateWeek();
        cusRateMonth();
        orderRateMonth();
        orderRateWeek();
        order();
        fact();
    }, 60000);
    //客资完成率 周
    function cusRateWeek(){
        $.ajax({
            type: "POST",
            url: "cusCompleteWeek",
            data: {},
            dataType:'json',
            success: function(ret){
                var inp = '';
                for(var i=0;i<ret.length;i++){
                    inp +="<tr> <td>"+ret[i]['index']+"</td> <td>"+ret[i]['department']+"</td> <td>"+ret[i]['kpi']+"/<small>"+ret[i]['rate']+"</small></td> </tr>";
                }
                $('#week_mkz').html(inp);
            },
        })
    }

    //客资完成率 月
    function cusRateMonth(){
        $.ajax({
            type: "POST",
            url: "cusCompleteMonth",
            data: {},
            dataType:'json',
            success: function(ret){
                var inp = '';
                for(var i=0;i<ret.length;i++){
                    inp +="<tr> <td>"+ret[i]['index']+"</td> <td>"+ret[i]['department']+"</td> <td>"+ret[i]['kpi']+"/<small>"+ret[i]['rate']+"</small></td> </tr>";
                }
                $('#month_mkz').html(inp);
            },
        })
    }

    //订单完成率 月
    function orderRateMonth(){
        $.ajax({
            type: "POST",
            url: "orderCompleteMonth",
            data: {},
            dataType:'json',
            success: function(ret){
                var inp = '';
                for(var i=0;i<ret.length;i++){
                    inp +="<tr> <td>"+ret[i]['index']+"</td> <td>"+ret[i]['department']+"</td> <td>"+ret[i]['kpi']+"/<small>"+ret[i]['rate']+"</small></td> </tr>";
                }
                $('#order_rate_month').html(inp);
            },
        })
    }

    //订单完成率 周
    function orderRateWeek(){
        $.ajax({
            type: "POST",
            url: "orderCompleteWeek",
            data: {},
            dataType:'json',
            success: function(ret){
                var inp = '';
                for(var i=0;i<ret.length;i++){
                    inp +="<tr> <td>"+ret[i]['index']+"</td> <td>"+ret[i]['department']+"</td> <td>"+ret[i]['kpi']+"/<small>"+ret[i]['rate']+"</small></td> </tr>";
                }
                $('#order_rate_week').html(inp);
            },
        })
    }

    //订单
    function order(){
        $.ajax({
            type: "POST",
            url: "orderSort",
            data: {},
            dataType:'json',
            success: function(ret){
                var inp = '';
                for(var i=0;i<ret.length;i++){
                    var index = i+1;
                    inp +="<tr> <td>"+index+"</td> <td>"+ret[i]['sales_staff']+"</td> <td>"+ret[i]['today_order']+"/<small>"+ret[i]['month_order']+"</small></td> </tr>";
                }
                $('#order').html(inp);
            },
        })
    }

    //实收
    function fact(){
        $.ajax({
            type: "POST",
            url: "factSort",
            data: {},
            dataType:'json',
            success: function(ret){
                var inp = '';
                for(var i=0;i<ret.length;i++){
                    inp +="<tr> <td>"+ret[i]['index']+"</td> <td>"+ret[i]['sales_staff']+"</td> <td>"+ret[i]['fact']+"</td> </tr>";
                }
                $('#fact').html(inp);
            },
        })
    }

});