var getcartlist_url="/account/getcartlist.html";var tp_cartlist;$(document).ready(function(){tp_cartlist=TrimPath.parseDOMTemplate("jst_list");initCartList()});function initCartList(){$.post(getcartlist_url,function(b){var c=[];var a=$.json.decode(b);if(a.length==0){clearCart()}else{a.each(function(e,d){if(e.stock>0){c.push(e)}else{setCart({id:e.id,amount:0})}})}$("#cartlist").html(tp_cartlist.process({items:c}));bindEvent();computeTotal()})}function bindEvent(){$('tr[stock][markId] [mark="-"]').click(function(){var a=Number($(this).next().val());a--;$(this).next().val(a);amountChange.call($(this).next().get(0))});$('tr[stock][markId] [mark="+"]').click(function(){var a=Number($(this).prev().val());a++;$(this).prev().val(a);amountChange.call($(this).prev().get(0))});$('tr[stock][markId] input[type="text"]').keydown(function(d){var c=d.keyCode;var b=c==8||c==46||c==37||c==39;var a=c>47&&c<58;var e=c>95&&c<106;if(!(b||a||e)){d.preventDefault()}});$('tr[stock][markId] input[type="text"]').keyup(function(c){var b=c.keyCode;var a=b>47&&b<58;var d=b>95&&b<106;if(a||d){amountChange.call(this)}});$('tr[stock][markId] input[type="text"]').focus(amountChange);$('tr[stock][markId] input[type="text"]').blur(amountChange);$("#btnClearCart").click(function(){if(window.confirm("确定要清空购物车吗?")){clearCart();$("#cartlist").html(tp_cartlist.process({items:[]}));computeTotal()}});$("tr[stock][markId]").children(":last-child").click(function(){if(window.confirm("确定删除该商品吗?")){var a=$(this).parent().attr("markId");setCart({id:a,amount:0});$(this).parent().remove();computeTotal()}})}function amountChange(){var d=Number($(this).parent().parent().attr("stock"));var a=$(this).parent().parent().attr("markId");var b=Number($(this).val());var c=1;if(b>d){c=d}else{if(b<1){c=1}else{c=b}}setCart({id:a,amount:c});$(this).val(c);computeTotal()}function computeTotal(){var b=0,a=0;$("tr[stock][markId]").each(function(){var e=Number($(this).children(":eq(2)").html());var f=Number($(this).children(":eq(3)").html());var d=Number($(this).children(":eq(4)").children('input[type="text"]').val());var c=e*d;a+=e*d;b+=f*d;$(this).children(":eq(5)").html(c.toFixed(2))});$("#tw").html(b.toFixed(2));$("#tc").html(a.toFixed(2))};
