/** layui-v2.1.0 MIT License By http://www.layui.com */ ;layui.define(["laytpl","laypage","layer","form"],function(e){"use strict";var t=layui.$,i=layui.laytpl,a=layui.laypage,l=layui.layer,n=layui.form,r=layui.hint(),o=layui.device(),d={config:{checkName:"LAY_CHECKED",indexName:"LAY_TABLE_INDEX"},cache:{},index:layui.table?layui.table.index+1e4:0,set:function(e){var i=this;return i.config=t.extend({},i.config,e),i},on:function(e,t){return layui.onevent.call(this,s,e,t)}},c=function(){var e=this,t=e.config,i=t.id;return i&&(c.config[i]=t),{reload:function(t){e.reload.call(e,t)},config:t}},s="table",u=".layui-table",f="layui-hide",h="layui-table-view",y=".layui-table-header",p=".layui-table-body",m=".layui-table-main",v=".layui-table-fixed",g=".layui-table-fixed-l",x=".layui-table-fixed-r",b=".layui-table-tool",k=".layui-table-sort",C="layui-table-edit",w="layui-table-hover",z=function(e){return e=e||{},['',"","{{# layui.each(d.data.cols, function(i1, item1){ }}","","{{# layui.each(item1, function(i2, item2){ }}",'{{# if(item2.fixed && item2.fixed !== "right"){ fixed = true; } }}',"{{# if(item2.fixed){ right = true; } }}",function(){return e.fixed&&"right"!==e.fixed?'{{# if(item2.fixed && item2.fixed !== "right"){ }}':"right"===e.fixed?'{{# if(item2.fixed === "right"){ }}':""}(),"{{# if(item2.checkbox){ }}",'',"{{# } else if(item2.space){ }}",'',"{{# } else { }}",'","{{# }; }}",e.fixed?"{{# }; }}":"","{{# }); }}","","{{# }); }}","","
',"{{# if(item2.colspan > 1){ }}",'
','{{item2.title||""}}',"
","{{# } else { }}",'
','{{item2.title||""}}',"{{# if(item2.sort){ }}",'',"{{# } }}","
","{{# } }}","
"].join("")},N=['',"","
"].join(""),F=['
',"{{# var fixed, right; }}",'
',z(),"
",'
',N,"
",'{{# if(fixed && fixed !== "right"){ }}','
','
',z({fixed:!0}),"
",'
',N,"
","
","{{# }; }}","{{# if(right){ }}",'
','
',z({fixed:"right"}),'
',"
",'
',N,"
","
","{{# }; }}","{{# if(d.data.page){ }}",'
','
',"
","{{# } }}","","
"].join(""),T=t(window),A=t(document),H=function(e){var i=this;i.index=++d.index,i.config=t.extend({},i.config,d.config,e),i.render()};H.prototype.config={limit:30,loading:!0},H.prototype.render=function(e){var a,l=this;if(e&&(l.config=e),a=l.config,a.elem=t(a.elem),a.where=a.where||{},a.request=t.extend({pageName:"page",limitName:"limit"},a.request),a.response=t.extend({statusName:"code",statusCode:0,msgName:"msg",dataName:"data",countName:"count"},a.response),!a.elem[0])return l;var n=a.elem,r=n.next("."+h);a.height&&/^full-\d+$/.test(a.height)&&(l.fullHeightGap=a.height.split("-")[1],a.height=T.height()-l.fullHeightGap);var o=l.elem=t(i(F).render({VIEW_CLASS:h,data:a,index:l.index}));a.index=l.index,r[0]&&r.remove(),n.after(o),l.layHeader=o.find(y),l.layMain=o.find(m),l.layBody=o.find(p),l.layFixed=o.find(v),l.layFixLeft=o.find(g),l.layFixRight=o.find(x),l.layTool=o.find(b),a.height&&l.fullSize(),l.pullData(1),l.events()},H.prototype.reload=function(e){var i=this;i.config=t.extend({},i.config,e),i.render()},H.prototype.pullData=function(e,i){var a=this,n=a.config,r=n.request,o=n.response;if(n.url){var d={};d[r.pageName]=e,d[r.limitName]=n.limit,t.ajax({type:n.method||"get",url:n.url,data:t.extend(d,n.where),dataType:"json",success:function(t){return t[o.statusName]!=o.statusCode?(a.renderForm(),a.layMain.html('
'+(t[o.msgName]||"返回的数据状态异常")+"
")):(a.renderData(t,e,t[o.countName]),i&&l.close(i),void("function"==typeof n.done&&n.done(t,e,t[o.countName])))},error:function(e,t){a.layMain.html('
数据接口请求异常
'),a.renderForm(),i&&l.close(i)}})}else if(n.data&&n.data.constructor===Array){var c={},s=e*n.limit-n.limit;c[o.dataName]=n.data.concat().splice(s,n.limit),c[o.countName]=n.data.length,a.renderData(c,e,n.data.length),"function"==typeof n.done&&n.done(c,e,c[o.countName])}},H.prototype.page=1,H.prototype.eachCols=function(e){layui.each(this.config.cols,function(t,i){layui.each(i,function(a,l){e(a,l,[t,i])})})},H.prototype.renderData=function(e,l,n,r){var o=this,c=o.config,s=e[c.response.dataName]||[],u=[],f=[],h=[],y=function(){return!r&&o.sortKey?o.sort(o.sortKey.field,o.sortKey.sort,!0):(layui.each(s,function(e,a){var l=[],n=[],s=[];0!==a.length&&(r||(a[d.config.indexName]=e),o.eachCols(function(e,r){var o=a[r.field||e];if(void 0!==o&&null!==o||(o=""),!(r.colspan>1)){var u=['",'
'+function(){return r.checkbox?'":r.toolbar?i(t(r.toolbar).html()||"").render(a):r.templet?i(t(r.templet).html()||String(o)).render(a):o}(),"
"].join("");l.push(u),r.fixed&&"right"!==r.fixed&&n.push(u),"right"===r.fixed&&s.push(u)}}),u.push(''+l.join("")+""),f.push(''+n.join("")+""),h.push(''+s.join("")+""))}),o.layBody.scrollTop(0),o.layMain.find("tbody").html(u.join("")),o.layFixLeft.find("tbody").html(f.join("")),o.layFixRight.find("tbody").html(h.join("")),o.renderForm(),o.syncCheckAll(),o.haveInit?o.scrollPatch():setTimeout(function(){o.scrollPatch()},50),void(o.haveInit=!0))};return o.key=c.id||c.index,d.cache[o.key]=s,r?y():0===s.length?(o.renderForm(),o.layFixed.remove(),o.layMain.html('
无数据
')):(y(),void(c.page&&(o.page=l,o.count=n,a.render({elem:"layui-table-page"+c.index,count:n,groups:3,limits:c.limits||[10,20,30,40,50,60,70,80,90],limit:c.limit,curr:l,layout:["prev","page","next","skip","count","limit"],prev:'',next:'',jump:function(e,t){t||(o.page=e.curr,c.limit=e.limit,o.pullData(e.curr,o.loading()))}}),o.layTool.find(".layui-table-count span").html(n))))},H.prototype.renderForm=function(e){n.render(e||"checkbox","LAY-table-"+this.index)},H.prototype.sort=function(e,i,a){var n,o,c=this,u=c.config,f=u.elem.attr("lay-filter"),h=d.cache[c.key];"string"==typeof e&&c.layHeader.find("th").each(function(i,a){var l=t(this),r=l.data("field");if(r===e)return e=l,n=r,!1});try{var n=n||e.data("field");if(c.sortKey&&!a&&n===c.sortKey.field&&i===c.sortKey.sort)return;var y=c.layHeader.find("th .laytable-cell-"+u.index+"-"+n).find(k);c.layHeader.find("th").find(k).removeAttr("lay-sort"),y.attr("lay-sort",i||null),c.layFixed.find("th")}catch(p){return r.error("Did not match to field")}c.sortKey={field:n,sort:i},"asc"===i?o=layui.sort(h,n):"desc"===i?o=layui.sort(h,n,!0):(o=layui.sort(h,d.config.indexName),delete c.sortKey),c.renderData({data:o},c.page,c.count,!0),l.close(c.tipsIndex),layui.event.call(e,s,"sort("+f+")",{field:n,type:i})},H.prototype.loading=function(){var e=this,t=e.config;if(t.loading&&t.url)return l.msg("数据请求中",{icon:16,offset:[e.layTool.offset().top-100-T.scrollTop()+"px",e.layTool.offset().left+e.layTool.width()/2-90-T.scrollLeft()+"px"],anim:-1,fixed:!1})},H.prototype.setCheckData=function(e,t){var i=this,a=i.config,l=d.cache[i.key];l[e]&&(l[e][a.checkName]=t)},H.prototype.syncCheckAll=function(){var e=this,t=e.config,i=e.layHeader.find('input[name="layTableCheckbox"]'),a=function(i){return e.eachCols(function(e,a){a.checkbox&&(a[t.checkName]=i)}),i};i[0]&&(d.checkStatus(e.key).isAll?(i[0].checked||(i.prop("checked",!0),e.renderForm()),a(!0)):(i[0].checked&&(i.prop("checked",!1),e.renderForm()),a(!1)))},H.prototype.getCssRule=function(e,t){var i=this,a=i.elem.find("style")[0],l=a.sheet||a.styleSheet,n=l.cssRules||l.rules;layui.each(n,function(a,l){if(l.selectorText===".laytable-cell-"+i.index+"-"+e)return t(l),!0})},H.prototype.fullSize=function(){var e,t=this,i=t.config,a=i.height;t.fullHeightGap&&(a=T.height()-t.fullHeightGap,a<135&&(a=135),t.elem.css("height",a)),e=parseFloat(a)-parseFloat(t.layHeader.height())-1,i.page&&(e-=parseFloat(t.layTool.outerHeight()+1)),t.layBody.css("height",e)},H.prototype.scrollPatch=function(){var e=this,i=e.layMain.width()-e.layMain.prop("clientWidth"),a=e.layMain.height()-e.layMain.prop("clientHeight");if(i&&a){if(!e.elem.find(".layui-table-patch")[0]){var l=t('
');l.find("div").css({width:i}),e.layHeader.eq(0).find("thead tr").append(l)}}else e.layHeader.eq(0).find(".layui-table-patch").remove();e.layFixed.find(p).css("height",e.layMain.height()-a),e.layFixRight[a?"removeClass":"addClass"](f),e.layFixRight.css("right",i-1)},H.prototype.events=function(){var e,a=this,n=a.config,r=t("body"),c={},u=a.layHeader.find("th"),f=".layui-table-cell",h=n.elem.attr("lay-filter");u.on("mousemove",function(e){var i=t(this),a=i.offset().left,l=e.clientX-a;i.attr("colspan")>1||i.attr("unresize")||c.resizeStart||(c.allowResize=i.width()-l<=10,r.css("cursor",c.allowResize?"col-resize":""))}).on("mouseleave",function(){t(this);c.resizeStart||r.css("cursor","")}).on("mousedown",function(e){if(c.allowResize){var i=t(this).data("field");e.preventDefault(),c.resizeStart=!0,c.offset=[e.clientX,e.clientY],a.getCssRule(i,function(e){c.rule=e,c.ruleWidth=parseFloat(e.style.width)})}}),A.on("mousemove",function(t){if(c.resizeStart){if(t.preventDefault(),c.rule){var i=c.ruleWidth+t.clientX-c.offset[0];c.rule.style.width=i+"px",l.close(a.tipsIndex)}e=1}}).on("mouseup",function(t){c.resizeStart&&(c={},r.css("cursor",""),a.scrollPatch()),2===e&&(e=null)}),u.on("click",function(){var i,l=t(this),n=l.find(k),r=n.attr("lay-sort");return n[0]&&1!==e?(i="asc"===r?"desc":"desc"===r?null:"asc",void a.sort(l,i)):e=2}).find(k+" .layui-edge ").on("click",function(e){var i=t(this),l=i.index(),n=i.parents("th").eq(0).data("field");layui.stope(e),0===l?a.sort(n,"asc"):a.sort(n,"desc")}),a.elem.on("click",'input[name="layTableCheckbox"]+',function(){var e=t(this).prev(),i=a.layBody.find('input[name="layTableCheckbox"]'),l=e.parents("tr").eq(0).data("index"),n=e[0].checked,r="layTableAllChoose"===e.attr("lay-filter");r?(i.each(function(e,t){t.checked=n,a.setCheckData(e,n)}),a.syncCheckAll(),a.renderForm()):(a.setCheckData(l,n),a.syncCheckAll()),layui.event.call(this,s,"checkbox("+h+")",{checked:n,data:d.cache[a.key][l],type:r?"all":"one"})}),a.layBody.on("mouseenter","tr",function(){var e=t(this),i=e.index();a.layBody.find("tr:eq("+i+")").addClass(w)}).on("mouseleave","tr",function(){var e=t(this),i=e.index();a.layBody.find("tr:eq("+i+")").removeClass(w)}),a.layBody.on("change","."+C,function(){var e=t(this),i=this.value,l=e.parent().data("field"),n=e.parents("tr").eq(0).data("index"),r=d.cache[a.key][n];r[l]=i,layui.event.call(this,s,"edit("+h+")",{value:i,data:r,field:l})}).on("blur","."+C,function(){var e,l=t(this),n=l.parent().data("field"),r=l.parents("tr").eq(0).data("index"),o=d.cache[a.key][r];a.eachCols(function(t,i){i.field==n&&i.templet&&(e=i.templet)}),l.siblings(f).html(e?i(t(e).html()||this.value).render(o):this.value),l.parent().data("content",this.value),l.remove()}),a.layBody.on("click","td",function(){var e=t(this),i=(e.data("field"),e.children(f));if(!e.data("off")){if(e.data("edit")){var r=t('');return r[0].value=e.data("content")||i.text(),e.find("."+C)[0]||e.append(r),r.focus()}i.prop("scrollWidth")>i.outerWidth()&&(a.tipsIndex=l.tips(['
',i.html(),"
",''].join(""),i[0],{tips:[3,""],time:-1,anim:-1,maxWidth:o.ios||o.android?300:600,isOutAnim:!1,skin:"layui-table-tips",success:function(e,t){e.find(".layui-table-tips-c").on("click",function(){l.close(t)})}}))}}),a.layBody.on("click","*[lay-event]",function(){var e=t(this),l=e.parents("tr").eq(0).data("index"),n=a.layBody.find('tr[data-index="'+l+'"]'),r="layui-table-click",o=d.cache[a.key][l];layui.event.call(this,s,"tool("+h+")",{data:d.clearCacheKey(o),event:e.attr("lay-event"),tr:n,del:function(){d.cache[a.key][l]=[],n.remove(),a.scrollPatch()},update:function(e){e=e||{},layui.each(e,function(e,l){if(e in o){var r;o[e]=l,a.eachCols(function(t,i){i.field==e&&i.templet&&(r=i.templet)}),n.children('td[data-field="'+e+'"]').children(f).html(r?i(t(r).html()||l).render(o):l)}})}}),n.addClass(r).siblings("tr").removeClass(r)}),a.layMain.on("scroll",function(){var e=t(this),i=e.scrollLeft(),n=e.scrollTop();a.layHeader.scrollLeft(i),a.layFixed.find(p).scrollTop(n),l.close(a.tipsIndex)}),T.on("resize",function(){a.fullSize(),a.scrollPatch()})},d.init=function(e,i){i=i||{};var a=this,l=t(e?'table[lay-filter="'+e+'"]':u+"[lay-data]"),n="Table element property lay-data configuration item has a syntax error: ";return l.each(function(){var a=t(this),l=a.attr("lay-data");try{l=new Function("return "+l)()}catch(o){r.error(n+l)}var c=[],s=t.extend({elem:this,cols:[],data:[],skin:a.attr("lay-skin"),size:a.attr("lay-size"),even:"string"==typeof a.attr("lay-even")},d.config,i,l);e&&a.hide(),a.find("thead>tr").each(function(e){s.cols[e]=[],t(this).children().each(function(i){var a=t(this),l=a.attr("lay-data");try{l=new Function("return "+l)()}catch(o){return r.error(n+l)}var d=t.extend({title:a.text(),colspan:a.attr("colspan"),rowspan:a.attr("rowspan")},l);c.push(d),s.cols[e].push(d)})}),a.find("tbody>tr").each(function(e){var i=t(this),a={};i.children("td").each(function(e,i){var l=t(this),n=l.data("field");if(n)return a[n]=l.html()}),layui.each(c,function(e,t){var l=i.children("td").eq(e);a[t.field]=l.html()}),s.data[e]=a}),d.render(s)}),a},d.checkStatus=function(e){var t=0,i=[],a=d.cache[e];return a?(layui.each(a,function(e,a){a[d.config.checkName]&&(t++,i.push(d.clearCacheKey(a)))}),{data:i,isAll:t===a.length}):{}},c.config={},d.reload=function(e,i){var a=c.config[e];return a?d.render(t.extend({},a,i)):r.error("The ID option was not found in the table instance")},d.render=function(e){var t=new H(e);return c.call(t)},d.clearCacheKey=function(e){return e=t.extend({},e),delete e[d.config.checkName],delete e[d.config.indexName],e},d.init(),e(s,d)});