类别: '+a+' ¥'+(t.price&&t.price.price)+"
"},genMdHtml:function(t){return''},genLgHtml:function(t){return''},genThumbnailHtml:function(t,e){return''},appendMdHtml:function(e){var a="",l=this,i=t(".name > font"),c=t(".name > a"),o=t(".list_price > font"),s=t(".list .title");e.forEach(function(t,e){a+=l.genMdHtml(t)}),this.$listContent.empty(),this.$listContent.html(a),i.text(this.web.name),c.attr("data-clipboard-text",this.web.name),o.text("¥"+this.web.price.price),s.text(this.web.title),this.$top_collect.attr("data-id",this.web._id),this.$top_cancel_collect.attr("data-id",this.web._id),this.$top_cancel_collect.parent().hide(),this.$top_collect.parent().hide(),this.web.isCollect?this.$top_cancel_collect.parent().show():this.$top_collect.parent().show()},appendPriceHtml:function(){var e=this,a='全部';t.ajax({url:"/api/price",method:"GET"}).done(function(t){if(!t.status)return console.error(t.err),void alert("有错误");t.data.forEach(function(t,e){a+=''+t.price+""}),e.$price.html(a)}).fail(function(t){console.error(t),alert("服务器错误")})},appendCategoryHtml:function(){var e=this,a='全部';t.ajax({url:"/api/shop/category",method:"GET"}).done(function(t){t.data.forEach(function(t,e){a+=''+t.name+""}),e.$category.html(a)}).fail(function(t){console.error(t),alert("服务器错误")})},appendWebHtml:function(e){var a=this,l="";t.ajax({url:"/api/web",method:"GET",data:{params:e}}).done(function(t){if(!t.status)return console.error(t.err),void alert("有错误");a.webs=t.data,a.webs.forEach(function(t,e){l+=a.boxHtml(t,e)}),a.$container.html(l),t.data.length<=0?a.$empty_container.show():a.$empty_container.hide()}).fail(function(t){console.error(t),alert("服务器错误")})},appendLgHtml:function(e){var a=this.genLgHtml(e);t(".lg > img").remove(),this.$lg.append(t(a))},initContainerClick:function(){var e=this;this.$container.click(function(a){i="";if("shade"===a.target.className&&(i=t(a.target).parents(".box").data("index"),e.web=e.webs[i],e.appendMdHtml(e.web.mds),e.$list.show(),t("html").css("overflow","hidden"),e.web.lgs=e.web.lgs.sort(),e.web.mds=e.web.mds.sort(),e.web.sms=e.web.sms.sort()),t(a.target).hasClass("collect")){var l=t(a.target).data("id"),i=t(a.target).data("index");if(t(a.target).hasClass("collected")){c=[];window.localStorage.collects&&window.localStorage.collects.split(","),c=c.filter(function(t){return t!==l}),window.localStorage.collects=c,t(a.target).removeClass("collected"),e.$message.show({icon:"tuichu",text:"已取消收藏",icon:"tuichu"}),e.webs[i].isCollect=!1}else{t(a.target).addClass("collected");i=t(a.target).data("index");if(e.$message.show({icon:"gou",text:"收藏成功",icon:"gou"}),e.webs[i].isCollect=!0,!window.localStorage.collects)return window.localStorage.collects=[l];var c;(c=window.localStorage.collects.split(",")).unshift(l),window.localStorage.collects=c}}})},initListOperator:function(){var e=this;t(".equipment").click(function(a){if(a.stopPropagation(),"LABEL"==a.target.tagName.toUpperCase()){var l=t(a.target);t(".equipment > .active").removeClass("active"),l.addClass("active"),e.params.equipment=l.next().val(),e.params.page=1,e.appendWebHtml(e.params),e.initPagination(e.params)}}),t(".color").click(function(a){if(a.stopPropagation(),"LABEL"==a.target.tagName.toUpperCase()){var l=t(a.target);l.hasClass("active")||(t(".color > .active").removeClass("active"),l.addClass("active"),e.params.colors=Number(l.next().val()),e.params.page=1,e.appendWebHtml(e.params),e.initPagination(e.params))}}),t(".price").click(function(a){if(a.stopPropagation(),"SPAN"==a.target.tagName.toUpperCase()){var l=t(a.target);l.hasClass("active")||(t(".price > .active").removeClass("active"),l.addClass("active"),e.params.price=l.data("id"),e.params.page=1,e.appendWebHtml(e.params),e.initPagination(e.params))}}),t(".category").click(function(a){if(a.stopPropagation(),"SPAN"==a.target.tagName.toUpperCase()){var l=t(a.target);l.hasClass("active")||(t(".category > .active").removeClass("active"),l.addClass("active"),e.params.categories=l.data("id"),e.params.page=1,e.appendWebHtml(e.params),e.initPagination(e.params))}}),t(".myCollects").click(function(){var t=[];e.collects_page=1,window.localStorage.collects?(window.localStorage.collects&&(t=window.localStorage.collects.split(",")),t=t.slice((e.collects_page-1)*e.collects_num,e.collects_page*e.collects_num),e.collects=t,e.getCollectData(t),e.initCollectsPagination(),e.$html.css("overflow","hidden")):(e.$empty_collects.show(),t=[]),e.$collects.css("right","0%")})},getCollectData:function(e){var a=this;t.ajax({url:"/api/collects",method:"GET",data:{ids:e}}).done(function(t){if(!t.status)return console.error(t.err),void alert("有错误");t.data.length>0?(a.appendCollectsHtml(t.data),a.collects=t.data,a.$empty_collects.hide()):(a.$collects_content.empty(),a.$empty_collects.show(),a.collects=[],a.$collect_page.hide())}).fail(function(t){console.error(t),alert("服务器错误")})},genCollectsHtml:function(t,e){var a=t.categories.map(function(t,e){return t.name}).join(",");return' 类别: '+a+' ¥'+(t.price&&t.price.price)+"
"},appendCollectsHtml:function(t){var e=this,a="";this.collects.forEach(function(l,i){t.forEach(function(t,i){t._id==l&&(a+=e.genCollectsHtml(t,i))})}),this.$collects_content.html(a)},appendCollectMdHtml:function(e){var a="",l=this,i=t(".name > font"),c=t(".name > a"),o=t(".list_price > font"),s=t(".list .title");e.forEach(function(t,e){a+=l.genMdHtml(t)}),this.$listContent.empty(),this.$listContent.html(a),i.text(this.collect.name),c.attr("data-clipboard-text",this.collect.name),o.text("¥"+this.collect.price.price),s.text(this.collect.title),this.$top_collect.attr("data-id",this.collect._id),this.$top_cancel_collect.attr("data-id",this.collect._id),this.$top_cancel_collect.parent().hide(),this.$top_collect.parent().hide(),this.$top_cancel_collect.parent().hide(),this.$top_collect.parent().hide()},initCollectClick:function(){var e=this;this.$collects_content.click(function(a){var l="",i=t(a.target);if(i.hasClass("shade")&&(l=t(a.target).parents(".box").data("index"),e.collect=e.collects[l],e.web=e.collects[l],e.appendCollectMdHtml(e.collect.mds),e.$top_collect.parent().is(":hidden")||e.$top_collect.parent().hide(),e.$list.show(),t("html").css("overflow","hidden"),e.collect.lgs=e.collect.lgs.sort(),e.collect.mds=e.collect.mds.sort(),e.collect.sms=e.collect.sms.sort()),i.hasClass("collected")){var c=i.data("id"),o=window.localStorage.collects.split(",");if(o=o.filter(function(t){return t!==c}),e.collects=o,window.localStorage.collects=o,o.length<=0)return e.$collects_content.empty(),e.$empty_collects.show(),void e.$collects_page.hide();e.$message.show({icon:"tuichu",text:"已取消收藏",icon:"tuichu"}),o.length<=e.collects_num&&i.parents(".box").remove(),e.initCollectsPagination();var s={};2===e.collects_page&&o.length===e.collects_num?e.getCollectData(o):((s=e.$collects_page.children().eq(e.collects_page+1)).hasClass("next")&&(s=e.$collects_page.children().eq(e.collects_page)),s.trigger("click"))}})},initListTopClick:function(){var e=this;this.$list.click(function(a){a.stopPropagation();var l=t(a.target);if((l.parent().hasClass("back")||l.parent().parent().hasClass("back"))&&(e.checkCollect(),e.$list.css("display","none"),e.$html.css("overflow","auto")),l.parent().hasClass("top_collect")){i=l.data("id");if(e.$message.show({icon:"gou",text:"收藏成功",icon:"gou"}),e.$top_collect.parent().hide(),e.$top_cancel_collect.parent().show(),e.webs[e.detailIndex].isCollect=!0,!window.localStorage.collects)return window.localStorage.collects=[i];(c=window.localStorage.collects.split(",")).unshift(i),window.localStorage.collects=c}if(l.parent().hasClass("top_cancel_collect")){var i=l.data("id"),c=window.localStorage.collects.split(",");c=c.filter(function(t){return t!==i}),window.localStorage.collects=c,t(a.target).removeClass("collected"),e.$message.show({icon:"tuichu",text:"已取消收藏",icon:"tuichu"}),e.$top_collect.parent().show(),e.$top_cancel_collect.parent().hide(),e.webs[e.detailIndex].isCollect=!1}}),this.$listContent.click(function(t){t.stopPropagation(),e.checkCollect(),e.$list.css("display","none"),e.$html.css("overflow","auto")})},initListClick:function(){var e=this;this.$listContent.click(function(a){a.stopPropagation();var l="";"box"!==a.target.className&&"IMG"!==a.target.tagName.toUpperCase()||("box"===a.target.className&&(e.detailIndex=t(a.target).index()),"IMG"===a.target.className&&(e.detailIndex=t(a.target).parent().index()),e.appendLgHtml(e.web.lgs[e.detailIndex]),e.$detail.css("display","block"),e.$html.css("overflow","hidden")),e.web.sms.forEach(function(t,a){l+=e.genThumbnailHtml(t,a)}),e.$thumbnailInner.html(l)})},initDetailClick:function(){var e=this;this.$detail.click(function(a){a.stopPropagation(),"back"==a.target.className||"FONT"===a.target.tagName.toUpperCase()?(e.$detail.hide(),e.$list.show()):"prev"==a.target.id?(e.detailIndex<=0&&(e.detailIndex=e.web.lgs.length),e.detailIndex--,t(".thumbnail > .inner > .active").removeClass("active"),t(".thumbnail > .inner > a").eq(e.detailIndex).addClass("active"),e.appendLgHtml(e.web.lgs[e.detailIndex])):"next"==a.target.id&&(e.detailIndex>=e.web.lgs.length-1&&(e.detailIndex=-1),e.detailIndex++,t(".thumbnail > .inner > .active").removeClass("active"),t(".thumbnail > .inner > a").eq(e.detailIndex).addClass("active"),e.appendLgHtml(e.web.lgs[e.detailIndex]))})},initThumbnailClick:function(){var e=this;t(".thumbnail").click(function(a){if(a.stopPropagation(),"IMG"==a.target.tagName.toUpperCase()){var l=t(a.target);t(".thumbnail .active").removeClass("active"),l.parent().addClass("active"),e.detailIndex=l.parent().index(),e.appendLgHtml(e.web.lgs[e.detailIndex])}})},initClipBoard:function(){var t=this,e=new ClipboardJS(".title");e.on("success",function(){t.$message.show({icon:"xiaolian",text:"复制成功"})}),e.on("error",function(){t.$message.show({icon:"kulian",text:"复制失败"})});var a=new ClipboardJS(".name > a");a.on("success",function(){t.$message.show({icon:"xiaolian",text:"复制成功"})}),a.on("error",function(){t.$message.show({icon:"kulian",text:"复制失败"})})},initPagination:function(){var e=this;t.ajax({url:"/api/shop/pageMax",method:"GET",data:{params:e.params}}).done(function(a){a.status?e.$page.pagination({pageCount:a.pageMax,count:7,coping:!0,homePage:"«",endPage:"»",prevContent:"‹",nextContent:"›",mode:"fixed",activeCls:"active",jump:!0,jumpIptVal:e.params.page,jumpIptCls:"jump_input",callback:function(a){e.params.page=a.getCurrent(),e.appendWebHtml(e.params),t(".jump_input").val(e.params.page)}}):alert("有错误")}).fail(function(t){console.error(t),alert("服务器错误")})},checkCollect:function(){this.webs.forEach(function(e,a){var l=!1;window.localStorage.collects&&(l=~window.localStorage.collects.split(",").indexOf(e._id)),l?(e.isCollect=!0,t(".collect").eq(a).addClass("collected")):(e.isCollect=!1,t(".collect").eq(a).removeClass("collected"))})},initCollectsTopClick:function(){var e=this;this.$collects_top.click(function(a){var l=t(a.target);l.hasClass("collect_back")&&(e.checkCollect(),e.$top_collect.parent().show(),e.$collects.css("right","-100%"),e.$html.css("overflow","auto")),l.hasClass("collect_clear")&&window.localStorage.collects&&e.confirm_delete.show(function(){delete window.localStorage.collects,e.$collects_content.empty(),e.$empty_collects.show(),e.$collects_page.hide()})})},initCollectsPagination:function(){var t=this,e=Math.ceil(window.localStorage.collects.split(",").length/this.collects_num);t.$collects_page.pagination({pageCount:e,count:7,coping:!0,homePage:"«",endPage:"»",prevContent:"‹",nextContent:"›",mode:"fixed",activeCls:"active",jump:!1,callback:function(e){t.collects_page=e.getCurrent();var a=window.localStorage.collects.split(",").slice((t.collects_page-1)*t.collects_num,t.collects_page*t.collects_num);t.collects=a,t.getCollectData(a)}})}};new e}(jQuery)