/**
 * 数据列表组件
 * date:2020-02-08   License By http://easyweb.vip
 */
layui.define(["laytpl","laypage"],function(E){var d=layui.jquery,v=layui.laytpl,F=layui.laypage,x={},y={},r={render:function(a){function b(a){function b(a){if(c){A();var b=d("#"+c.elem);b.click(function(){d(this).hasClass("ew-loading")||(c.first?c.first=!1:c.curr++,h(1),a({page:c.curr,limit:c.limit},function(a){0==a.code?(a.data.length<c.limit?h(2):h(0),1==c.curr&&(l.html(""),m=[]),e(a.data,(c.curr-1)*c.limit,!0),f&&f(a.data,c.curr,a.count)):h(3)}))});b.trigger("click")}else g?a({page:1,limit:g.limit},
function(b){0==b.code&&(g.count=b.count,g.jump=function(b,c){c||a({page:b.curr,limit:b.limit},function(a){0==a.code&&(e(a.data,(b.curr-1)*b.limit),f&&f(a.data,b.curr,b.count))})},B(),e(b.data),f&&f(b.data,1,b.count))}):a({page:1},function(a){0==a.code&&(e(a.data),f&&f(a.data,1,a.count))})}function B(){g.elem="ew-datagrid-page-"+q.substring(1);l.after('<div class="ew-datagrid-page '+g.class+'" id="'+g.elem+'"></div>');F.render(g)}function A(){c.elem="ew-datagrid-page-"+q.substring(1);l.after('<div id="'+
c.elem+'" class="ew-datagrid-loadmore '+c.class+'"><div><span class="ew-icon-loading"><i class="layui-icon layui-icon-loading-1 layui-anim layui-anim-rotate layui-anim-loop"></i></span><span class="ew-loadmore-text">'+c.text+"</span></div></div>")}function h(a){var b=d("#"+c.elem),g=b.find(".ew-loadmore-text");b.removeClass("ew-loading");0==a?g.html(c.text):1==a?(g.html(c.loadingText),b.addClass("ew-loading")):2==a?g.html(c.noMoreText):g.html(c.errorText)}var k=a.data,z=a.reqData,g=a.page,c=a.loadMore,
p=a.parseData,n=a.where,t=a.headers,u=a.method,v=a.request;c&&(c="object"==typeof c?d.extend(w,c):w);g&&(g="object"==typeof g?d.extend(C,g):C);l.html("");d(q+"+.ew-datagrid-loadmore").remove();d(q+"+.ew-datagrid-page").remove();k?"string"==typeof k?b(function(a,b){l.addClass("ew-datagrid-loading");var c=r.deepClone(n);c[v.pageName]=a.page;c[v.limitName]=a.limit;var g={url:k,data:c,headers:t,type:u,dataType:"json",success:function(a,c,g){l.removeClass("ew-datagrid-loading");p&&(a=p(a));b(a)},error:function(a){g.success({code:a.status,
msg:a.statusText})}};d.ajax(g)}):c?(A(),h(2),e(k),f&&f(k,1,k.length)):g?(g.count=k.length,g.jump=function(a,b){var c=(a.curr-1)*g.limit;b=c+g.limit;b>k.length&&(b=k.length);for(var d=[];c<b;c++)d.push(k[c]);e(d,(a.curr-1)*a.limit);f&&f(d,a.curr,a.count)},B()):(e(k),f&&f(k,1,k.length)):z&&b(z)}function e(a,b,e){void 0==b&&(b=0);void 0==e&&(e=!1);for(var f="",h=0;h<a.length;h++){var k=a[h];k.LAY_INDEX=h;k.LAY_NUMBER=h+b+1;v(d(D).html()).render(k,function(a){f+=a})}if(e){for(h=0;h<a.length;h++)m.push(a[h]);
l.append(f)}else m=a,l.html(f);p()}function p(){l.children().each(function(a){var b=d(this);b.attr("data-index",a);b.addClass("ew-datagrid-item")})}var w={class:"",first:!0,curr:1,limit:10,text:"\u52a0\u8f7d\u66f4\u591a",loadingText:"\u52a0\u8f7d\u4e2d...",noMoreText:"\u6ca1\u6709\u66f4\u591a\u6570\u636e\u4e86~",errorText:"\u52a0\u8f7d\u5931\u8d25\uff0c\u8bf7\u91cd\u8bd5"},C={class:"",limit:10,layout:"prev page next skip count limit".split(" ")},n=d.extend({page:!1,loadMore:!1,where:{},headers:{},
method:"GET",request:{pageName:"page",limitName:"limit"}},a),q=n.elem,D=n.templet,f=n.done,t=n.onItemClick,u=n.onToolBarClick,l=d(q),m=[];"static"==l.css("position")&&l.css("position","relative");b(n);(function(){function a(a,b,e,h,k,f){return{data:a,index:b,elem:e,event:h,e:k,del:function(){f.remove();m.splice(b,1);p()},update:function(a){a.LAY_INDEX=m[b].LAY_INDEX;a.LAY_NUMBER=m[b].LAY_NUMBER;m[b]=a;v(d(D).html()).render(a,function(a){f.before(a);f.remove();p()})}}}l.off("click.dgItem").on("click.dgItem",
">.ew-datagrid-item",function(b){var e=d(this),f=e.data("index");t||(t=x[q.substring(1)]);t&&t(a(m[f],f,b.currentTarget,void 0,b,e))});l.off("click.dgToolBar").on("click.dgToolBar","[lay-event]",function(b){b.stopPropagation();var e=d(this).parentsUntil(".ew-datagrid-item").parent(),f=e.data("index"),h=d(this).attr("lay-event");u||(u=y[q.substring(1)]);u&&u(a(m[f],f,b.currentTarget,h,b,e))})})();return{data:m,reload:function(a){b(d.extend(n,a))}}},onItemClick:function(a,b){x[a]=b},onToolBarClick:function(a,
b){y[a]=b},deepClone:function(a){var b=r.isClass(a);if("Object"===b)b={};else if("Array"===b)b=[];else return a;for(var e in a){var d=a[e];"Object"==r.isClass(d)?b[e]=arguments.callee(d):"Array"==r.isClass(d)?b[e]=arguments.callee(d):b[e]=a[e]}return b},isClass:function(a){return null===a?"Null":void 0===a?"Undefined":Object.prototype.toString.call(a).slice(8,-1)},autoRender:function(){d("[data-grid]").each(function(){var a=d(this),b=a.attr("id");b||(b="ew-datagrid-"+d('[id^="ew-datagrid-"]').length+
1,a.attr("id",b));var e=a.children("[data-grid-tpl]");if(0<e.length){e.attr("id",b+"-tpl");a.after(e[0].outerHTML);e.remove();a=d(this).attr("lay-data");if(a)try{var p=(new Function("return "+a))()}catch(w){console.error("element property data- configuration item has a syntax error: "+a)}a=p;a.elem="#"+b;a.templet="#"+b+"-tpl";r.render(a)}})}};r.autoRender();d("head").append('<style id="ew-css-datagrid">.ew-datagrid-loadmore, .ew-datagrid-page {    text-align: center;}.ew-datagrid-loadmore {    color: #666;    cursor: pointer;}.ew-datagrid-loadmore > div {    padding: 12px;}.ew-datagrid-loadmore > div:hover {    background-color: rgba(0, 0, 0, .03);}.ew-datagrid-loadmore .ew-icon-loading {    margin-right: 6px;    display: none;}.ew-datagrid-loadmore.ew-loading .ew-icon-loading {    display: inline;}.ew-datagrid-loading:before {    content: "\\e63d";    font-family: layui-icon !important;    font-size: 32px;    color: #C3C3C3;    position: absolute;    left: 50%;    margin-left: -16px;    margin-top: -16px;    z-index: 999;    -webkit-animatione: layui-rotate 1s linear;    animation: layui-rotate 1s linear;    -webkit-animation-iteration-count: infinite;    animation-iteration-count: infinite;}</style>');
E("dataGrid",r)});