﻿// JScript 文件
window.IncludeFile={"header":"head.html","tailer":"tail.html"}; 
window.JsModule=["system/jqframe.js","plugins/grid/js/jqModal.js","plugins/grid/js/jqDnR.js","js/all_jpgys.js"];
window.EhaiGrid={curPage:1,curRowNum:1,totalRecord:-1,curFun:null,bDiv:null,sc:null,sortName:"ehai_product.PubTime",sortOrder:"desc"};
function WebMain()
{
    $.SetFormat("zh","settypesmal2","<p><a href=\"zdjglist.html?{'Sort':'#1#'}\">#0#</a></p>","","");
    $.SetFormat("zh","settypesmall","<div class='quo_type2'><a style='font-weight:bold;' href=\"zdjglist.html?{'Sort':'#1#'}\">#0#</a></div><div id=\"quo_typep#2#\"><p></p></div>","","");
    $.SetFormat("zh","zxcpbj","<ul><li><a style='width:110px;height:20px;color:#666666;background:none;padding:0px 5px;font-weight:lighter;line-height:180%;' href=\"propricedetaile.html?{'id':#2#}\">#0#</a>#1##3#</li></ul>","","");
    /*产品分类列表*/$.SendMessage({callback:setbigtype,bLoading:false,type:"DBSelect",id:"getproducttypebig",pm :"<@ehai_typetable%16Id%16eName,Class,Id%16%16%16Class asc%160%16Sort=2 and LENGTH(Class)=2%16@>"});
    /*金牌供应商*/$("#jpgys").SendMessage({bLoading:false,type:"DBSelect",id:"jpgys",pm :"<@ehai_user%16Id%16Id,Company%16%16%16CreateTime desc%160%16RoleType=1 and IsGold=1@>%16",format:"jpgys",start:0,total:5}); 
    /*产品报价--最新产品报价*/$("#zxcpbj").SendMessage({bLoading:false,type:"DBSelect",id:"zxcpbj",pm :"<@ehai_product%16Id%16ProductName,Price,Id,procsunit%16%16%16PubTime desc%160%16IsCheck=1 and ispricheck=1 and IsShow=1@>%16",format:"zxcpbj",start:0,total:6});
    if($.PageParam.Sort)
        {
            getCategoryData($.PageParam.Sort); 
        }
        EhaiGrid.grid = jQuery("#list").jqGrid({
            url:'Default.aspx',
            datatype: 'json',
            colNames:['图片','产品类别','租赁价格','租赁单位','出售价格','出售单位'],
            colModel :[ 
            {name:'pic',index:'pic', width:60,sortable:false},
            {name:'eName',index:'eName', width:100,sortable:true},
            {name:'zlprice',index:'zlprice', width:70,sortable:true},
            {name:'zlunit',index:'zlunit', width:70,sortable:true},
            {name:'csprice',index:'csprice', width:70,sortable:true},
            {name:'csunit',index:'csunit', width:70,sortable:true}
            ],
            pager: jQuery('#pager'),
            rowNum:12,
            rowList:[12,18,24],
            sortname: 'Class',
            sortorder: "desc",
            viewrecords: true,
            imgpath: 'Controls/grid/themes/ehai_front1/images',
            caption: "",
            width:540,
            height:600,
            jsonReader : {
                root: "rows",
                page: "page",
                total: "total",
                records: "records",
                repeatitems: true,
                cell: "cell",
                id: "id",
                userdata: "userdata"
            }
        });
        $(".selbox:last").before("<span>&nbsp;显示&nbsp;</span>"); 
        $(".selbox:last").after("<span>&nbsp;条&nbsp;</span>"); 
        getAdsInfo(23);
    }
//产品分类
function setbigtype(re)
{
    if(re)
    {
        var h=""
        for(i=0;i<re.length;i++)
        {

            h+="<div><a style='color:#1A679D;font-weight:bold;clear:both;margin-left:5px;'  href=\"zdjglist.html?{'Sort':'"+re[i][1]+"'}\">"+re[i][0]+"</a></div><div id=\"bigtypeli"+re[i][1]+"\" ></div>";
        }
         $("#quo_type").html(h);
        for(i=0;i<re.length;i++)
        {
            /*产品二级类*/$("#bigtypeli"+re[i][1]).SendMessage({bLoading:false,type:"DBSelect",pm :"<@ehai_typetable%16Id%16eName,Class,Id%16%16%16Class asc%160%16Sort=2 and LENGTH(Class)=4 and left(Class,2)='@>"+re[i][1]+"'%16",format:"settypesmall"});
        }
        /*产品分类列表*/$.SendMessage({callback:setsmalltype,bLoading:false,type:"DBSelect",id:"getproducttypesmall",pm :"<@ehai_typetable%16Id%16eName,Class,Id%16%16%16Class asc%160%16Sort=2 and LENGTH(Class)=4%16@>"});
    }
};
function setsmalltype(re)
{
    if(re)
    {
        for(i=0;i<re.length;i++)
        {
            /*产品三级类*/$("#quo_typep"+re[i][2]).SendMessage({bLoading:false,type:"DBSelect",pm :"<@ehai_typetable%16Id%16eName,Class,Id%16%16%16Class asc%160%16Sort=2 and LENGTH(Class)=6 and left(Class,4)='@>"+re[i][1]+"'%16",format:"settypesmal2"});
        }
    }
};

var curSid;
var curPage,curRowNum,totalRecord,curFun,bDiv;
function getNews(page,rowNum,sortname,sortorder,fun,bd)
{            
    EhaiGrid.curPage=page;
    EhaiGrid.sortName=sortname; //多个表查询，必须添加表名
	EhaiGrid.sortOrder=sortorder;
    EhaiGrid.curRowNum=rowNum;
    EhaiGrid.curFun=fun;
    EhaiGrid.bDiv=bd;
    if(EhaiGrid.curPage==1)
    $("div.r_slider").css("left","0px");
    if(EhaiGrid.totalRecord==-1)
        getTotalRecord();
    else
        sendMsg();
};
function getTotalRecord()
{
    $.SendMessage({type:"DBSelect",bDefCall:false,callback:sendMsg,pm :"<@ehai_typetable%16Id%16Count(*)%16%16%16%160%16Sort=2 and LENGTH(Class)<8@>"+(EhaiGrid.sc?EhaiGrid.sc:"")+"%16"},true);
    
};
function sendMsg(re,msg)
{
    var t={type:"DBSelect",callback:newsCallback,bDefCall:false,id:"quotationlist",pm :"<@ehai_typetable%16Id%16Id,eName,zlprice,zlunit,csprice,csunit,typepic%16%16%16%160%16Sort=2 and LENGTH(Class)<8@>"+(EhaiGrid.sc?EhaiGrid.sc:"")+"%16",start:EhaiGrid.curRowNum*(EhaiGrid.curPage-1),total:EhaiGrid.curRowNum};
    if(re)
    {
        EhaiGrid.totalRecord=re[0][0];
    }        t.bRefresh=true;

    $.SendMessage(t,true);
};
function newsCallback(re,msg)
{var picimg="";
    var records={total:Math.ceil(EhaiGrid.totalRecord/EhaiGrid.curRowNum),page:EhaiGrid.curPage,records:EhaiGrid.totalRecord};
    var rows="[";
    for(var i=msg.start,j=msg.start+msg.total;i<j;i++)
    {
        if(re[i][6]=="")
            picimg="images/nophoto.gif";
        else
            picimg=re[i][6];           
        rows+="{id:'"+re[i][0]+"',cell:['<span class=\"ckprice1\"><img style=\"width:48px;height:32px;display:block;border:1px solid #D9D9D9;\" src=\""+picimg+"\" alt=\"图片\" /></span>','<span class=\"ckprice1\" style=\"padding:0 10px;width:120px;overflow:hidden;\"><a href=\"zdjgdetail.html?{id:"+re[i][0]+"}\">"+re[i][1]+"</a></span>','<span class=\"ckprice1\" style=\"width:80px;\">"+re[i][2]+"</span>','<span class=\"ckprice1\" style=\"width:80px;padding-left:10px;\">"+re[i][3]+"</span>','<span class=\"ckprice1\" style=\"width:80px;padding-left:10px;\">"+re[i][4]+"</span>','<span class=\"ckprice1\" style=\"width:80px;padding-left:10px;\">"+re[i][5]+"</span>']},";
    }
    if(rows.lastIndexOf(',')==rows.length-1)
        rows=rows.substring(0,rows.length-1);
    rows+="]";
	//debugger;
    rows=rows.replace(/\n/ig,'<br />'); //换行的问题
    records.rows=eval("("+rows+")");
    EhaiGrid.curFun(records,EhaiGrid.bDiv);
};  
function getarea(area)
{
    
    window.location="quotationlist.html?{'area':'"+area+"'}";
}
function getCategoryData(classid)  
{
    EhaiGrid.sc=" and Class like '"+classid+"%'";
    EhaiGrid.totalRecord=-1;
    jQuery("#list").trigger("reloadGrid"); 
}
