// Generated by CoffeeScript 1.8.0
(function() {
  var moneyLoadData, 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 class=\"am-page-result-button\"><button class=\"am-button am-button-red am-button-lg\" onclick=\"location.href='../product/index.html'\">现在就去预约</button></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();
  };

  moneyLoadData = function() {
    var item, swp;
    item = $("#moneyTpl")[0].innerHTML;
    swp = new $.compent.swiper("#listMoney", {
      tpl: item,
      refreshEnabled: false,
      noDataTpl: noDataTpl
    });
    swp.dataSource = function(pageIndex, s, opt) {
      return Ajax({
        url: baseUrl + '/api/order/get_money.do',
        data: {
          page: pageIndex
        },
        type: 'get',
        callback: function(obj) {
        	$.each(obj.datas,function(idx,item){
        		  item.postTime = item.postTime.substr(0,10);
        	  });
        	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("个人中心");
    $("#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;
    			$(".circle").attr("onclick","location.href='../product/photo.html?src=/"+user.portraitUri+"'");
    		}
    		if(user.isVerify===1){
    			roleImg="../../static/images/yi.png";
    			$("#author").html(user.companyName);
    		}else{
    			roleImg="../../static/images/wei.png";
    			$("#author").html("&nbsp;&nbsp;认证即享理财师特权");
    		}
    		name=user.name;
    		$(".name").html(name);
    		$(".circle").attr("style","background-image: url(" +
    				img +
    				")");
    		$("#roleImg").attr("src",roleImg);
    	}
    	
    });
    orderLoadData();
    moneyLoadData();
    $(".order").on("click", function() {
      $(this).addClass("activity").siblings().removeClass("activity");
      return $(".tab_order").show().siblings().hide();
    });
    $(document).on("click", ".order_item", function() {
        return location.href = "../product/appointmentDetail.html?id=" + $(this).data("id");
      });
    $(document).on("click", "#product", function() {
        return location.href = "../product/product.html?id=" + $(this).data("id");
      });
    return $(".money").on("click", function() {
      $(this).addClass("activity").siblings().removeClass("activity");
      return $(".tab_money").show().siblings().hide();
    });
  });

}).call(this);
