coupon-admin/public/static/layuimini/js/lay-module/soulTable/tableChild.js

9 lines
15 KiB
JavaScript
Raw Normal View History

2021-11-18 09:57:04 +00:00
/**
*
* @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;t<a.length;t++)a[t].children&&0<a[t].children.length&&n.push(t);if(void 0===l.attr("lay-filter")&&l.attr("lay-filter",i),0===l.parents(".childTr").length&&("function"==typeof f.rowEvent&&table.on("row("+l.attr("lay-filter")+")",function(e){f.rowEvent(y.commonMember.call(this,y,f,e))}),"function"==typeof f.rowDoubleEvent&&table.on("rowDouble("+l.attr("lay-filter")+")",function(e){f.rowDoubleEvent(y.commonMember.call(this,y,f,e))}),"function"==typeof f.checkboxEvent&&table.on("checkbox("+l.attr("lay-filter")+")",function(e){f.checkboxEvent(y.commonMember.call(this,y,f,e))}),"function"==typeof f.editEvent&&table.on("edit("+l.attr("lay-filter")+")",function(e){f.editEvent(y.commonMember.call(this,y,f,e))}),"function"==typeof f.toolEvent&&table.on("tool("+l.attr("lay-filter")+")",function(e){f.toolEvent(y.commonMember.call(this,y,f,e))}),"function"==typeof f.toolbarEvent&&table.on("toolbar("+l.attr("lay-filter")+")",function(e){f.toolbarEvent(y.commonMember.call(this,y,f,e))})),0<n.length)for(t=0;t<n.length;t++)!function(){var u=a[n[t]],e=n[t],b=u.icon||["layui-icon layui-icon-right","layui-icon layui-icon-down"];!d||f.url&&f.page||table.on("sort("+l.attr("lay-filter")+")",function(){y.render(f)}),u.isChild&&"function"==typeof u.isChild?x.find("tr").find('td[data-key$="'+u.key+'"]>div').each(function(){u.isChild(layui.table.cache[i][$(this).parents("tr:eq(0)").data("index")])&&(u.field?$(this).prepend('<i style="cursor: pointer" class="childTable '+b[0]+'"></i>'):$(this).html('<i style="cursor: pointer" class="childTable '+b[0]+'"></i>'))}):u.field?x.find("tr").find('td[data-key$="'+u.key+'"]>div').prepend('<i style="cursor: pointer" class="childTable '+b[0]+'"></i>'):x.find("tr").find('td[data-key$="'+u.key+'"]>div').html('<i style="cursor: pointer" class="childTable '+b[0]+'"></i>'),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]