//删除元素 function hintremove(obj){ $("#"+obj).remove(); } //添加进购物车 function cartadd(obj, webpath, linktype, linkurl){ var goods_id = $("#goods_id").val(); var goods_quantity = $("#goods_quantity").val(); var item = $(obj).parents('.shopitem'); if (!goods_id) { if (item.length < 1) return false; goods_id = item.data('id'); } if (!goods_quantity ) { goods_quantity = item.find('[name=goods_quantity]').val() || 1; } $.ajax({ type: "post", url: webpath + "tools/submit_ajax.ashx?action=cart_goods_add", data: { "goods_id": goods_id, "goods_quantity": goods_quantity }, datatype: "json", beforesend: function (xmlhttprequest) { //发送前动作 }, success: function (data, textstatus) { if (data.status == 1) { if (linktype == 1) { location.href = linkurl; } else { $("#cart_info_hint").remove(); var hinthtml = '
' + '
' + '
' + '' + lang.shop_cart_title_ok + '' + '

购物车共有' + data.quantity + '件商品,合计:' + data.amount + '

' + '去结算  ' + '再逛逛' + '关闭' + '
' + '
'; $(obj).after(hinthtml); //添加节点 } } else { $("#cart_info_hint").remove(); var hinthtml = '
' + '
' + '
' + '' + lang.shop_cart_title_fail + '' + '

' + data.msg + '

' + '关闭' + '
' + '
'; $(obj).after(hinthtml); //添加节点 //alert(data.msg); } }, error: function (xmlhttprequest, textstatus, errorthrown) { alert("状态:" + textstatus + ";出错提示:" + errorthrown); }, timeout: 20000 }); return false; } //删除购物车商品 function deletecart(obj, webpath, goods_id){ if(!confirm("您确认要从购物车中移除吗?") || goods_id==""){ return false; } $.ajax({ type: "post", url: webpath + "tools/submit_ajax.ashx?action=cart_goods_delete", data: {"goods_id" : goods_id}, datatype: "json", beforesend: function(xmlhttprequest) { //发送前动作 }, success: function(data, textstatus) { if (data.status == 1) { location.reload(); } else { alert(data.msg); } }, error: function (xmlhttprequest, textstatus, errorthrown) { alert("状态:" + textstatus + ";出错提示:" + errorthrown); }, timeout: 20000 }); return false; } //计算购物车金额 function cartamounttotal(obj, webpath, goods_id){ if(isnan($(obj).val())){ alert('商品数量只能输入数字!'); $(obj).val("1"); } $.ajax({ type: "post", url: webpath + "tools/submit_ajax.ashx?action=cart_goods_update", data: { "goods_id" : goods_id, "goods_quantity" : $(obj).val() }, datatype: "json", beforesend: function(xmlhttprequest) { //发送前动作 }, success: function(data, textstatus) { if (data.status == 1) { location.reload(); } else { alert(data.msg); location.reload(); } }, error: function (xmlhttprequest, textstatus, errorthrown) { alert("状态:" + textstatus + ";出错提示:" + errorthrown); }, timeout: 20000 }); return false; } //购物车数量加减 function cartcomputnum(obj, webpath, goods_id, num, countall) { if(num > 0){ var goods_quantity = $(obj).prev("input[name='goods_quantity']"); $(goods_quantity).val(parseint($(goods_quantity).val()) + 1); //计算购物车金额 if (countall !== false) cartamounttotal($(goods_quantity), webpath, goods_id); }else{ var goods_quantity = $(obj).next("input[name='goods_quantity']"); if(parseint($(goods_quantity).val()) > 1){ $(goods_quantity).val(parseint($(goods_quantity).val()) - 1); //计算购物车金额 if (countall !== false) cartamounttotal($(goods_quantity), webpath, goods_id); } } } //计算支付手续费总金额 function paymentamounttotal(obj){ var payment_price = $(obj).next("input[name='payment_price']").val(); $("#payment_fee").text(payment_price); //运费 orderamounttotal(); } //计算配送费用总金额 function freightamounttotal(obj){ var express_price = $(obj).next("input[name='express_price']").val(); $("#express_fee").text(express_price); //运费 orderamounttotal(); } //计算订单总金额 function orderamounttotal(){ var goods_amount = $("#goods_amount").text(); //商品总金额 var payment_fee = $("#payment_fee").text(); //手续费 var express_fee = $("#express_fee").text(); //运费 var order_amount = parsefloat(goods_amount) + parsefloat(payment_fee) + parsefloat(express_fee); //订单总金额 = 商品金额 + 手续费 + 运费 $("#order_amount").text(order_amount.tofixed(2)); }