channel.js 4.83 KB
define('channel',function(require, exports)
{
	var swipe = require("plugins/swipe");
	var $ = require("jquery");
	var freetile = require("lib/ui/jquery.freetile");
	require("plugins/pagination");
	function setLayout()
	{
		$('.fluid-list-inner').freetile({ animate: false, elementDelay: 0 });
	}
	function getTopProduct(gender)
    {
		$.ajax
		({
			type:"post",
			url:'/default/getTopProduct',
			data:{gender:gender},
			dataType:"json",
			success:function(data)
			{
				if(data.code == 200)
				{
					var html = '';
					var pos = 1;
					var number_class = '';
					var number = '';
					$.each(data.data, function(key, val)
					{
						if(pos == 1)
						{
							number_class = 'number_1';
							number = '';
						}
						else
						{
							number = pos;
							number_class = 'number_2';
						}
						html += '<li><div class="goods-image">'+
                        '<img src="'+val.product_img+'" alt=""/>'+
                        '<span class="'+number_class+'">'+number+'</span></div>'+
                        '<h3><a  target="_blank" href="'+val.product_url+'">'+val.product_name+'</a></h3><p>人气: '+val.sale_sum+'</p></li>';
						pos++;
					});
					$(".show-goods-list").html('<ul>'+html+'</ul>');
				}
			}
		});
    }
	//yohood展会页面
	exports.exhibition=function(){
		swipe.init
		({
            slideBox: '.slide-box-exhibition',
            prev: '.slide-prev-exhibition',
            next: '.slide-next-exhibition',
            pagination: '.dib a',
            activeClass: 'on',
            auto:3000,
            continuous:true
        });
	}
	//首页
	exports.index = function()
	{
		var sortPos = 0;
		var productGenders = [];
		var currentGenderPos = 0;
		var productListNames = [];
		if($(".show-goods").size() > 0)
		{
			productGenders = $(".show-goods").attr("product_genders").split(',');
			currentGenderPos = $(".show-goods").attr("current_gender_pos");
			productListNames = $(".show-goods").attr("product_list_names").split(',');
			getTopProduct(productGenders[currentGenderPos]);
		}
		swipe.init
		({
            slideBox: '.slide-box',
            prev: '.slide-prev',
            next: '.slide-next',
            pagination: '.dib a',
            activeClass: 'on',
            auto:3000,
            continuous:true
        });
		$(".goods_prev, .goods_next").bind("click", function()
		{
			currentGenderPos = parseInt($(".show-goods").attr("current_gender_pos"));
			if($(this).attr("class") == 'goods_prev')
			{
				genderPos = parseInt(currentGenderPos - 1 >= 0 ? currentGenderPos-1 : 0);
			}
			else
			{
				genderPos = parseInt(currentGenderPos + 1 < productGenders.length ? currentGenderPos + 1 : currentGenderPos);
			}
			if(genderPos != currentGenderPos)
			{
				$(".show-goods").attr("current_gender_pos", genderPos);
				getTopProduct(productGenders[genderPos]);
				$(".show-goods").find("span").remove();
				$(".show-goods").find("h2").prepend("<span>"+productListNames[genderPos]+"</span>");
			}
		});
		
		setLayout();
	};
	//资讯
	exports.news = function()
	{
		setLayout();
	}
   
	//show页面
	exports.show = function()
	{
	   $(".look_big_image").bind("click",function(event)
	   {
			var divName = '#mask';
			var sourceImage = $(this).attr("source");
			var imageWidth = parseInt($(divName).children().attr("width"));
			var imageHeight = parseInt($(divName).children().attr("height"));
			$(divName).html('<img src="'+sourceImage+'" width="'+imageWidth+'" height="'+imageHeight+'" />').attr("current_class",$(this).parent().attr("class"));  
	   		var top = ($(window).height() - imageHeight)/2;   
			var left = ($(window).width() -  imageWidth)/2;
			var scrollTop = 0;//$(document).scrollTop();   
	   	    var scrollLeft = 0;//$(document).scrollLeft();  
		    $(divName).css( { position : 'absolute', 'top' : top + scrollTop, left : left + scrollLeft });
		    $(".model").show();
		    if(left-75 > 10)
		    {
				$(".image-prev").css("left", left-75);
				$(".image-next").css("right", left-75);
		    }
		    $.each($(this).parents("span").children("span"), function(index, dom)
		    {    
			    var style_top = parseInt($(dom).attr("x"))/10000 * imageHeight;
			    var style_left = parseInt($(dom).attr("y"))/10000 * imageWidth;
				$(divName).append('<a class="pic-tip" style="left:'+style_left+'px;top:'+style_top+'px;">'+$(dom).attr("label")+'</a>')
		    });
		    event.stopPropagation();
		});
		$(".image-next, .image-prev").bind("click",function()
		{
			var current_class = $("#mask").attr("current_class");
			var pos = parseInt(current_class.replace('single_',''));
			if($(this).attr("class").indexOf("image-next") != -1)
			{
				pos = pos + 1;
			}
			else
			{
	           pos = pos - 1;
			}
			if($(".single_"+pos).size() > 0)
			{
				$(".single_"+pos).find(".look_big_image").click();
			}
		});
		$(".ui-dialog-close").bind("click",function(event)
		{
			$(".model").hide();
			event.stopPropagation();
		}); 		
	}
});