$(function () {
	//实例化编辑器
	//建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
	UE.delEditor('customer_memo_edit');
	var customer_memo_edit = UE.getEditor('customer_memo_edit'); //客户备注编辑器
	customer_memo_edit.addListener("ready", function () {
		 // editor准备好之后才可以使用 
		 ajaxModifyQuery();
	}); 
  function ajaxModifyQuery() {	
	$.ajax({
		url : "Customer/" + $("#customer_customerId_edit").val() + "/update",
		type : "get",
		data : {
			//customerId : $("#customer_customerId_edit").val(),
		},
		beforeSend : function () {
			$.messager.progress({
				text : "正在获取中...",
			});
		},
		success : function (customer, response, status) {
			$.messager.progress("close");
			if (customer) { 
				$("#customer_customerId_edit").val(customer.customerId);
				$("#customer_customerId_edit").validatebox({
					required : true,
					missingMessage : "请输入记录id",
					editable: false
				});
				$("#customer_customerName_edit").val(customer.customerName);
				$("#customer_customerName_edit").validatebox({
					required : true,
					missingMessage : "请输入客户名称",
				});
				$("#customer_customerType_edit").val(customer.customerType);
				$("#customer_customerType_edit").validatebox({
					required : true,
					missingMessage : "请输入客户类型",
				});
				$("#customer_telephone_edit").val(customer.telephone);
				$("#customer_telephone_edit").validatebox({
					required : true,
					missingMessage : "请输入客户电话",
				});
				$("#customer_customerAddress_edit").val(customer.customerAddress);
				$("#customer_customerAddress_edit").validatebox({
					required : true,
					missingMessage : "请输入客户地址",
				});
				customer_memo_edit.setContent(customer.memo);
			} else {
				$.messager.alert("获取失败！", "未知错误导致失败，请重试！", "warning");
				$(".messager-window").css("z-index",10000);
			}
		}
	});

  }

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