G.app.order.products = {
	_packIds:function(a){
		var b=[];
		$.each(a,function(c,d){$.each(d.items,function(e,f){b.push(e)})});
		return b.join(",")
	},
	init:function(){
			if(G.logic.login.ifLogin(this,arguments)===false){return}
			var c=G.logic.login.getLoginUid(),d=G.app.order,a=d.products,b=G.util.parse.url();
			if(b.search.login==1||b.hash.login==1){
				G.util.post("/json.php?mod=shoppingcart&act=clear&uid="+c,{},function(){location.replace("/purchase/shoppingcart")})
			}else{
					if(b.search.ism==2){
						if(b.search.prule){
							G.util.localShare(function(e){d._esInfo=e.getItem("esshoppingcart_info");if("es_type" in d._esInfo&&"es_name" in d._esInfo){d._isES=true}a.initEsFn()})
						}else{a.initEsFn()}
					}else{a.initFn()}
			}
	},
	initEsFn:function(){
		var b=G.app.order,a=b.products;b.getESShoppingCart().getAll(function(f,e){var d;$.each(f||[],function(h,g){if(g.pid){d=g.pid}});if(!d){var c=function(){location.href="/purcahse/shoppingcart"};return G.ui.popup.showMsg("购物车为空，请先添加商品",c,c,c)}a._init(d)})},
	initFn:function(){//alert("pro");
		var b=G.app.order,a=b.products;
		b.getNormalShoppingCart().getAll(function(f,c){
			var e=[];
			$.each(f||[],function(h,g){if(g.pid){e.push((g.pid-0)+"|"+((g.pnum||1)-0)+"|"+(g.main_product_id-0)+"|"+(g.price_id-0)+"|"+(g.y_track||""))}});
			
			if(e.length>0){var d=G.logic.login.getLoginUid();G.util.post("/json.php?mod=shoppingcart&act=addproduct&uid="+d,{ids:e.join(",")},function(g){a._init();if(g&&g.errno==0){b.getNormalShoppingCart().clear()}})}else{a._init()}})
	},
	_init:function(b){
				if(G.logic.login.ifLogin(this,arguments)===false){return}
				var c=G.util.parse.url(),e=0,a=999;if(c.search.prule&&(c.search.tms-0)){e=c.search.prule;a=c.search.tms}
				var d=G.logic.login.getLoginUid();
				//prule:e,tms:a,ism:c.search.ism||0,items:b||"","act":"listcart"
				//alert($.post)

			G.util.post("/purchase/order/",{"act":"listcart"},function(f){
				
				if(f&&f.errno==0){
				var j=[],l={},g={},h={},k=0;
				if(f.data.conflictProducts){$.each(f.data.conflictProducts,function(o,q){h[q.pid1]={pid2:q.pid2,pName2:q.pName2}})}
				var i=0;
				$.each(f.data.items,function(o,s){
					//if(DisplayVerifyCode!==undefined&&DisplayVerifyCode){$.each(s.items,function(u,t){if(t.hasOwnProperty("rushing_buy")&&t.rushing_buy){G.app.order.verifycode.show()}})}
					var r=[];i++;s.groupName="订单"+i;
					l[o]={totalAmt:s.totalAmt,totalCut:s.totalCut,totalWeight:s.totalWeight,isVirtual:s.isVirtual,groupName:s.groupName,rule_benefits:s.rule_benefits,items:{}};
					$.each(s.items,function(u,t){
						t.match_cut=t.priceCutByMatch||0;t.price_chn=(t.price/100).toFixed(2);
						t.cash_back_chn=(((t.cash_back-0)+(t.match_cut-0))/100).toFixed(2);
						t.pic_url=G.logic.constants.getSmallUrl(t.product_char_id,0);
						t.cancoupon_desc=t.canUseCoupon?"":' <span class="hot">特价商品，不能使用优惠券</span>';
						t.desc=(t.color?("<span>颜色："+t.color+"</span>"):"")+(t.size?("<span>规格："+t.size.Size2Name+"</span>"):"");
						t.array_days=t.array_days=="有货，1-3天出货"||t.array_days=="有货，2-7天出货"?('<span class="hot">'+t.array_days+"</span>"):t.array_days;
						if(h[t.product_id]){t.conflictProductsDesc=G.logic.constants.getTipStr("与 "+h[t.product_id].pName2+" 不兼容。")}
						var w=[];
						$.each(t.gift||[],function(x,v){w.push('<p class="gifts"><span class="strong">['+(v.type==1?"组件":"赠品")+']</span> <span class="nor">'+v.name+"</span>"+(v.type==1?"":('<span class="no">x<span class="strong">'+v.num+"</span></span>"))+"</p>")});
						t.gifts_block=w.join("");
						t.total_sum="";
						t.oGroupId=o;
						r.push(t);
						l[o].items[t.product_id]=t;g[t.product_id]=t;k++
					});
					if(r.length>0){
						s.rule_benefits=isNaN(parseInt(s.rule_benefits,10))?0:parseInt(s.rule_benefits,10);
						var q=((s.totalAmt-s.totalCut-s.rule_benefits)/100).toFixed(2);q=(q<0)?0:q;r[0].total_sum='<td class="total" rowspan="'+r.length+'"><p psubid="'+o+'">&yen;'+q+'</p><span psdes="'+o+'"></span></td>'
					}
					j.push({groupName:" - <strong>["+s.groupName+"]</strong>",list:r})
				});

				if(k<=0){return G.ui.popup.showMsg(["您的购物车里面没有商品，请先将需要的商品加入购物车"],1,G.app.order.goBackURL,G.app.order.goBackURL)}
				var n=i>1;
				var m=$.extend(f.data,{isSubMode:n,productIds:G.app.order.products._packIds(f.data.items),items:l,pinfo:g,isCanVAT:f.data.invoice.isCanVAT,contentOpt:f.data.invoice.contentOpt,hasNoteBook:f.data.invoice.hasNoteBook});
				if(!n){$.each(j,function(q,o){o.groupName=""})}
				
				G.app.order.status.set("product",m);
				$("#summary").find("span[t=weight]").html((m.totalWeight/1000).toFixed(3)+"千克");
				G.app.order.price.set({shippingprice:0,goodsprice:f.data.totalAmt/100,discount:f.data.totalCut/100,centcut:0,prcode:0,benefits:f.data.promotion?(f.data.promotion.benefits||0)/100:0,prizePrice:f.data.prizePrice/100,scorePrice:f.data.scorePrice,interestAmount:0,downPayment:0,divideMoney:0});
				
				//if(f.data.promotion&&(!$.isEmptyObject(f.data.promotion))){G.app.order.status.set("tms",a);G.app.order.status.set("prule",e);$("#prbox").hide()}else{G.app.order.status.set("tms",null);G.app.order.status.set("prule",null);if(!f.data.userIsDealer){G.app.order.coupon.init()}else{$("#prbox").html("您属于炒货商用户，不能使用优惠券。").show()}}
					//alert(j[0]['list'][0]['pic_url']);
				G.ui.template.fillWithTPL("cartinfo",{sub_order:j});
				G.app.order.coupon.init();
				G.app.order.address.init();
				//G.app.order.point.init()
			}else{if(f&&f.errno==999){var p=function(){location.href="/purcahse/shoppingcart"};return G.ui.popup.showMsg(f.data,p,p,p)}else{if(f&&f.errno==500){G.logic.login.ifLoginJump();return}}var p=function(){location.reload()};return G.ui.popup.showMsg('系统繁忙，请稍候<a href="#" onclick="location.reload();return false">刷新</a>重试',p,p,p)}},"jsonp")
		}			
}