define(["jquery"],function(a){var b=a(".js-table"),c=a('tbody tr td:first-child [type="checkbox"]',b),d=b.closest("form"),e=d.find(".js-bar"),f=d.find(".js-batch");if(b.length>0){a(document).on("change",'.js-table thead th:first [type="checkbox"]',function(b){b&&b.preventDefault();var c=a(this).closest("table"),d=a(this).prop("checked");a('tbody tr td:first-child [type="checkbox"]',c).prop("checked",d),d?e.show():e.hide()}),a(document).on("change",'.js-table tbody td:first-child [type="checkbox"]',function(b){b&&b.preventDefault();var d=a(this).closest("table"),f=a(this).prop("checked"),g=a('tbody tr td:first-child [type="checkbox"]:checked',d);a('thead th:first [type="checkbox"]',d).prop("checked",f&&g.length==c.length),g.length>0?e.show():e.hide()});var g=function(){var c=a('tbody tr td:first-child [type="checkbox"]:checked',b);return selecteds=c.map(function(){return a(this).val()}).get(),selecteds};f.on("click",function(c){c.preventDefault();var d=a(this),e=d.attr("href")||d.data("href")||d.data("url"),f=d.val()||d.html(),h=d.val()?"input":"button";d.attr("disabled","disabled");var i=a('tbody tr td:first-child [type="checkbox"]:checked',b),j=g();if(j.length<=0)return Notify.info("请先选择要操作的数据"),d.removeAttr("disabled","disabled"),!1;var k=function(){"button"==h?d.html('<i class="fa fa-spinner fa-spin"></i> '+Notify.lang.processing):d.val(Notify.lang.processing),a.post(e,{id:j}).done(function(c){var c=a.parseJSON(c),e=c.message.errno,g=c.message.url,j=c.message.message;if(e)"button"==h?d.html(f):d.val(f),Notify.error(j||Notify.lang.error);else{if("remove"==d.data("batch")){var k=a.Deferred();a.when(function(b){var c=0;return i.parents("tr").fadeOut(function(){a(this).remove(),c++,i.length==c&&b.resolve()}),b}(k)).done(function(){a("table tbody tr",b).length||window.location.reload()})}else Notify.success(j||Notify.lang.success,g);"button"==h?d.html(f):d.val(f)}}).fail(function(){"button"==h?d.html(f):d.val(f),Notify.error(Notify.lang.exception)})};d.data("confirm")?Notify.confirm(d.data("confirm"),k,function(){d.removeAttr("disabled","disabled")}):k()}),a(document).on("click",".table-responsive .js-remove",function(c){c.preventDefault();var d=a(this),e=d.attr("href")||d.data("href")||d.data("url"),f=d.data("confirm"),g=function(){d.html('<i class="fa fa-spinner fa-spin"></i> '+Notify.lang.processing),a.post(e).done(function(c){var c=a.parseJSON(c),e=c.message.errno,f=c.message.url,g=c.message.message;if(e)d.button("reset"),Notify.error(g||Notify.lang.error,f);else{var h=d.parents("tr");h.fadeOut(function(){h.remove(),0==b.find(".js-remove").length&&window.location.reload()})}}).fail(function(){d.button("reset"),Notify.error(Notify.lang.exception)})};f?Notify.confirm(f,g,function(){d.removeAttr("disabled","disabled")}):g()}),a("#page-loading").remove()}});