/
ZKEACMS.Basket.min.js
4 lines (4 loc) · 3.52 KB
/
ZKEACMS.Basket.min.js
1
2
3
4
/*! http://www.zkea.net/
* Copyright (c) ZKEASOFT. All rights reserved.
* http://www.zkea.net/licenses */
var ZKEACMS=ZKEACMS||{};ZKEACMS.Basket={Add:function(n,t){Object.assign(n,ZKEACMS.AntiToken);$.post("/Basket/Add",n,function(n){n.location?window.location=n.location:t&&t.call(n)})},Update:function(n,t){Object.assign(n,ZKEACMS.AntiToken);$.post("/Basket/Update",n,function(n){n.location?window.location=n.location:t&&t.call(n)})},Remove:function(n,t){$.post("/Basket/Remove",Object.assign({basketId:n},ZKEACMS.AntiToken),function(n){n.location?window.location=n.location:t&&t.call(n)})},Get:function(n){$.post("/Basket/GetBaskets",Object.assign({},ZKEACMS.AntiToken),function(t){n&&n.call(t)})},ShowBasket:function(){$.post("/Basket/Index",Object.assign({},ZKEACMS.AntiToken),function(n){if(n.location)window.location=n.location;else{var i=$("body>.basket"),t=$(n);i.length>0?(t.addClass("active"),i.replaceWith(t)):($("body").append(t),setTimeout(function(){t.addClass("active")},10))}})}};$(function(){function t(t){n.length>0&&(t.data&&t.data.quantity>0?(n.children().addClass("active"),n.children(".quantity").text(t.data.quantity)):(n.children().removeClass("active"),n.children(".quantity").text("")))}$(document).on("click",".basket .close",function(){$("body>.basket").removeClass("active");setTimeout(function(){$("body>.basket").remove()},300)});$(document).on("click",".add-to-basket",function(){var i=$(this).data("tags"),n;i||(n=[],$(this).closest(".product-ecommerce").find("input[type=radio]:checked").each(function(){n.push($(this).val())}),n.length>0&&(i=n.join(";")));ZKEACMS.Basket.Add({productId:$(this).data("productid"),quantity:$(this).data("quantity"),tags:i},function(){ZKEACMS.Basket.ShowBasket();t(this)})});$(document).on("click",".basket .quantity-minus",function(){var n=Number($.trim($(this).closest(".quantity-set").find(".quantity").text())),i,r;n>1&&(n-=1,i=$(this).closest(".basket-item"),i.find(".quantity").text(n),r=i.data("id"),Easy.Processor(function(){ZKEACMS.Basket.Update({basketId:r,quantity:n},function(){$(".basket .total-items").text(this.data.quantity);$(".basket .total-price").text(this.data.total.toFixed(2));t(this)})},300))});$(document).on("click",".basket .quantity-plus",function(){var n=Number($.trim($(this).closest(".quantity-set").find(".quantity").text())),i,r;n+=1;i=$(this).closest(".basket-item");i.find(".quantity").text(n);r=i.data("id");Easy.Processor(function(){ZKEACMS.Basket.Update({basketId:r,quantity:n},function(){$(".basket .total-items").text(this.data.quantity);$(".basket .total-price").text(this.data.total.toFixed(2));t(this)})},300)});$(document).on("click",".basket .remove",function(){var n=$(this).closest(".basket-item").data("id");ZKEACMS.Basket.Remove(n,function(){$(".basket #basket-"+n).remove();$(".basket .basket-body>ul>li").length==0&&($(".basket .basket-body>ul").append('<li class="row empty text-center">您的购物车是空的<\/li >'),$(".basket .basket-footer").remove());t(this)})});$(document).on("click",".basket .ckeck-out",function(){$.post("/Basket/CheckOut",Object.assign({},ZKEACMS.AntiToken),function(n){if(n.location)window.location=n.location;else{var i=$("body>.basket"),t=$(n);i.length>0?(t.addClass("active"),i.replaceWith(t)):($("body").append(t),setTimeout(function(){t.addClass("active")},10))}},"html")});$(document).on("click",".basket .confirm-order",function(){$("#PaymentGateway").val($(this).data("payment"));$(this).closest("form").submit()});var n=$(".navigation .show-basket");n.length>0&&(ZKEACMS.Basket.Get(function(){t(this)}),n.click(ZKEACMS.Basket.ShowBasket))});