/** * * @name: 子表格扩展 * @author: yelog * @link: https://github.com/yelog/layui-soul-table * @license: MIT * @version: v1.6.2 */ layui.define(["table","element","form","laytpl"],function(exports){var $=layui.jquery,table=layui.table,laytpl=layui.laytpl,tableChildren={},HIDE="layui-hide",ELEM_HOVER="soul-table-hover",mod={render:function(f){var t,y=this,l=$(f.elem),e=l.next().children(".layui-table-box"),i=f.id,p=e.children(".layui-table-header").children("table"),m=e.children(".layui-table-fixed").children(".layui-table-body").children("table"),v=e.children(".layui-table-body").children("table"),x=$.merge(e.children(".layui-table-body").children("table"),m),a=y.getCompleteCols(f.cols),n=[],d=void 0===f.soulSort||f.soulSort;for(y.fixHoverStyle(f),t=0;tdiv').each(function(){u.isChild(layui.table.cache[i][$(this).parents("tr:eq(0)").data("index")])&&(u.field?$(this).prepend(''):$(this).html(''))}):u.field?x.find("tr").find('td[data-key$="'+u.key+'"]>div').prepend(''):x.find("tr").find('td[data-key$="'+u.key+'"]>div').html(''),x.children("tbody").children("tr").each(function(){$(this).children("td:eq("+e+")").find(".childTable").on("click",function(e){layui.stope(e);var t,l=$(this).parents("tr:eq(0)").data("index"),a=f.id,i=$(this).parents("td:eq(0)").data("key"),n=v.children("tbody").children("tr[data-index="+l+"]").children('td[data-key="'+i+'"]').find(".childTable:eq(0)"),d=m.find("tr[data-index="+l+"]").children('td[data-key="'+i+'"]').find(".childTable:eq(0)"),r=table.cache[a][l],o=u.children,c=!1,e="",h=x.children("tbody").children('tr[data-index="'+l+'"]'),s={data:r,tr:h,del:function(){table.cache[a][l]=[],y.destroyChildren(l,f,b),h.remove(),table.resize(a)},update:function(e){e=e||{},layui.each(e,function(l,e){var i,t;l in r&&(t=h.children('td[data-field="'+l+'"]'),r[l]=e,table.eachCols(a,function(e,t){t.field==l&&t.templet&&(i=t.templet)}),t.children(".layui-table-cell").html(i?"function"==typeof i?i(r):laytpl($(i).html()||e).render(r):e),t.data("content",e))})},close:function(){y.destroyChildren(l,f,b),table.resize(a)}};if(n.hasClass(b[1])){if("function"==typeof u.childClose&&!1===u.childClose(s))return}else if("function"==typeof u.childOpen&&!1===u.childOpen(s))return;"function"==typeof o&&(o=o(r)),"string"==typeof o&&(c=!0,e=y.parseTempData(u,u.field?r[u.field]:null,r)),2===u.show?(!u.layerOption||"function"==typeof u.layerOption.title&&(u.layerOption.title=u.layerOption.title(r)),layer.open($.extend({type:1,title:"子表",maxmin:!0,content:y.getTables(this,r,u,f,o,c,e),area:"1000px",offset:"100px",cancel:function(){"function"==typeof u.childClose&&u.childClose(s)}},u.layerOption||{})),c||y.renderTable(this,r,u,f,o,b)):(!n.hasClass(b[1])&&u.collapse&&x.children("tbody").children("tr").children("td").find(".childTable").each(function(){$(this).hasClass(b[1])&&y.destroyChildren($(this).parents("tr:eq(0)").data("index"),f,b)}),n.hasClass(b[1])||n.parents("tr:eq(0)").children("td").find(".childTable").each(function(){$(this).hasClass(b[1])&&($(this).removeClass(b[1]).addClass(b[0]),y.destroyChildren($(this).parents("tr:eq(0)").data("index"),f,b))}),n.hasClass(b[1])?(n.removeClass(b[1]).addClass(b[0]),d.removeClass(b[1]).addClass(b[0])):(n.removeClass(b[0]).addClass(b[1]),d.removeClass(b[0]).addClass(b[1])),i=n.parents("td:eq(0)").attr("rowspan"),n.hasClass(b[1])?((d=[]).push(''),d.push(y.getTables(this,r,u,f,o,c,e)),d.push(""),i?(i=parseInt(n.parents("tr:eq(0)").data("index"))+parseInt(i)-1,n.parents("table:eq(0)").children().children("[data-index='"+i+"']").after(d.join(""))):n.parents("tr:eq(0)").after(d.join("")),layui.element.init("tab"),c||(y.renderTable(this,r,u,f,o,b),n.parents("tr:eq(0)").next().children("td").children(".layui-tab").children(".layui-tab-content").on("click",function(e){$(e.target.parentElement).hasClass("layui-tab-title")||e.stopPropagation()}).off("dblclick").on("dblclick",function(e){e.stopPropagation()}).on("mouseenter","td",function(e){e.stopPropagation()}).on("change",function(e){layui.stope(e)})),0',o.children("td").children(".soul-table-child-wrapper").css({position:"absolute",top:0,width:"100%",background:"white","z-index":200}),o.children("td").append(t),m.find('tr[data-index="'+l+'"]').each(function(){$(this).after(''+t+"")}),table.resize(a)),3===u.show&&(n.parents("tr:eq(0)").next().find(".layui-table-view").css({margin:0,"border-width":0}),n.parents("tr:eq(0)").next().find(".layui-table-header").css("display","none"))):(y.destroyChildren(l,f,b),table.resize(a)))})}),u.spread&&2!==u.show&&x.children("tbody").children("tr").children("td").find(".childTable").trigger("click")}()},getTables:function(e,t,l,i,a,n,d){var r,o=[],c=$(i.elem),h=c.next().children(".layui-table-box"),s=i.id+$(e).parents("tr:eq(0)").data("index"),i=h.children(".layui-table-header").children("table"),e=c.next().children(".layui-table-box").children(".layui-table-body"),h=e.children("table"),c=0;if(n?o.push('
'):3===l.show||"full"===l.childWidth?o.push('">'):(e.prop("scrollHeight")+(0e.height()&&(c=this.getScrollWidth()),c=e.width()-1-c,o.push("max-width: "+(c>i.width()?i.width():c)+'px">')),n)o.push(d);else{if(3!==l.show&&(void 0===l.childTitle||l.childTitle)){for(o.push('
    '),r=0;r'+("function"==typeof a[r].title?a[r].title(t):a[r].title)+"");o.push("
")}for(3===l.show?o.push('
'):o.push('
'),r=0;r
')}o.push("
")}return o.push("
"),o.join("")},renderTable:function(a,n,d,r,o,e){var t=[],c=this,h=r.id,s=h+$(a).parents("tr:eq(0)").data("index");if(d.lazy)t.push(b(c,a,n,d,r,0,o,e));else for(var u=0;u"+t+"").text():t},commonMember:function(a,e,t){var l=$(this),n=e.id,i=$(e.elem).next().children(".layui-table-box"),d=i.children(".layui-table-fixed").children(".layui-table-body").children("table"),d=$.merge(i.children(".layui-table-body").children("table"),d),r=("TR"===l[0].tagName?$(this):l.parents("tr:eq(0)")).data("index"),o=d.children("tbody").children('tr[data-index="'+r+'"]'),c=(c=table.cache[n]||[])[r]||{};return $.extend(t,{tr:o,oldValue:l.prev()?l.prev().text():null,del:function(){table.cache[n][r]=[],o.remove(),a.scrollPatch(e)},update:function(e){e=e||{},layui.each(e,function(l,e){var i,t;l in c&&(t=o.children('td[data-field="'+l+'"]'),c[l]=e,table.eachCols(n,function(e,t){t.field==l&&t.templet&&(i=t.templet)}),t.children(".layui-table-cell").html(a.parseTempData({templet:i},e,c)),t.data("content",e))})}})},scrollPatch:function(e){var t=$(e.elem),l=t.next().children(".layui-table-box").children(".layui-table-header"),i=t.next().children(".layui-table-total"),a=t.next().children(".layui-table-box").children(".layui-table-main"),n=t.next().children(".layui-table-box").children(".layui-table-fixed"),d=t.next().children(".layui-table-box").children(".layui-table-fixed-r"),r=a.children("table"),o=a.width()-a.prop("clientWidth"),c=a.height()-a.prop("clientHeight"),e=r.outerWidth()-a.width(),t=function(e){var t;o&&c?(e=e.eq(0)).find(".layui-table-patch")[0]||((t=$('
')).find("div").css({width:o}),e.find("tr").append(t)):e.find(".layui-table-patch").remove()};t(l),t(i);a=a.height()-c;n.find(".layui-table-body").css("height",r.height()>=a?a:"auto"),d[0