UrlGridTable_wev8.js 12.2 KB
define("UrlGridTable_html",function(){return'<div id="NMEC_${id}" class="wev-comp-${compType}">\t<div class="wev-search" {@if normalSearch.hide == true}style="display:none;"{@/if}>\t\t<div class="wev-search-inner">\t\t\t<form action="javascript:void(0)">\t\t\t\t<input type="search" placeholder="${normalSearch.tip}">\t\t\t</form>\t\t\t<div class="wev-placeholder">\t\t\t\t<div class="wev-placeholder-inner wev-ellipsis">\t\t\t\t\t<span class="wev-small-icon wev-icon-search"></span><span class="wev-placeholder-text">$${normalSearch.tip}</span>\t\t\t\t</div>\t\t\t</div>\t\t\t<div class="wev-clear-btn"></div>\t\t</div>\t\t<div class="wev-list-btn-container">\t\t\t{@each btns as btn, index}\t\t\t<button class="btn">$${btn.text}</button>\t\t\t{@/each} \t\t</div>\t</div>\t$${loading.content}\t<div class="wev-table-view-wrapper wev-gridtable-view-wrapper">\t\t<div class="wev-gridtable-content-wrapper">\t\t\t<div class="wev-gridtable-main-content-wrapper">\t\t\t\t<table style="${options.width}">\t\t\t\t\t<thead>\t\t\t\t\t\t<tr>\t\t\t\t\t\t\t{@each headerView.normal as viewCol}\t\t\t\t\t\t\t<th {@if viewCol.fixedColumn === true}class="wev-gridtable-fixed-col"{@/if} style="${viewCol.width}">$${viewCol.text}</th>\t\t\t\t\t\t\t{@/each} \t\t\t\t\t\t</tr>\t\t\t\t\t</thead>\t\t\t\t</table>\t\t\t\t<div class="wev-gridtable-main-content-body-wrapper" style="${options.height}">\t\t\t\t\t{@if options.autoHeight !== true}\t\t\t\t\t<div class="wev-gridtable-fixed-content-body-wrapper-mapping">\t\t\t\t\t\t\t\t\t\t\t</div>\t\t\t\t\t{@/if}\t\t\t\t\t<table style="${options.width}">\t\t\t\t\t\t<tbody>\t\t\t\t\t\t\t\t\t\t\t\t\t</tbody>\t\t\t\t\t</table>\t\t\t\t</div>\t\t\t</div>\t\t\t\t\t\t<div class="wev-gridtable-fixed-content-wrapper">\t\t\t\t<table>\t\t\t\t\t<thead>\t\t\t\t\t\t<tr>\t\t\t\t\t\t\t{@each headerView.fixed as viewCol}\t\t\t\t\t\t\t<th style="${viewCol.width}">$${viewCol.text}</th>\t\t\t\t\t\t\t{@/each} \t\t\t\t\t\t</tr>\t\t\t\t\t</thead>\t\t\t\t</table>\t\t\t\t<div class="wev-gridtable-fixed-content-body-wrapper" style="${options.height}">\t\t\t\t\t\t\t\t\t</div>\t\t\t\t</div>\t\t</div>\t\t$${moreLoading.content}\t</div></div>'}),define(["mUtil","Component","wev-loading"],function(x,a,n){return a.init(function(t){var m={},i={};a.super(this,t),this.type="UrlGridTable",this.tpl=this.type+"_html",this.css="GridTable_css",this.keysOfSkipedVarParse=["dataurl","value"],this.dataload=!0,this.components={loading:new n({delay:300,animation:1}),moreLoading:new n({btn:1,onclick:function(t){m.loadData(t)}})};var b=this.viewModel={pageSize:10,showFields:[],normalSearch:{hide:!1,tip:""},btns:[],options:{fixedColumn:0,width:"100%",height:300,groupsum:!1,groupsum_title:"小计",readonly:!1,inParams:[{paramName:"pageNo",paramValue:"{PAGE_NO}",isSystem:"1",desc:""},{paramName:"pageSize",paramValue:"{PAGE_SIZE}",isSystem:"1",desc:""},{paramName:"searchKey",paramValue:"{SEARCH_KEY}",isSystem:"1",desc:""}],outFormat:{DATAS:"datas",TOTAL_SIZE:"totalSize"}}};function o(t,e){var i,a=t.toString().split(".")[1],n=e.toString().split(".")[1];return a=a&&a.length||0,n=n&&n.length||0,i=Math.pow(10,Math.max(a,n)),(Math.round(t*i+e*i)/i).toFixed(Math.max(a,n))}function l(t){return function(t){if(!(t=(t+="").replace(/[ ]/g,""))||isNaN(t))return"";var e=t.indexOf("."),i=/(-?\d+)(\d{3})/;if(-1==e)for(;i.test(t);)t=t.replace(i,"$1,$2");else{for(var a=t.substring(0,e),n=t.substring(e+1,t.length);i.test(a);)a=a.replace(i,"$1,$2");t=a+"."+n}return t}(t=t.replace(/\s+/g,"")||"")}for(var e in this.beforeMount=function(){var t=b.showFields;if(b.headerView={},x.isArray(t)&&(b.headerView.normal=t.map(function(t){return{text:t.title,width:t.width}})),b.headerView.normal){var i=b.options.fixedColumn||0,a=[];b.headerView.normal.forEach(function(t,e){e<i&&(a.push(t),t.fixedColumn=!0),t.width=x.toPixel(t.width,"width")}),b.headerView.fixed=a}var e=b.options.width;e&&(b.options.width=x.toPixel(e,"width"));var n=b.options.height;b.options.height=n?x.toPixel(n,"max-height"):(b.options.autoHeight=!0,"height:auto")},this.mounted=function(){var n=this,t=this.$comp;m.refreshList(),m.initSearch(),m.initBtns(this.pageid),-1<=$(window).height()-$(".page-scroller",this.$container).height()&&t.find(".wev-gridtable-main-content-wrapper>table").on("touchmove",function(t){t.preventDefault()}),b.options.readonly||t.find(".wev-gridtable-main-content-body-wrapper > table").on("click","tr:not(.wev-groupsum)",function(t){if(!$(t.target).closest(".wev-file[data-docid]").length){var e,i=$(this).attr("data-id"),a={};m.state.list.every(function(t){return t.uuid!=i||!!(e=(a=t).dataurl)&&void(0===e.indexOf("javascript")?x.eval(e,n.pageid):$u(e))}),b.callback&&x.isFunction(b.callback.click)&&b.callback.click.call(this,a)}})},this.reload=function(t,e){i={},x.isObject(t)&&$.extend(i,t),m.refreshList(e)},m.state={timestamp:0,pageNo:0,list:[],conditions:{}},m.initSearch=function(){var e=$(".wev-search",this.$comp),i=$("input",e);e.on("click.active",".wev-placeholder",function(t){e.addClass("wev-active").removeClass("wev-inactive"),i.focus()}).on("click.clear",".wev-clear-btn",function(){i.val("").focus().triggerHandler("input"),m.state.conditions={}}),i.on("blur",function(){this.value||e.removeClass("wev-active").addClass("wev-inactive")}).on("input",function(){e.toggleClass("wev-has-value",!!this.value)}).on("keyup",function(t){13===t.keyCode&&(m.state.conditions.searchKey=encodeURIComponent(this.value),m.refreshList(),this.blur())})},m.initBtns=function(e){b.btns.length&&$(".wev-list-btn-container",this.$comp).on("click",".btn",function(){var t=$(this).index();x.eval(b.btns[t].click,e)})},m.refreshList=function(i){var a=this,n=this.components.loading,r=this.components.moreLoading,t=m.state,o=this.$comp;n.setRefs(this.$comp,"wev-refreshing"),n.show(),t.pageNo=0,t.list=[],m.loadData(function(t,e){n.hide(),r.hide(t,e),i&&i(),x.trigger("dataload",a.pageid,a.id),!t||b.options.autoHeight&&!x.canPullToRefresh(a.id)||require(["pullToRefreshHelper"],function(t){var e=o.find(".wev-gridtable-main-content-body-wrapper"),i=e;b.options.autoHeight&&(i=o.closest(".page-content")),new t({el:e.children("table"),container:i.get(0),loadData:m.loadData,loading:a.components.moreLoading})})})},m.loadData=function(u){var v=(new Date).valueOf(),w=this.$comp,f=m.state;f.timestamp=v,f.pageNo++;var e={},g={pageNo:f.pageNo,pageSize:b.pageSize,searchKey:this.searchKey};b.options.inParams.forEach(function(t){e[t.paramName]=x.fmtParamValue(t.paramValue,g)}),$.extend(!0,e,x.getPageParam(this.pageid),i,f.conditions),x.ajax(b.url,e,function(e){if(v==f.timestamp){var t=e;try{"string"==typeof e&&(t=JSON.parse(e))}catch(t){return x.getLabel(5294,"列表数据转换成JSON时出现异常,数据如下:",function(t){console.error(t+"\n"+e)}),void("function"==typeof u&&u.call(this,!1))}var i=b.options.outFormat,a=t[i.DATAS],n=parseInt(t[i.TOTAL_SIZE]),r=n%g.pageSize==0?n/g.pageSize:parseInt(n/g.pageSize)+1,o=b.showFields||[],l={},s=[];a.forEach(function(a){var t={},e="javascript:void(0);";t.uuid=x.UUID(),a.uuid=t.uuid,b.options.readonly||(e=x.replaceValAndVarParser(b.options.dataurl||"",a)),t.dataurl=e,a.dataurl=e,t.cols=o.map(function(t,e){var i=x.replaceValAndVarParser(t.value,a);return{columnValue:i,columnRealValue:i.replace(/<[^>]+>/g,""),columnWidth:x.toPixel(t.width,"width"),fixedColumn:e<b.options.fixedColumn}}),s.push(t)}),l.datas=s;var d=["{@each datas as row}",'<tr data-id="${row.uuid}">',"{@each row.cols as col}",'<td {@if col.fixedColumn === true}class="wev-gridtable-fixed-col"{@/if} style="${col.columnWidth}" data-value="${col.columnRealValue}">$${col.columnValue}</td>',"{@/each}","</tr>","{@/each}"].join(""),c=x.parseTemplate(d,l),h=$(c),p=$(".wev-gridtable-main-content-body-wrapper > table > tbody",w);1==g.pageNo&&p.html(""),p.append(h),x.concat(f.list,a),m.groupSum(),1==g.pageNo&&(m.resetGridColumnWidth(),m.initFixedColumn()),m.updateFixedContentColumn(),u(g.pageNo<r,n<=0)}})},m.groupSum=function(){if(b.options.groupsum||b.options.totalsum){var n=[],r=[],t=$(".wev-gridtable-main-content-body-wrapper",this.$el);t.find("tr.wev-groupsum").remove(),t.find("tr").each(function(t){var e=$(this);if(e.children("td").each(function(t){var e=$(this).attr("data-value"),i=n[t]||"0",a=r[t]||"0";if(!isNaN(e)&&!isNaN(i))return n[t]=o(i,e),void(r[t]=o(a,e));e=e.replace(/,/g,""),isNaN(e)||(i=o(i=i.replace(/,/g,""),e),n[t]=l(i),a=o(a=a.replace(/,/g,""),e),r[t]=l(a))}),b.options.groupsum&&e.children("td").first().attr("data-value")!=e.next().children("td").first().attr("data-value")){var i=e.clone(),a=i.children("td");i[0].className="wev-groupsum",a.html("").first().html(b.options.groupsum_title),a.each(function(t){0!==t&&$(this).html(n[t]||"")}),e.after(i),n=[]}});var e=t.find("tr").last();if(b.options.totalsum&&e.length){var i=e.clone(),a=i.children("td");i[0].className="wev-groupsum",a.html("").first().html("总计"),a.each(function(t){0!==t&&$(this).html(r[t]||"")}),e.after(i)}}},m.resetGridColumnWidth=function(){var t=this.$el,r=[];$(".wev-gridtable-main-content-body-wrapper>table>tbody>tr",t).first().children("td").each(function(){var t=$(this).width();r.push(t)}),$(".wev-gridtable-main-content-wrapper>table>thead>tr",t).first().children("th").each(function(t){var e=$(this),i=r[t],a=e.width();if(i&&i!=a){var n=i-function(t){var e=t.css("padding-left")||"";e=e.replace("px",""),e=parseInt(e)||0;var i=t.css("padding-right")||"";return i=i.replace("px",""),i=parseInt(i)||0,e+i}(e);e.css("width",n+"px")}});var e=$(".wev-gridtable-main-content-body-wrapper>table",t).width();$(".wev-gridtable-main-content-body-wrapper",t).width(e)},m.fixedColumnWidth=0,m.initFixedColumn=function(){var t=this.$el,e=b.options.fixedColumn,i=0;$(".wev-gridtable-main-content-wrapper>table>thead>tr",t).first().children("th").each(function(t){t<e&&(i+=$(this).width()+1)}),$(".wev-gridtable-fixed-content-wrapper > table",t).css("width",i+"px"),$(".wev-gridtable-fixed-content-wrapper",t).css("width",i+"px"),$(".wev-gridtable-fixed-content-body-wrapper-mapping",t).css("width",i+"px"),m.fixedColumnWidth=i;var a=$(".wev-gridtable-main-content-wrapper>table>thead>tr",t).first(),n=$(".wev-gridtable-fixed-content-wrapper>table>thead>tr",t).first();if(n.length){var r=a.children("th").eq(0),o=r.height(),l=r.css("height"),s=n.children("th").eq(0),d=s.height(),c=s.css("height");d<o?s.css("height",l):o<d&&r.css("height",c)}if(!b.autoHeight){var h=!1,p=null;$(".wev-gridtable-main-content-body-wrapper",t).on("scroll",function(){u||w||(h=!0,p&&clearTimeout(p),$(".wev-gridtable-fixed-content-body-wrapper-mapping",t).show(),$(".wev-gridtable-fixed-content-body-wrapper",t).css("visibility","hidden"),$(".wev-gridtable-fixed-content-body-wrapper",t).scrollTop($(this).scrollTop()),p=setTimeout(function(){h=!1},1e3))});var u=!1,v=null;$(".wev-gridtable-fixed-content-body-wrapper",t).on("scroll",function(){h||w||(u=!0,v&&clearTimeout(v),$(".wev-gridtable-fixed-content-body-wrapper-mapping",t).show(),$(this).css("visibility","hidden"),$(".wev-gridtable-main-content-body-wrapper",t).scrollTop($(this).scrollTop()),v=setTimeout(function(){u=!1},1e3))});var w=!1,f=null;$(".wev-gridtable-main-content-wrapper",t).on("scroll",function(){w=!0,f&&clearTimeout(f),$(".wev-gridtable-fixed-content-body-wrapper",t).css("visibility","visible"),$(".wev-gridtable-fixed-content-body-wrapper-mapping",t).hide().css("left",$(this).scrollLeft()+"px"),f=setTimeout(function(){w=!1},100)})}},m.updateFixedContentColumn=function(){var t=this.$el;if(b.options.fixedColumn&&!(b.options.fixedColumn<1)){var e=$(".wev-gridtable-main-content-body-wrapper>table",t).clone();$("tr",e).each(function(){var t=$(this);t.children("td").not(".wev-gridtable-fixed-col").remove(),t.children("td").removeClass("wev-gridtable-fixed-col")}),e.css("width",m.fixedColumnWidth+"px"),$(".wev-gridtable-fixed-content-body-wrapper",t).html("").append(e);var i=e.clone();$(".wev-gridtable-fixed-content-body-wrapper-mapping",t).html("").append(i),m.resetFixedGridContentHeight()}},m.resetFixedGridContentHeight=function(){var s=this.$el;$(".wev-gridtable-main-content-body-wrapper>table>tbody>tr",s).each(function(t){var e=$(this).children("td").eq(0),i=e.height(),a=e.css("height"),n=$(".wev-gridtable-fixed-content-body-wrapper>table>tbody>tr",s).eq(t).children("td").eq(0),r=n.height(),o=n.css("height"),l=$(".wev-gridtable-fixed-content-body-wrapper-mapping>table>tbody>tr",s).eq(t).children("td").eq(0);l.height(),r<i?(n.css("height",a),l.css("height",a)):i<r&&e.css("height",o)})},m)x.isFunction(m[e])&&(m[e]=m[e].bind(this))})});