table.js 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240
  1. /** layui-v2.5.6 MIT License By https://www.layui.com */
  2. ; layui.define(["laytpl", "laypage", "layer", "form", "util"], function (e) {
  3. "use strict";
  4. var t = layui.$
  5. , i = layui.laytpl
  6. , a = layui.laypage
  7. , l = layui.layer
  8. , n = layui.form
  9. , o = (layui.util,
  10. layui.hint())
  11. , r = layui.device()
  12. , d = {
  13. config: {
  14. checkName: "LAY_CHECKED",
  15. indexName: "LAY_TABLE_INDEX"
  16. },
  17. cache: {},
  18. index: layui.table ? layui.table.index + 1e4 : 0,
  19. set: function (e) {
  20. var i = this;
  21. return i.config = t.extend({}, i.config, e),
  22. i
  23. },
  24. on: function (e, t) {
  25. return layui.onevent.call(this, y, e, t)
  26. }
  27. }
  28. , c = function () {
  29. var e = this
  30. , t = e.config
  31. , i = t.id || t.index;
  32. return i && (c.that[i] = e,
  33. c.config[i] = t),
  34. {
  35. config: t,
  36. reload: function (t) {
  37. e.reload.call(e, t)
  38. },
  39. setColsWidth: function () {
  40. e.setColsWidth.call(e)
  41. },
  42. resize: function () {
  43. e.resize.call(e)
  44. }
  45. }
  46. }
  47. , s = function (e) {
  48. var t = c.config[e];
  49. return t || o.error("The ID option was not found in the table instance"),
  50. t || null
  51. }
  52. , u = function (e, a, l, n) {
  53. var o = e.templet ? function () {
  54. return "function" == typeof e.templet ? e.templet(l) : i(t(e.templet).html() || String(a)).render(l)
  55. }() : a;
  56. return n ? t("<div>" + o + "</div>").text() : o
  57. }
  58. , y = "table"
  59. , h = ".layui-table"
  60. , f = "layui-hide"
  61. , p = "layui-none"
  62. , v = "layui-table-view"
  63. , m = ".layui-table-tool"
  64. , g = ".layui-table-box"
  65. , b = ".layui-table-init"
  66. , x = ".layui-table-header"
  67. , k = ".layui-table-body"
  68. , C = ".layui-table-main"
  69. , w = ".layui-table-fixed"
  70. , T = ".layui-table-fixed-l"
  71. , A = ".layui-table-fixed-r"
  72. , L = ".layui-table-total"
  73. , N = ".layui-table-page"
  74. , S = ".layui-table-sort"
  75. , R = "layui-table-edit"
  76. , W = "layui-table-hover"
  77. , _ = function (e) {
  78. var t = '{{#if(item2.colspan){}} colspan="{{item2.colspan}}"{{#} if(item2.rowspan){}} rowspan="{{item2.rowspan}}"{{#}}}';
  79. return e = e || {},
  80. ['<table cellspacing="0" cellpadding="0" border="0" class="layui-table" ', '{{# if(d.data.skin){ }}lay-skin="{{d.data.skin}}"{{# } }} {{# if(d.data.size){ }}lay-size="{{d.data.size}}"{{# } }} {{# if(d.data.even){ }}lay-even{{# } }}>', "<thead>", "{{# layui.each(d.data.cols, function(i1, item1){ }}", "<tr>", "{{# layui.each(item1, function(i2, item2){ }}", '{{# if(item2.fixed && item2.fixed !== "right"){ left = true; } }}', '{{# if(item2.fixed === "right"){ right = true; } }}', function () {
  81. return e.fixed && "right" !== e.fixed ? '{{# if(item2.fixed && item2.fixed !== "right"){ }}' : "right" === e.fixed ? '{{# if(item2.fixed === "right"){ }}' : ""
  82. }(), "{{# var isSort = !(item2.colGroup) && item2.sort; }}", '<th data-field="{{ item2.field||i2 }}" data-key="{{d.index}}-{{i1}}-{{i2}}" {{# if( item2.parentKey){ }}data-parentkey="{{ item2.parentKey }}"{{# } }} {{# if(item2.minWidth){ }}data-minwidth="{{item2.minWidth}}"{{# } }} ' + t + ' {{# if(item2.unresize || item2.colGroup){ }}data-unresize="true"{{# } }} class="{{# if(item2.hide){ }}layui-hide{{# } }}{{# if(isSort){ }} layui-unselect{{# } }}{{# if(!item2.field){ }} layui-table-col-special{{# } }}">', '<div class="layui-table-cell laytable-cell-', "{{# if(item2.colGroup){ }}", "group", "{{# } else { }}", "{{d.index}}-{{i1}}-{{i2}}", '{{# if(item2.type !== "normal"){ }}', " laytable-cell-{{ item2.type }}", "{{# } }}", "{{# } }}", '" {{#if(item2.align){}}align="{{item2.align}}"{{#}}}>', '{{# if(item2.type === "checkbox"){ }}', '<input type="checkbox" name="layTableCheckbox" lay-skin="primary" lay-filter="layTableAllChoose" {{# if(item2[d.data.checkName]){ }}checked{{# }; }}>', "{{# } else { }}", '<span>{{item2.title||""}}</span>', "{{# if(isSort){ }}", '<span class="layui-table-sort layui-inline"><i class="layui-edge layui-table-sort-asc" title="升序"></i><i class="layui-edge layui-table-sort-desc" title="降序"></i></span>', "{{# } }}", "{{# } }}", "</div>", "</th>", e.fixed ? "{{# }; }}" : "", "{{# }); }}", "</tr>", "{{# }); }}", "</thead>", "</table>"].join("")
  83. }
  84. , E = ['<table cellspacing="0" cellpadding="0" border="0" class="layui-table" ', '{{# if(d.data.skin){ }}lay-skin="{{d.data.skin}}"{{# } }} {{# if(d.data.size){ }}lay-size="{{d.data.size}}"{{# } }} {{# if(d.data.even){ }}lay-even{{# } }}>', "<tbody></tbody>", "</table>"].join("")
  85. , z = ['<div class="layui-form layui-border-box {{d.VIEW_CLASS}}" lay-filter="LAY-table-{{d.index}}" lay-id="{{ d.data.id }}" style="{{# if(d.data.width){ }}width:{{d.data.width}}px;{{# } }} {{# if(d.data.height){ }}height:{{d.data.height}}px;{{# } }}">', "{{# if(d.data.toolbar){ }}", '<div class="layui-table-tool">', '<div class="layui-table-tool-temp"></div>', '<div class="layui-table-tool-self"></div>', "</div>", "{{# } }}", '<div class="layui-table-box">', "{{# if(d.data.loading){ }}", '<div class="layui-table-init" style="background-color: #fff;">', '<i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i>', "</div>", "{{# } }}", "{{# var left, right; }}", '<div class="layui-table-header">', _(), "</div>", '<div class="layui-table-body layui-table-main">', E, "</div>", "{{# if(left){ }}", '<div class="layui-table-fixed layui-table-fixed-l">', '<div class="layui-table-header">', _({
  86. fixed: !0
  87. }), "</div>", '<div class="layui-table-body">', E, "</div>", "</div>", "{{# }; }}", "{{# if(right){ }}", '<div class="layui-table-fixed layui-table-fixed-r">', '<div class="layui-table-header">', _({
  88. fixed: "right"
  89. }), '<div class="layui-table-mend"></div>', "</div>", '<div class="layui-table-body">', E, "</div>", "</div>", "{{# }; }}", "</div>", "{{# if(d.data.totalRow){ }}", '<div class="layui-table-total">', '<table cellspacing="0" cellpadding="0" border="0" class="layui-table" ', '{{# if(d.data.skin){ }}lay-skin="{{d.data.skin}}"{{# } }} {{# if(d.data.size){ }}lay-size="{{d.data.size}}"{{# } }} {{# if(d.data.even){ }}lay-even{{# } }}>', '<tbody><tr><td><div class="layui-table-cell" style="visibility: hidden;">Total</div></td></tr></tbody>', "</table>", "</div>", "{{# } }}", "{{# if(d.data.page){ }}", '<div class="layui-table-page">', '<div id="layui-table-page{{d.index}}"></div>', "</div>", "{{# } }}", "<style>", "{{# layui.each(d.data.cols, function(i1, item1){", "layui.each(item1, function(i2, item2){ }}", ".laytable-cell-{{d.index}}-{{i1}}-{{i2}}{ ", "{{# if(item2.width){ }}", "width: {{item2.width}}px;", "{{# } }}", " }", "{{# });", "}); }}", "</style>", "</div>"].join("")
  90. , H = t(window)
  91. , j = t(document)
  92. , F = function (e) {
  93. var i = this;
  94. i.index = ++d.index,
  95. i.config = t.extend({}, i.config, d.config, e),
  96. i.render()
  97. };
  98. F.prototype.config = {
  99. limit: 20,
  100. loading: !0,
  101. cellMinWidth: 60,
  102. defaultToolbar: ["filter", "exports", "print"],
  103. autoSort: !0,
  104. text: {
  105. none: "无数据"
  106. }
  107. },
  108. F.prototype.render = function () {
  109. var e = this
  110. , a = e.config;
  111. if (a.elem = t(a.elem),
  112. a.where = a.where || {},
  113. a.id = a.id || a.elem.attr("id") || e.index,
  114. a.request = t.extend({
  115. pageName: "Page",
  116. limitName: "Rows"
  117. }, a.request),
  118. a.response = t.extend({
  119. statusName: "Code",
  120. statusCode: 0,
  121. msgName: "msg",
  122. dataName: "Data",
  123. totalRowName: "totalRow",
  124. countName: "Total"
  125. }, a.response),
  126. "object" == typeof a.page && (a.limit = a.page.limit || a.limit,
  127. a.limits = a.page.limits || a.limits,
  128. e.page = a.page.curr = a.page.curr || 1,
  129. delete a.page.elem,
  130. delete a.page.jump),
  131. !a.elem[0])
  132. return e;
  133. a.height && /^full-\d+$/.test(a.height) && (e.fullHeightGap = a.height.split("-")[1],
  134. a.height = H.height() - e.fullHeightGap),
  135. e.setInit();
  136. var l = a.elem
  137. , n = l.next("." + v)
  138. , o = e.elem = t(i(z).render({
  139. VIEW_CLASS: v,
  140. data: a,
  141. index: e.index
  142. }));
  143. if (a.index = e.index,
  144. e.key = a.id || a.index,
  145. n[0] && n.remove(),
  146. l.after(o),
  147. e.layTool = o.find(m),
  148. e.layBox = o.find(g),
  149. e.layHeader = o.find(x),
  150. e.layMain = o.find(C),
  151. e.layBody = o.find(k),
  152. e.layFixed = o.find(w),
  153. e.layFixLeft = o.find(T),
  154. e.layFixRight = o.find(A),
  155. e.layTotal = o.find(L),
  156. e.layPage = o.find(N),
  157. e.renderToolbar(),
  158. e.fullSize(),
  159. a.cols.length > 1) {
  160. var r = e.layFixed.find(x).find("th");
  161. r.height(e.layHeader.height() - 1 - parseFloat(r.css("padding-top")) - parseFloat(r.css("padding-bottom")))
  162. }
  163. e.pullData(e.page),
  164. e.events()
  165. }
  166. ,
  167. F.prototype.initOpts = function (e) {
  168. var t = this
  169. , i = (t.config,
  170. {
  171. checkbox: 48,
  172. radio: 48,
  173. space: 15,
  174. numbers: 40
  175. });
  176. e.checkbox && (e.type = "checkbox"),
  177. e.space && (e.type = "space"),
  178. e.type || (e.type = "normal"),
  179. "normal" !== e.type && (e.unresize = !0,
  180. e.width = e.width || i[e.type])
  181. }
  182. ,
  183. F.prototype.setInit = function (e) {
  184. var t = this
  185. , i = t.config;
  186. return i.clientWidth = i.width || function () {
  187. var e = function (t) {
  188. var a, l;
  189. t = t || i.elem.parent(),
  190. a = t.width();
  191. try {
  192. l = "none" === t.css("display")
  193. } catch (n) { }
  194. return !t[0] || a && !l ? a : e(t.parent())
  195. };
  196. return e()
  197. }(),
  198. "width" === e ? i.clientWidth : void layui.each(i.cols, function (e, a) {
  199. layui.each(a, function (l, n) {
  200. if (!n)
  201. return void a.splice(l, 1);
  202. if (n.key = e + "-" + l,
  203. n.hide = n.hide || !1,
  204. n.colGroup || n.colspan > 1) {
  205. var o = 0;
  206. layui.each(i.cols[e + 1], function (t, i) {
  207. i.HAS_PARENT || o > 1 && o == n.colspan || (i.HAS_PARENT = !0,
  208. i.parentKey = e + "-" + l,
  209. o += parseInt(i.colspan > 1 ? i.colspan : 1))
  210. }),
  211. n.colGroup = !0
  212. }
  213. t.initOpts(n)
  214. })
  215. })
  216. }
  217. ,
  218. F.prototype.renderToolbar = function () {
  219. var e = this
  220. , a = e.config
  221. , l = ['<div class="layui-inline" lay-event="add"><i class="layui-icon layui-icon-add-1"></i></div>', '<div class="layui-inline" lay-event="update"><i class="layui-icon layui-icon-edit"></i></div>', '<div class="layui-inline" lay-event="delete"><i class="layui-icon layui-icon-delete"></i></div>'].join("")
  222. , n = e.layTool.find(".layui-table-tool-temp");
  223. if ("default" === a.toolbar)
  224. n.html(l);
  225. else if ("string" == typeof a.toolbar) {
  226. var o = t(a.toolbar).html() || "";
  227. o && n.html(i(o).render(a))
  228. }
  229. var r = {
  230. filter: {
  231. title: "筛选列",
  232. layEvent: "LAYTABLE_COLS",
  233. icon: "layui-icon-cols"
  234. },
  235. exports: {
  236. title: "导出",
  237. layEvent: "LAYTABLE_EXPORT",
  238. icon: "layui-icon-export"
  239. },
  240. print: {
  241. title: "打印",
  242. layEvent: "LAYTABLE_PRINT",
  243. icon: "layui-icon-print"
  244. }
  245. }
  246. , d = [];
  247. "object" == typeof a.defaultToolbar && layui.each(a.defaultToolbar, function (e, t) {
  248. var i = "string" == typeof t ? r[t] : t;
  249. i && d.push('<div class="layui-inline" title="' + i.title + '" lay-event="' + i.layEvent + '"><i class="layui-icon ' + i.icon + '"></i></div>')
  250. }),
  251. e.layTool.find(".layui-table-tool-self").html(d.join(""))
  252. }
  253. ,
  254. F.prototype.setParentCol = function (e, t) {
  255. var i = this
  256. , a = i.config
  257. , l = i.layHeader.find('th[data-key="' + a.index + "-" + t + '"]')
  258. , n = parseInt(l.attr("colspan")) || 0;
  259. if (l[0]) {
  260. var o = t.split("-")
  261. , r = a.cols[o[0]][o[1]];
  262. e ? n-- : n++ ,
  263. l.attr("colspan", n),
  264. l[n < 1 ? "addClass" : "removeClass"](f),
  265. r.colspan = n,
  266. r.hide = n < 1;
  267. var d = l.data("parentkey");
  268. d && i.setParentCol(e, d)
  269. }
  270. }
  271. ,
  272. F.prototype.setColsPatch = function () {
  273. var e = this
  274. , t = e.config;
  275. layui.each(t.cols, function (t, i) {
  276. layui.each(i, function (t, i) {
  277. i.hide && e.setParentCol(i.hide, i.parentKey)
  278. })
  279. })
  280. }
  281. ,
  282. F.prototype.setColsWidth = function () {
  283. var e = this
  284. , t = e.config
  285. , i = 0
  286. , a = 0
  287. , l = 0
  288. , n = 0
  289. , o = e.setInit("width");
  290. e.eachCols(function (e, t) {
  291. t.hide || i++
  292. }),
  293. o = o - function () {
  294. return "line" === t.skin || "nob" === t.skin ? 2 : i + 1
  295. }() - e.getScrollWidth(e.layMain[0]) - 1;
  296. var r = function (e) {
  297. layui.each(t.cols, function (i, r) {
  298. layui.each(r, function (i, d) {
  299. var c = 0
  300. , s = d.minWidth || t.cellMinWidth;
  301. return d ? void (d.colGroup || d.hide || (e ? l && l < s && (a-- ,
  302. c = s) : (c = d.width || 0,
  303. /\d+%$/.test(c) ? (c = Math.floor(parseFloat(c) / 100 * o),
  304. c < s && (c = s)) : c || (d.width = c = 0,
  305. a++)),
  306. d.hide && (c = 0),
  307. n += c)) : void r.splice(i, 1)
  308. })
  309. }),
  310. o > n && a && (l = (o - n) / a)
  311. };
  312. r(),
  313. r(!0),
  314. e.autoColNums = a,
  315. e.eachCols(function (i, a) {
  316. var n = a.minWidth || t.cellMinWidth;
  317. a.colGroup || a.hide || (0 === a.width ? e.getCssRule(t.index + "-" + a.key, function (e) {
  318. e.style.width = Math.floor(l >= n ? l : n) + "px"
  319. }) : /\d+%$/.test(a.width) && e.getCssRule(t.index + "-" + a.key, function (e) {
  320. e.style.width = Math.floor(parseFloat(a.width) / 100 * o) + "px"
  321. }))
  322. });
  323. var d = e.layMain.width() - e.getScrollWidth(e.layMain[0]) - e.layMain.children("table").outerWidth();
  324. if (e.autoColNums && d >= -i && d <= i) {
  325. var c = function (t) {
  326. var i;
  327. return t = t || e.layHeader.eq(0).find("thead th:last-child"),
  328. i = t.data("field"),
  329. !i && t.prev()[0] ? c(t.prev()) : t
  330. }
  331. , s = c()
  332. , u = s.data("key");
  333. e.getCssRule(u, function (t) {
  334. var i = t.style.width || s.outerWidth();
  335. t.style.width = parseFloat(i) + d + "px",
  336. e.layMain.height() - e.layMain.prop("clientHeight") > 0 && (t.style.width = parseFloat(t.style.width) - 1 + "px")
  337. })
  338. }
  339. e.loading(!0)
  340. }
  341. ,
  342. F.prototype.resize = function () {
  343. var e = this;
  344. e.fullSize(),
  345. e.setColsWidth(),
  346. e.scrollPatch()
  347. }
  348. ,
  349. F.prototype.reload = function (e) {
  350. var i = this;
  351. e = e || {},
  352. delete i.haveInit,
  353. e.data && e.data.constructor === Array && delete i.config.data,
  354. i.config = t.extend(!0, {}, i.config, e),
  355. i.render()
  356. }
  357. ,
  358. F.prototype.errorView = function (e) {
  359. var i = this
  360. , a = i.layMain.find("." + p)
  361. , l = t('<div class="' + p + '">' + (e || "Error") + "</div>");
  362. a[0] && (i.layNone.remove(),
  363. a.remove()),
  364. i.layFixed.addClass(f),
  365. i.layMain.find("tbody").html(""),
  366. i.layMain.append(i.layNone = l),
  367. d.cache[i.key] = []
  368. }
  369. ,
  370. F.prototype.page = 1,
  371. F.prototype.pullData = function (e) {
  372. var i = this
  373. , a = i.config
  374. , l = a.request
  375. , n = a.response
  376. , o = function () {
  377. "object" == typeof a.initSort && i.sort(a.initSort.field, a.initSort.type)
  378. };
  379. if (i.startTime = (new Date).getTime(),
  380. a.url) {
  381. var r = {};
  382. r[l.pageName] = e,
  383. r[l.limitName] = a.limit;
  384. var d = t.extend(r, a.where);
  385. a.contentType && 0 == a.contentType.indexOf("application/json") && (d = JSON.stringify(d)),
  386. i.loading(),
  387. t.ajax({
  388. type: a.method || "get",
  389. url: a.url,
  390. contentType: a.contentType,
  391. data: d,
  392. dataType: "json",
  393. headers: a.headers || {},
  394. success: function (t) {
  395. "function" == typeof a.parseData && (t = a.parseData(t) || t),
  396. t[n.statusName] != n.statusCode ? (i.renderForm(),
  397. i.errorView(t[n.msgName] || '返回的数据不符合规范,正确的成功状态码应为:"' + n.statusName + '": ' + n.statusCode)) : (i.renderData(t, e, t[n.countName]),
  398. o(),
  399. a.time = (new Date).getTime() - i.startTime + " ms"),
  400. i.setColsWidth(),
  401. "function" == typeof a.done && a.done(t, e, t[n.countName])
  402. },
  403. error: function (e, t) {
  404. i.errorView("数据接口请求异常:" + t),
  405. i.renderForm(),
  406. i.setColsWidth()
  407. }
  408. })
  409. } else if (a.data && a.data.constructor === Array) {
  410. var c = {}
  411. , s = e * a.limit - a.limit;
  412. c[n.dataName] = a.data.concat().splice(s, a.limit),
  413. c[n.countName] = a.data.length,
  414. "object" == typeof a.totalRow && (c[n.totalRowName] = t.extend({}, a.totalRow)),
  415. i.renderData(c, e, c[n.countName]),
  416. o(),
  417. i.setColsWidth(),
  418. "function" == typeof a.done && a.done(c, e, c[n.countName])
  419. }
  420. }
  421. ,
  422. F.prototype.eachCols = function (e) {
  423. var t = this;
  424. return d.eachCols(null, e, t.config.cols),
  425. t
  426. }
  427. ,
  428. F.prototype.renderData = function (e, n, o, r) {
  429. var c = this
  430. , s = c.config
  431. , y = e[s.response.dataName] || []
  432. , h = e[s.response.totalRowName]
  433. , v = []
  434. , m = []
  435. , g = []
  436. , b = function () {
  437. var e;
  438. return !r && c.sortKey ? c.sort(c.sortKey.field, c.sortKey.sort, !0) : (layui.each(y, function (a, l) {
  439. var o = []
  440. , y = []
  441. , h = []
  442. , p = a + s.limit * (n - 1) + 1;
  443. 0 !== l.length && (r || (l[d.config.indexName] = a),
  444. c.eachCols(function (n, r) {
  445. var c = r.field || n
  446. , v = s.index + "-" + r.key
  447. , m = l[c];
  448. if (void 0 !== m && null !== m || (m = ""),
  449. !r.colGroup) {
  450. var g = ['<td data-field="' + c + '" data-key="' + v + '" ' + function () {
  451. var e = [];
  452. return r.edit && e.push('data-edit="' + r.edit + '"'),
  453. r.align && e.push('align="' + r.align + '"'),
  454. r.templet && e.push('data-content="' + m + '"'),
  455. r.toolbar && e.push('data-off="true"'),
  456. r.event && e.push('lay-event="' + r.event + '"'),
  457. r.style && e.push('style="' + r.style + '"'),
  458. r.minWidth && e.push('data-minwidth="' + r.minWidth + '"'),
  459. e.join(" ")
  460. }() + ' class="' + function () {
  461. var e = [];
  462. return r.hide && e.push(f),
  463. r.field || e.push("layui-table-col-special"),
  464. e.join(" ")
  465. }() + '">', '<div class="layui-table-cell laytable-cell-' + function () {
  466. return "normal" === r.type ? v : v + " laytable-cell-" + r.type
  467. }() + '">' + function () {
  468. var n = t.extend(!0, {
  469. LAY_INDEX: p
  470. }, l)
  471. , o = d.config.checkName;
  472. switch (r.type) {
  473. case "checkbox":
  474. return '<input type="checkbox" name="layTableCheckbox" lay-skin="primary" ' + function () {
  475. return r[o] ? (l[o] = r[o],
  476. r[o] ? "checked" : "") : n[o] ? "checked" : ""
  477. }() + ">";
  478. case "radio":
  479. return n[o] && (e = a),
  480. '<input type="radio" name="layTableRadio_' + s.index + '" ' + (n[o] ? "checked" : "") + ' lay-type="layTableRadio">';
  481. case "numbers":
  482. return p
  483. }
  484. return r.toolbar ? i(t(r.toolbar).html() || "").render(n) : u(r, m, n)
  485. }(), "</div></td>"].join("");
  486. o.push(g),
  487. r.fixed && "right" !== r.fixed && y.push(g),
  488. "right" === r.fixed && h.push(g)
  489. }
  490. }),
  491. v.push('<tr data-index="' + a + '">' + o.join("") + "</tr>"),
  492. m.push('<tr data-index="' + a + '">' + y.join("") + "</tr>"),
  493. g.push('<tr data-index="' + a + '">' + h.join("") + "</tr>"))
  494. }),
  495. c.layBody.scrollTop(0),
  496. c.layMain.find("." + p).remove(),
  497. c.layMain.find("tbody").html(v.join("")),
  498. c.layFixLeft.find("tbody").html(m.join("")),
  499. c.layFixRight.find("tbody").html(g.join("")),
  500. c.renderForm(),
  501. "number" == typeof e && c.setThisRowChecked(e),
  502. c.syncCheckAll(),
  503. c.haveInit ? c.scrollPatch() : setTimeout(function () {
  504. c.scrollPatch()
  505. }, 50),
  506. c.haveInit = !0,
  507. l.close(c.tipsIndex),
  508. s.HAS_SET_COLS_PATCH || c.setColsPatch(),
  509. void (s.HAS_SET_COLS_PATCH = !0))
  510. };
  511. return d.cache[c.key] = y,
  512. c.layPage[0 == o || 0 === y.length && 1 == n ? "addClass" : "removeClass"](f),
  513. r ? b() : 0 === y.length ? (c.renderForm(),
  514. c.errorView(s.text.none)) : (c.layFixed.removeClass(f),
  515. b(),
  516. c.renderTotal(y, h),
  517. void (s.page && (s.page = t.extend({
  518. elem: "layui-table-page" + s.index,
  519. count: o,
  520. limit: s.limit,
  521. limits: s.limits || [20, 40, 60, 80, 100, 120, 140, 160, 180],
  522. groups: 3,
  523. layout: ["prev", "page", "next", "skip", "count", "limit"],
  524. prev: '<i class="layui-icon">&#xe603;</i>',
  525. next: '<i class="layui-icon">&#xe602;</i>',
  526. jump: function (e, t) {
  527. t || (c.page = e.curr,
  528. s.limit = e.limit,
  529. c.pullData(e.curr))
  530. }
  531. }, s.page),
  532. s.page.count = o,
  533. a.render(s.page))))
  534. }
  535. ,
  536. F.prototype.renderTotal = function (e, t) {
  537. var i = this
  538. , a = i.config
  539. , l = {};
  540. if (a.totalRow) {
  541. layui.each(e, function (e, t) {
  542. 0 !== t.length && i.eachCols(function (e, i) {
  543. var a = i.field || e
  544. , n = t[a];
  545. i.totalRow && (l[a] = (l[a] || 0) + (parseFloat(n) || 0))
  546. })
  547. }),
  548. i.dataTotal = {};
  549. var n = [];
  550. i.eachCols(function (e, o) {
  551. var r = o.field || e
  552. , d = function () {
  553. var e = o.totalRowText || ""
  554. , i = parseFloat(l[r]).toFixed(2)
  555. , a = {};
  556. return a[r] = i,
  557. i = u(o, i, a),
  558. t ? t[o.field] || e : o.totalRow ? i || e : e
  559. }()
  560. , c = ['<td data-field="' + r + '" data-key="' + a.index + "-" + o.key + '" ' + function () {
  561. var e = [];
  562. return o.align && e.push('align="' + o.align + '"'),
  563. o.style && e.push('style="' + o.style + '"'),
  564. o.minWidth && e.push('data-minwidth="' + o.minWidth + '"'),
  565. e.join(" ")
  566. }() + ' class="' + function () {
  567. var e = [];
  568. return o.hide && e.push(f),
  569. o.field || e.push("layui-table-col-special"),
  570. e.join(" ")
  571. }() + '">', '<div class="layui-table-cell laytable-cell-' + function () {
  572. var e = a.index + "-" + o.key;
  573. return "normal" === o.type ? e : e + " laytable-cell-" + o.type
  574. }() + '">' + d, "</div></td>"].join("");
  575. o.field && (i.dataTotal[r] = d),
  576. n.push(c)
  577. }),
  578. i.layTotal.find("tbody").html("<tr>" + n.join("") + "</tr>")
  579. }
  580. }
  581. ,
  582. F.prototype.getColElem = function (e, t) {
  583. var i = this
  584. , a = i.config;
  585. return e.eq(0).find(".laytable-cell-" + (a.index + "-" + t) + ":eq(0)")
  586. }
  587. ,
  588. F.prototype.renderForm = function (e) {
  589. n.render(e, "LAY-table-" + this.index)
  590. }
  591. ,
  592. F.prototype.setThisRowChecked = function (e) {
  593. var t = this
  594. , i = (t.config,
  595. "layui-table-click")
  596. , a = t.layBody.find('tr[data-index="' + e + '"]');
  597. a.addClass(i).siblings("tr").removeClass(i)
  598. }
  599. ,
  600. F.prototype.sort = function (e, i, a, l) {
  601. var n, r, c = this, s = {}, u = c.config, h = u.elem.attr("lay-filter"), f = d.cache[c.key];
  602. "string" == typeof e && c.layHeader.find("th").each(function (i, a) {
  603. var l = t(this)
  604. , o = l.data("field");
  605. if (o === e)
  606. return e = l,
  607. n = o,
  608. !1
  609. });
  610. try {
  611. var n = n || e.data("field")
  612. , p = e.data("key");
  613. if (c.sortKey && !a && n === c.sortKey.field && i === c.sortKey.sort)
  614. return;
  615. var v = c.layHeader.find("th .laytable-cell-" + p).find(S);
  616. c.layHeader.find("th").find(S).removeAttr("lay-sort"),
  617. v.attr("lay-sort", i || null),
  618. c.layFixed.find("th")
  619. } catch (m) {
  620. return o.error("Table modules: Did not match to field")
  621. }
  622. c.sortKey = {
  623. field: n,
  624. sort: i
  625. },
  626. u.autoSort && ("asc" === i ? r = layui.sort(f, n) : "desc" === i ? r = layui.sort(f, n, !0) : (r = layui.sort(f, d.config.indexName),
  627. delete c.sortKey)),
  628. s[u.response.dataName] = r || f,
  629. c.renderData(s, c.page, c.count, !0),
  630. l && layui.event.call(e, y, "sort(" + h + ")", {
  631. field: n,
  632. type: i
  633. })
  634. }
  635. ,
  636. F.prototype.loading = function (e) {
  637. var i = this
  638. , a = i.config;
  639. a.loading && (e ? (i.layInit && i.layInit.remove(),
  640. delete i.layInit,
  641. i.layBox.find(b).remove()) : (i.layInit = t(['<div class="layui-table-init">', '<i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i>', "</div>"].join("")),
  642. i.layBox.append(i.layInit)))
  643. }
  644. ,
  645. F.prototype.setCheckData = function (e, t) {
  646. var i = this
  647. , a = i.config
  648. , l = d.cache[i.key];
  649. l[e] && l[e].constructor !== Array && (l[e][a.checkName] = t)
  650. }
  651. ,
  652. F.prototype.syncCheckAll = function () {
  653. var e = this
  654. , t = e.config
  655. , i = e.layHeader.find('input[name="layTableCheckbox"]')
  656. , a = function (i) {
  657. return e.eachCols(function (e, a) {
  658. "checkbox" === a.type && (a[t.checkName] = i)
  659. }),
  660. i
  661. };
  662. i[0] && (d.checkStatus(e.key).isAll ? (i[0].checked || (i.prop("checked", !0),
  663. e.renderForm("checkbox")),
  664. a(!0)) : (i[0].checked && (i.prop("checked", !1),
  665. e.renderForm("checkbox")),
  666. a(!1)))
  667. }
  668. ,
  669. F.prototype.getCssRule = function (e, t) {
  670. var i = this
  671. , a = i.elem.find("style")[0]
  672. , l = a.sheet || a.styleSheet || {}
  673. , n = l.cssRules || l.rules;
  674. layui.each(n, function (i, a) {
  675. if (a.selectorText === ".laytable-cell-" + e)
  676. return t(a),
  677. !0
  678. })
  679. }
  680. ,
  681. F.prototype.fullSize = function () {
  682. var e, t = this, i = t.config, a = i.height;
  683. t.fullHeightGap && (a = H.height() - t.fullHeightGap,
  684. a < 135 && (a = 135),
  685. t.elem.css("height", a)),
  686. a && (e = parseFloat(a) - (t.layHeader.outerHeight() || 38),
  687. i.toolbar && (e -= t.layTool.outerHeight() || 50),
  688. i.totalRow && (e -= t.layTotal.outerHeight() || 40),
  689. i.page && (e -= t.layPage.outerHeight() || 41),
  690. t.layMain.css("height", e - 2))
  691. }
  692. ,
  693. F.prototype.getScrollWidth = function (e) {
  694. var t = 0;
  695. return e ? t = e.offsetWidth - e.clientWidth : (e = document.createElement("div"),
  696. e.style.width = "100px",
  697. e.style.height = "100px",
  698. e.style.overflowY = "scroll",
  699. document.body.appendChild(e),
  700. t = e.offsetWidth - e.clientWidth,
  701. document.body.removeChild(e)),
  702. t
  703. }
  704. ,
  705. F.prototype.scrollPatch = function () {
  706. var e = this
  707. , i = e.layMain.children("table")
  708. , a = e.layMain.width() - e.layMain.prop("clientWidth")
  709. , l = e.layMain.height() - e.layMain.prop("clientHeight")
  710. , n = (e.getScrollWidth(e.layMain[0]),
  711. i.outerWidth() - e.layMain.width())
  712. , o = function (e) {
  713. if (a && l) {
  714. if (e = e.eq(0),
  715. !e.find(".layui-table-patch")[0]) {
  716. var i = t('<th class="layui-table-patch"><div class="layui-table-cell"></div></th>');
  717. i.find("div").css({
  718. width: a
  719. }),
  720. e.find("tr").append(i)
  721. }
  722. } else
  723. e.find(".layui-table-patch").remove()
  724. };
  725. o(e.layHeader),
  726. o(e.layTotal);
  727. var r = e.layMain.height()
  728. , d = r - l;
  729. e.layFixed.find(k).css("height", i.height() >= d ? d : "auto"),
  730. e.layFixRight[n > 0 ? "removeClass" : "addClass"](f),
  731. e.layFixRight.css("right", a - 1)
  732. }
  733. ,
  734. F.prototype.events = function () {
  735. var e, i = this, a = i.config, o = t("body"), c = {}, s = i.layHeader.find("th"), h = ".layui-table-cell", p = a.elem.attr("lay-filter");
  736. i.layTool.on("click", "*[lay-event]", function (e) {
  737. var o = t(this)
  738. , c = o.attr("lay-event")
  739. , s = function (e) {
  740. var l = t(e.list)
  741. , n = t('<ul class="layui-table-tool-panel"></ul>');
  742. n.html(l),
  743. a.height && n.css("max-height", a.height - (i.layTool.outerHeight() || 50)),
  744. o.find(".layui-table-tool-panel")[0] || o.append(n),
  745. i.renderForm(),
  746. n.on("click", function (e) {
  747. layui.stope(e)
  748. }),
  749. e.done && e.done(n, l)
  750. };
  751. switch (layui.stope(e),
  752. j.trigger("table.tool.panel.remove"),
  753. l.close(i.tipsIndex),
  754. c) {
  755. case "LAYTABLE_COLS":
  756. s({
  757. list: function () {
  758. var e = [];
  759. return i.eachCols(function (t, i) {
  760. i.field && "normal" == i.type && e.push('<li><input type="checkbox" name="' + i.field + '" data-key="' + i.key + '" data-parentkey="' + (i.parentKey || "") + '" lay-skin="primary" ' + (i.hide ? "" : "checked") + ' title="' + (i.title || i.field) + '" lay-filter="LAY_TABLE_TOOL_COLS"></li>')
  761. }),
  762. e.join("")
  763. }(),
  764. done: function () {
  765. n.on("checkbox(LAY_TABLE_TOOL_COLS)", function (e) {
  766. var l = t(e.elem)
  767. , n = this.checked
  768. , o = l.data("key")
  769. , r = l.data("parentkey");
  770. layui.each(a.cols, function (e, t) {
  771. layui.each(t, function (t, l) {
  772. if (e + "-" + t === o) {
  773. var d = l.hide;
  774. l.hide = !n,
  775. i.elem.find('*[data-key="' + a.index + "-" + o + '"]')[n ? "removeClass" : "addClass"](f),
  776. d != l.hide && i.setParentCol(!n, r),
  777. i.resize()
  778. }
  779. })
  780. })
  781. })
  782. }
  783. });
  784. break;
  785. case "LAYTABLE_EXPORT":
  786. r.ie ? l.tips("导出功能不支持 IE,请用 Chrome 等高级浏览器导出", this, {
  787. tips: 3
  788. }) : s({
  789. list: function () {
  790. return ['<li data-type="csv">导出到 Csv 文件</li>', '<li data-type="xls">导出到 Excel 文件</li>'].join("")
  791. }(),
  792. done: function (e, l) {
  793. l.on("click", function () {
  794. var e = t(this).data("type");
  795. d.exportFile.call(i, a.id, null, e)
  796. })
  797. }
  798. });
  799. break;
  800. case "LAYTABLE_PRINT":
  801. var u = window.open("打印窗口", "_blank")
  802. , h = ["<style>", "body{font-size: 12px; color: #666;}", "table{width: 100%; border-collapse: collapse; border-spacing: 0;}", "th,td{line-height: 20px; padding: 9px 15px; border: 1px solid #ccc; text-align: left; font-size: 12px; color: #666;}", "a{color: #666; text-decoration:none;}", "*.layui-hide{display: none}", "</style>"].join("")
  803. , v = t(i.layHeader.html());
  804. v.append(i.layMain.find("table").html()),
  805. v.append(i.layTotal.find("table").html()),
  806. v.find("th.layui-table-patch").remove(),
  807. v.find(".layui-table-col-special").remove(),
  808. u.document.write(h + v.prop("outerHTML")),
  809. u.document.close(),
  810. u.print(),
  811. u.close()
  812. }
  813. layui.event.call(this, y, "toolbar(" + p + ")", t.extend({
  814. event: c,
  815. config: a
  816. }, {}))
  817. }),
  818. s.on("mousemove", function (e) {
  819. var i = t(this)
  820. , a = i.offset().left
  821. , l = e.clientX - a;
  822. i.data("unresize") || c.resizeStart || (c.allowResize = i.width() - l <= 10,
  823. o.css("cursor", c.allowResize ? "col-resize" : ""))
  824. }).on("mouseleave", function () {
  825. t(this);
  826. c.resizeStart || o.css("cursor", "")
  827. }).on("mousedown", function (e) {
  828. var l = t(this);
  829. if (c.allowResize) {
  830. var n = l.data("key");
  831. e.preventDefault(),
  832. c.resizeStart = !0,
  833. c.offset = [e.clientX, e.clientY],
  834. i.getCssRule(n, function (e) {
  835. var t = e.style.width || l.outerWidth();
  836. c.rule = e,
  837. c.ruleWidth = parseFloat(t),
  838. c.minWidth = l.data("minwidth") || a.cellMinWidth
  839. })
  840. }
  841. }),
  842. j.on("mousemove", function (t) {
  843. if (c.resizeStart) {
  844. if (t.preventDefault(),
  845. c.rule) {
  846. var a = c.ruleWidth + t.clientX - c.offset[0];
  847. a < c.minWidth && (a = c.minWidth),
  848. c.rule.style.width = a + "px",
  849. l.close(i.tipsIndex)
  850. }
  851. e = 1
  852. }
  853. }).on("mouseup", function (t) {
  854. c.resizeStart && (c = {},
  855. o.css("cursor", ""),
  856. i.scrollPatch()),
  857. 2 === e && (e = null)
  858. }),
  859. s.on("click", function (a) {
  860. var l, n = t(this), o = n.find(S), r = o.attr("lay-sort");
  861. return o[0] && 1 !== e ? (l = "asc" === r ? "desc" : "desc" === r ? null : "asc",
  862. void i.sort(n, l, null, !0)) : e = 2
  863. }).find(S + " .layui-edge ").on("click", function (e) {
  864. var a = t(this)
  865. , l = a.index()
  866. , n = a.parents("th").eq(0).data("field");
  867. layui.stope(e),
  868. 0 === l ? i.sort(n, "asc", null, !0) : i.sort(n, "desc", null, !0)
  869. });
  870. var v = function (e) {
  871. var a = t(this)
  872. , l = a.parents("tr").eq(0).data("index")
  873. , n = i.layBody.find('tr[data-index="' + l + '"]')
  874. , o = d.cache[i.key] || [];
  875. return o = o[l] || {},
  876. t.extend({
  877. tr: n,
  878. data: d.clearCacheKey(o),
  879. del: function () {
  880. d.cache[i.key][l] = [],
  881. n.remove(),
  882. i.scrollPatch()
  883. },
  884. update: function (e) {
  885. e = e || {},
  886. layui.each(e, function (e, t) {
  887. if (e in o) {
  888. var a, l = n.children('td[data-field="' + e + '"]');
  889. o[e] = t,
  890. i.eachCols(function (t, i) {
  891. i.field == e && i.templet && (a = i.templet)
  892. }),
  893. l.children(h).html(u({
  894. templet: a
  895. }, t, o)),
  896. l.data("content", t)
  897. }
  898. })
  899. }
  900. }, e)
  901. };
  902. i.elem.on("click", 'input[name="layTableCheckbox"]+', function () {
  903. var e = t(this).prev()
  904. , a = i.layBody.find('input[name="layTableCheckbox"]')
  905. , l = e.parents("tr").eq(0).data("index")
  906. , n = e[0].checked
  907. , o = "layTableAllChoose" === e.attr("lay-filter");
  908. o ? (a.each(function (e, t) {
  909. t.checked = n,
  910. i.setCheckData(e, n)
  911. }),
  912. i.syncCheckAll(),
  913. i.renderForm("checkbox")) : (i.setCheckData(l, n),
  914. i.syncCheckAll()),
  915. layui.event.call(e[0], y, "checkbox(" + p + ")", v.call(e[0], {
  916. checked: n,
  917. type: o ? "all" : "one"
  918. }))
  919. }),
  920. i.elem.on("click", 'input[lay-type="layTableRadio"]+', function () {
  921. var e = t(this).prev()
  922. , a = e[0].checked
  923. , l = d.cache[i.key]
  924. , n = e.parents("tr").eq(0).data("index");
  925. layui.each(l, function (e, t) {
  926. n === e ? t.LAY_CHECKED = !0 : delete t.LAY_CHECKED
  927. }),
  928. i.setThisRowChecked(n),
  929. layui.event.call(this, y, "radio(" + p + ")", v.call(this, {
  930. checked: a
  931. }))
  932. }),
  933. i.layBody.on("mouseenter", "tr", function () {
  934. var e = t(this)
  935. , a = e.index();
  936. e.data("off") || i.layBody.find("tr:eq(" + a + ")").addClass(W)
  937. }).on("mouseleave", "tr", function () {
  938. var e = t(this)
  939. , a = e.index();
  940. e.data("off") || i.layBody.find("tr:eq(" + a + ")").removeClass(W)
  941. }).on("click", "tr", function () {
  942. m.call(this, "row")
  943. }).on("dblclick", "tr", function () {
  944. m.call(this, "rowDouble")
  945. });
  946. var m = function (e) {
  947. var i = t(this);
  948. i.data("off") || layui.event.call(this, y, e + "(" + p + ")", v.call(i.children("td")[0]))
  949. };
  950. i.layBody.on("change", "." + R, function () {
  951. var e = t(this)
  952. , a = this.value
  953. , l = e.parent().data("field")
  954. , n = e.parents("tr").eq(0).data("index")
  955. , o = d.cache[i.key][n];
  956. o[l] = a,
  957. layui.event.call(this, y, "edit(" + p + ")", v.call(this, {
  958. value: a,
  959. field: l
  960. }))
  961. }).on("blur", "." + R, function () {
  962. var e, a = t(this), l = this, n = a.parent().data("field"), o = a.parents("tr").eq(0).data("index"), r = d.cache[i.key][o];
  963. i.eachCols(function (t, i) {
  964. i.field == n && i.templet && (e = i.templet)
  965. }),
  966. a.siblings(h).html(function (t) {
  967. return u({
  968. templet: e
  969. }, t, r)
  970. }(l.value)),
  971. a.parent().data("content", l.value),
  972. a.remove()
  973. }),
  974. i.layBody.on("click", "td", function (e) {
  975. var i = t(this)
  976. , a = (i.data("field"),
  977. i.data("edit"))
  978. , l = i.children(h);
  979. if (!i.data("off") && a) {
  980. var n = t('<input class="layui-input ' + R + '">');
  981. return n[0].value = i.data("content") || l.text(),
  982. i.find("." + R)[0] || i.append(n),
  983. n.focus(),
  984. void layui.stope(e)
  985. }
  986. }).on("mouseenter", "td", function () {
  987. b.call(this)
  988. }).on("mouseleave", "td", function () {
  989. b.call(this, "hide")
  990. });
  991. var g = "layui-table-grid-down"
  992. , b = function (e) {
  993. var i = t(this)
  994. , a = i.children(h);
  995. if (!i.data("off"))
  996. if (e)
  997. i.find(".layui-table-grid-down").remove();
  998. else if (a.prop("scrollWidth") > a.outerWidth()) {
  999. if (a.find("." + g)[0])
  1000. return;
  1001. i.append('<div class="' + g + '"><i class="layui-icon layui-icon-down"></i></div>')
  1002. }
  1003. };
  1004. i.layBody.on("click", "." + g, function (e) {
  1005. var n = t(this)
  1006. , o = n.parent()
  1007. , d = o.children(h);
  1008. i.tipsIndex = l.tips(['<div class="layui-table-tips-main" style="margin-top: -' + (d.height() + 16) + "px;" + function () {
  1009. return "sm" === a.size ? "padding: 4px 15px; font-size: 12px;" : "lg" === a.size ? "padding: 14px 15px;" : ""
  1010. }() + '">', d.html(), "</div>", '<i class="layui-icon layui-table-tips-c layui-icon-close"></i>'].join(""), d[0], {
  1011. tips: [3, ""],
  1012. time: -1,
  1013. anim: -1,
  1014. maxWidth: r.ios || r.android ? 300 : i.elem.width() / 2,
  1015. isOutAnim: !1,
  1016. skin: "layui-table-tips",
  1017. success: function (e, t) {
  1018. e.find(".layui-table-tips-c").on("click", function () {
  1019. l.close(t)
  1020. })
  1021. }
  1022. }),
  1023. layui.stope(e)
  1024. }),
  1025. i.layBody.on("click", "*[lay-event]", function () {
  1026. var e = t(this)
  1027. , a = e.parents("tr").eq(0).data("index");
  1028. layui.event.call(this, y, "tool(" + p + ")", v.call(this, {
  1029. event: e.attr("lay-event")
  1030. })),
  1031. i.setThisRowChecked(a)
  1032. }),
  1033. i.layMain.on("scroll", function () {
  1034. var e = t(this)
  1035. , a = e.scrollLeft()
  1036. , n = e.scrollTop();
  1037. i.layHeader.scrollLeft(a),
  1038. i.layTotal.scrollLeft(a),
  1039. i.layFixed.find(k).scrollTop(n),
  1040. l.close(i.tipsIndex)
  1041. }),
  1042. H.on("resize", function () {
  1043. i.resize()
  1044. })
  1045. }
  1046. ,
  1047. function () {
  1048. j.on("click", function () {
  1049. j.trigger("table.remove.tool.panel")
  1050. }),
  1051. j.on("table.remove.tool.panel", function () {
  1052. t(".layui-table-tool-panel").remove()
  1053. })
  1054. }(),
  1055. d.init = function (e, i) {
  1056. i = i || {};
  1057. var a = this
  1058. , l = t(e ? 'table[lay-filter="' + e + '"]' : h + "[lay-data]")
  1059. , n = "Table element property lay-data configuration item has a syntax error: ";
  1060. return l.each(function () {
  1061. var a = t(this)
  1062. , l = a.attr("lay-data");
  1063. try {
  1064. l = new Function("return " + l)()
  1065. } catch (r) {
  1066. o.error(n + l)
  1067. }
  1068. var c = []
  1069. , s = t.extend({
  1070. elem: this,
  1071. cols: [],
  1072. data: [],
  1073. skin: a.attr("lay-skin"),
  1074. size: a.attr("lay-size"),
  1075. even: "string" == typeof a.attr("lay-even")
  1076. }, d.config, i, l);
  1077. e && a.hide(),
  1078. a.find("thead>tr").each(function (e) {
  1079. s.cols[e] = [],
  1080. t(this).children().each(function (i) {
  1081. var a = t(this)
  1082. , l = a.attr("lay-data");
  1083. try {
  1084. l = new Function("return " + l)()
  1085. } catch (r) {
  1086. return o.error(n + l)
  1087. }
  1088. var d = t.extend({
  1089. title: a.text(),
  1090. colspan: a.attr("colspan") || 0,
  1091. rowspan: a.attr("rowspan") || 0
  1092. }, l);
  1093. d.colspan < 2 && c.push(d),
  1094. s.cols[e].push(d)
  1095. })
  1096. }),
  1097. a.find("tbody>tr").each(function (e) {
  1098. var i = t(this)
  1099. , a = {};
  1100. i.children("td").each(function (e, i) {
  1101. var l = t(this)
  1102. , n = l.data("field");
  1103. if (n)
  1104. return a[n] = l.html()
  1105. }),
  1106. layui.each(c, function (e, t) {
  1107. var l = i.children("td").eq(e);
  1108. a[t.field] = l.html()
  1109. }),
  1110. s.data[e] = a
  1111. }),
  1112. d.render(s)
  1113. }),
  1114. a
  1115. }
  1116. ,
  1117. c.that = {},
  1118. c.config = {},
  1119. d.eachCols = function (e, i, a) {
  1120. var l = c.config[e] || {}
  1121. , n = []
  1122. , o = 0;
  1123. a = t.extend(!0, [], a || l.cols),
  1124. layui.each(a, function (e, t) {
  1125. layui.each(t, function (t, i) {
  1126. if (i.colGroup) {
  1127. var l = 0;
  1128. o++ ,
  1129. i.CHILD_COLS = [],
  1130. layui.each(a[e + 1], function (e, t) {
  1131. t.PARENT_COL_INDEX || l > 1 && l == i.colspan || (t.PARENT_COL_INDEX = o,
  1132. i.CHILD_COLS.push(t),
  1133. l += parseInt(t.colspan > 1 ? t.colspan : 1))
  1134. })
  1135. }
  1136. i.PARENT_COL_INDEX || n.push(i)
  1137. })
  1138. });
  1139. var r = function (e) {
  1140. layui.each(e || n, function (e, t) {
  1141. return t.CHILD_COLS ? r(t.CHILD_COLS) : void ("function" == typeof i && i(e, t))
  1142. })
  1143. };
  1144. r()
  1145. }
  1146. ,
  1147. d.checkStatus = function (e) {
  1148. var t = 0
  1149. , i = 0
  1150. , a = []
  1151. , l = d.cache[e] || [];
  1152. return layui.each(l, function (e, l) {
  1153. return l.constructor === Array ? void i++ : void (l[d.config.checkName] && (t++ ,
  1154. a.push(d.clearCacheKey(l))))
  1155. }),
  1156. {
  1157. data: a,
  1158. isAll: !!l.length && t === l.length - i
  1159. }
  1160. }
  1161. ,
  1162. d.exportFile = function (e, t, i) {
  1163. var a = this;
  1164. t = t || d.clearCacheKey(d.cache[e]),
  1165. i = i || "csv";
  1166. var l = c.config[e] || {}
  1167. , n = {
  1168. csv: "text/csv",
  1169. xls: "application/vnd.ms-excel"
  1170. }[i]
  1171. , s = document.createElement("a");
  1172. return r.ie ? o.error("IE_NOT_SUPPORT_EXPORTS") : (s.href = "data:" + n + ";charset=utf-8,\ufeff" + encodeURIComponent(function () {
  1173. var i = []
  1174. , l = []
  1175. , n = [];
  1176. return layui.each(t, function (t, a) {
  1177. var n = [];
  1178. "object" == typeof e ? (layui.each(e, function (e, a) {
  1179. 0 == t && i.push(a || "")
  1180. }),
  1181. layui.each(d.clearCacheKey(a), function (e, t) {
  1182. n.push('"' + (t || "") + '"')
  1183. })) : d.eachCols(e, function (e, l) {
  1184. if (l.field && "normal" == l.type && !l.hide) {
  1185. var o = a[l.field];
  1186. void 0 !== o && null !== o || (o = ""),
  1187. 0 == t && i.push(l.title || ""),
  1188. n.push('"' + u(l, o, a, "text") + '"')
  1189. }
  1190. }),
  1191. l.push(n.join(","))
  1192. }),
  1193. layui.each(a.dataTotal, function (e, t) {
  1194. n.push(t)
  1195. }),
  1196. i.join(",") + "\r\n" + l.join("\r\n") + "\r\n" + n.join(",")
  1197. }()),
  1198. s.download = (l.title || "table_" + (l.index || "")) + "." + i,
  1199. document.body.appendChild(s),
  1200. s.click(),
  1201. void document.body.removeChild(s))
  1202. }
  1203. ,
  1204. d.resize = function (e) {
  1205. if (e) {
  1206. var t = s(e);
  1207. if (!t)
  1208. return;
  1209. c.that[e].resize()
  1210. } else
  1211. layui.each(c.that, function () {
  1212. this.resize()
  1213. })
  1214. }
  1215. ,
  1216. d.reload = function (e, t) {
  1217. var i = s(e);
  1218. if (i) {
  1219. var a = c.that[e];
  1220. return a.reload(t),
  1221. c.call(a)
  1222. }
  1223. }
  1224. ,
  1225. d.render = function (e) {
  1226. var t = new F(e);
  1227. return c.call(t)
  1228. }
  1229. ,
  1230. d.clearCacheKey = function (e) {
  1231. return e = t.extend({}, e),
  1232. delete e[d.config.checkName],
  1233. delete e[d.config.indexName],
  1234. e
  1235. }
  1236. ,
  1237. d.init(),
  1238. e(y, d)
  1239. });