// Generated by CoffeeScript 1.8.0
(function() {
  var collectLoadData, noDataTpl, orderLoadData;

  noDataTpl = "<div class=\"noData\">\n	<div class=\"am-page-result\">\n		<div class=\"am-page-result-wrap\">\n			<div class=\"am-page-result-pic\">\n				<img src=\"../../static/images/noData_03.png\" width=\"140\" />\n			</div>\n			<div class=\"am-page-result-title\">暂无数据</div>\n				</div>\n	</div>\n</div> ";

  orderLoadData = function() {
	    var item, swp;
	    item = $("#orderTpl")[0].innerHTML;
	    swp = new $.compent.swiper("#listOrder", {
	      tpl: item,
	      refreshEnabled: false,
	      noDataTpl: noDataTpl
	    });
	    swp.dataSource = function(pageIndex, s, opt) {
	      return Ajax({
	        url: baseUrl + '/api/order/get_orders.do',
	        data: {
	          page: pageIndex
	        },
	        type: 'get',
	        callback: function(obj) {
	        	$.each(obj.datas,function(idx,item){
	      		  item.postTime = item.postTime.substr(0,10);
	      		  if(item.minorStatusName===null||item.minorStatusName==="N/A"||item.minorStatusName===undefined){
	      			  item.minorStatusName="已完成";
	      		  }
	      	  });
	        	if(pageIndex>1&&obj.datas.length===0){
	  			  var a = $(".swiper-wrapper").children('div:last-child');
	  				a.after("<div class=\"swiper-slide\" style=\"height:0px;\"></div>");
	  		  }
//	          opt['topData'] = {
//	            imgSrc: "../../static/images/head.jpg"
//	          };
	          return swp.dataList(obj.datas);
	        },
	        error: function(res) {
	          opt.timeStatu = res.status;
	          return swp.timeOut();
	        }
	      });
	    };
	    return swp.initData();
	  };

  collectLoadData = function() {
    var item, swp;
    item = $("#collectTpl")[0].innerHTML;
    swp = new $.compent.swiper("#listCollect", {
      tpl: item,
      refreshEnabled: false,
      noDataTpl: noDataTpl
    });
    swp.dataSource = function(pageIndex, s, opt) {
    	
      return Ajax({
        url: baseUrl + '/api/user/get_collect.do',
        type: 'get',
        data:{pageIndex:pageIndex,flag:true},
        callback: function(obj) {
        	$.each(obj.datas,function(idx,item){
        		  if(item.thumbnail==undefined||item.thumbnail==""){
        			  
		                	if(item.favoriteType==1){
		                		item.thumbnail="../../static/images/news_collect.jpg";
		                	}
		                	if(item.favoriteType==2){
		                		item.thumbnail="../../static/images/product_collect.jpg";
		                	}
		                	if(item.favoriteType==3){
		                		item.thumbnail="../../static/images/meet_collect.jpg";
		                	}
		                   
		                }
        	  });
        	if(pageIndex>1&&obj.datas.length===0){
  			  var a = $(".swiper-wrapper").children('div:last-child');
  				a.after("<div class=\"swiper-slide\" style=\"height:0px;\"></div>");
  		  }
          return swp.dataList(obj.datas);
        },
        error: function(res) {
          opt.timeStatu = res.status;
          return swp.timeOut();
        }
      });
    };
    return swp.initData();
  };
  

  $(function() {
    $(".toast").hide();
    $("#text").html("个人中心");
    
    $('.join-enter').find('em').click(function(){
		$(this).parent().hide();
	});
    
    $("#img").attr("onclick","location.href='../product/index.html'");
    
    $.ajax({
    	url:baseUrl+'/api/user/get_user_info.do',
    	beforeSend: function() {
            $$.am_toast.innerHTML = tipTpl.loading;
            return toast.show();
          },
          complete:function(){
          	return toast.hide();
          },
    	success:function(data){
    		var user = data.data.userinfo;
    		if(user.portraitUri == null){
    			img="../../static/images/head.jpg";
    		}else{
    			img="/"+user.portraitUri;
    		}
    		$("#name").html(user.name);
    		$("#mobile").html(user.mobile);
    		//$("#portrait")[0].src=img;
    		$("#portrait").css({'background':'url('+img+') center center no-repeat;','background-size':'100% auto','-webkit-background-size':'100% auto', '-o-background-size':'100% auto', '-ms-background-size':'100% auto'});
    	}
    	
    });
    orderLoadData();
    collectLoadData();
    
    $(".order").on("click", function() {
        $(this).addClass("spcur").siblings().removeClass("spcur");
        return $(".tab_order").show().siblings().hide();
      });
    
    $(document).on("click", "#collect", function() {
        return location.href = $(this).data("id");
      });
    return $(".collect").on("click", function() {
        $(this).addClass("spcur").siblings().removeClass("spcur");
        return $(".tab_collect").show().siblings().hide();
      });
  });

  

}).call(this);
