
Array.prototype.push_all = function(arr){
    for(var i= 0; i< arr.length; i++){
        this.push(arr[i])
    }
}
Array.prototype.upd= function (arr){
    this.splice(0)
    this.push_all(arr)
}
/*组件*/
Vue.component('pages',{
    props: ['page_info','change_page'],
    template: '\
	<div class="row dt-rb">\
										<div class="col-sm-6">\
											<div class="dataTables_info" id="DataTables_Table_0_info">\
		显示第 {{page_info.row_from}}到 {{page_info.row_to}}条记录 总数{{page_info.row_cnt}}\
											</div>\
										</div>\
										<template v-if="page_info.lst">\
										<div class="col-sm-6">\
											<div class="dataTables_paginate paging_bootstrap">\
												<ul class="pagination">\
													<template v-if="(page_info.cur_page-1) > 0">\
													<li class="prev " v-on:click="change_page(page_info.cur_page-1)"><a href="#">← 上一页</a></li>\
													</template>\
													<template v-else>\
													<li class="prev disabled" v-on:click="change_page(page_info.cur_page-1)"><a href="#">← 上一页</a></li>\
													</template>\
														<template v-for="v  in page_info.lst">\
															<template v-if="v == page_info.cur_page">\
													<li class="active" v-on:click="change_page(v)"><a href="javascript:void(0)">{{v}}</a></li>\
															</template>\
															<template v-else>\
													<li class="" v-on:click="change_page(v)"><a href="javascript:void(0)">{{v}}</a></li>\
															</template>\
														</template>\
													<template v-if="page_info.cur_page < page_info.page_cnt">\
													<li class="next" v-on:click="change_page(page_info.cur_page + 1)"><a href="#">下一页 → </a></li>\
													</template>\
													<template v-else>\
													<li class="next disabled" v-on:click="change_page(page_info.cur_page + 1)"><a href="#">下一页 → </a></li>\
													</template>\
												</ul>\
											</div>\
										</div>\
										</template>\
									</div>\
	',
})


function ajax_get(url,params,succ,error,complete){
    $.ajax({
        type: "GET",
        url: url,
        data: params,
        dataType: "json",
        processData:true,
        success: function(res){
            if (res.state === '-1')
            {
                window.location.href = '/play/login.html';
            }
            else {
                succ(res);
            }
        },
        error: function (res,err,e) {
            if (error != undefined)
                error(res,err,e);
        },
        complete:function(res){
            if (complete != undefined)
                complete(res);
        }
    });
}

function ajax_post(url,params,succ,error,complete){
    $.ajax({
        type: "POST",
        url: url,
        data: params,
        dataType: "json",
        processData:true,
        success: function(res){
            if (res.state === '-1')
            {
                window.location.href = '/play/login.html';
            }
            else {
                succ(res);
            }
        },
        error: function (res,err,e) {
            if (error != undefined)
                error(res,err,e);
        },
        complete:function(res){
            if (complete != undefined)
                complete(res);
        }
    });
}

function update(_old, _new){
    if(typeof(_old)  == 'object'){
        for(var k in _old){
            var t = typeof(_old[k])
            if(t=='string')
                _old[k] = null;
        }
        for(var k in _new){
            var t = typeof(_new[k])
            if(t=='string')
                _old[k] = _new[k]
        }
    }else if(typeof(_old) == 'Array'){
        _old.upd(_new)
    }
}

function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
    return currentdate;
}

function getFormatDate(d) {
    var date = d;
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 0 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
    return currentdate;
}

function getFormatTime(d) {
    var date = d;
    var seperator2 = ":";
    var h = date.getHours();
    var m = date.getMinutes();
    if (h >= 0 && h <= 9) {
        h = "0" + h;
    }
    if (m >= 0 && m <= 9) {
        m = "0" + m;
    }
    var time = h + seperator2 + m + ":00";
    return time;
}

function getFormatAllTime() {
    var date = new Date();
    var seperator2 = ":";
    var h = date.getHours();
    var m = date.getMinutes();
    var s = date.getSeconds();
    if (h >= 0 && h <= 9) {
        h = "0" + h;
    }
    if (m >= 0 && m <= 9) {
        m = "0" + m;
    }
    if (s >= 0 && s <= 9) {
        s = "0" + s;
    }
    var time = h + seperator2 + m + seperator2 + s;
    return time;
}

function getNowFormatTime(){
    var date = new Date();
    return getFormatTime(date);
}

function getDateFromString(sDate){
    var arr = sDate.split('-');
    var date = new Date();
    date.setFullYear(Number(arr[0]),Number(arr[1])-1,Number(arr[2]));

    return date;
}

function getTimeFromDate(date,stime){
    var arr = stime.split(':');
    date.setHours(Number(arr[0]),Number(arr[1]),Number(arr[2]));

    return date;
}

function getCurDayByDate() {
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var d = new Date(year, month, 0);
        return d.getDate();
}

function getNextDate(AddDayCount) {
    var date = new Date();
    date.setDate(date.getDate() + AddDayCount);//获取AddDayCount天后的日期 
    var year = date.getFullYear();
    var month = date.getMonth() + 1;//获取当前月份的日期 
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    return year + "-" + month + "-" + strDate;
}

function getWeek(date) {
    var week = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日'];

    var currentDate = new Date(date);

    var day = [];

    var show_day = week;//new Array(week);

    var lw = new Date(currentDate.getTime());
    var lastDay = lw.getDay();
    var week;
    if (lastDay === 0) {
        week = show_day[6];
    } else {
        week = show_day[lastDay - 1];
    }

    return week;
}

function GetDateTimeDiff(startTime, endTime) {
    var retValue = {};

    var date3 = endTime.getTime() - startTime.getTime();  //时间差的毫秒数  

    //计算出相差天数  
    var days = Math.floor(date3 / (24 * 3600 * 1000));
    retValue.Days = days;

    var years = Math.floor(days / 365);
    retValue.Years = years;

    var months = Math.floor(days / 30);
    retValue.Months = months;


    //计算出小时数  
    var leave1 = date3 % (24 * 3600 * 1000);    //计算天数后剩余的毫秒数  
    var hours = Math.floor(leave1 / (3600 * 1000));
    retValue.Hours = hours;

    //计算相差分钟数  
    var leave2 = leave1 % (3600 * 1000);        //计算小时数后剩余的毫秒数  
    var minutes = Math.floor(leave2 / (60 * 1000));
    retValue.Minutes = minutes;

    //计算相差秒数  
    var leave3 = leave2 % (60 * 1000);      //计算分钟数后剩余的毫秒数  
    var seconds = Math.round(leave3 / 1000);
    retValue.Seconds = seconds;

    var strTime = "";
    if (years >= 1) {
        strTime = years + "年";
    } else if (months >= 1) {
        strTime = months + "个月";
    } else if (days >= 1) {
        strTime = days + "天";
    } else if (hours >= 1) {
        strTime = hours + "小时";
    } else {
        if (minutes <= 0) {
            strTime = "0分钟";
        } else {
            strTime = minutes + "分钟";
        }
    }
    retValue.PubTime = strTime;     //帖子,文章,博客发表时间的一种简短表示方法  
    return retValue;
}

function getCookie(c_name)
{
    if (document.cookie.length>0)
    {
        c_start=document.cookie.indexOf(c_name + "=")
        if (c_start!=-1)
        {
            c_start=c_start + c_name.length+1
            c_end=document.cookie.indexOf(";",c_start)
            if (c_end==-1) c_end=document.cookie.length
            return unescape(document.cookie.substring(c_start,c_end))
        }
    }
    return ""
}

function GetLocalAddressParam(name)
{
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null)return  unescape(r[2]); return null;
}

function guid() {
    function S4() {
        return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
    }
    return (S4()+S4()+S4()+S4()+S4()+S4()+S4()+S4());
}

function getKeyValue(kv){
    var arr = kv.split('=');

    return {key:arr[0],value:arr[1]};
}

//文档高度
function getDocumentTop() {
    var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0;
    if (document.body) {
        bodyScrollTop = document.body.scrollTop;
    }
    if (document.documentElement) {
        documentScrollTop = document.documentElement.scrollTop;
    }
    scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop; return scrollTop;
}

//可视窗口高度
function getWindowHeight() {
    var windowHeight = 0; if (document.compatMode == "CSS1Compat") {
        windowHeight = document.documentElement.clientHeight;
    } else {
        windowHeight = document.body.clientHeight;
    }
    return windowHeight;
}

//滚动条滚动高度
function getScrollHeight() {
    var scrollHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0;
    if (document.body) {
        bodyScrollHeight = document.body.scrollHeight;
    }
    if (document.documentElement) {
        documentScrollHeight = document.documentElement.scrollHeight;
    }
    scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight; return scrollHeight;
}

