$(function(){
	$("#orderForm").ajaxForm({ dataType:'json',success:function(rt){
			if(rt.success){ qlib.tips({ icon:'success',msg:'操作成功' }); }else{ qlib.tips('操作失败'); }
		}
	});

});


function editGoods(orderGoodsId){
	if(!orderGoodsId || isNaN(parseInt(orderGoodsId,10))){ return; }
	var config = { name:"", action:"/qkadmin/order/", method:"POST", className:"form", id:"editGoodsForm",input:[{ label:"购买数量：",name:"pnum",className:"text",tip:"",value:"" }],hidden:[{ name:"act",value:"editGoods" },{ name:"inajax",value:"1" },{ name:"orderGoodsId",value:orderGoodsId }]};
	var html = "";
		$('<div id="editGoodsDialog"></div>').dialog({ title:'订单编辑',width:570,height:200,resizable:false,modal:false,buttons:[{
				text:'确定',click:function(){
					$("#editGoodsForm").validate({
						rules:{
							pnum:{ required:true,number:true }
						},
						submitHandler:function(){
							$("#editGoodsForm").ajaxSubmit({ cache:false,dataType:"json",success:function(rt){
									var tr = $("table.orderGoods").find("tbody").find("tr");
									if(rt.success){
										$("#orderGoods"+orderGoodsId).find("td").eq(1).find("span.pnum").text(rt.data.pnum);
										$("input[name='amount']").val(rt.data.amount);
										$.fn.popupClose();
									}else{
										$("#ajaxError").html(rt.message);
									}
								}
							});
						}
					});
					$("#editGoodsForm").submit();
				}
			}]
		});
		var form = createForm(config);
		$("#editGoodsDialog").append(form);
		$("#editGoodsDialog").append($("<div id='ajaxError'></div>"));
}

