;
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,
o = layui.hint(),
r = 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",
h = "layui-hide",
f = "layui-none",
y = "layui-table-view",
p = ".layui-table-header",
m = ".layui-table-body",
v = ".layui-table-main",
g = ".layui-table-fixed",
x = ".layui-table-fixed-l",
b = ".layui-table-fixed-r",
k = ".layui-table-tool",
C = ".layui-table-page",
w = ".layui-table-sort",
N = "layui-table-edit",
F = "layui-table-hover",
W = function(e) {
var t = '{{#if(item2.colspan){}} colspan="{{item2.colspan}}"{{#} if(item2.rowspan){}} rowspan="{{item2.rowspan}}"{{#}}}';
return e = e || {},
['
")) : (v(), void(s.page && (s.page = t.extend({
elem: "layui-table-page" + s.index,
count: o,
limit: s.limit,
limits: s.limits || [10, 20, 30, 40, 50, 60, 70, 80, 90],
groups: 3,
layout: ["prev", "page", "next", "skip", "count", "limit"],
prev: '',
next: '',
jump: function(e, t) {
t || (c.page = e.curr, s.limit = e.limit, c.pullData(e.curr, c.loading()))
}
},
s.page), s.page.count = o, a.render(s.page))))
},
S.prototype.getColElem = function(e, t) {
var i = this,
a = i.config;
return e.eq(0).find(".laytable-cell-" + (a.index + "-" + t) + ":eq(0)")
},
S.prototype.renderForm = function(e) {
n.render(e, "LAY-table-" + this.index)
},
S.prototype.sort = function(e, i, a, l) {
var n, r, c = this,
u = {},
h = c.config,
f = h.elem.attr("lay-filter"),
y = d.cache[c.key];
"string" == typeof e && c.layHeader.find("th").each(function(i, a) {
var l = t(this),
o = l.data("field");
if (o === e) return e = l,
n = o,
!1
});
try {
var n = n || e.data("field");
if (c.sortKey && !a && n === c.sortKey.field && i === c.sortKey.sort) return;
var p = c.layHeader.find("th .laytable-cell-" + h.index + "-" + n).find(w);
c.layHeader.find("th").find(w).removeAttr("lay-sort"),
p.attr("lay-sort", i || null),
c.layFixed.find("th")
} catch(m) {
return o.error("Table modules: Did not match to field")
}
c.sortKey = {
field: n,
sort: i
},
"asc" === i ? r = layui.sort(y, n) : "desc" === i ? r = layui.sort(y, n, !0) : (r = layui.sort(y, d.config.indexName), delete c.sortKey),
u[h.response.dataName] = r,
c.renderData(u, c.page, c.count, !0),
l && layui.event.call(e, s, "sort(" + f + ")", {
field: n,
type: i
})
},
S.prototype.loading = function() {
var e = this,
t = e.config;
if (t.loading && t.url) return l.msg("数据请求中", {
icon: 16,
offset: [e.elem.offset().top + e.elem.height() / 2 - 35 - T.scrollTop() + "px", e.elem.offset().left + e.elem.width() / 2 - 90 - T.scrollLeft() + "px"],
time: -1,
anim: -1,
fixed: !1
})
},
S.prototype.setCheckData = function(e, t) {
var i = this,
a = i.config,
l = d.cache[i.key];
l[e] && l[e].constructor !== Array && (l[e][a.checkName] = t)
},
S.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) {
"checkbox" === a.type && (a[t.checkName] = i)
}),
i
};
i[0] && (d.checkStatus(e.key).isAll ? (i[0].checked || (i.prop("checked", !0), e.renderForm("checkbox")), a(!0)) : (i[0].checked && (i.prop("checked", !1), e.renderForm("checkbox")), a(!1)))
},
S.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
})
},
S.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.toolbar && (e -= t.layTool.outerHeight()),
i.page && (e = e - t.layPage.outerHeight() - 1),
t.layMain.css("height", e)
},
S.prototype.getScrollWidth = function(e) {
var t = 0;
return e ? t = e.offsetWidth - e.clientWidth: (e = document.createElement("div"), e.style.width = "100px", e.style.height = "100px", e.style.overflowY = "scroll", document.body.appendChild(e), t = e.offsetWidth - e.clientWidth, document.body.removeChild(e)),
t
},
S.prototype.scrollPatch = function() {
var e = this,
i = e.layMain.children("table"),
a = e.layMain.width() - e.layMain.prop("clientWidth"),
l = e.layMain.height() - e.layMain.prop("clientHeight"),
n = e.getScrollWidth(e.layMain[0]),
o = i.outerWidth() - e.layMain.width();
if (e.autoColNums && o < 5 && !e.scrollPatchWStatus) {
var r = e.layHeader.eq(0).find("thead th:last-child"),
d = r.data("field");
e.getCssRule(d,
function(t) {
var i = t.style.width || r.outerWidth();
t.style.width = parseFloat(i) - n - o + "px",
e.layMain.height() - e.layMain.prop("clientHeight") > 0 && (t.style.width = parseFloat(t.style.width) - 1 + "px"),
e.scrollPatchWStatus = !0
})
}
if (a && l) {
if (!e.elem.find(".layui-table-patch")[0]) {
var c = t('
');
c.find("div").css({
width: a
}),
e.layHeader.eq(0).find("thead tr").append(c)
}
} else e.layHeader.eq(0).find(".layui-table-patch").remove();
var s = e.layMain.height(),
u = s - l;
e.layFixed.find(m).css("height", i.height() > u ? u: "auto"),
e.layFixRight[o > 0 ? "removeClass": "addClass"](h),
e.layFixRight.css("right", a - 1)
},
S.prototype.events = function() {
var e, a = this,
n = a.config,
o = t("body"),
c = {},
u = a.layHeader.find("th"),
h = ".layui-table-cell",
f = 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.data("unresize") || c.resizeStart || (c.allowResize = i.width() - l <= 10, o.css("cursor", c.allowResize ? "col-resize": ""))
}).on("mouseleave",
function() {
t(this);
c.resizeStart || o.css("cursor", "")
}).on("mousedown",
function(e) {
var i = t(this);
if (c.allowResize) {
var l = i.data("field");
e.preventDefault(),
c.resizeStart = !0,
c.offset = [e.clientX, e.clientY],
a.getCssRule(l,
function(e) {
var t = e.style.width || i.outerWidth();
c.rule = e,
c.ruleWidth = parseFloat(t),
c.minWidth = i.data("minwidth") || n.cellMinWidth
})
}
}),
M.on("mousemove",
function(t) {
if (c.resizeStart) {
if (t.preventDefault(), c.rule) {
var i = c.ruleWidth + t.clientX - c.offset[0];
i < c.minWidth && (i = c.minWidth),
c.rule.style.width = i + "px",
l.close(a.tipsIndex)
}
e = 1
}
}).on("mouseup",
function(t) {
c.resizeStart && (c = {},
o.css("cursor", ""), a.scrollPatch()),
2 === e && (e = null)
}),
u.on("click",
function() {
var i, l = t(this),
n = l.find(w),
o = n.attr("lay-sort");
return n[0] && 1 !== e ? (i = "asc" === o ? "desc": "desc" === o ? null: "asc", void a.sort(l, i, null, !0)) : e = 2
}).find(w + " .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", null, !0) : a.sort(n, "desc", null, !0)
}),
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,
o = "layTableAllChoose" === e.attr("lay-filter");
o ? (i.each(function(e, t) {
t.checked = n,
a.setCheckData(e, n)
}), a.syncCheckAll(), a.renderForm("checkbox")) : (a.setCheckData(l, n), a.syncCheckAll()),
layui.event.call(this, s, "checkbox(" + f + ")", {
checked: n,
data: d.cache[a.key] ? d.cache[a.key][l] || {}: {},
type: o ? "all": "one"
})
}),
a.layBody.on("mouseenter", "tr",
function() {
var e = t(this),
i = e.index();
a.layBody.find("tr:eq(" + i + ")").addClass(F)
}).on("mouseleave", "tr",
function() {
var e = t(this),
i = e.index();
a.layBody.find("tr:eq(" + i + ")").removeClass(F)
}),
a.layBody.on("change", "." + N,
function() {
var e = t(this),
i = this.value,
l = e.parent().data("field"),
n = e.parents("tr").eq(0).data("index"),
o = d.cache[a.key][n];
o[l] = i,
layui.event.call(this, s, "edit(" + f + ")", {
value: i,
data: o,
field: l
})
}).on("blur", "." + N,
function() {
var e, l = t(this),
n = l.parent().data("field"),
o = l.parents("tr").eq(0).data("index"),
r = d.cache[a.key][o];
a.eachCols(function(t, i) {
i.field == n && i.templet && (e = i.templet)
}),
l.siblings(h).html(e ? i(t(e).html() || this.value).render(r) : 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.data("edit")),
o = e.children(h);
if (l.close(a.tipsIndex), !e.data("off")) if (i) if ("select" === i);
else {
var d = t('');
d[0].value = e.data("content") || o.text(),
e.find("." + N)[0] || e.append(d),
d.focus()
} else o.find(".layui-form-switch,.layui-form-checkbox")[0] || Math.round(o.prop("scrollWidth")) > Math.round(o.outerWidth()) && (a.tipsIndex = l.tips(['
', o.html(), "
", 'ဆ'].join(""), o[0], {
tips: [3, ""],
time: -1,
anim: -1,
maxWidth: r.ios || r.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 + '"]'),
o = "layui-table-click",
r = d.cache[a.key][l];
layui.event.call(this, s, "tool(" + f + ")", {
data: d.clearCacheKey(r),
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 r) {
var o, d = n.children('td[data-field="' + e + '"]');
r[e] = l,
a.eachCols(function(t, i) {
i.field == e && i.templet && (o = i.templet)
}),
d.children(h).html(o ? i(t(o).html() || l).render(r) : l),
d.data("content", l)
}
})
}
}),
n.addClass(o).siblings("tr").removeClass(o)
}),
a.layMain.on("scroll",
function() {
var e = t(this),
i = e.scrollLeft(),
n = e.scrollTop();
a.layHeader.scrollLeft(i),
a.layFixed.find(m).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(r) {
o.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(r) {
return o.error(n + l)
}
var d = t.extend({
title: a.text(),
colspan: a.attr("colspan") || 0,
rowspan: a.attr("rowspan") || 0
},
l);
d.colspan < 2 && 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 = 0,
a = [],
l = d.cache[e] || [];
return layui.each(l,
function(e, l) {
return l.constructor === Array ? void i++:void(l[d.config.checkName] && (t++, a.push(d.clearCacheKey(l))))
}),
{
data: a,
isAll: !!l.length && t === l.length - i
}
},
c.config = {},
d.reload = function(e, i) {
var a = c.config[e];
return i = i || {},
a ? (i.data && i.data.constructor === Array && delete a.data, d.render(t.extend(!0, {},
a, i))) : o.error("The ID option was not found in the table instance")
},
d.render = function(e) {
var t = new S(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)
});