-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdcr.js
1 lines (1 loc) · 19.8 KB
/
dcr.js
1
(function(e){"use strict";var t=window.navigator.userAgent.indexOf("Chrome")>-1;if(!t){document.body.innerHTML='<br><h2> 您目前的浏览器不是chrome(谷歌)浏览器,不支持相关操作。 请更换浏览器后再进入本页面。<br><br> <a href="https://www.baidu.com/s?ie=UTF-8&wd=chrome">点击此处下载</a></h2>'}else{var a="";if(typeof getContextPath=="function"){a="../../"}else{window.getContextPath=function(){return"http://localhost:3000"}}var o=getContextPath()+"/goods/appGoodsList";var r=getContextPath()+"/goods/appSaveDecoration";var i=getContextPath()+"/goods/appUploadShopPic";var n=getContextPath()+"/goods/appShopDecoration";var c=function(e){return document.getElementById("temp-"+e).innerHTML};var l=function(e){return document.getElementById("temp-ctrl-"+e).innerHTML};var s={"tb-features":"品牌优势<hr>四个LOGO,醒目展现亲小店的优势","hd-features":"品牌优势<hr>四个LOGO,醒目展现亲小店的优势","bb-features":"品牌优势<hr>四个LOGO,醒目展现亲小店的优势","hd-brands":"各大品牌LOGO陈列<hr>一个品牌一个贴图,琳琅满目,快拖进手机里看看吧~","tb-category":"商品分类<hr>列出宝贝的几大类,供顾客挑选哦~","bb-category":"商品分类<hr>列出宝贝的几大类,供顾客挑选哦~","hd-category":"商品分类<hr>列出宝贝的几大类,供顾客挑选哦~",singleGood:"这是单宝贝模块<hr>拖入手机 ,然后点击,可以在右侧自定义宝贝的信息",doubleGood:"这是双宝贝模块<hr>两个宝贝并列, 拖入手机后点击,在右侧自定义宝贝的信息",singlePic:"单图片模块<hr>一般选择一张宣传热图, 或者,可以一张装饰性的图片.<br>如果是纯装饰性的 ,可以不要文字和链接",slideBox:"轮播图片模块<hr>也称幻灯片,可以选择多张图片(直接输入链接或上传),将在首页自动切换轮播",doublePic:"并列图片<hr>一般用来做品牌区域,块状LOGO图",wordPic:"图文并茂<hr> 做图需要美工在左侧纯色或留白",bannerPic:"横幅图片<hr>醒目的广告宣传横图,独占一行,可以放入多幅",titleOnly:"纯文字的标题<hr>用于分段标注",wordOnly:"纯粹的文字<hr>说一些你想跟卖家说的话吧",contract:"您的联系方式<hr>写上电话卖家更容易联系到你",singleGoodList:"宝贝列表模块<hr>多行, 每行展示一个宝贝,包括图片,文字介绍和价格.<br>具体设置请拖入手机后, 单击手机内该模块",doubleGoodList:"宝贝列表模块<hr>多行, 每行展示两个宝贝,包括图片,文字介绍和价格.<br>具体设置请拖入手机后, 单击手机内该模块"};var d={"val-singleGood":{href:"#",picPath:a+"img/decorate/re-good.jpg",name:"宝乐滋3罐超值特价装!",price:92},"val-doubleGood":{href:"#",picPath:a+"img/decorate/good17.jpg",name:"漂亮的女童裤子 纯棉",price:56,href2:"#",picPath2:a+"img/decorate/good13.jpg",name2:"小脚裤子批发 颜色多",price2:52},"val-wordPic":{href:"#",imgsrc:a+"img/decorate/word-pic.jpg",desc:"图片描述文字,一些文字,怕怕拉拉,什么的<br>或者,图片可以做成100%<br>文字遮罩在图片左上角<br>这需要图片设计配合<br>左上角统一色调或留白"},"val-slideBox":[{href:"#",imgsrc:a+"img/decorate/slide.jpg"},{href:"#",imgsrc:a+"img/decorate/slide2.jpg"},{href:"#",imgsrc:a+"img/decorate/slide3.jpg"}],"val-singlePic":{href:"#",imgsrc:a+"img/decorate/baby-house.jpg",desc:"婴童夏装换季清仓中! 点击进入专区!"},"val-doublePic":{href:"#",imgsrc:a+"img/decorate/baby-joy01.jpg",desc:"童车特价中! 点击进入专区!",href2:"#",imgsrc2:a+"img/decorate/baby-joy02.jpg",desc2:"玩具特价! 点击进入专区!"},"val-tb-category":{href:"#",imgsrc:a+"img/decorate/area-logo-01.jpg",desc:"LOGO AREA<br>奶粉专区",href2:"#",imgsrc2:a+"img/decorate/area-logo-02.jpg",desc2:"LOGO AREA<br>日用品专区",href3:"#",imgsrc3:a+"img/decorate/area-logo-03.jpg",desc3:"LOGO AREA<br>尿不湿专区",href4:"#",imgsrc4:a+"img/decorate/area-logo-04.jpg",desc4:"LOGO AREA<br>妈妈专区"},"val-bannerPic":{imgsrc:a+"img/decorate/banner.jpg",href:"#"},"val-bb-category":{imgsrc:a+"img/decorate/masonry.png"},"val-bb-features":{imgsrc:a+"img/decorate/hdnew-features.png"},"val-titleOnly":{title:"推荐宝贝"},"val-wordOnly":{desc:"欢迎光临小店!<br>本店的所有商品都是真宗境外海淘<br>海关保税仓发货, 优惠多多, 还有包邮<br>欢迎亲多多选购~~~ "},"val-contract":{tel:window.telphoneAccount||"1381396655",wechat:window.wechatAccount||"weixina2017006"},"val-hd-category":{href:"1100",imgsrc:a+"img/decorate/category/hd-category01.jpg",title:"奶粉",desc:"全球奶粉跨境购",href2:"1200",imgsrc2:a+"img/decorate/category/hd-category02.jpg",title2:"尿不湿",desc2:"轻松透气一整天",href3:"1300",imgsrc3:a+"img/decorate/category/hd-category03.jpg",title3:"辅食",desc3:"肠胃健康妈妈放心",href4:"1700",imgsrc4:a+"img/decorate/category/hd-category04.jpg",title4:"保健品",desc4:"全球保健品一站购"}};var f={"tb-features":2,"bb-features":2,"hd-features":2,"tb-category":2,"bb-category":2,"hd-category":2,"hd-brands":2,singleGood:8,doubleGood:8,slideBox:1,singlePic:6,bannerPic:6,doublePic:2,wordPic:3,wordOnly:3,titleOnly:12,contract:2,singleGoodList:1,doubleGoodList:1};var p={tempDefault:["singlePic","wordOnly","hd-brands","titleOnly","singleGoodList","contract"],tbstyle:[{name:"singlePic"},{name:"wordOnly"},{name:"tb-features"},{name:"titleOnly",data:{title:"热门品类"}},{name:"tb-category"},{name:"titleOnly"},{name:"doubleGoodList"},{name:"contract"}],bbstyle:[{name:"slideBox"},{name:"bb-features"},{name:"bb-category"},{name:"titleOnly",data:{title:"热门推荐"}},{name:"bannerPic"},{name:"titleOnly",data:{title:"热销宝贝"}},{name:"singleGood",data:{href:"#",picPath:"http://120.26.112.178/statics/attachment/adv/201508251150129137.jpg",name:"德国 碧然德 滤水壶,给健康的限时特价!",price:168}},{name:"singleGood",data:{href:"#",picPath:"http://120.26.112.178/statics/attachment/adv/201508251150511809.jpg",name:"荷兰牛栏三段,市场优选!",price:252}},{name:"singleGood",data:{href:"#",picPath:"http://120.26.112.178/statics/attachment/adv/201508251150338462.jpg",name:"宝宝的小屁屁最好的呵护~~~ 金装尿不湿!",price:268}},{name:"titleOnly"},{name:"doubleGoodList"},{name:"contract"}],hdstyle:[{name:"slideBox",data:[{href:"#",imgsrc:a+"img/decorate/hot.jpg"},{href:"#",imgsrc:a+"img/decorate/hot2.jpg"}]},{name:"hd-features"},{name:"titleOnly",data:{title:"品牌馆"}},{name:"hd-brands"},{name:"titleOnly",data:{title:"热门分类"}},{name:"hd-category"},{name:"titleOnly"},{name:"singleGoodList"},{name:"contract"}]};var h=[];var g=[];var m=[];e.ajax(o).always(function(e){if(e.result){h=e.data;d["val-singleGoodList"]=d["val-doubleGoodList"]=h.slice(0,6)}});var u=e("#temp-good-cell").html();var v=e("#show-mobile");var b='<a class="go-recycle">删除</a><a class="go-up">移上</a><a class="go-down">移下</a>';var w=e(".submit-reset-wrap");var y=e("#ctrl-area");var x=e("#ctrl-wrap");var O;var G=e("#goods-checked-done");var k=e("#goods-list-cls");var P='<a class="all-goods-href">查看所有宝贝 >></a>';var L=e("#goods-checked-list");var j=e("#goods-list");var C=e("#keyword-for-search");var D=e(".mask-main");var A=e("#main");var S=e("#helps");var T=e("#btn-help");var E=e("#never-again");var I=e("#confirm-main");var _=e("#confirm-content");var B=e("#confirm-cancel");var N=e("#confirm-ok");var H={str:"",handleEvent:function(){}};var q=e(".alert-assertive");var M=function(t,a){q.fadeIn(300,function(){setTimeout(function(){e(this).fadeOut(600)}.bind(this),a||2400)}).html(function(e,a){return t});return false};q.click(function(){e(this).hide()});B.click(function(){I.hide();D.hide()});var F=function(e,t){_.html(e.replace(/\n/gm,"<br>"));D.show();I.show();H.handleEvent=function(){I.hide();D.hide();t()};N[0].addEventListener("click",H,false)};var R={};window.indexCheckedGoods=window.indexCheckedGoods||[{_id:"5616195a5eb52804daf0f122",goods_id:1002,picPath:"img/decorate/goods/good32.jpg",href:"",mktprice:110,price:20,name:"童装男童男孩小孩纯棉夏天好用"}];window.indexCheckedGoods.forEach(function(e,t){R[e.goods_id||e.goodsId]=e});var z=function(){var t=e(document.createDocumentFragment());var a;g.forEach(function(o,r){a=e(u.replace(/\{name\}/gm,o["name"]).replace("{picPath}",o["thumbnail"]||o["picPath"]).replace("{href}","#/tab/goods/"+o["goods_id"]||o["goodsId"]).replace("{price}",o["price"]));a.data("good-info",o).html(function(e,t){return t+"<i>×</i>"});t.append(a)});e(".ctrlArea-goodsChecked-wrap").empty().append(t)};var J=function(t){var a=C.val();e.ajax({url:o,data:{pageSize:20,pageNum:t||1,keyword:a},type:"post"}).always(function(t){console.info(t);if(t.result==1){var a;j.empty();var o=e(document.createDocumentFragment());t.data.forEach(function(t,r){a=e(u.replace(/\{name\}/gm,t["name"]).replace("{picPath}",t["thumbnail"]||t["picPath"]).replace("{href}","#/tab/goods/"+t["goodsId"]).replace("{price}",t["price"]));a.data("good-info",t);o.append(a)});j.append(o);e("#now-pagenum").text(t.page.pageNum);e("#total-pagenum").text(t.page.pageCount)}else{console.info(t)}})};var K=function(t,a,o){var r,i,n;t.every(function(t,c){if(L.children().length<12){i=t["picPath"]||t["thumbnail"];n=e("<img>").prop("src",i);r=e('<div class="good-tag">').append(n).append("<i>×</i>").data("good-info",t);if(!a){o?m.push(t):g.push(t);L.append(r)}return true}else{M("首页推荐宝贝列表最多装载12个, 其余的可点击[全部宝贝]查看");return false}})};var U=function(t,a){var o=e(this).parent().index();a?m.splice(o,1):g.splice(o,1);e(this).parent().remove()};var Q=function(t,a){var o,r,i=e("<div>");if(a==1){o='<div class="" molid="singleGood"></div>';r='<a class="singleGood-wrap-one" > <img src="{picPath}" ><p>{name}</p><i>¥{price}</i></a>'}else{o='<div class="" molid="doubleGood"></div>';r='<a class="doubleGood-wrap-one" > <img src="{picPath}" ><p>{name}</p><i>¥{price}</i></a>'}var n,c,l=e(o)[0];t.forEach(function(s,d){n=r.replace("{name}",s["name"]).replace("{picPath}",s["thumbnail"]||s["picPath"]).replace("{href}",s["href"]).replace("{price}",s["price"]);c=e(n)[0];if(a==1){i[0].appendChild(c)}else{if(d%2==0){l=e(o)[0]}l.appendChild(c);if(d%2!=0||d==t.length-1){i[0].appendChild(l)}}});return i.html()+P};var V=function(e){L.empty();j.empty();m=[];!e&&z()};var W=function(t){t=t||[];var a,o,r,i,n,l,s,p=e("#show-mobile")[0];for(i=0;i<t.length;i++){l=t[i].name;s=t[i].data||d["val-"+l];a=c(l);if(l=="slideBox"){a=a.replace("{imgsrc}",s[0]["imgsrc"]).replace("{href}",s[0]["href"])}else if(l.lastIndexOf("GoodList")>-1){s=s||h.slice(0,8);a=a.replace("{content}",Q(s,l.indexOf("single")==0?1:2))}else{for(n in s){a=a.replace("{"+n+"}",s[n])}}r=e(a)[0];r.innerHTML+=b;p.appendChild(r);e(r).data("native",s);f[r.getAttribute("molid")]-=1}e(".go-recycle,.go-up,.go-down").hide()};var X=function(){var t=e(".img-up-file")[0].files;if(!t.length){return false}else if(t.length>3){M("最多上传3张图片");return false}for(var a=0;a<t.length;a++){if(t[a].size>200*1024){M("单张图片大小不能超过200k,请压缩后重新上传");return false}}var o=new FormData(document.querySelector(".img-up-form"));e.ajax({url:i,type:"POST",data:o,dataType:"JSON",cache:false,processData:false,contentType:false,success:function(t){if(t.result==1){t.srcs=t.data}else{console.info(t);t.srcs=[]}if(t.srcs){var a=e("#show-mobile").find(".mol-wrap").eq(+e("#ctrl-wrap").data("index")),o=document.querySelector(".mol-ctrl-wrap"),r=document.createDocumentFragment(),i,n;a.data("native",t.srcs);e(".mol-ctrl-wrap").find("[mapid^=imgsrc]").each(function(a,o){this.value=t.srcs[a]||this.value;if(a<t.srcs.length){e(this).css("background","#fbb")}});a.find("img")[0].src=t.srcs[0];M("上传成功,图片地址已自动依次填入. 也可以手动剪切图片地址, 调整次序.",2400);document.querySelector(".img-up-file").value=null}}});return false};var Y=function(){var t=[];var a={};var o;var r=[];var i=e("#show-mobile").find(".mol-wrap");i.each(function(t,i){o=this.getAttribute("molid");if(o=="tb-category"){e(this).data("native",null)}else if(o.lastIndexOf("GoodList")>-1){e(this).data("native",e(this).data("native")||h.slice(0,8));e(this).data("native").forEach(function(e){a[e.goods_id+""]=""})}r.push({name:o,data:e(this).data("native")||d["val-"+o]||null})});for(var n in a){t.push(n)}console.log(t);console.table(r);return{content:JSON.stringify(r),goods_id_arr:t}};var Z=function(t){var a=E[0].checked;a&&(localStorage.hdDecorateHelpKnew=1);D.hide();A.removeClass("blur");if(t===true){S.find("p").animate({width:0,height:30},300,function(){e(this).hide(200)})}else{S.find("p").hide()}};var $=function(e){S.show();S.find("p").css({width:208,height:118}).show();e===true&&D.show();A.addClass("blur")};var ee=function(){T.mouseenter($).mouseleave(Z)};e("[tempid]").on("click",function(){var t=e(this).attr("tempid");var a;if(t==""){a="\n确定清空? \n\n将清除页面当前的装修预览.\n "}else{a="确定应用此模版? \n\n替换页面当前的装修预览. "}F(a,function(){e("#show-mobile").find(".mol-wrap").each(function(){e(this).remove();f[this.getAttribute("molid")]++});e("#ctrl-wrap").empty();W(p[t]);e(".submit-reset-wrap").hide();e("#mols-modal").modal("hide");M("操作成功",600)})});v.on("drop",function(t){event.preventDefault();var a=event.dataTransfer.getData("Text");var o=a.replace("tag-","");var r=e(".mol-wrap").filter(".blue-top")[0];if(!f[o]&&a.indexOf("tag")==0){M("该组件的使用次数已达上限。");return false}var i=c(o);var n=d["val-"+o]||h.slice(0,8);if(o=="slideBox"){i=i.replace("{imgsrc}",n[0]["imgsrc"]).replace("{href}",n[0]["href"])}else if(o.lastIndexOf("GoodList")>-1){i=i.replace("{content}",Q(n,o.indexOf("single")==0?1:2))}else{for(var l in n){i=i.replace("{"+l+"}",n[l])}}var s=e(i)[0];s.innerHTML+=b;r?this.insertBefore(s,r):this.appendChild(s);f[s.getAttribute("molid")]--;e(".mol-wrap").removeClass("blue-top");x[0].innerHTML="";e(s).data("native",n)}).on("dragenter",function(e){}).on("dragover",function(t){event.preventDefault();e(".mol-wrap").removeClass("assertive blue-top");e(event.target).parents(".mol-wrap").eq(0).addClass("blue-top")});e(".mol-tag").on("selectstart",function(e){return false}).on("dragstart",function(e){event.dataTransfer.setData("Text",this.id)}).on("dragend",function(e){event.preventDefault();w.hide()}).on("mouseover",function(){e(".mol-tip").html('<div class="arrow"></div>');var t=this;e(".mol-tip").show().css("opacity",0).animate({top:e(t).offset().top-80,opacity:.9},"fast",function(){e(this).html(function(e,t){return'<div class="arrow"></div>'+s[this.id.replace("tag-","")]}.bind(t))})}).on("mouseleave",function(){e(".mol-tip").html('<div class="arrow"></div>').hide()}).on("mousedown",function(){e(".mol-tip").fadeOut(300,function(){e(this).html('<div class="arrow"></div>')})});v.on("selectstart",".go-down,.go-up,.go-recycle",function(e){return false}).on("click",".go-recycle",function(t){event.preventDefault();e(this.parentNode).remove();setTimeout(function(){e("#ctrl-wrap").empty();w.hide()},100);f[this.parentNode.getAttribute("molid")]+=1}).on("click",".go-down",function(t){event.preventDefault();var a=this.parentNode;var o=a.nextSibling;if(o==null){return false}var r=e("#show-mobile")[0];var i=a.previousSibling;var n=o.cloneNode(true);r.removeChild(o);r.insertBefore(n,a)}).on("click",".go-up",function(t){event.preventDefault();var a=e(this).parent();var o=a.prev();if(o.length<1){return false}var r=o.clone();var i=a.next();o.remove();i.length?i.before(r):e("#show-mobile").append(r)}).on("mouseover",".mol-wrap",function(t){e(this).find(".go-down,.go-up,.go-recycle").show()}).on("mouseleave",".mol-wrap",function(t){e(this).find(".go-down,.go-up,.go-recycle").hide()}).on("click",".mol-wrap",function(t){g=[];var a=this.getAttribute("molid");var o=e(this).data("native")||d["val-"+a];var r;e(".mol-wrap").removeClass("assertive");e(this).addClass("assertive");e("#ctrl-wrap").data("index",e(this).index()-3).html(l(a));O=e(".mol-ctrl-wrap");if(a=="slideBox"){var i=o;O.find("[mapid^=imgsrc]").each(function(e,t){i[e]?this.value=i[e].imgsrc||"":void 0});O.find("[mapid^=href]").each(function(e,t){i[e]?this.value=i[e].href||"":void 0})}else if(a.indexOf("GoodList")>-1){g=e(this).data("native").slice(0);z()}else{O.find("input,textarea").each(function(){r=this.getAttribute("mapid")||"none";if(o&&o[r])this.value=(o[r]+"").replace(/\<br\>/gm,"\n")})}a.indexOf("GoodList")>-1||d["val-"+a]?w.show():w.hide()});y.on("click",".submit",function(t){var a=e(".mol-ctrl-wrap").attr("ctrlid"),o=c(a),r,i={},n=v.find(".mol-wrap").eq(+e("#ctrl-wrap").data("index"));if(a.indexOf("GoodList")>-1){o=o.replace("{content}",Q(g,a.indexOf("single")==0?1:2));i=g}else if(a=="slideBox"){i=[];e(".mol-ctrl-wrap").find("[mapid^=imgsrc]").each(function(e,t){if(this.value.length>4){i[e]={imgsrc:this.value}}else{i[e]={}}}).end().find("[mapid^=href]").each(function(e,t){typeof i[e]=="object"&&i[e].imgsrc?i[e].href=this.value||"":void 0});o=o.replace("{imgsrc}",i[0]["imgsrc"]).replace("{href}",i[0]["href"])}else{e(this.parentNode).prev().find("input,textarea").each(function(){r=this.getAttribute("mapid")||"none";i[r]=this.value.replace(/\n/gm,"<br>")||""});for(var l in i){o=o.replace("{"+l+"}",i[l])}}n.data("native",i);n.html(e(o)[0].innerHTML+b)}).on("click",".reset",function(t){var a=e(".mol-ctrl-wrap");var o=a.attr("ctrlid");if(o.indexOf("GoodList")>-1){e(".ctrlArea-goodsChecked-wrap").empty();g=[]}a.find("[type=text],[type=number],textarea,[type=file],[type=color]").each(function(){this.value=""});a.find("p.uploaded-info,p.upload-ok-tip").remove()});x.on("click",".show-goods-list",function(){var t=e(this).parent().attr("ctrlid");G.data("for-ctrlid",t);J();m=[];K(g,false,true)});e("#goods-list").on("click",".good-cell",function(){var t=e(this).data("good-info");var a=m.map(function(e){return e.goods_id||e.goodsId});var o=a.indexOf(+(t["goods_id"]||t["goodsId"]))>-1;K([t],o,true)});L.on("click","i",function(e){U.bind(this)(e,true)});x.on("click",".ctrlArea-goodsChecked-wrap i",U);G.click(function(){var t=this;var a=e("#show-mobile").find(".mol-wrap").eq(+e("#ctrl-wrap").data("index"));var o=e(t).data("for-ctrlid")=="doubleGoodList"?2:1;a.html(Q(g,o)+b);g=m.slice();a.data("native",g);V();M("宝贝挑选成功",900)});k.click(V);e("#goods-modal .close").click(function(){V(true)});e(".btn-search").click(function(){J(1)});e(".go-next").click(function(){var t=+e("#now-pagenum").text();if(t==e("#total-pagenum").text()){return false}J(t+1)});e(".go-prev").click(function(){var t=+e("#now-pagenum").text();if(t<2){return false}J(t-1)});e(".go-first").click(function(){var t=+e("#now-pagenum").text();if(t==1||t==0){return false}J(1)});e(".go-last").click(function(){var t=+e("#now-pagenum").text();var a=+e("#total-pagenum").text();if(t==a){return false}J(a)});e(document).on("submit",".img-up-form",X);e("#btn-count").click(function(){console.info(f)});e(".btn-save").click(function(){var t="确定发布? \n\n将把店铺首页更新为当前页面的布置.";F(t,function(){var t=Y();var a=t.content;var o=e("#shopId-inp").val();var i=e("#shopName-inp").val();e.post(r,{shopId:o||"",shopName:i||"",content:a,goodsIds:t.goods_id_arr.join(",")}).always(function(t){console.info(t);if(t.result){localStorage.hdDecorateTempSaveData="";M('<b>发布成功!</b><a href="#" target="_blank"> 立刻前往我的店铺查看效果</a>'.replace("#",e("#goto-shop")[0].href),1500)}else if(t.resul.msg="session过期"){localStorage.hdDecotateTempSaveData=a;M("登陆状态过期,请刷新重新登陆!")}})})});e(".temp-save").click(function(){var e=Y().content;localStorage.hdDecorateTempSaveData=e;M("暂存成功,下次本机打开可以继续编辑.",600)});e("#helps .btn").on("click",function(){Z(true);ee()});e("document").ready(function(){localStorage.hdDecorateHelpKnew==1?ee():$(true)});window.init_current=function(e){var t;e.forEach(function(e){t=[];if(e.name.indexOf("GoodList")>-1){e.data.forEach(function(e){if(R[e.goods_id||e.goodsId]){t.push(R[e.goods_id||e.goodsId])}else{}});e.data=t}});W(e)};window.bootAlert=M}})(window.jQuery);