!function(p){p.tree={},p.extend(p.tree,{_check_box_cascade:function(e,n,t){var r=e.check.chkboxType[n];-1===r.indexOf(t)&&(r=t+r),e.check.chkboxType[n]=r},getZTreeSetting:function(e){var n="sync",t=null,r=!1,c=!1;"object"==typeof e&&(e.hasOwnProperty("mode")&&(n=e.mode),e.hasOwnProperty("checkStyle")&&(t=e.checkStyle),e.hasOwnProperty("parentCascade")&&(r=e.parentCascade),e.hasOwnProperty("childrenCascade")&&(c=e.childrenCascade));var a={};return"sync"===n&&(a={data:{simpleData:{enable:!0,idKey:"id",pIdKey:"pid",rootPId:0}}}),"object"==typeof e&&e.hasOwnProperty("setting")&&(a=p.extend(a,e.setting)),t&&(a.check={enable:!0,chkStyle:"checkbox",chkboxType:{Y:"",N:""}},r&&(p.tree._check_box_cascade(a,"Y","p"),p.tree._check_box_cascade(a,"N","p")),c&&(p.tree._check_box_cascade(a,"Y","s"),p.tree._check_box_cascade(a,"N","s"))),a},all_leaf_nodes_filter_generator:function(n){return void 0===n&&(n=!0),function(e){return!e.isParent&&n}},checked_leaf_nodes_filter_generator:function(){return function(e){return!e.isParent&&e.checked}},clickHandlerWrap:function(c){return function(e,n,t){var r=p.fn.zTree.getZTreeObj(n);!0===r.setting.check.enable&&(r.checkNode(t,!t.checked,!0),p.tree.sync_to_select_field(c,r,t))}},checkHandlerWrap:function(c){return function(e,n,t){var r=p.fn.zTree.getZTreeObj(n);p.tree.sync_to_select_field(c,r,t)}},sync_to_select_field:function(n,e,t){if(t.isParent){var r=e.getNodesByFilter(p.tree.all_leaf_nodes_filter_generator(),!1,t);r.push(t),r.forEach(function(e){n.children(interject("option[value={}]",[e.id])).prop("selected",t.checked)})}else n.children(interject("option[value={}]",[t.id])).prop("selected",t.checked)},autoLoadNode:function(d,s){return function(e,n,t,r){if(null!==r&&"null"!==r||s.parent().show(),!(t&&t.level>=d-1)){var c,a,o,l=p.fn.zTree.getZTreeObj(n),i=t?t.children:l.getNodes();for(c=0,a=i.length;c<a;c++)(o=i[c]).isParent&&l.reAsyncChildNodes(o,"refresh",!0)}}},nodeFuzzySearch:function(e,n,t){var i=!0,d=!1,s=!1,r=null,f=/\s*(\(\d+\/\d+\))$/;t&&(i=!!t.highlight,d=!!t.expand,s=!!t.percent,r=t.callback);var a=p.fn.zTree.getZTreeObj(e);a||layer.alert("Fail to get ztree object");var h=a.setting.data.key.name;a.setting.view.nameIsHTML=i;var u=new RegExp("[\\[\\]\\\\^\\$\\.\\|\\?\\*\\+\\(\\)]","gi");function c(o,l){l=l||"",function(e,n){var c=[];if(e&&0<e.length)if(0<n.length)p.each(e,function(e,n){var t=n.getPath();if(t&&0<t.length)for(var r=0;r<t.length-1;r++)c.push(t[r]),a.showNode(t[r]),a.expandNode(t[r],!0);n&&c.push(n)});else{var t=a.getNodesByParam("level","0");p.each(t,function(e,n){a.expandNode(n,!0)})}void 0!==r&&"function"==typeof r&&r(c)}(o.getNodesByFilter(function(e){e&&e.oldname&&0<e.oldname.length&&(e[h]=e.oldname);var n=e[h],t="";if(s&&e.isParent&&n){var r=f.exec(n);r&&(t=r[0],n=n.replace(f,""))}if(o.updateNode(e),0===l.length)return o.showNode(e),o.expandNode(e,d),!0;if(n&&-1!==n.toLowerCase().indexOf(l.toLowerCase())){if(i){var c=l.replace(u,function(e){return"\\"+e});e.oldname=n+t;var a=new RegExp(c,"gi");e[h]=n.replace(a,function(e){return'<span style="color: #fff;background-color: #5fb878;">'+e+"</span>"})+t,o.updateNode(e)}return o.showNode(e),!0}return o.hideNode(e),!1}),l)}p(n).bind("input propertychange change",function(){!function(e){o&&clearTimeout(o);o=setTimeout(function(){c(a,e),p(n).focus()},500)}(p(this).val())});var o=null},fixCheckState:function(e,n){var t,r,c,a,o,l,i=null,d=0;i="string"==typeof e?p.fn.zTree.getZTreeObj(e):e,n&&(a=n.all,o=n.checked,l=n.include_parent),a=a||p.tree.all_leaf_nodes_filter_generator(),o=o||p.tree.checked_leaf_nodes_filter_generator(),l=!!l;for(var s=(t=i.getNodesByParam("isParent",!0)).length-1;0<=s;s--){r=t[s];var f=i.getNodesByFilter(o,!1,r);r.children||(d=0),d=i.getNodesByFilter(a,!1,r).length,c=f.length,r.srcName||(r.srcName=r.name),l&&(d+=1,r.checked&&(c+=1)),r.name=interpolate("%(source_name)s (%(checked)s/%(all)s)",{source_name:r.srcName,checked:c,all:d}),i.updateNode(r)}}})}(jQuery);