﻿
//网站的路径
var ajaxUrl = "/";

var loadingstr = '&nbsp;'//'<div style="margin:5px;"><img src="'+ajaxUrl+'images/loading.gif"/>加载中...</div>' ; //加载中的信息

//提交数据
function sendProduct(tid)
{
    if(typeof(tid)!=undefined && tid != null && tid!=""){
        $.ajax({
          url: ajaxUrl + "WebUserControl/productShop.ashx",
          data: "tid="+tid,
          dataType: "json",
          //complete :function(){alert('complete');$("#productdiv").empty();},//AJAX请求完成时隐藏loading提示
          success: function(data){
            if(data!= null){
                readProduct(data); //AJAX请求成功时显示数据
            }
            else{
                $("#productdiv").html("&nbsp");
            }
          },
          //beforeSend:function(){
          //  //$('#productdiv').empty();
          //  $("#productdiv").html(loadingstr);
          //},
          error:function(xhr){$("#productdiv").html("Error:"+xhr.status);}
        });
    }
    else{
         $("#productdiv").html("&nbsp");
    }
}

//读取数据
function readProduct(data)
{
    $('#productdiv').empty();
    var html = '';
    $.each(data, function(i,item){
        if(i < 4){
            html += "<li><a href=\""+ajaxUrl+"productinfo.aspx?id="+item.proid+"\" target=\"_blank\"><img src=\""+item.imgurl+"\" onerror=\"this.src='"+ajaxUrl+"System/Upload/nopic7.gif'\" width=\"132\" height=\"140\" /></a><div class=\"txt1\"><a href=\""+ajaxUrl+"productinfo.aspx?id="+item.proid+"\" class=\"aname\" target=\"_blank\">"+item.proname+"</a></div>";
            
            if (item.isprice == 'True')
            {
                if (item.isnegotiate == 'True')
                {
                    html += "<div class='div3'>批发价：商议</div>";
                }
                else
                {
                    html += "<div class='div3'>批发价：￥" + item.pricewhol + "</div>";
                }

                html += "<div class='div2'>零售价：￥" + item.pricesale + "</div>";
            }
            else
            {
                html += "<div class='div1'>价格商议</div>";
            }
            html += "</li>";
        }
        else{
            return false;
        }
    });
    
    html = '<ul class="list_recpro_index">'+html+'</ul>';
    
    //alert(html);
    $('#productdiv').html(html);
    
}
