$(function(){
	 $("#text").html("产品预约");
	  var productId =GetQueryString("productId");
    $.ajax({
    	url:baseUrl+ '/api/product/appointment.do',
        data: {
          productId: productId
        },
        beforeSend: function() {
            $$.am_toast.innerHTML = tipTpl.loading;
            return toast.show();
          },
          complete:function(){
          	return toast.hide();
          },
        success: function(data) {
        	var basic,user;
            basic = data.data.basic;
            user = data.data.user;
            $("#productName").val(basic.productName);
            $("#productId").val(productId);
            if(user!=null&&user.isVerify==1){
            	$("#uname").val(user.name).show();
            	$(".uname").show();
            }else{
            	$(".uname").hide();
            	$("#username")[0].placeholder="请输入您的姓名(必填)";
            	$("#phone")[0].placeholder="请输入您的手机号码(必填)";
            }          
        }
    });
});


// Generated by CoffeeScript 1.8.0
$(function() {
  var loadData;
  loadData = (function(_this) {
    return function() {
    	var uname=$("#uname").val();
    	if (uname===null||uname===""||uname===undefined){
    		if (!isNotNull($("#username")[0], "名字")) {
    				return;
    	      } else if (!isMobile($("#phone")[0], "手机号")){
    	    	  	return;
    	      } else if (!isNumber($("#orderMount")[0],"预约金额")) {
    	    	  	return;
    	      } else if(!tooSmall($("#orderMount")[0],"预约金额")){
    	    	  return;
    	      }
    	}else{
    		  if (!isNotNull($("#username")[0], "名字")) {
    			  	return;
    	      } else if(!isUserMobile($("#phone")[0], "手机号")){
    	    	  	return;
    	      }else if (!isNumber($("#orderMount")[0],"预约金额")) {
    	    	  	return;
    	      }else if(!tooSmall($("#orderMount")[0],"预约金额")){
    	    	  return;
    	      }
    	}	
      _this.Ajax({
        url: _this.baseUrl + '/api/order/add_order.do',
        type:"post",
        data: {
        	mobile:$("#phone").val(),
        	userName:$("#username").val(),
        	orderMount:$("#orderMount").val(),
        	productId:$("#productId").val(),
        	description:$("#description").val(),
        	orgin:1
        },
        callback: function(obj) {
        	console.log(obj.status);
          if (obj.status === 200) {
        	  setTimeout(function(){
        		  location.href = "../product/appointmentSuc.html";
        	  },1200);
          }
        }
      });
      return false;
    };
  })(this);

  $(function() {
    $(".toast").hide();	
    return $(".am-button").on("click", function() {
      return loadData();
    });
  });
});

