TopSearch_wev8.js
5.09 KB
define("TopSearch_html",function(){return'<div id="NMEC_${id}" class="wev-comp-${compType}" > <div class="wev-topsearch-nav" data-container="NMEC_${id}"> <div class="wev-filter-items wev-flex"> {@each navs as nav} <div data-rowid="${nav.id}" class="wev-filter-item wev-flex-item wev-ellipsis{@if nav.cls} ${nav.cls}{@/if}"> <span class="wev-ellipsis">$${nav.text}</span> </div> {@/each} </div> </div></div>'}),define(["mUtil","Component","mService","i18n"],function(b,i,E,a){return i.init(function(e){var p,u,m,g,C,w,T,y,x={},S={};i.super(this,e),this.type="TopSearch",this.css=this.type+"_css",this.tpl=this.type+"_html";var _=this.viewModel={actionType:0,actionTarget:{},onSearch:function(){},conditions:[],standalone:!0};this.beforeMount=function(){for(var e=[],i=_.conditions.length,t=4<i?3:i,n=0;n<t;n++){var o=_.conditions[n];e.push({id:b.UUID(),text:o.showname,items:[o]})}4<i&&e.push({id:b.UUID(),text:a.FILTER,cls:"more",items:_.conditions.slice(3)}),_.navs=e},this.mounted=function(){var t=x.initConditions(),a=this;this.pageid,p=a.$container,u=p.children(".page-header"),m=p.children(".page-content"),g=m.children(".page-scroller"),C=this.$el.children(".wev-comp-"+_.compType),w=C.find(".wev-topsearch-nav");var o="[data-container='NMEC_"+a.id+"']",n=C.closest(".wev-tab-panel"),s=1==n.length,e="scroll.topsearch_"+a.id,r="fixer",d="open";T=$(".wev-topsearch-page",p),y=$(".wev-topsearch-mask",p),0==T.length&&(T=$('<div class="wev-topsearch-page out"></div>'),y=$('<div class="wev-topsearch-mask out"></div>'),p.append(y).append(T)),u.length||(u=$("<div class='page-header'></div>"),m.before(u)),u.children(o).remove(),x.resetPageTop(),m.off(e).on(e,function(e){if(!(s&&"none"===n.css("display")||"hidden"===u.css("visibility"))&&x.canScrollToFixed()){var i=C.offset().top,t=parseInt(m.css("top"))+p.offset().top;i<=t&&!u.children(o).length?(C.css("height","auto"),u.find(".wev-topsearch-nav").hide(),u.append(w.show())):t<i&&!C.children(o).length&&(C.css("height","auto"),C.append(w.show())),x.resetPageTop(),w[i<=t?"addClass":"removeClass"](r)}});var c=function(e,i,t){x.fixCompAndScrollTarget(!1,!0),y.removeClass("in").addClass("out"),T.removeClass("in").addClass("out");var n=w.find(".wev-filter-item."+d);if(w.find(".wev-filter-item").removeClass(d),e){n[t.length?"addClass":"removeClass"]("active");var o="",a=_.navs.filter(function(e){return e.id===i})[0]||{},s=a.items||[];if(1==s.length){var r=s[0],c=r.data||[],l=t[0]||{};!c.length||5!=r.htmltype||1!=r.type&&3!=r.type||(l.fieldvalue&&(o=(c.filter(function(e){return l.fieldvalue==e.selectvalue})[0]||{}).selectname||""),n.find("span").html(o||a.text||""))}}},i=_.actionTarget,l=i.compoid,h=i.sourceType,f=1==h||3==h,v=function(e,i,n,o){t.then(function(){var t;t={preload:e,classAnimation:"show_hide_topsearch",target:i,conditions:n,container:p,closeCallback:c,onSearch:function(e){if(S[o]=e,c(!0,o,e),e=Object.keys(S).reduce(function(e,i){return e.concat(S[i])},[]),0==_.actionType){var i={};e.forEach(function(e){i[e.fieldname]=e.fieldvalue}),b.eval(_.onSearch,a.pageid,i)}else{var t=function(){x.fixCompAndScrollTarget(!1,!0)};if(f)Mobile_NS.refreshList(l,"_asArray="+encodeURIComponent(JSON.stringify(e)),t);else{var n=e.reduce(function(e,i){return e&&(e+=";"),e+i.fieldname+"="+i.fieldvalue},"");Mobile_NS.refreshList(l,n,t)}}}},u.css("z-index","9"),y.removeClass("out").addClass("in"),T.removeClass("out").addClass("animation in").empty(),E.load("topsearch",function(e,i){T.html(b.replaceI18n(e)),T.on("webkitAnimationEnd animationend",function(){u.css("z-index",""),T.removeClass("animation")}),i.mounted(T,y,t)})})};w.on("click",".wev-filter-item",function(e){var i=$(this),t=i.data("rowid"),n=[];i.hasClass(d)?c():(w.hasClass(r)&&u.find(o).length||(w.addClass(r),x.fixCompAndScrollTarget(!0,!1)),i.siblings(".wev-filter-item").removeClass(d),i.addClass(d),_.navs.every(function(e){return e.id!==t||(n=e.items,!1)}),v(!1,w,n,t))}),u.on("click","abbr",function(){0<w.find(".wev-filter-item."+d).length&&c()})},x.resetPageTop=function(){m.css("top",u.height()+"px")},x.canScrollToFixed=function(){var e=m[0].scrollHeight+g.offset().top-C.height();return m.height()+C.offset().top+C.height()+1<e},x.fixCompAndScrollTarget=function(i,e){var t=$("#NMEC_"+_.actionTarget.compoid);x.canScrollToFixed()?setTimeout(function(){var e=t.offset().top+m.scrollTop()-w.height();e-=i?u.height():w.offset().top,m.scrollTop(e),0==e&&m.trigger("scroll")},10):(u.find(".wev-topsearch-nav")[e?"show":"hide"](),e?e&&C.append(w.show()):u.append(w.show()),x.resetPageTop())},x.initConditions=function(){var o=_.actionTarget.sourceType,i=$.Deferred(),t=1==o;if(!t&&_.conditions.every(function(e){return"select"!=e.fieldTypeFace||2!=e.sourceType||!(t=!0)}),delete _.conditions,!t)return i.resolve(),i;var e=b.getActionUrl(this.type,{action:"getFieldData",mec_id:this.id},this.pageid);return b.getJSON(e,function(e){var n=e.data;_.navs.forEach(function(t,e){t.items.forEach(function(e,i){1==o&&n[e.id]?$.extend(t.items[i],n[e.id]):5==e.htmltype&&2==e.sourceType&&(e.data=n[e.id]||[])})}),i.resolve()},function(e){i.resolve()}),i},x.initConditions=x.initConditions.bind(this)})});