$(function () {
	$("#sell_productObj_productId").combobox({
	    url:'Product/listAll',
	    valueField: "productId",
	    textField: "productName",
	    panelHeight: "auto",
        editable: false, //不允许手动输入
        required : true,
        onLoadSuccess: function () { //数据加载完毕事件
            var data = $("#sell_productObj_productId").combobox("getData"); 
            if (data.length > 0) {
                $("#sell_productObj_productId").combobox("select", data[0].productId);
            }
        }
	});
	$("#sell_customerObj_customerId").combobox({
	    url:'Customer/listAll',
	    valueField: "customerId",
	    textField: "customerName",
	    panelHeight: "auto",
        editable: false, //不允许手动输入
        required : true,
        onLoadSuccess: function () { //数据加载完毕事件
            var data = $("#sell_customerObj_customerId").combobox("getData"); 
            if (data.length > 0) {
                $("#sell_customerObj_customerId").combobox("select", data[0].customerId);
            }
        }
	});
	$("#sell_price").validatebox({
		required : true,
		validType : "number",
		missingMessage : '请输入销售单价',
		invalidMessage : '销售单价输入不对',
	});

	$("#sell_sellCount").validatebox({
		required : true,
		validType : "integer",
		missingMessage : '请输入销售数量',
		invalidMessage : '销售数量输入不对',
	});

	$("#sell_sellDate").datebox({
	    required : true, 
	    showSeconds: true,
	    editable: false
	});

	$("#sell_payWay").validatebox({
		required : true, 
		missingMessage : '请输入支付方式',
	});

	$("#sell_logistics").validatebox({
		required : true, 
		missingMessage : '请输入物流公司',
	});

	$("#sell_wayNumber").validatebox({
		required : true, 
		missingMessage : '请输入运单号',
	});

	//单击添加按钮
	$("#sellAddButton").click(function () {
		//验证表单 
		if(!$("#sellAddForm").form("validate")) {
			$.messager.alert("错误提示","你输入的信息还有错误！","warning");
			$(".messager-window").css("z-index",10000);
		} else {
			$("#sellAddForm").form({
			    url:"Sell/add",
			    onSubmit: function(){
					if($("#sellAddForm").form("validate"))  { 
	                	$.messager.progress({
							text : "正在提交数据中...",
						}); 
	                	return true;
	                } else {
	                    return false;
	                }
			    },
			    success:function(data){
			    	$.messager.progress("close");
                    //此处data={"Success":true}是字符串
                	var obj = jQuery.parseJSON(data); 
                    if(obj.success){ 
                        $.messager.alert("消息","保存成功！");
                        $(".messager-window").css("z-index",10000);
                        $("#sellAddForm").form("clear");
                    }else{
                        $.messager.alert("消息",obj.message);
                        $(".messager-window").css("z-index",10000);
                    }
			    }
			});
			//提交表单
			$("#sellAddForm").submit();
		}
	});

	//单击清空按钮
	$("#sellClearButton").click(function () { 
		$("#sellAddForm").form("clear"); 
	});
});
