var mmg;
function initGrid(){
    var h = WST.pageHeight();
    var cols = [
            {title:'商品主图', name:'goodsImg', width: 30, renderer: function(val,item,rowIndex){
            	var thumb = item['goodsImg'];
	        	//thumb = thumb.replace('.','_thumb.');
	        	return "
 ";
            }},
            {title:'订单号', name:'orderNo',sortable: true, width: 90},
            {title:'商品', name:'goodsName',sortable: true, width: 100,renderer: function(val,item,rowIndex){
                return "
";
            }},
            {title:'订单号', name:'orderNo',sortable: true, width: 90},
            {title:'商品', name:'goodsName',sortable: true, width: 100,renderer: function(val,item,rowIndex){
                return ""+item['goodsName']+"
";
            }},
            
            {title:'商品评分', name:'goodsScore',sortable: true, width: 80, renderer: function(val,item,rowIndex){
            	var s="
";
	        	for(var i=0;i";
	        	}
	        	s += "
";
	        	return s;
            }},
            {title:'时效评分', name:'timeScore',sortable: true, width: 80, renderer: function(val,item,rowIndex){
            	var s="";
	        	for(var i=0;i";
	        	}
	        	s += "
";
	        	return s;
            }},
            {title:'服务评分', name:'serviceScore',sortable: true, width: 80, renderer: function(val,item,rowIndex){
            	var s="";
	        	for(var i=0;i";
	        	}
	        	s += "
";
	        	return s;
            }},
            {title:'评价内容', name:'content', width: 155},
            {title:'状态', name:'isShow', width: 20,sortable: true, renderer: function(val,item,rowIndex){
            	return (val==0)?" 隐藏":" 显示";
            }},
            {title:'操作', name:'' ,width:95, align:'center', renderer: function(val,item,rowIndex){
                var h = "";
	            if(WST.GRANT.PJGL_02)h += "修改 ";
	            if(WST.GRANT.PJGL_03)h += "删除 "; 
	            return h;
            }}
            ];
 
    mmg = $('.mmg').mmGrid({height: h-85,indexCol: true,indexColWidth:50, cols: cols,method:'POST',
        url: WST.U('admin/goodsappraises/pageQuery'), fullWidthRows: true, autoLoad: true,
        remoteSort:true ,
        sortName: 'orderNo',
        sortStatus: 'desc',
        plugins: [
            $('#pg').mmPaginator({})
        ]
    });  
}
function toDel(id){
	var box = WST.confirm({content:"您确定要删除该记录吗?",yes:function(){
	           var loading = WST.msg('正在提交数据,请稍后...', {icon: 16,time:60000});
	           	$.post(WST.U('admin/goodsappraises/del'),{id:id},function(data,textStatus){
	           			  layer.close(loading);
	           			  var json = WST.toAdminJson(data);
	           			  if(json.status=='1'){
	           			    	WST.msg("操作成功",{icon:1});
	           			    	layer.close(box);
	           		            loadGrid();
	           			  }else{
	           			    	WST.msg(json.msg,{icon:2});
	           			  }
	           		});
	            }});
}
function loadGrid(){
	var query = WST.getParams('.query');
  query.page = 1;
	mmg.load(query);
}
function editInit(){
	
/* 表单验证 */
    $('#goodsAppraisesForm').validator({
            fields: {
                content: {
                  rule:"required;length(3~50)",
                  msg:{length:"评价内容为3-50个字",required:"评价内容为3-50个字"},
                  tip:"评价内容为3-50个字",
                  ok:"",
                },
                score:  {
                  rule:"required",
                  msg:{required:"评分必须大于0"},
                  ok:"",
                  target:"#score_error",
                },
                
            },
          valid: function(form){
            var params = WST.getParams('.ipt');
                //获取修改的评分
                params.goodsScore = $('.goodsScore').find('[name=score]').val();
                params.timeScore = $('.timeScore').find('[name=score]').val();
                params.serviceScore = $('.serviceScore').find('[name=score]').val();
            var loading = WST.msg('正在提交数据,请稍后...', {icon: 16,time:60000});
            $.post(WST.U('admin/goodsappraises/'+((params.id==0)?"add":"edit")),params,function(data,textStatus){
              layer.close(loading);
              var json = WST.toAdminJson(data);
              if(json.status=='1'){
                  WST.msg("操作成功",{icon:1});
                  location.href=WST.U('Admin/goodsappraises/index');
              }else{
                    WST.msg(json.msg,{icon:2});
              }
            });
      }
    });
}
function toolTip(){
    $('body').mousemove(function(e){
    	var windowH = $(window).height();  
        if(e.pageY >= windowH*0.8){
        	var top = windowH*0.233;
        	$('.imged').css('margin-top',-top);
        }else{
        	var top = windowH*0.06;
        	$('.imged').css('margin-top',-top);
        }
    });
}