/**
 * Created by wangwei on 2017-2-14.
 */

function getTotalContractCount(){
    $.ajax({
        type: 'GET',
        url: 'con/conHomepage/statisticalChart/query',
        contentType: "application/json; charset=utf-8",
        success: function (datas) {
            if (datas[0]) {
                $("#con-contract-total-count").append(datas[0].contractSumCount);
                var width1 = (datas[0].currentMonthAppend/datas[0].contractSumCount).toFixed(2)*680;
                var width2 = 680 - width1;
                $('#con-percent-color-1').width(width1);
                $('#con-percent-color-2').width(width2);
                getInceptReceiptContractCount(datas);
            } else {
                $("#con-contract-total-count").append('0.00%');
            }
        }
    });
}

function getInceptReceiptContractCount(datas){
 
       /*     var inceptReceipt=0;
            var inceptNotReceipt=0;
            var terminating=0;
            var signNotIncept=0;
            var others = 0;*/
            
            var conNewCount = 0;
            var conSignCount = 0;
            var conInceptCount = 0;
            var conEndCount = 0;
            var conCancelCount = 0;
            var conChangeCount = 0;
            
            
           // var conContractTotal = datas[0].contractSumCount;
            for(i=0;i<datas.length;i++){
                if(datas[i].contractStatus=="NEW"){
                    $("#newCount").html(datas[i].contractCount);

                    $("#newPercent").html(datas[i].contractCountPercent+'%');
                    
                    //$("#Incept-Receipt-Contract-Count").append((datas[i].contractCount/conContractTotal*100).toFixed(2)+'%');
                    if(datas[i].overdueCount != 0){
                       	$("#newOverdueCount").html(datas[i].overdueCount);
                       	$("#newOverdueCount").css("color","red");
                    }
                    conNewCount=datas[i].contractCount;
                }
                if(datas[i].contractStatus=="SIGN"){
                	$("#signCount").html(datas[i].contractCount);
                    $("#signPercent").html(datas[i].contractCountPercent+'%');
                    if(datas[i].overdueCount != 0){
                       	$("#signOverdueCount").html(datas[i].overdueCount);
                       	$("#signOverdueCount").css("color","red");
                    }
                    conSignCount=datas[i].contractCount;
                }
                if(datas[i].contractStatus=="INCEPT"){
                	$("#inceptCount").html(datas[i].contractCount);
                    $("#inceptPercent").html(datas[i].contractCountPercent+'%');
                    if(datas[i].overdueCount != 0){
                       	$("#inceptOverdueCount").html(datas[i].overdueCount);
                       	$("#inceptOverdueCount").css("color","red");
                    }
                    conInceptCount=datas[i].contractCount;
                }
                if(datas[i].contractStatus=="PENDING"){
                	$("#changeCount").html(datas[i].contractCount);
                    $("#changePercent").html(datas[i].contractCountPercent+'%');
                    if(datas[i].overdueCount != 0){
                       	$("#changeOverdueCount").html(datas[i].overdueCount);
                       	$("#changeOverdueCount").css("color","red");
                    }
                    conChangeCount=datas[i].contractCount;
                }
                if(datas[i].contractStatus=="TERMINATE"){
                   $("#endCount").html(datas[i].contractCount);
                   $("#endPercent").html(datas[i].contractCountPercent+'%');
                   if(datas[i].overdueCount != 0){
                   	$("#endOverdueCount").html(datas[i].overdueCount);
                   	$("#endOverdueCount").css("color","red");
                   }
                   conEndCount=datas[i].contractCount;
                }
                if(datas[i].contractStatus=="CANCEL"){
                    $("#cancelCount").html(datas[i].contractCount);
                    $("#cancelPercent").html(datas[i].contractCountPercent+'%');
                    if(datas[i].overdueCount != 0){
                    	$("#cancelOverdueCount").html(datas[i].overdueCount);
                    	$("#cancelOverdueCount").css("color","red");
  					}
                    conCancelCount=datas[i].contractCount;
                 }
            }
           // var others=conContractTotal-inceptReceipt-inceptNotReceipt-terminating-signNotIncept;
        //    $("#terminate-Count").append( (others/conContractTotal*100).toFixed(2)+'%');
            //合同总数
            var data = [
                {
                    data: [[1, conNewCount]],
                    color: '#58b0ff'
                },
                {
                    data: [[1, conSignCount]],
                    color: '#fd6d4c'
                },
                {
                    data: [[1, conInceptCount]],
                    color: '#e9598d'
                },
                {
                    data: [[1, conChangeCount]],
                    color: '#a5d868'
                },
                {
                    data: [[1, conEndCount]],
                    color: '#ffcf48'
                },
                {
                    data: [[1, conCancelCount]],
                    color: '#00b3b3'
                }
            ];
            var placeholder = $("#row-second-middle-top-body-foot1");
            placeholder.unbind();

            $.plot(placeholder, data, {
                series: {
                    pie: {
                        innerRadius: 0.45,
                        show: true,
                        stroke: {
                            width: 4
                        }
                    }
                }
            });
   
}



function conContractInit() {
    getTotalContractCount();
    //stockCountAndMonthNewCount();
}


