/// ec.product = { api: new ec.api("product"), init: function () { ke.ui.render(); //$(".history .list").each(function () { // var el = $(this); // el.css({ width: 244 * el.children().length }); //}); this.getProductPage(); $(".product .tab li").click(function () { ec.product.changeShowDesc($(this).attr("value")); }); $(".sidenav dd").hover(function () { $(this).find(".children").stop().slideToggle(); $(this).siblings().find(".children").slideUp(); }) }, changeShowDesc: function (i) { $(".base-item").hide().eq(i).show(); $(".product .tab li").removeClass("fb3 ch1").eq(i).addClass("fb3 ch1"); }, shareUrl: function () { var url = window.location.href; var input = $(".favorite .share"); input.val(url); input.select(); try { if (document.execCommand('copy', false, null)) { document.execCommand("copy"); ec.notify(L.G("已经复制到剪切板")); } else { ec.notify(L.G("复制失败,您的浏览器不支持,请手动复制"), "error"); } } catch (err) { ec.notify(L.G("复制失败,您的浏览器不支持,请手动复制"), "error"); } }, getProductPage: function () { var isBar = $(".rightbar").length > 0; $(".history .list").each(function () { var el = $(this); var productCount = el.find(".item").length; if (productCount > 0) { var count = 0; count = Math.ceil(productCount / 5); var html = ""; for (var i = 0; i < count; i++) { html += ""; } el.parent().next().html(html); el.css({ width: 220 * el.children().length }); } }); }, pageTurned: function (el) { var index = $(el).index(); $(el).siblings().find(".ico").removeClass("ico-diamond2-hover"); $(el).find(".ico").addClass("ico-diamond2-hover"); $(el).parent().prev().find(".list").stop().animate({ left: -1100 * index }, 600); }, coa: function (isTop, num) { var num = isTop ? num : ItemNumber.get(); var lot = isTop ? CoaDown.get() : LotNumber.get(); var msg = ""; if (!num) msg = L.G("请输入产品编号"); else if (!lot) msg = L.G("请输入产品批次"); if (!msg) ec.search.coaDownload(num, lot); else ec.notify(msg, "question", 3000); }, sds: function () { ec.notify(L.G("暂不开放"), "question", 3000); //ke.openWindow(L.G("下载MSDS"), $("#sdsUrl").val(), 400, 400); }, alter: function (el, mins) { input = $(el).parents(".price .amount").find("input"); var amount = parseInt(input.val()); amount += (mins || 0); amount = (amount >= 0 ? amount : 0); input.val(amount); }, addCart: function (el) { var r = ""; var info = []; var items = $(el).parents("tr"); items.each(function () { var proItem = {}; var num = parseInt($(this).find("input").val()); if (num > 0 && num <= 100) { proItem.ProductPriceRid = $(this).attr("data-id"); proItem.Amount = num; info.push(proItem); }; }); var callbck = function (r) { ec.product.addCartSuc(r, el); }; if (info.length <= 0) ec.notify(L.G("请输入1-100之间的产品数量"), "question", 3000); else { ec.disable(el); ec.cart.add(info, callbck); } }, addCartSuc: function (r, el) { var amount = 0; var rid = parseInt($("#proRid").attr("value")); var tip = $(".product .info .tip"); var pic = $(".product .info img").attr("src"); var btn = $(el);; r.forEach(function (d) { if (rid == d.ProductRID) amount += d.Amount; }); ec.enable(el); tip.toggle(amount > 0); ec.notify(L.G("成功添加至购物车中")); }, } ec.productList = { api: new ec.api("product"), classId: "", init: function () { ke.ui.render(); ke.ui.findControls("filter", "input").forEach(function (con) { con.change(function () { ec.productList.filter.getData(1); }); }); var type = ke.parm("filter"); ke.ui.findControls("product_tags", "input").forEach(function (con) { if (con.skin.id == type) { con.click(); ec.productList.filter.getData(1); } }); $(".sidenav dd").hover(function () { $(this).find(".children").stop().slideToggle(); $(this).siblings().find(".children").slideUp(); }) }, sidenavToggle: function (e,el) { if (!e) e = window.event; var reltg = e.relatedTarget ? e.relatedTarget : e.toElement; while (reltg && reltg != this) reltg = reltg.parentNode; if (reltg != this) { $(el).children().stop().slideToggle(); $(el).siblings().children().slideUp(); } }, price: { getData: function (el, productNum) { var isShow = $(el).parents("tr").hasClass("active"); if (!isShow) { ec.utilities.loading(); ec.productList.api.get("getPrice?productNum=" + productNum, function (r) { ec.productList.price.render(el, r); }); } else { ec.productList.price.render(el); } }, render: function (el, r) { var item = $(el).parents("tr"); item.toggleClass("active"); var price = item.next(); price.toggleClass("active1").toggle(); item.prev().prev().toggleClass("active2"); $(el).find("span").html(item.hasClass("active") ? L.G("收回") : L.G("价格库存")); if (r) { var html = ke.template.get("price_table").render(r); item.next().find(".price").html(html); ec.utilities.unLoading(); } } }, filter: { pn: 1, getData: function (pn, mode) { if (pn) this.pn = pn; ec.utilities.loading(); var url = "/getListData"; if (ec.productList.classId) url += "?classId=" + ec.productList.classId + "&pn=" + pn; else url += "?pn=" + this.pn; if (mode >= 0) url += "&mode=" + mode; var info = ke.createObject("filter"); info.Tags = []; $("#product_tags .input").each(function () { var el = $(this); if (el.hasClass("checkbox-selected")) info.Tags.push(el.attr("id")); }) ec.productList.api.post(url, info, function (r) { ec.productList.filter.render(r); }); }, render: function (r) { ec.utilities.unLoading(); $(".product-data").html(r.dataHtml); $(".ico-array1").toggleClass("ico-array1-hover", r.mode != 2); $(".ico-array2").toggleClass("ico-array2-hover", r.mode == 2); $("#search_total").html(r.Pager.Total); $(".paging a").removeClass("active").eq(r.Pager.PageIndex).addClass("active"); $(".nodata").toggle(r.Pager.Total == 0); $(".paging").toggle(r.Pager.Total > 0); $(".product-data").toggle(r.Pager.Total > 0); this.paging(r.Pager); window.scrollTo(0, 0); }, paging: function (data) { var html = ""; html += ""; for (var i = data.Start; i <= data.End; i++) { html += "" + i + ""; } html += ""; $(".paging").html(html); } }, navToggle: function (el) { $(el).find(".ico10").toggleClass("ico-up10"); $(el).parent().nextAll().slideToggle(); }, alter: function (el, mins) { input = $(el).parents("#product_list1 .amount").find("input"); var amount = parseInt(input.val()); amount += (mins || 0); amount = (amount >= 0 ? amount : 0); input.val(amount); }, } $(window.document).ready(function () { _api_error = ec.api.error; ec.api.error = function (req, textStatus) { ec.enable(".btn-cart .btn1"); _api_error(req, textStatus); } });