$(function () {
	$.ajax({
		url : "Supplier/" + $("#supplier_supplierId_edit").val() + "/update",
		type : "get",
		data : {
			//supplierId : $("#supplier_supplierId_edit").val(),
		},
		beforeSend : function () {
			$.messager.progress({
				text : "正在获取中...",
			});
		},
		success : function (supplier, response, status) {
			$.messager.progress("close");
			if (supplier) { 
				$("#supplier_supplierId_edit").val(supplier.supplierId);
				$("#supplier_supplierId_edit").validatebox({
					required : true,
					missingMessage : "请输入记录id",
					editable: false
				});
				$("#supplier_supplierName_edit").val(supplier.supplierName);
				$("#supplier_supplierName_edit").validatebox({
					required : true,
					missingMessage : "请输入单位全称",
				});
				$("#supplier_fddbr_edit").val(supplier.fddbr);
				$("#supplier_fddbr_edit").validatebox({
					required : true,
					missingMessage : "请输入法定代表人",
				});
				$("#supplier_lxfs_edit").val(supplier.lxfs);
				$("#supplier_lxfs_edit").validatebox({
					required : true,
					missingMessage : "请输入联系方式",
				});
				$("#supplier_address_edit").val(supplier.address);
				$("#supplier_address_edit").validatebox({
					required : true,
					missingMessage : "请输入单位地址",
				});
			} else {
				$.messager.alert("获取失败！", "未知错误导致失败，请重试！", "warning");
				$(".messager-window").css("z-index",10000);
			}
		}
	});

	$("#supplierModifyButton").click(function(){ 
		if ($("#supplierEditForm").form("validate")) {
			$("#supplierEditForm").form({
			    url:"Supplier/" +  $("#supplier_supplierId_edit").val() + "/update",
			    onSubmit: function(){
					if($("#supplierEditForm").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);
                    } 
			    }
			});
			//提交表单
			$("#supplierEditForm").submit();
		} else {
			$.messager.alert("错误提示","你输入的信息还有错误！","warning");
			$(".messager-window").css("z-index",10000);
		}
	});
});
