var pageIndex=1;
$(document).ready(function(){
    //调用查询
    pageIndex=StringUtil.getQueryString('pageIndex');
    if(pageIndex==undefined||pageIndex==null){
        pageIndex=1;
    }
    queryUserApp(pageIndex);
    //绑定hover操作
    $(document).on('mouseenter','.listOperaters',function(){
        $(this).children(".ops_itemDiv").show();
        var width=15;
        $(this).children('div').find('li').each(function(){
            //获取li宽度
            width+=$(this).width();
        });
        $(this).children('div').width(width);
    })
    $(document).on('mouseleave','.listOperaters',function(){
        $(this).children(".ops_itemDiv").hide();
    });

    //日历控件
    layui.use(['layer', 'laydate'], function() {
        var layer = layui.layer;
        laydate = layui.laydate;
        laydate.render({
            elem: '#date1' //指定元素
        });
        laydate.render({
            elem: '#date2' //指定元素
        });
    });

    //行选中事件
    $("#allCheck").find("span").click(function() {
        $(this).toggleClass('checked');
        if($(this).hasClass('checked')){
            //所有列选中
            $(".checker").find("span").each(function () {
                $(this).addClass("checked");
            })
        }else{
            //所有列取消选中
            $(".checker").find("span").each(function () {
                $(this).removeClass("checked");
            })
        }
    });
    //左右div高度相等
    var left_content_height = $(".right-content").height();
    $(".left-content").height(left_content_height+35);
    var sub_left_height=$(".res-menu").height(left_content_height-60);
});

//查询
function queryUserApp(index){
    if(typeof(index)=='undefined'){
        index=1;
    }
    var url=ctx+'/merchantStore/queryMerchantStoreParticulars';
    $.ajax({
        url:url,
        type:"post",
        dataType:"json",
        data:{
            "currPage":index,
            "id":$("#id").val(),
        },
        success:function(result){
            var presentPage = result.currPage;
            //渲染数据
            $('#data_content').empty();
            var header='';
            $.each(result.operationRecordList,function(i){
                var orderNumber = (presentPage-1)*12+i+1;
                var operationRecordList=result.operationRecordList[i];
                var data='';
                data+='<tr class="odd">';
                data+='<td class="textc">'+orderNumber+'</td>';
                if (result.admin){
                    data+='<td class="textc">'+operationRecordList.loginName+'</td>';
                }
                data+='<td class="textc">'+operationRecordList.dictName+'</td>';
                data+='<td class="textc">'+operationRecordList.remark+'</td>';
                var createTime='';
                if(StringUtil.isNotBlank(operationRecordList.createTime)){
                    // createDt=new Date(operationRecordList.createDt).toYYYYMMDD();
                    createTime= dateFtt("yyyy-MM-dd hh:mm:ss",new Date(operationRecordList.createTime));
                }
                data+='<td class="textc">'+createTime+'</td>';
                data+='</tr>';
                $('#data_content').append(data);
            });
            //分页
            $('#pageCount').html(result.pageCount);
            $('#currPage').html(result.currPage);
            $('#totalCount').html(result.count);
            //设置分页
            pageIndex=result.currPage;
            $('#pagination').pagination({
                pageCount: result.pageCount,
                jump: true,
                coping: true,
                jump: true,
                homePage: '首页',
                endPage: '末页',
                prevContent: '上页',
                nextContent: '下页',
                current:result.currPage,
                callback:function(api){
                    pageIndex=api.getCurrent();
                    queryUserApp(api.getCurrent());
                }
            });
        }
    });
    //表头列不选中
    $("#allCheck").find("span").removeClass('checked');
}

function dateFtt(fmt,date)
{ //author: meizz
    var o = {
        "M+" : date.getMonth()+1,                 //月份
        "d+" : date.getDate(),                    //日
        "h+" : date.getHours(),                   //小时
        "m+" : date.getMinutes(),                 //分
        "s+" : date.getSeconds(),                 //秒
        "q+" : Math.floor((date.getMonth()+3)/3), //季度
        "S"  : date.getMilliseconds()             //毫秒
    };
    if(/(y+)/.test(fmt))
        fmt=fmt.replace(RegExp.$1, (date.getFullYear()+"").substr(4 - RegExp.$1.length));
    for(var k in o)
        if(new RegExp("("+ k +")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
    return fmt;
}

