detailShopping.js 8.21 KB
define(function( require, exports, module ) {

	var _Droll = require( "droll" ),
		_Tools = require( "tools" ),
		_Ntab = require( "ntab" ),
		_Base = require( 'base' ),
		_Pophint = require( 'pophint' ),
        _Miniclock = require( 'miniclock' );


	require( 'hoverex' );
	require( 'charts' );
	require( 'fancybox' );

	$(function(){
		/* 
			商品图片切换 
		*/
		$(".thumb-list img").click(function(){
			var src = $( this ).attr( "src" );
			var large = $( this ).data( "large" );
			$( "#zoomblock>img" ).attr( "src",src );
			$( "#zoomblock .he-zoom > img" ).attr("src",large);

			$( this ).parent().addClass( 'current' ).siblings().removeClass( 'current' );
		});

		/*
			商品属性选择
		*/
		// 品种
		var _index = 0;
		if( $( '#standard-list1' ).length > 0 ){
			_Tools.setSelected({
				container : "#standard-list1",
				tags : "li",
				selected : "current",
				disabledClass:"disabled",
				cllback : function( index ){
					_index = index;
					//调用规格切换
					standardShow( index );
				}
			});
			//默认第一个展示
			 $( '#standard-list1 li' ).eq( 0 ).trigger( "click" );
		}

		/* 规格展示切换 */
		function standardShow( index ){
			var _elem = $( '.standard-box' ).find( '.standard-group' ).eq( index );

			if( _elem.find( 'tr' ).length > 2 ){
				_elem.height( '111px' );
				$( '.need-more' ).show();
			}else{
				$( '.need-more' ).hide();
				$( '.need-more span' ).removeClass( 'up' );
			}

			$( _elem ).css({'display':'block'})
			.animate({
				'left':0
			}, 300 ).siblings( '.standard-group' ).css({
				'display':'none',
				'left':'-100%'
			});
		}
		//规格更多展示
		$( '.need-more span' ).click(function(){
			var _elem = $( '.standard-box' ).find( '.standard-group' ).eq( _index );

			if( !$( this ).hasClass( 'up' ) ){
				$( this ).addClass( 'up' );
				var _height = _elem.find( 'tr' ).height() * _elem.find( 'tr' ).length + 5;
				_elem.animate({ 'height' : _height },300 );
			}else{
				$( this ).removeClass( 'up' );
				_elem.animate({ 'height' : '111px' } ,300 );
			}
		});

		//提货点
		if( $( '#standard-list2' ).length > 0 ){
			_Tools.setSelected({
				container : "#standard-list2",
				tags : "li",
				selected : "current",
				disabledClass:"disabled",
				cllback : function( index ){

				}
			});
		}
		//地利服务

		$( '#standard-list3  li' ).click(function(){
			if( $( this ).hasClass( 'current' ) ){
				$( this ).removeClass( 'current' );
			}else{
				$( this ).addClass( 'current' );
			}
		});

		// 选购清单展示
		$( '.door' ).click(function(){
			if( $( this ).hasClass( 'selected' ) ){
				$( this ).removeClass( 'selected' );
				$( '.room' ).hide();
			}else{
				$( this ).addClass( 'selected' );
				$( '.room' ).show();
			}
		});

		if( $( '.account-house' ).length > 0 ){
			$( document ).on( 'click' , function( event ){
			
				var click_target = event.target;

				if(isContain( $( '.account-house' ) , click_target )){
					return;
				}else{
					$( '.door' ).removeClass( 'selected' );
					$( '.room' ).hide();
				}

			});
		}
		
		// 判断是否为自身或者子集
		function isContain( elem, cur ){
			var _in = false;

			$( elem ).each(function() {

				if( this == $( cur )[0] || $( this ).find( cur ).length ) {
					_in = true;
				}
			});

			return _in;
		}

		/* 
			推荐商品滚动 
		*/
		new _Droll( $( '#goods-recommend2 .recommend-list' )[0],{
			step        : $( '#goods-recommend2 li' ).width() + 20,
			moveNum     : 5,
			dirButton   : true,
			Media:true,// 轮播图适应响应式
			onBeforeInView:function( list ){
                _Base.handLazy( list );
            }
		});


		/*  
			tab 切换
		*/
		if( $( '.n-tab' ).length > 0 ){
			$( '.n-tab' ).each( function(){
				new _Ntab( this, {
					handler:'a',
					eventType:'click',
					currentClass:'current',
					onShow:function( target ){
						var _id = $( target ).attr( 'id' );
						$( '.n-tab li' ).each( function(){
							var _href = $( this ).find( 'a' ).attr( 'href' );
							if( _href == '#'+_id ){
								$( this ).find( 'a' ).addClass( 'current' );
							}else{
								$( this ).find( 'a' ).removeClass( 'current' );
							}
						});
					}
				});
			});
		}
		/*  
			tab 悬浮
		*/

		var _fixedTop = $( '.content' ).offset().top;

		$( window ).scroll( function(){
			if( $( window ).scrollTop() > _fixedTop ){
				$( '.tab-fixed' ).show();
			}else{
				$( '.tab-fixed' ).hide();
			}
		});


		$( '.tab-fixed li' ).click( function(){
			_Base.goto({
				elem: $( '.content' )
			});

		});

		//价格走势
		var myChart = echarts.init(document.getElementById('graphic'));
		var option = {
			    title : {
			        text: '',
			        subtext: ''
			    },
			    tooltip : {
			        trigger: 'axis'
			    },
			    legend: {
			        data:['寿光地利','哈尔滨哈达']
			    },
			    toolbox: {
			        show : false,
			        feature : {
			            mark : {show: true},
			            dataView : {show: true, readOnly: false},
			            magicType : {show: true, type: ['line', 'bar']},
			            restore : {show: true},
			            saveAsImage : {show: true}
			        }
			    },
			    calculable : true,
			    xAxis : [
			        {
			            type : 'category',
			            boundaryGap : false,
			            data : ['周一','周二','周三','周四','周五','周六','周日']
			        }
			    ],
			    yAxis : [
			        {
			            type : 'value',
			            axisLabel : {
			                formatter: '{value}'
			            }
			        }
			    ],
			    series : [
			        {
			            name:'寿光地利',
			            type:'line',
			            data:[11, 11, 15, 13, 12, 13, 10],
			            markPoint : {
			                data : [
			                    {type : 'max', name: '最大值'},
			                    {type : 'min', name: '最小值'}
			                ]
			            },
			            markLine : {
			                data : [
			                    {type : 'average', name: '平均值'}
			                ]
			            }
			        },
			        {
			            name:'哈尔滨哈达',
			            type:'line',
			            data:[1, -2, 2, 5, 3, 2, 0],
			            markPoint : {
			                data : [
			                    {name : '周最低', value : -2, xAxis: 1, yAxis: -1.5}
			                ]
			            },
			            markLine : {
			                data : [
			                    {type : 'average', name : '平均值'}
			                ]
			            }
			        }
			    ]
			};
                    
                    
		myChart.setOption(option);


		$( window ).resize(function(){
			myChart.resize();
		});
		

		/**
			询价
		*/
		$( '#inquiryBtn' ).fancybox({
			padding:0
		});

		$( '#inquiry-send' ).click(function(){
			$.fancybox.close();

			setTimeout(function(){
				new _Pophint( this,{
		            operation: function( target ){
						//确定要执行的操作
		                
					}, 
		            content: "您的询价单已成功提交,我们已通知供应商为您报价,并通过短信通知您报价结果,请随时关注您的询价单。",
		            showButton:false
		        });
			} , 500 );
			
		});
		$( '#common-words' ).change(function(){
			$( '#words-area' ).val( $( this ).val() );
		});

		/*
			加入进货单成功
		*/
		$( '.joincart' ).click(function(){
			//加入成功后
			if( $( '#popup-start' ).length > 0 ){
				$( '#popup-start' ).trigger( "click" );
			}
			
		});
		$( '#popup-start' ).fancybox({
			padding:0
		});


		// 登录

		if( !login_flag && $( '#s-login-pop' ).length ){
			$( '.nowbuy' ).click(function(){
				$( '#s-login-pop' ).click();
			});
			$( '#s-login-pop' ).fancybox({
				width:'380px',
				height:'310px',
				type: 'iframe',
				fitToView:false,
				iframe : {
			        preload: false,
			        scrolling:'no'
			    },
			    scrolling:'visible'
			});
		}

        /*
         * 集采计时器
         */

        $( ".shopping-timer" ).each(function(){

            new _Miniclock( this, {
                //建议使用小数点两位以上的数值,
                //计算基数为天,可传入任意非负数值,
                //使用该参数时,倒计时展现形式将会改变。
                waitByDay: 0.1
            });
            
        });

	});

});