Files
jiapu/dist/public/js/lay-module/openTable/openTable.js
T

2 lines
3.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
layui.define(["form","table"],function(w){var i=layui.$,v=layui.table,R=layui.form,D=1,O="openTable",J=".layui-openTable",C="on",m="off",d={index:layui.openTable?layui.openTable.index+1e4:0,set:function(o){var e=this;return e.config=i.extend({},e.config,o),e},on:function(o,e){return layui.onevent.call(this,O,o,e)}},E=function(){var o=this,e=o.config,f=e.id||e.index;return{reload:function(c){o.reload.call(o,c)},config:e}},u=function(o){var e=this;e.index=++d.index,e.config=i.extend({},e.config,d.config,o),e.render()};u.prototype.config={openType:0},u.prototype.render=function(){var o=this,e=o.config,f=e.cols[0],c=e.openCols||[],y=e.done;delete e.done,f.splice(0,0,{align:"left",width:50,templet:function(n){return"<i class='openTable-i-table-open ' status='off' data='"+JSON.stringify(n)+"' title='展开'></i>"}}),v.render(i.extend({done:function(n,b,T){g(),y&&y(n,b,T)}},e));function g(){i(".openTable-i-table-open").parent().unbind().click(function(){var n=i(this).children();if(e.openType===0){var b=i(".openTable-open-dow").attr("status"),T=n.attr("data")===i(".openTable-open-dow").attr("data");if(i(".openTable-open-dow").addClass("openTable-open-up").removeClass("openTable-open-dow").attr("status",m),b===C&&T){i(".openTable-open-td").slideUp(100,function(){i(".openTable-open-td").remove()});return}else n.attr("status",m),i(".openTable-open-td").remove()}var N=this,s=JSON.parse(n.attr("data")),S=n.attr("status")==="on";if(S){n.removeClass("openTable-open-dow"),n.attr("status","off"),this.addTR.find("div").slideUp(100,function(){N.addTR.remove()});return}var p=["<div style='margin-left: 50px;display: none'>"];c.forEach(function(t,h){if(t.templet)p.push("<div class='openTable-open-item-div'>"),p.push(t.templet(s)),p.push("</div>");else if(t.type&&t.type==="select"){var l=["<div id='"+t.field+"' class='openTable-open-item-div' >"];l.push("<span style='color: #99a9bf'>"+t.title+"</span>"),l.push("<div class='layui-input-inline'><select lay-filter='"+t.field+"'>"),t.items.forEach(function(a){a=t.onDraw(a,s),l.push("<option value='"+a.id+"' "),l.push(a.isSelect?" selected='selected' ":""),l.push(" >"+a.value+"</option>")}),l.push("</select></div>"),l.push("</div>"),p.push(l.join("")),setTimeout(function(){layui.form.render(),layui.form.on("select("+t.field+")",function(a){if(e.edit&&t.onSelect(a,s)){var r={};r.value=a.value,r.field=t.field,s[t.field]=a.value,r.data=JSON.parse(JSON.stringify(s)),e.edit(r)}})},20)}else p.push("<div class='openTable-open-item-div'>"),p.push("<span class='openTable-item-title'>"+t.title+"</span>"),p.push(t.edit?"<input class='openTable-exp-value openTable-exp-value-edit' autocomplete='off' name='"+t.field+"' value='"+s[t.field]+"'/>":"<span class='openTable-exp-value' >"+s[t.field]+"</span>"),p.push("</div>")}),n.addClass("openTable-open-dow"),this.addTR=i(["<tr><td class='openTable-open-td' colspan='"+(f.length+1)+"'>",p.join("")+"</div>","</td></tr>"].join("")),n.parent().parent().parent().after(this.addTR),this.addTR.find("div").slideDown(200),n.attr("status","on"),i(".openTable-exp-value-edit").blur(function(){var t=i(this),h=t.attr("name"),l=t.val();if(e.edit&&s[h]+""!==l){var a={};a.value=t.val(),a.field=t.attr("name"),s[h]=l,a.data=s,e.edit(a)}}).keypress(function(t){t.which===13&&i(this).blur()})})}var x=i(e.elem).attr("lay-filter");v.on("sort("+x+")",function(n){e.sort&&e.sort(n),g()}),layui.table.on("edit("+x+")",function(n){e.edit&&e.edit(n)})},d.render=function(o){var e=new u(o);return E.call(e)},layui.link(layui.cache.base+"openTable/openTable.css?v="+new Date().getTime(),function(){},"openTable"),w("openTable",d)});