$(function () {
	$.ajax({
		url : "Sell/" + $("#sell_sellId_edit").val() + "/update",
		type : "get",
		data : {
			//sellId : $("#sell_sellId_edit").val(),
		},
		beforeSend : function () {
			$.messager.progress({
				text : "正在获取中...",
			});
		},
		success : function (sell, response, status) {
			$.messager.progress("close");
			if (sell) { 
				$("#sell_sellId_edit").val(sell.sellId);
				$("#sell_sellId_edit").validatebox({
					required : true,
					missingMessage : "请输入销售id",
					editable: false
				});
				$("#sell_productObj_productId_edit").combobox({
					url:"Product/listAll",
					valueField:"productId",
					textField:"productName",
					panelHeight: "auto",
					editable: false, //不允许手动输入 
					onLoadSuccess: function () { //数据加载完毕事件
						$("#sell_productObj_productId_edit").combobox("select", sell.productObjPri);
						//var data = $("#sell_productObj_productId_edit").combobox("getData"); 
						//if (data.length > 0) {
							//$("#sell_productObj_productId_edit").combobox("select", data[0].productId);
						//}
					}
				});
				$("#sell_customerObj_customerId_edit").combobox({
					url:"Customer/listAll",
					valueField:"customerId",
					textField:"customerName",
					panelHeight: "auto",
					editable: false, //不允许手动输入 
					onLoadSuccess: function () { //数据加载完毕事件
						$("#sell_customerObj_customerId_edit").combobox("select", sell.customerObjPri);
						//var data = $("#sell_customerObj_customerId_edit").combobox("getData"); 
						//if (data.length > 0) {
							//$("#sell_customerObj_customerId_edit").combobox("select", data[0].customerId);
						//}
					}
				});
				$("#sell_price_edit").val(sell.price);
				$("#sell_price_edit").validatebox({
					required : true,
					validType : "number",
					missingMessage : "请输入销售单价",
					invalidMessage : "销售单价输入不对",
				});
				$("#sell_sellCount_edit").val(sell.sellCount);
				$("#sell_sellCount_edit").validatebox({
					required : true,
					validType : "integer",
					missingMessage : "请输入销售数量",
					invalidMessage : "销售数量输入不对",
				});
				$("#sell_sellDate_edit").datebox({
					value: sell.sellDate,
					required: true,
					showSeconds: true,
				});
				$("#sell_payWay_edit").val(sell.payWay);
				$("#sell_payWay_edit").validatebox({
					required : true,
					missingMessage : "请输入支付方式",
				});
				$("#sell_logistics_edit").val(sell.logistics);
				$("#sell_logistics_edit").validatebox({
					required : true,
					missingMessage : "请输入物流公司",
				});
				$("#sell_wayNumber_edit").val(sell.wayNumber);
				$("#sell_wayNumber_edit").validatebox({
					required : true,
					missingMessage : "请输入运单号",
				});
				$("#sell_sellMemo_edit").val(sell.sellMemo);
			} else {
				$.messager.alert("获取失败！", "未知错误导致失败，请重试！", "warning");
				$(".messager-window").css("z-index",10000);
			}
		}
	});

	$("#sellModifyButton").click(function(){ 
		if ($("#sellEditForm").form("validate")) {
			$("#sellEditForm").form({
			    url:"Sell/" +  $("#sell_sellId_edit").val() + "/update",
			    onSubmit: function(){
					if($("#sellEditForm").form("validate"))  {
	                	$.messager.progress({
							text : "正在提交数据中...",
						});
	                	return true;
	                } else {
	                    return false;
	                }
			    },
			    success:function(data){
			    	$.messager.progress("close");
                	var obj = jQuery.parseJSON(data);
                    if(obj.success){
                        $.messager.alert("消息","信息修改成功！");
                        $(".messager-window").css("z-index",10000);
                        //location.href="frontlist";
                    }else{
                        $.messager.alert("消息",obj.message);
                        $(".messager-window").css("z-index",10000);
                    } 
			    }
			});
			//提交表单
			$("#sellEditForm").submit();
		} else {
			$.messager.alert("错误提示","你输入的信息还有错误！","warning");
			$(".messager-window").css("z-index",10000);
		}
	});
});
