App.select2={i18n:{TAG_INPUT:"请输入或选择，如有多个用逗号隔开",TAG_SELECT:"请输入关键词后从搜索列表中选择",SELECT:"请选择"},tags:function(r,i,e,t,a,n){if(i==null){i=$(r).data("tags")||[]}else if(typeof i=="object"&&!$.isArray(i)&&e==null){e=i}if(e==null)e=$(r).data("url");if(t==null)t=$(r).data("sortable")||false;if(a==null)a=$(r).data("onlyselect")||false;var l=$(r).data("single")||false;var s=$(r).data("map");if(l)l=App.parseBool(l);var u={multiple:!l,width:"100%",minimumInputLength:0,tokenSeparators:[",","，"]};if(a){u.placeholder=App.select2.i18n.TAG_SELECT;u.data=i;u.tags=true}else{u.placeholder=App.select2.i18n.TAG_INPUT;u.tags=i}var f=$(r).data("listkey")||"list";var o=null,p=null;if(e){switch(typeof e){case"string":o=App.select2.buildQueryFunction(e,{},f,s);break;default:if($.isArray(e)){var c=e.length>2?e[2]:f;o=App.select2.buildQueryFunction(e[0],e.length>1?e[1]:{},c,s);break}p=e;break}}if(!a){u.tags=function(e){var t="",a="";var n=1;if(e){t=e.term;n=e.page}else{a=$(r).val()}var l=function(e){i=e.results};if(o){o({term:t,callback:l,value:a})}else if(p){if(typeof p.data=="undefined"||p.data==null)p.data=function(e,t){return{q:e,page:t}};if(typeof p.results=="undefined"||p.results==null)p.results=function(e,t){var a=typeof e.Data[f]!="undefined"?e.Data.resp.Data[f]:e.Data.listData;var n=typeof e.Data.pagination!="undefined"?e.Data.pagination.pages:0;return App.select2.buildResults(t,n,a,s)};$.ajax(p.url,{dataType:p.dataType||"json",data:p.data(t,n),async:false}).done(function(e){if(e.Code!=1){App.message({title:App.i18n.SYS_INFO,text:e.Info,type:"error"},false);return{results:[],more:false}}var t=p.results(e,n);l(t)})}return i}}else{if(o)u.query=o;else if(p)u.ajax=p}if(n)u=$.extend(u,n);var d=$(r).select2(u);$(r).data("select2",d);var v=$(r).data("init");if(v)$(r).val(v.split(",")).trigger("change");if(!t)return;$(r).on("change",function(){var e;if(typeof r=="string"&&r.indexOf("#")===0){e=r+"_val"}else{e=$(r).attr("id")+"_val"}$(e).html($(r).val())});$(r).select2("container").find("ul.select2-choices").sortable({containment:"parent",start:function(){$(r).select2("onSortStart")},update:function(){$(r).select2("onSortEnd")}})},select:function(e,t){var a={placeholder:App.select2.i18n.SELECT,width:"100%",minimumInputLength:0};t=$.extend({},a,t||{});var n=$(e).select2(t);$(e).data("select2",n)},update:function(e,t){$(e).select2("data",t)},enable:function(e,t){$(e).prop("disabled",!t)},readonly:function(e,t){$(e).prop("disabled",t)},clear:function(e){$(e).val(null).trigger("change")},buildQueryFunction:function(e,t,s,u){if(s==null)s="list";return function(i){if($.isFunction(t))t=t.call(this,arguments);t.q=i.term;t.value=i.value;t.select2=1;$.ajax(e,{dataType:"json",data:t,async:false}).done(function(e){if(e.Code!=1){App.message({title:App.i18n.SYS_INFO,text:e.Info,type:"error"},false);return}var t={results:[]};if(e.Data[s]==null)return i.callback(t);if(u){for(var a=0;a<e.Data[s].length;a++){var n=e.Data[s][a],l={};for(var r in u){l[r]=n[u[r]]}t.results.push(l)}}else{t.results=e.Data[s]}return i.callback(t)})}},buildResults:function(e,t,a,n){var l=e<t;var r={results:[],more:l};if(a==null)return r;if(n){for(var i=0;i<a.length;i++){var s=a[i],u={};for(var f in n){u[f]=s[n[f]]}r.results.push(u)}}else{r.results=a}return r},buildAjaxOptions:function(e,a,n,l){if(n==null)n="list";var t={url:"",dataType:"json",quietMillis:250,data:function(e,t){if($.isFunction(a))a=a.call(this,arguments);return $.extend({},{q:e,page:t,select2:1},a||{})},results:function(e,t){if(e.Code!=1){App.message({title:App.i18n.SYS_INFO,text:res.Info,type:"error"},false);return{results:[],more:false}}var a=typeof e.Data.pagination!="undefined"?e.Data.pagination.pages:0;return App.select2.buildResults(t,a,e.Data[n],l)}};return $.extend({},t,e||{})},buildOriginalResults:function(e,t,a){if(!a.term)return{results:e};var n=false;for(var l=0;l<e.length;l++){if(e[l].text==a.term){n=true;break}}if(!n)e.push({id:a.term,text:a.term})}};