").attr({src:this.storeHost+t.sm,alt:"设计图"}).appendTo(n);if(this.isAdmin&&t.labels.length>0&&this.addImgLabels(n,t.labels),this.isAdmin){$('
').appendTo(n)}$("#container").append(n)},initLayerClose:function(){var t=$(".layer"),i=$("html");$("#close").click(function(){i.css("overflow","auto"),t.hide(),$("#originalImage").remove()})},arrangeFirstRow:function(t){if($("#container").html(""),!(t.length<=0)){this.initStatus();for(var i=t.length0&&this.arrange(t)}},arrange:function(t){function i(t){if(t&&!(t.length<1)){for(var a=Math.min.apply(null,e.logs),n=0,s=0;s.5*i&&t.getDesigns(++t.pageNum,t.label,t.category,t.color,t.arrange):e+i>t.preMinimum&&t.getDesigns(++t.pageNum,t.label,t.category,t.color,t.arrange)})},getDesigns:function(t,i,e,a,n){var t=t||1,s=this;s.label=i,s.category=e,s.color=a,$.get("/api/designs/?pageNum="+t+"&label="+i+"&category="+e+"&color="+a,function(t){if(!t)return alert("服务器错误!");s.isAdmin=t.isAdmin?1*t.isAdmin:0,t.code&&t.designs.length<=0&&(s.hasNext=!1),t.code&&n.call(s,t.designs),t.code||(alert(t.msg),console.error(t.err))})},showBottomMessage:function(){$(".alert").length>0||$('没有更多了
').css("top",Math.max.apply(null,this.logs)+"px").appendTo("#container")},getWrapWidth:function(){return this.wrapWidth},getMargin:function(){return this.margin},addImgLabels:function(t,i){var e="",a=$('');$.each(i,function(t,i){e+=''+(i.name?i.name:"")+""}),a.html(e),a.appendTo(t)},checkMbt:function(){this.isMbt="block"==$("#mbt").css("display")}};var i=new t;$.get("/api/labels",function(t){if(!t)return alert("服务器错误!");t.code&&(n(t.labels),a.setLabels(t.labels)),t.code||lert("获取标签信息失败!")});var e=function(){this.arr=[]};e.prototype={setLabels:function(t){this.arr=t},getLabels:function(){return this.arr}};var a=new e,n=function(t){if(!(t.length<=0)){var i=$(".labels"),e='全部';$.each(t,function(t,i){e+=''+i.name+""}),i.html(e)}};$(".top").delegate("li","click",function(t){$(this).parent().children(".active").removeClass("active"),$(this).addClass("active"),function(){var t=$(".top > .labels > .active").data("id"),e=$(".top > .category > .active").data("id"),a=$(".top > .color > .active").data("id");i.getDesigns(1,t,e,a,i.arrangeFirstRow)}()});!function(){var t=$(".layer"),e=$("html");i.originalImagePath;$("#container").delegate(".box","click",function(a){var n=$(this).data().lg;$('').attr({src:i.storeHost+n,alt:"设计原图"}).appendTo(t),t.show(),e.css("overflow","hidden")})}();$("#container").delegate("li","click",function(t){var i=$(this),e=i.parents(".box"),a=i.attr("class"),n=e.data("id");"edit"===a&&s(n,e),"del"===a&&confirm("确定删除吗?")&&r(n,e),t.stopPropagation()});var s=function(t,i){$(".edit-zone").children("p").text(t),c(i),o(i)},o=function(t){var e=$(".edit-zone"),a=e.width(),n=t.offset(),s=n.left,o=n.top,c=parseInt($(document).width()/2,10),l=i.getWrapWidth(),r=i.getMargin(),d={x:0,y:0};d.y=o,d.x=c>s+l/2?s+l-r:s-a-r,e.css({top:d.y,left:d.x,display:"block"})},c=function(t){var i=$(".edit-zone"),e=$(".edit-zone > #labels"),n=($(".edit-zone > .color > label"),$(".edit-zone > .color > input")),s=$(".edit-zone > .category > label.pc"),o=$(".edit-zone > .category > input#pc"),c=$(".edit-zone > .category > label.mb"),l=$(".edit-zone > .category > input#mb");e.html(""),$(".edit-zone .active").removeClass("active"),$(".edit-zone :checked").removeAttr("checked");var r=a.getLabels(),d=t.children(".box-labels").children(),h=t.data("colors");console.log(h),h="string"==typeof h?h.split(","):[h];var g=t.data("category");$.each(r,function(t,i){var a=$("").text(i.name);$.each(d,function(t,e){i._id===$(e).data().id&&a.addClass("active")}),e.append(a)}),h.length>0&&$.each(n,function(t,e){$.each(h,function(t,a){$(e).val()==a&&($(e).attr("checked","checked"),i.find("label."+$(e).attr("id")).addClass("active"))})}),g?(c.addClass("active"),l.attr("checked","checked")):(s.addClass("active"),o.attr("checked","checked"))};$(".edit-zone").delegate("li","click",function(t){$this=$(this),$this.hasClass("active")?$this.removeClass("active"):$this.addClass("active")});!function(){var t=$("#confirm"),i=$("#cancel"),e=$(".edit-zone"),a=$(".edit-zone > #labels");t.click(function(){$(this).parents(".box");var t=e.children("#title").text(),i=a.children(".active"),n=$(".edit-zone > .color > :checked"),s=$(".edit-zone > .category > :checked"),o=$.map(i,function(t){return $(t).data("id")}),c=$.map(n,function(t){return $(t).val()}),r=s.val();l({id:t,labelIds:o,colors:c,category:r}),e.hide()}),i.click(function(){e.hide()})}();var l=function(t){console.log(t),$.ajax({url:"/api/design",type:"PUT",data:t,success:function(t){if(t.code)return i.getDesigns(1,0,-1,-1,i.arrangeFirstRow);alert("标签修改失败")},error:function(t){alert("服务器错误")}})},r=function(t,i){var e={url:"/api/design/"+t,type:"DELETE",success:function(t){t.code&&function(t){t.click(function(){return!1}),$('').appendTo(t)}(i),t.code||alert("删除失败,请刷新后重试!")},error:function(t){alert("服务器错误!")}};$.ajax(e)};initScollTop(),$(".category > label, .category > li").click(function(t){$(this).parent().children(".active").removeClass("active"),$(this).addClass("active")}),$(".color > li").click(function(t){$(this),$(".color > li.active").removeClass("active"),$(this).addClass("active")}),$(".color > label").click(function(){var t=$(this);t.hasClass("active")?t.removeClass("active"):t.addClass("active")})})