﻿// 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,sc1:null,sortName:"ehai_product.PubTime",sortOrder:"desc"};
function WebMain()
{
    $.SetFormat("zh","settypesmal2","<p><a href=\"quotationlist.html?{'Sort':'#1#'}\">#0#</a></p>","","");
    $.SetFormat("zh","settypesmall","<div class='quo_type2'><a style='font-weight:bold;' href=\"quotationlist.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); 
        }
        if($.PageParam.area)
        {
            getareaid($.PageParam.area); 
        }
        getCategoryRightData($.PageParam.keys1,$.PageParam.keys2,$.PageParam.keys3,$.PageParam.keys4);
        EhaiGrid.grid = jQuery("#list").jqGrid({
            url:'Default.aspx',
            datatype: 'json',
            colNames:['产品图片','产品名称','公司名称','产品价格'],
            colModel :[ 
            {name:'pic',index:'pic', width:60,sortable:false},
            {name:'proname',index:'ehai_product.ProductName', width:100,sortable:true},
            {name:'firmname',index:'ehai_user.Company', width:130,sortable:true},
            {name:'proprice',index:'ehai_product.Price', width:60,sortable:true}
            ],
            pager: jQuery('#pager'),
            rowNum:12,
            rowList:[12,18,24],
            sortname: 'ehai_product.PubTime',
            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=\"quotationlist.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_product  left join ehai_user on ehai_product.UserName=ehai_user.UserName%16Id%16Count(*)%16%16%16%160%16ehai_product.IsShow=1 and ehai_product.IsCheck=1 and ispricheck=1@>"+(EhaiGrid.sc?EhaiGrid.sc:"")+(EhaiGrid.sc1?EhaiGrid.sc1:"")+"%16"},true);
    
};
function sendMsg(re,msg)
{
    var t={type:"DBSelect",callback:newsCallback,bDefCall:false,id:"quotationlist",pm :"<@ehai_product  left join ehai_user on ehai_product.UserName=ehai_user.UserName%16Id%16ehai_product.Id,ehai_product.Pic,ehai_product.ProductName,ehai_user.Company,ehai_product.Price,ehai_product.PubTime,procsunit%16%16%16@>" + EhaiGrid.sortName + " " + EhaiGrid.sortOrder + "<@%160%16ehai_product.IsShow=1 and ehai_product.IsCheck=1  and ispricheck=1@>"+(EhaiGrid.sc?EhaiGrid.sc:"")+(EhaiGrid.sc1?EhaiGrid.sc1:"")+"%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][1]=="" || re[i][1]== "undefinedundefined" || re[i][1]=="ProductImg/")
            picimg="images/nophoto.gif";
        else
            picimg=re[i][1];           
        rows+="{id:'"+re[i][0]+"',cell:['<span style=\"padding-left:10px;\" class=\"ckprice1\"><img style=\"width:48px;height:32px;display:block;border:1px solid #D9D9D9;\" src=\""+picimg+"\" alt=\"图片\" /></span>','<span class=\"ckprice1\" style=\"width:150px;overflow:hidden;\"><a href=\"propricedetaile.html?{id:"+re[i][0]+"}\">"+re[i][2]+"</a></span>','<span class=\"ckprice1\" style=\"width:180px;overflow:hidden;\">"+re[i][3]+"</span>','<span class=\"ckprice1\" style=\"width:120px;overflow:hidden;\">"+re[i][4]+re[i][6]+"</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);
    $("table.scroll tr.over td").css("backgroundColor","#FFF"); 
};  
function getCategoryData(classid)  
{
    EhaiGrid.sc=" and eType like '"+classid+"%'";
    EhaiGrid.totalRecord=-1;
    jQuery("#list").trigger("reloadGrid");
    
} 
function getarea(area)
{   
    window.location="quotationlist.html?{'area':'"+area+"'}";
}
function getareaid(area)  
{
    EhaiGrid.sc=" and ehai_product.proarea like '"+area+"%'";
    EhaiGrid.totalRecord=-1;
    jQuery("#list").trigger("reloadGrid"); 
}; 
function qyrightsearch()
{
    var aimUrl;
    var qytj=$("#qytj").val();
    var zztj=$("#zztj").val();
    aimUrl="searchqiye.html{'qytj':'"+qytj+"','zztj':'"+zztj+"'}";
    window.location=aimUrl;
};
function getCategoryRightData(k1,k2,k3,k4)
{
     EhaiGrid.sc1="";
    if(k1){
    EhaiGrid.sc1+="";
    }
    if(k2)
    {
        EhaiGrid.sc1+=" and ehai_product.ProductName like '%"+k2+"%'";
    }
    if(k3)
    {
        EhaiGrid.sc1+=" and ehai_user.Company like '%"+k3+"%'";
    }
     if(k4)
    {
        EhaiGrid.sc1+=" and ehai_product.Price like '%"+k4+"%'";
    }
    EhaiGrid.totalRecord=-1;
    jQuery("#list").trigger("reloadGrid");
}
