formselects.js 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830
  1. 'use strict';
  2. var surl = '';
  3. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  4. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  5. /**
  6. * name: formSelects
  7. * 基于Layui Select多选
  8. * version: 4.0.0.0910
  9. * http://sun.faysunshine.com/layui/formSelects-v4/dist/formSelects-v4.js
  10. */
  11. (function (layui, window, factory) {
  12. if ((typeof exports === 'undefined' ? 'undefined' : _typeof(exports)) === 'object') {
  13. // 支持 CommonJS
  14. module.exports = factory();
  15. } else if (typeof define === 'function' && define.amd) {
  16. // 支持 AMD
  17. define(factory);
  18. } else if (window.layui && layui.define) {
  19. //layui加载
  20. layui.define(['jquery'], function (exports) {
  21. exports('formSelects', factory());
  22. });
  23. } else {
  24. window.formSelects = factory();
  25. }
  26. })(typeof layui == 'undefined' ? null : layui, window, function () {
  27. var v = '4.0.0.0910',
  28. NAME = 'xm-select',
  29. PNAME = 'xm-select-parent',
  30. INPUT = 'xm-select-input',
  31. TDIV = 'xm-select--suffix',
  32. THIS = 'xm-select-this',
  33. LABEL = 'xm-select-label',
  34. SEARCH = 'xm-select-search',
  35. SEARCH_TYPE = 'xm-select-search-type',
  36. SHOW_COUNT = 'xm-select-show-count',
  37. CREATE = 'xm-select-create',
  38. CREATE_LONG = 'xm-select-create-long',
  39. MAX = 'xm-select-max',
  40. SKIN = 'xm-select-skin',
  41. DIRECTION = "xm-select-direction",
  42. HEIGHT = 'xm-select-height',
  43. DISABLED = 'xm-dis-disabled',
  44. DIS = 'xm-select-dis',
  45. TEMP = 'xm-select-temp',
  46. RADIO = 'xm-select-radio',
  47. LINKAGE = 'xm-select-linkage',
  48. DL = 'xm-select-dl',
  49. DD_HIDE = 'xm-select-hide',
  50. HIDE_INPUT = 'xm-hide-input',
  51. SANJIAO = 'xm-select-sj',
  52. ICON_CLOSE = 'xm-icon-close',
  53. FORM_TITLE = 'xm-select-title',
  54. FORM_SELECT = 'xm-form-select',
  55. FORM_SELECTED = 'xm-form-selected',
  56. FORM_NONE = 'xm-select-none',
  57. FORM_EMPTY = 'xm-select-empty',
  58. FORM_INPUT = 'xm-input',
  59. FORM_DL_INPUT = 'xm-dl-input',
  60. FORM_SELECT_TIPS = 'xm-select-tips',
  61. FORM_SELECT_PH = 'xm-select-placeholder',
  62. CHECKBOX_YES = 'xm-iconfont',
  63. FORM_TEAM_PID = 'XM_PID_VALUE',
  64. CZ = 'xm-cz',
  65. CZ_GROUP = 'xm-cz-group',
  66. TIPS = '请选择',
  67. data = {},
  68. events = {
  69. on: {},
  70. endOn: {},
  71. filter: {},
  72. maxTips: {},
  73. opened: {},
  74. closed: {}
  75. },
  76. ajax = {
  77. type: 'get',
  78. header: {},
  79. first: true,
  80. data: {},
  81. searchUrl: '',
  82. searchName: 'keyword',
  83. searchVal: null,
  84. keyName: 'name',
  85. keyVal: 'value',
  86. keySel: 'selected',
  87. keyDis: 'disabled',
  88. keyChildren: 'children',
  89. dataType: '',
  90. delay: 500,
  91. beforeSuccess: null,
  92. success: null,
  93. error: null,
  94. beforeSearch: null,
  95. response: {
  96. statusCode: 0,
  97. statusName: 'code',
  98. msgName: 'msg',
  99. dataName: 'data'
  100. },
  101. tree: {
  102. nextClick: function nextClick(id, item, callback) {
  103. callback([]);
  104. },
  105. folderChoose: true,
  106. lazy: true
  107. }
  108. },
  109. quickBtns = [{ icon: 'xm-iconfont icon-quanxuan', name: '全选', click: function click(id, cm) {
  110. cm.selectAll(id, true, true);
  111. } }, { icon: 'xm-iconfont icon-qingkong', name: '清空', click: function click(id, cm) {
  112. cm.removeAll(id, true, true);
  113. } }, { icon: 'xm-iconfont icon-fanxuan', name: '反选', click: function click(id, cm) {
  114. cm.reverse(id, true, true);
  115. } }, { icon: 'xm-iconfont icon-pifu', name: '换肤', click: function click(id, cm) {
  116. cm.skin(id);
  117. } }],
  118. $ = window.$ || window.layui && window.layui.jquery,
  119. $win = $(window),
  120. ajaxs = {},
  121. fsConfig = {},
  122. fsConfigs = {},
  123. FormSelects = function FormSelects(options) {
  124. var _this = this;
  125. this.config = {
  126. name: null, //xm-select="xxx"
  127. max: null,
  128. maxTips: function maxTips(id, vals, val, max) {
  129. var ipt = $('[xid="' + _this.config.name + '"]').prev().find('.' + NAME);
  130. if (ipt.parents('.layui-form-item[pane]').length) {
  131. ipt = ipt.parents('.layui-form-item[pane]');
  132. }
  133. ipt.attr('style', 'border-color: red !important');
  134. setTimeout(function () {
  135. ipt.removeAttr('style');
  136. }, 300);
  137. },
  138. init: null, //初始化的选择值,
  139. on: null, //select值发生变化
  140. opened: null,
  141. closed: null,
  142. filter: function filter(id, inputVal, val, isDisabled) {
  143. return val.name.indexOf(inputVal) == -1;
  144. },
  145. clearid: -1,
  146. direction: 'auto',
  147. height: null,
  148. isEmpty: false,
  149. btns: [quickBtns[0], quickBtns[1], quickBtns[2]],
  150. searchType: 0,
  151. create: function create(id, name) {
  152. return Date.now();
  153. },
  154. template: function template(id, item) {
  155. return item.name;
  156. },
  157. showCount: 0,
  158. isCreate: false,
  159. placeholder: TIPS,
  160. clearInput: false
  161. };
  162. this.select = null;
  163. this.values = [];
  164. $.extend(true, this.config, options, {
  165. searchUrl: options.isSearch ? options.searchUrl : null,
  166. placeholder: options.placeholder ? TIPS + options.placeholder : TIPS,
  167. btns: options.radio ? [quickBtns[1]] : [quickBtns[0], quickBtns[1], quickBtns[2]]
  168. }, fsConfigs[options.name] || fsConfig);
  169. this.config.searchUrl = options.searchUrl;
  170. if (isNaN(this.config.showCount) || this.config.showCount <= 0) {
  171. this.config.showCount = 19921012;
  172. }
  173. };
  174. //一些简单的处理方法
  175. var Common = function Common() {
  176. this.appender();
  177. this.on();
  178. this.onreset();
  179. };
  180. Common.prototype.appender = function () {
  181. //针对IE做的一些拓展
  182. //拓展Array map方法
  183. if (!Array.prototype.map) {
  184. Array.prototype.map = function (i, h) {
  185. var b,
  186. a,
  187. c,
  188. e = Object(this),
  189. f = e.length >>> 0;if (h) {
  190. b = h;
  191. }a = new Array(f);c = 0;while (c < f) {
  192. var d, g;if (c in e) {
  193. d = e[c];g = i.call(b, d, c, e);a[c] = g;
  194. }c++;
  195. }return a;
  196. };
  197. };
  198. //拓展Array foreach方法
  199. if (!Array.prototype.forEach) {
  200. Array.prototype.forEach = function forEach(g, b) {
  201. var d, c;if (this == null) {
  202. throw new TypeError("this is null or not defined");
  203. }var f = Object(this);var a = f.length >>> 0;if (typeof g !== "function") {
  204. throw new TypeError(g + " is not a function");
  205. }if (arguments.length > 1) {
  206. d = b;
  207. }c = 0;while (c < a) {
  208. var e;if (c in f) {
  209. e = f[c];g.call(d, e, c, f);
  210. }c++;
  211. }
  212. };
  213. };
  214. //拓展Array filter方法
  215. if (!Array.prototype.filter) {
  216. Array.prototype.filter = function (b) {
  217. if (this === void 0 || this === null) {
  218. throw new TypeError();
  219. }var f = Object(this);var a = f.length >>> 0;if (typeof b !== "function") {
  220. throw new TypeError();
  221. }var e = [];var d = arguments[1];for (var c = 0; c < a; c++) {
  222. if (c in f) {
  223. var g = f[c];if (b.call(d, g, c, f)) {
  224. e.push(g);
  225. }
  226. }
  227. }return e;
  228. };
  229. };
  230. };
  231. Common.prototype.init = function (target) {
  232. var _this2 = this;
  233. //初始化页面上已有的select
  234. $(target ? target : 'select[' + NAME + ']').each(function (index, select) {
  235. var othis = $(select),
  236. id = othis.attr(NAME),
  237. hasLayuiRender = othis.next('.layui-form-select'),
  238. hasRender = othis.next('.' + PNAME),
  239. options = {
  240. name: id,
  241. disabled: select.disabled,
  242. max: othis.attr(MAX) - 0,
  243. isSearch: othis.attr(SEARCH) != undefined,
  244. searchUrl: othis.attr(SEARCH),
  245. isCreate: othis.attr(CREATE) != undefined,
  246. radio: othis.attr(RADIO) != undefined,
  247. skin: othis.attr(SKIN),
  248. direction: othis.attr(DIRECTION),
  249. optionsFirst: select.options[0],
  250. placeholder: othis.attr(FORM_SELECT_PH),
  251. height: othis.attr(HEIGHT),
  252. formname: othis.attr('name') || othis.attr('_name'),
  253. layverify: othis.attr('lay-verify') || othis.attr('_lay-verify'),
  254. layverType: othis.attr('lay-verType'),
  255. searchType: othis.attr(SEARCH_TYPE) == 'dl' ? 1 : 0,
  256. showCount: othis.attr(SHOW_COUNT) - 0
  257. },
  258. value = othis.find('option[selected]').toArray().map(function (option) {
  259. //获取已选中的数据
  260. return {
  261. name: option.innerHTML,
  262. value: option.value
  263. };
  264. }),
  265. fs = new FormSelects(options);
  266. fs.values = value;
  267. if (fs.config.init) {
  268. fs.values = fs.config.init.map(function (item) {
  269. if ((typeof item === 'undefined' ? 'undefined' : _typeof(item)) == 'object') {
  270. return item;
  271. }
  272. return {
  273. name: othis.find('option[value="' + item + '"]').text(),
  274. value: item
  275. };
  276. }).filter(function (item) {
  277. return item.name;
  278. });
  279. fs.config.init = fs.values.concat([]);
  280. } else {
  281. fs.config.init = value.concat([]);
  282. }
  283. !fs.values && (fs.values = []);
  284. data[id] = fs;
  285. surl = fs.config.searchUrl;
  286. //先取消layui对select的渲染
  287. hasLayuiRender[0] && hasLayuiRender.remove();
  288. hasRender[0] && hasRender.remove();
  289. //构造渲染div
  290. var dinfo = _this2.renderSelect(id, fs.config.placeholder, select);
  291. var heightStyle = !fs.config.height || fs.config.height == 'auto' ? '' : 'xm-hg style="height: 34px;"';
  292. var inputHtml = ['<div class="' + LABEL + '">', '<input type="text" fsw class="' + FORM_INPUT + ' ' + INPUT + '" ' + (fs.config.isSearch ? '' : 'style="display: none;"') + ' autocomplete="off" debounce="0" />', '</div>'];
  293. var reElem = $('<div class="' + FORM_SELECT + '" ' + SKIN + '="' + fs.config.skin + '">\n\t\t\t\t\t<input class="' + HIDE_INPUT + '" value="" name="' + fs.config.formname + '" lay-verify="' + fs.config.layverify + '" lay-verType="' + fs.config.layverType + '" type="text" style="position: absolute;bottom: 0; z-index: -1;width: 100%; height: 100%; border: none; opacity: 0;"/>\n\t\t\t\t\t<div class="' + FORM_TITLE + ' ' + (fs.config.disabled ? DIS : '') + '">\n\t\t\t\t\t\t<div class="' + FORM_INPUT + ' ' + NAME + '" ' + heightStyle + '>\n\t\t\t\t\t\t\t' + inputHtml.join('') + '\n\t\t\t\t\t\t\t<i class="' + SANJIAO + '"></i>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<div class="' + TDIV + '">\n\t\t\t\t\t\t\t<input type="text" autocomplete="off" placeholder="' + fs.config.placeholder + '" readonly="readonly" unselectable="on" class="' + FORM_INPUT + '">\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<div></div>\n\t\t\t\t\t</div>\n\t\t\t\t\t<dl xid="' + id + '" class="' + DL + ' ' + (fs.config.radio ? RADIO : '') + '">' + dinfo + '</dl>\n\t\t\t\t</div>');
  294. var $parent = $('<div class="' + PNAME + '" FS_ID="' + id + '"></div>');
  295. $parent.append(reElem);
  296. othis.after($parent);
  297. othis.attr('lay-ignore', '');
  298. othis.removeAttr('name') && othis.attr('_name', fs.config.formname);
  299. othis.removeAttr('lay-verify') && othis.attr('_lay-verify', fs.config.layverify);
  300. //如果可搜索, 加上事件
  301. if (fs.config.isSearch) {
  302. ajaxs[id] = $.extend({}, ajax, { searchUrl: fs.config.searchUrl }, ajaxs[id]);
  303. ajaxs[id].searchUrl = fs.config.searchUrl;
  304. $(document).on('input', 'div.' + PNAME + '[FS_ID="' + id + '"] .' + INPUT, function (e) {
  305. _this2.search(id, e, fs.config.searchUrl);
  306. });
  307. if (fs.config.searchUrl) {
  308. //触发第一次请求事件
  309. _this2.triggerSearch(reElem, true);
  310. }
  311. } else {
  312. //隐藏第二个dl
  313. reElem.find('dl dd.' + FORM_DL_INPUT).css('display', 'none');
  314. }
  315. });
  316. };
  317. Common.prototype.search = function (id, e, searchUrl, call) {
  318. var _this3 = this;
  319. var input = void 0;
  320. if (call) {
  321. input = call;
  322. } else {
  323. input = e.target;
  324. var keyCode = e.keyCode;
  325. if (keyCode === 9 || keyCode === 13 || keyCode === 37 || keyCode === 38 || keyCode === 39 || keyCode === 40) {
  326. return false;
  327. }
  328. }
  329. var inputValue = $.trim(input.value);
  330. //过滤一下tips
  331. this.changePlaceHolder($(input));
  332. var ajaxConfig = ajaxs[id] ? ajaxs[id] : ajax;
  333. searchUrl = ajaxConfig.searchUrl || searchUrl;
  334. var fs = data[id],
  335. isCreate = fs.config.isCreate,
  336. reElem = $('dl[xid="' + id + '"]').parents('.' + FORM_SELECT);
  337. //如果开启了远程搜索
  338. if (searchUrl) {
  339. if (ajaxConfig.searchVal) {
  340. inputValue = ajaxConfig.searchVal;
  341. ajaxConfig.searchVal = '';
  342. }
  343. if (!ajaxConfig.beforeSearch || ajaxConfig.beforeSearch && ajaxConfig.beforeSearch instanceof Function && ajaxConfig.beforeSearch(id, searchUrl, inputValue)) {
  344. var delay = ajaxConfig.delay;
  345. if (ajaxConfig.first) {
  346. ajaxConfig.first = false;
  347. delay = 10;
  348. }
  349. clearTimeout(fs.clearid);
  350. fs.clearid = setTimeout(function () {
  351. reElem.find('dl > *:not(.' + FORM_SELECT_TIPS + ')').remove();
  352. reElem.find('dd.' + FORM_NONE).addClass(FORM_EMPTY).text('请求中');
  353. _this3.ajax(id, searchUrl, inputValue, false, null, true);
  354. }, delay);
  355. }
  356. } else {
  357. reElem.find('dl .' + DD_HIDE).removeClass(DD_HIDE);
  358. //遍历选项, 选择可以显示的值
  359. reElem.find('dl dd:not(.' + FORM_SELECT_TIPS + ')').each(function (idx, item) {
  360. var _item = $(item);
  361. var searchFun = events.filter[id] || data[id].config.filter;
  362. if (searchFun && searchFun(id, inputValue, _this3.getItem(id, _item), _item.hasClass(DISABLED)) == true) {
  363. _item.addClass(DD_HIDE);
  364. }
  365. });
  366. //控制分组名称
  367. reElem.find('dl dt').each(function (index, item) {
  368. if (!$(item).nextUntil('dt', ':not(.' + DD_HIDE + ')').length) {
  369. $(item).addClass(DD_HIDE);
  370. }
  371. });
  372. //动态创建
  373. this.create(id, isCreate, inputValue);
  374. var shows = reElem.find('dl dd:not(.' + FORM_SELECT_TIPS + '):not(.' + DD_HIDE + ')');
  375. if (!shows.length) {
  376. reElem.find('dd.' + FORM_NONE).addClass(FORM_EMPTY).text('无匹配项');
  377. } else {
  378. reElem.find('dd.' + FORM_NONE).removeClass(FORM_EMPTY);
  379. }
  380. }
  381. };
  382. Common.prototype.isArray = function (obj) {
  383. return Object.prototype.toString.call(obj) == "[object Array]";
  384. };
  385. Common.prototype.triggerSearch = function (div, isCall) {
  386. var _this4 = this;
  387. (div ? [div] : $('.' + FORM_SELECT).toArray()).forEach(function (reElem, index) {
  388. reElem = $(reElem);
  389. var id = reElem.find('dl').attr('xid');
  390. if (id && data[id] && data[id].config.isEmpty || isCall) {
  391. _this4.search(id, null, null, data[id].config.searchType == 0 ? reElem.find('.' + LABEL + ' .' + INPUT) : reElem.find('dl .' + FORM_DL_INPUT + ' .' + INPUT));
  392. }
  393. });
  394. };
  395. Common.prototype.clearInput = function (id) {
  396. var div = $('.' + PNAME + '[fs_id="' + id + '"]');
  397. var input = data[id].config.searchType == 0 ? div.find('.' + LABEL + ' .' + INPUT) : div.find('dl .' + FORM_DL_INPUT + ' .' + INPUT);
  398. input.val('');
  399. };
  400. Common.prototype.ajax = function (id, searchUrl, inputValue, isLinkage, linkageWidth, isSearch, successCallback, isReplace) {
  401. var _this5 = this;
  402. var reElem = $('.' + PNAME + ' dl[xid="' + id + '"]').parents('.' + FORM_SELECT);
  403. if (!reElem[0] || !searchUrl) {
  404. return;
  405. }
  406. var ajaxConfig = ajaxs[id] ? ajaxs[id] : ajax;
  407. var ajaxData = $.extend(true, {}, ajaxConfig.data);
  408. ajaxData[ajaxConfig.searchName] = inputValue;
  409. if (searchUrl.indexOf('{') != -1) {
  410. var start = searchUrl.split('{');
  411. var end = start[1].split('}');
  412. searchUrl = start[0] + end[1];
  413. if (end[0].indexOf(',')) {
  414. var param = end[0].split(',');
  415. } else {
  416. var param = [];
  417. param[0] = end[0];
  418. }
  419. for (var i in param) {
  420. if (typeof(param[i]) == 'string') {
  421. var e = $('.update_'+param[i]);
  422. if (e.length > 1) {
  423. e.each(function() {
  424. if ($(this).get(0).checked) {
  425. ajaxData[param[i]] = $(this).val();
  426. }
  427. })
  428. } else {
  429. ajaxData[param[i]] = e.val();
  430. }
  431. }
  432. }
  433. }
  434. //是否需要对ajax添加随机时间
  435. //ajaxData['_'] = Date.now();
  436. $.ajax({
  437. type: ajaxConfig.type,
  438. headers: ajaxConfig.header,
  439. url: searchUrl,
  440. data: ajaxConfig.dataType == 'json' ? JSON.stringify(ajaxData) : ajaxData,
  441. success: function success(res) {
  442. if (typeof res == 'string') {
  443. res = JSON.parse(res);
  444. }
  445. ajaxConfig.beforeSuccess && ajaxConfig.beforeSuccess instanceof Function && (res = ajaxConfig.beforeSuccess(id, searchUrl, inputValue, res));
  446. if (_this5.isArray(res)) {
  447. var newRes = {};
  448. newRes[ajaxConfig.response.statusName] = ajaxConfig.response.statusCode;
  449. newRes[ajaxConfig.response.msgName] = "";
  450. newRes[ajaxConfig.response.dataName] = res;
  451. res = newRes;
  452. }
  453. if (res[ajaxConfig.response.statusName] != ajaxConfig.response.statusCode) {
  454. reElem.find('dd.' + FORM_NONE).addClass(FORM_EMPTY).text(res[ajaxConfig.response.msgName]);
  455. } else {
  456. reElem.find('dd.' + FORM_NONE).removeClass(FORM_EMPTY);
  457. _this5.renderData(id, res[ajaxConfig.response.dataName], isLinkage, linkageWidth, isSearch, isReplace);
  458. data[id].config.isEmpty = res[ajaxConfig.response.dataName].length == 0;
  459. }
  460. successCallback && successCallback(id);
  461. ajaxConfig.success && ajaxConfig.success instanceof Function && ajaxConfig.success(id, searchUrl, inputValue, res);
  462. },
  463. error: function error(err) {
  464. reElem.find('dd[lay-value]:not(.' + FORM_SELECT_TIPS + ')').remove();
  465. reElem.find('dd.' + FORM_NONE).addClass(FORM_EMPTY).text('服务异常');
  466. ajaxConfig.error && ajaxConfig.error instanceof Function && ajaxConfig.error(id, searchUrl, inputValue, err);
  467. }
  468. });
  469. };
  470. Common.prototype.renderData = function (id, dataArr, linkage, linkageWidth, isSearch, isReplace) {
  471. var _this6 = this;
  472. if (linkage) {
  473. //渲染多级联动
  474. this.renderLinkage(id, dataArr, linkageWidth);
  475. return;
  476. }
  477. if (isReplace) {
  478. this.renderReplace(id, dataArr);
  479. return;
  480. }
  481. var reElem = $('.' + PNAME + ' dl[xid="' + id + '"]').parents('.' + FORM_SELECT);
  482. var ajaxConfig = ajaxs[id] ? ajaxs[id] : ajax;
  483. var pcInput = reElem.find('.' + TDIV + ' input');
  484. dataArr = this.exchangeData(id, dataArr);
  485. var values = [];
  486. reElem.find('dl').html(this.renderSelect(id, pcInput.attr('placeholder') || pcInput.attr('back'), dataArr.map(function (item) {
  487. var itemVal = $.extend({}, item, {
  488. innerHTML: item[ajaxConfig.keyName],
  489. value: item[ajaxConfig.keyVal],
  490. sel: item[ajaxConfig.keySel],
  491. disabled: item[ajaxConfig.keyDis],
  492. type: item.type,
  493. name: item[ajaxConfig.keyName]
  494. });
  495. if (itemVal.sel) {
  496. values.push(itemVal);
  497. }
  498. return itemVal;
  499. })));
  500. var label = reElem.find('.' + LABEL);
  501. var dl = reElem.find('dl[xid]');
  502. if (isSearch) {
  503. //如果是远程搜索, 这里需要判重
  504. var oldVal = data[id].values;
  505. oldVal.forEach(function (item, index) {
  506. dl.find('dd[lay-value="' + item.value + '"]').addClass(THIS);
  507. });
  508. values.forEach(function (item, index) {
  509. if (_this6.indexOf(oldVal, item) == -1) {
  510. _this6.addLabel(id, label, item);
  511. dl.find('dd[lay-value="' + item.value + '"]').addClass(THIS);
  512. oldVal.push(item);
  513. }
  514. });
  515. } else {
  516. values.forEach(function (item, index) {
  517. _this6.addLabel(id, label, item);
  518. dl.find('dd[lay-value="' + item.value + '"]').addClass(THIS);
  519. });
  520. data[id].values = values;
  521. }
  522. this.commonHandler(id, label);
  523. };
  524. Common.prototype.renderLinkage = function (id, dataArr, linkageWidth) {
  525. var result = [],
  526. index = 0,
  527. temp = { "0": dataArr },
  528. ajaxConfig = ajaxs[id] ? ajaxs[id] : ajax;
  529. db[id] = {};
  530. var _loop = function _loop() {
  531. var group = result[index++] = [],
  532. _temp = temp;
  533. temp = {};
  534. $.each(_temp, function (pid, arr) {
  535. $.each(arr, function (idx, item) {
  536. var val = {
  537. pid: pid,
  538. name: item[ajaxConfig.keyName],
  539. value: item[ajaxConfig.keyVal]
  540. };
  541. db[id][val.value] = $.extend(item, val);
  542. group.push(val);
  543. var children = item[ajaxConfig.keyChildren];
  544. if (children && children.length) {
  545. temp[val.value] = children;
  546. }
  547. });
  548. });
  549. };
  550. do {
  551. _loop();
  552. } while (Object.getOwnPropertyNames(temp).length);
  553. var reElem = $('.' + PNAME + ' dl[xid="' + id + '"]').parents('.' + FORM_SELECT);
  554. var html = ['<div class="xm-select-linkage">'];
  555. $.each(result, function (idx, arr) {
  556. var groupDiv = ['<div style="left: ' + (linkageWidth - 0) * idx + 'px;" class="xm-select-linkage-group xm-select-linkage-group' + (idx + 1) + ' ' + (idx != 0 ? 'xm-select-linkage-hide' : '') + '">'];
  557. $.each(arr, function (idx2, item) {
  558. var span = '<li title="' + item.name + '" pid="' + item.pid + '" xm-value="' + item.value + '"><span>' + item.name + '</span></li>';
  559. groupDiv.push(span);
  560. });
  561. groupDiv.push('</div>');
  562. html = html.concat(groupDiv);
  563. });
  564. html.push('<div style="clear: both; height: 288px;"></div>');
  565. html.push('</div>');
  566. reElem.find('dl').html(html.join(''));
  567. reElem.find('.' + INPUT).css('display', 'none'); //联动暂时不支持搜索
  568. };
  569. Common.prototype.renderReplace = function (id, dataArr) {
  570. var _this7 = this;
  571. var dl = $('.' + PNAME + ' dl[xid="' + id + '"]');
  572. var ajaxConfig = ajaxs[id] ? ajaxs[id] : ajax;
  573. dataArr = this.exchangeData(id, dataArr);
  574. db[id] = dataArr;
  575. var html = dataArr.map(function (item) {
  576. var itemVal = $.extend({}, item, {
  577. innerHTML: item[ajaxConfig.keyName],
  578. value: item[ajaxConfig.keyVal],
  579. sel: item[ajaxConfig.keySel],
  580. disabled: item[ajaxConfig.keyDis],
  581. type: item.type,
  582. name: item[ajaxConfig.keyName]
  583. });
  584. return _this7.createDD(id, itemVal);
  585. }).join('');
  586. dl.find('dd:not(.' + FORM_SELECT_TIPS + '),dt:not([style])').remove();
  587. dl.find('dt[style]').after($(html));
  588. };
  589. Common.prototype.exchangeData = function (id, arr) {
  590. //这里处理树形结构
  591. var ajaxConfig = ajaxs[id] ? ajaxs[id] : ajax;
  592. var childrenName = ajaxConfig['keyChildren'];
  593. var disabledName = ajaxConfig['keyDis'];
  594. db[id] = {};
  595. var result = this.getChildrenList(arr, childrenName, disabledName, [], false);
  596. return result;
  597. };
  598. Common.prototype.getChildrenList = function (arr, childrenName, disabledName, pid, disabled) {
  599. var result = [],
  600. offset = 0;
  601. for (var a = 0; a < arr.length; a++) {
  602. var item = arr[a];
  603. if (item.type && item.type == 'optgroup') {
  604. result.push(item);
  605. continue;
  606. } else {
  607. offset++;
  608. }
  609. var parentIds = pid.concat([]);
  610. parentIds.push(offset - 1 + '_E');
  611. item[FORM_TEAM_PID] = JSON.stringify(parentIds);
  612. item[disabledName] = item[disabledName] || disabled;
  613. result.push(item);
  614. var child = item[childrenName];
  615. if (child && common.isArray(child) && child.length) {
  616. item['XM_TREE_FOLDER'] = true;
  617. var pidArr = parentIds.concat([]);
  618. var childResult = this.getChildrenList(child, childrenName, disabledName, pidArr, item[disabledName]);
  619. result = result.concat(childResult);
  620. }
  621. }
  622. return result;
  623. };
  624. Common.prototype.create = function (id, isCreate, inputValue) {
  625. if (isCreate && inputValue) {
  626. var fs = data[id],
  627. dl = $('[xid="' + id + '"]'),
  628. tips = dl.find('dd.' + FORM_SELECT_TIPS + '.' + FORM_DL_INPUT),
  629. tdd = null,
  630. temp = dl.find('dd.' + TEMP);
  631. dl.find('dd:not(.' + FORM_SELECT_TIPS + '):not(.' + TEMP + ')').each(function (index, item) {
  632. if (inputValue == $(item).find('span').attr('name')) {
  633. tdd = item;
  634. }
  635. });
  636. if (!tdd) {
  637. //如果不存在, 则创建
  638. var val = fs.config.create(id, inputValue);
  639. if (temp[0]) {
  640. temp.attr('lay-value', val);
  641. temp.find('span').text(inputValue);
  642. temp.find('span').attr("name", inputValue);
  643. temp.removeClass(DD_HIDE);
  644. } else {
  645. tips.after($(this.createDD(id, {
  646. name: inputValue,
  647. innerHTML: inputValue,
  648. value: val
  649. }, TEMP + ' ' + CREATE_LONG)));
  650. }
  651. }
  652. } else {
  653. $('[xid=' + id + '] dd.' + TEMP).remove();
  654. }
  655. };
  656. Common.prototype.createDD = function (id, item, clz) {
  657. var ajaxConfig = ajaxs[id] ? ajaxs[id] : ajax;
  658. var name = $.trim(item.innerHTML);
  659. db[id][item.value] = $(item).is('option') ? item = function () {
  660. var resultItem = {};
  661. resultItem[ajaxConfig.keyName] = name;
  662. resultItem[ajaxConfig.keyVal] = item.value;
  663. resultItem[ajaxConfig.keyDis] = item.disabled;
  664. return resultItem;
  665. }() : item;
  666. var template = data[id].config.template(id, item);
  667. var pid = item[FORM_TEAM_PID];
  668. pid ? pid = JSON.parse(pid) : pid = [-1];
  669. var attr = pid[0] == -1 ? '' : 'tree-id="' + pid.join('-') + '" tree-folder="' + !!item['XM_TREE_FOLDER'] + '"';
  670. return '<dd lay-value="' + item.value + '" class="' + (item.disabled ? DISABLED : '') + ' ' + (clz ? clz : '') + '" ' + attr + '>\n\t\t\t\t\t<div class="xm-unselect xm-form-checkbox ' + (item.disabled ? DISABLED : '') + '" style="margin-left: ' + (pid.length - 1) * 30 + 'px">\n\t\t\t\t\t\t<i class="' + CHECKBOX_YES + '"></i>\n\t\t\t\t\t\t<span name="' + name + '">' + template + '</span>\n\t\t\t\t\t</div>\n\t\t\t\t</dd>';
  671. };
  672. Common.prototype.createQuickBtn = function (obj, right) {
  673. return '<div class="' + CZ + '" method="' + obj.name + '" title="' + obj.name + '" ' + (right ? 'style="margin-right: ' + right + '"' : '') + '><i class="' + obj.icon + '"></i><span>' + obj.name + '</span></div>';
  674. };
  675. Common.prototype.renderBtns = function (id, show, right) {
  676. var _this8 = this;
  677. var quickBtn = [];
  678. var dl = $('dl[xid="' + id + '"]');
  679. quickBtn.push('<div class="' + CZ_GROUP + '" show="' + show + '" style="max-width: ' + (dl.prev().width() - 54) + 'px;">');
  680. $.each(data[id].config.btns, function (index, item) {
  681. quickBtn.push(_this8.createQuickBtn(item, right));
  682. });
  683. quickBtn.push('</div>');
  684. quickBtn.push(this.createQuickBtn({ icon: 'xm-iconfont icon-caidan', name: '' }));
  685. return quickBtn.join('');
  686. };
  687. Common.prototype.renderSelect = function (id, tips, select) {
  688. var _this9 = this;
  689. db[id] = {};
  690. var arr = [];
  691. if (data[id].config.btns.length) {
  692. setTimeout(function () {
  693. var dl = $('dl[xid="' + id + '"]');
  694. dl.parents('.' + FORM_SELECT).attr(SEARCH_TYPE, data[id].config.searchType);
  695. dl.find('.' + CZ_GROUP).css('max-width', dl.prev().width() - 54 + 'px');
  696. }, 10);
  697. arr.push(['<dd lay-value="" class="' + FORM_SELECT_TIPS + '" style="background-color: #FFF!important;display:none;">', this.renderBtns(id, null, '30px'), '</dd>', '<dd lay-value="" class="' + FORM_SELECT_TIPS + ' ' + FORM_DL_INPUT + '" style="background-color: #FFF!important;">', '<i class="xm-iconfont icon-sousuo"></i>', '<input type="text" class="' + FORM_INPUT + ' ' + INPUT + '" placeholder="\u8BF7\u641C\u7D22"/>', '</dd>'].join(''));
  698. } else {
  699. arr.push('<dd lay-value="" class="' + FORM_SELECT_TIPS + '">' + tips + '</dd>');
  700. }
  701. if (this.isArray(select)) {
  702. $(select).each(function (index, item) {
  703. if (item) {
  704. if (item.type && item.type === 'optgroup') {
  705. arr.push('<dt>' + item.name + '</dt>');
  706. } else {
  707. arr.push(_this9.createDD(id, item));
  708. }
  709. }
  710. });
  711. } else {
  712. $(select).find('*').each(function (index, item) {
  713. if (item.tagName.toLowerCase() == 'option' && index == 0 && !item.value) {
  714. return;
  715. }
  716. if (item.tagName.toLowerCase() === 'optgroup') {
  717. arr.push('<dt>' + item.label + '</dt>');
  718. } else {
  719. arr.push(_this9.createDD(id, item));
  720. }
  721. });
  722. }
  723. arr.push('<dt style="display:none;"> </dt>');
  724. arr.push('<dd class="' + FORM_SELECT_TIPS + ' ' + FORM_NONE + ' ' + (arr.length === 2 ? FORM_EMPTY : '') + '">\u6CA1\u6709\u9009\u9879</dd>');
  725. return arr.join('');
  726. };
  727. Common.prototype.on = function () {
  728. var _this10 = this;
  729. //事件绑定
  730. this.one();
  731. $(document).on('click', function (e) {
  732. if (!$(e.target).parents('.' + FORM_TITLE)[0]) {
  733. //清空input中的值
  734. $('.' + PNAME + ' dl .' + DD_HIDE).removeClass(DD_HIDE);
  735. $('.' + PNAME + ' dl dd.' + FORM_EMPTY).removeClass(FORM_EMPTY);
  736. $('.' + PNAME + ' dl dd.' + TEMP).remove();
  737. $.each(data, function (key, fs) {
  738. _this10.clearInput(key);
  739. if (!fs.values.length) {
  740. _this10.changePlaceHolder($('div[FS_ID="' + key + '"] .' + LABEL));
  741. }
  742. });
  743. }
  744. $('.' + PNAME + ' .' + FORM_SELECTED).each(function (index, item) {
  745. _this10.changeShow($(item).find('.' + FORM_TITLE), false);
  746. });
  747. });
  748. };
  749. Common.prototype.calcLabelLeft = function (label, w, call) {
  750. var pos = this.getPosition(label[0]);
  751. pos.y = pos.x + label[0].clientWidth;
  752. var left = label[0].offsetLeft;
  753. if (!label.find('span').length) {
  754. left = 0;
  755. } else if (call) {
  756. //校正归位
  757. var span = label.find('span:last');
  758. span.css('display') == 'none' ? span = span.prev()[0] : span = span[0];
  759. var spos = this.getPosition(span);
  760. spos.y = spos.x + span.clientWidth;
  761. if (spos.y > pos.y) {
  762. left = left - (spos.y - pos.y) - 5;
  763. } else {
  764. left = 0;
  765. }
  766. } else {
  767. if (w < 0) {
  768. var _span = label.find(':last');
  769. _span.css('display') == 'none' ? _span = _span.prev()[0] : _span = _span[0];
  770. var _spos = this.getPosition(_span);
  771. _spos.y = _spos.x + _span.clientWidth;
  772. if (_spos.y > pos.y) {
  773. left -= 10;
  774. }
  775. } else {
  776. if (left < 0) {
  777. left += 10;
  778. }
  779. if (left > 0) {
  780. left = 0;
  781. }
  782. }
  783. }
  784. label.css('left', left + 'px');
  785. };
  786. Common.prototype.one = function (target) {
  787. var _this11 = this;
  788. //一次性事件绑定
  789. $(target ? target : document).off('click', '.' + FORM_TITLE).on('click', '.' + FORM_TITLE, function (e) {
  790. var othis = $(e.target),
  791. title = othis.is(FORM_TITLE) ? othis : othis.parents('.' + FORM_TITLE),
  792. dl = title.next(),
  793. id = dl.attr('xid');
  794. //清空非本select的input val
  795. $('dl[xid]').not(dl).each(function (index, item) {
  796. _this11.clearInput($(item).attr('xid'));
  797. });
  798. $('dl[xid]').not(dl).find('dd.' + DD_HIDE).removeClass(DD_HIDE);
  799. //如果是disabled select
  800. if (title.hasClass(DIS)) {
  801. return false;
  802. }
  803. //如果点击的是右边的三角或者只读的input
  804. if (othis.is('.' + SANJIAO) || othis.is('.' + INPUT + '[readonly]')) {
  805. _this11.changeShow(title, !title.parents('.' + FORM_SELECT).hasClass(FORM_SELECTED));
  806. return false;
  807. }
  808. //如果点击的是input的右边, focus一下
  809. if (title.find('.' + INPUT + ':not(readonly)')[0]) {
  810. var input = title.find('.' + INPUT),
  811. epos = { x: e.pageX, y: e.pageY },
  812. pos = _this11.getPosition(title[0]),
  813. width = title.width();
  814. while (epos.x > pos.x) {
  815. if ($(document.elementFromPoint(epos.x, epos.y)).is(input)) {
  816. input.focus();
  817. _this11.changeShow(title, true);
  818. return false;
  819. }
  820. epos.x -= 50;
  821. }
  822. }
  823. //如果点击的是可搜索的input
  824. if (othis.is('.' + INPUT)) {
  825. _this11.changeShow(title, true);
  826. return false;
  827. }
  828. //如果点击的是x按钮
  829. if (othis.is('i[fsw="' + NAME + '"]')) {
  830. var val = _this11.getItem(id, othis),
  831. dd = dl.find('dd[lay-value=\'' + val.value + '\']');
  832. if (dd.hasClass(DISABLED)) {
  833. //如果是disabled状态, 不可选, 不可删
  834. return false;
  835. }
  836. _this11.handlerLabel(id, dd, false, val);
  837. return false;
  838. }
  839. _this11.changeShow(title, !title.parents('.' + FORM_SELECT).hasClass(FORM_SELECTED));
  840. return false;
  841. });
  842. $(target ? target : document).off('click', 'dl.' + DL).on('click', 'dl.' + DL, function (e) {
  843. var othis = $(e.target);
  844. if (othis.is('.' + LINKAGE) || othis.parents('.' + LINKAGE)[0]) {
  845. //linkage的处理
  846. othis = othis.is('li') ? othis : othis.parents('li[xm-value]');
  847. var _group = othis.parents('.xm-select-linkage-group'),
  848. _id = othis.parents('dl').attr('xid');
  849. if (!_id) {
  850. return false;
  851. }
  852. //激活li
  853. _group.find('.xm-select-active').removeClass('xm-select-active');
  854. othis.addClass('xm-select-active');
  855. //激活下一个group, 激活前显示对应数据
  856. _group.nextAll('.xm-select-linkage-group').addClass('xm-select-linkage-hide');
  857. var nextGroup = _group.next('.xm-select-linkage-group');
  858. nextGroup.find('li').addClass('xm-select-linkage-hide');
  859. nextGroup.find('li[pid="' + othis.attr('xm-value') + '"]').removeClass('xm-select-linkage-hide');
  860. //如果没有下一个group, 或没有对应的值
  861. if (!nextGroup[0] || nextGroup.find('li:not(.xm-select-linkage-hide)').length == 0) {
  862. var vals = [],
  863. index = 0,
  864. isAdd = !othis.hasClass('xm-select-this');
  865. if (data[_id].config.radio) {
  866. othis.parents('.xm-select-linkage').find('.xm-select-this').removeClass('xm-select-this');
  867. }
  868. do {
  869. vals[index++] = {
  870. name: othis.find('span').text(),
  871. value: othis.attr('xm-value')
  872. };
  873. othis = othis.parents('.xm-select-linkage-group').prev().find('li[xm-value="' + othis.attr('pid') + '"]');
  874. } while (othis.length);
  875. vals.reverse();
  876. var val = {
  877. name: vals.map(function (item) {
  878. return item.name;
  879. }).join('/'),
  880. value: vals.map(function (item) {
  881. return item.value;
  882. }).join('/')
  883. };
  884. _this11.handlerLabel(_id, null, isAdd, val);
  885. } else {
  886. nextGroup.removeClass('xm-select-linkage-hide');
  887. }
  888. return false;
  889. }
  890. if (othis.is('dl')) {
  891. return false;
  892. }
  893. if (othis.is('dt')) {
  894. othis.nextUntil('dt').each(function (index, item) {
  895. item = $(item);
  896. if (item.hasClass(DISABLED) || item.hasClass(THIS)) {} else {
  897. item.find('i:not(.icon-expand)').click();
  898. }
  899. });
  900. return false;
  901. }
  902. var dd = othis.is('dd') ? othis : othis.parents('dd');
  903. var id = dd.parent('dl').attr('xid');
  904. if (dd.hasClass(DISABLED)) {
  905. //被禁用选项的处理
  906. return false;
  907. }
  908. //菜单功效
  909. if (othis.is('i.icon-caidan')) {
  910. var opens = [],
  911. closes = [];
  912. othis.parents('dl').find('dd[tree-folder="true"]').each(function (index, item) {
  913. $(item).attr('xm-tree-hidn') == undefined ? opens.push(item) : closes.push(item);
  914. });
  915. var arr = closes.length ? closes : opens;
  916. arr.forEach(function (item) {
  917. return item.click();
  918. });
  919. return false;
  920. }
  921. //树状结构的选择
  922. var treeId = dd.attr('tree-id');
  923. if (treeId) {
  924. //忽略右边的图标
  925. if (othis.is('i:not(.icon-expand)')) {
  926. _this11.handlerLabel(id, dd, !dd.hasClass(THIS));
  927. return false;
  928. }
  929. var ajaxConfig = ajaxs[id] || ajax;
  930. var treeConfig = ajaxConfig.tree;
  931. var childrens = dd.nextAll('dd[tree-id^="' + treeId + '"]');
  932. if (childrens && childrens.length) {
  933. var len = childrens[0].clientHeight;
  934. len ? (_this11.addTreeHeight(dd, len), len = 0) : (len = dd.attr('xm-tree-hidn') || 36, dd.removeAttr('xm-tree-hidn'), dd.find('>i').remove(), childrens = childrens.filter(function (index, item) {
  935. return $(item).attr('tree-id').split('-').length - 1 == treeId.split('-').length;
  936. }));
  937. childrens.animate({
  938. height: len
  939. }, 150);
  940. return false;
  941. } else {
  942. if (treeConfig.nextClick && treeConfig.nextClick instanceof Function) {
  943. treeConfig.nextClick(id, _this11.getItem(id, dd), function (res) {
  944. if (!res || !res.length) {
  945. _this11.handlerLabel(id, dd, !dd.hasClass(THIS));
  946. } else {
  947. dd.attr('tree-folder', 'true');
  948. var ddChilds = [];
  949. res.forEach(function (item, idx) {
  950. item.innerHTML = item[ajaxConfig.keyName];
  951. item[FORM_TEAM_PID] = JSON.stringify(treeId.split('-').concat([idx]));
  952. ddChilds.push(_this11.createDD(id, item));
  953. db[id][item[ajaxConfig.keyVal]] = item;
  954. });
  955. dd.after(ddChilds.join(''));
  956. }
  957. });
  958. return false;
  959. }
  960. }
  961. }
  962. if (dd.hasClass(FORM_SELECT_TIPS)) {
  963. //tips的处理
  964. var btn = othis.is('.' + CZ) ? othis : othis.parents('.' + CZ);
  965. if (!btn[0]) {
  966. return false;
  967. }
  968. var method = btn.attr('method');
  969. var obj = data[id].config.btns.filter(function (bean) {
  970. return bean.name == method;
  971. })[0];
  972. obj && obj.click && obj.click instanceof Function && obj.click(id, _this11);
  973. return false;
  974. }
  975. _this11.handlerLabel(id, dd, !dd.hasClass(THIS));
  976. return false;
  977. });
  978. };
  979. Common.prototype.addTreeHeight = function (dd, len) {
  980. var _this12 = this;
  981. var treeId = dd.attr('tree-id');
  982. var childrens = dd.nextAll('dd[tree-id^="' + treeId + '"]');
  983. if (childrens.length) {
  984. dd.append('<i class="xm-iconfont icon-expand"></i>');
  985. dd.attr('xm-tree-hidn', len);
  986. childrens.each(function (index, item) {
  987. var that = $(item);
  988. _this12.addTreeHeight(that, len);
  989. });
  990. }
  991. };
  992. var db = {};
  993. Common.prototype.getItem = function (id, value) {
  994. if (value instanceof $) {
  995. if (value.is('i[fsw="' + NAME + '"]')) {
  996. var span = value.parent();
  997. return db[id][value] || {
  998. name: span.find('font').text(),
  999. value: span.attr('value')
  1000. };
  1001. }
  1002. var val = value.attr('lay-value');
  1003. return !db[id][val] ? db[id][val] = {
  1004. name: value.find('span[name]').attr('name'),
  1005. value: val
  1006. } : db[id][val];
  1007. } else if (typeof value == 'string' && value.indexOf('/') != -1) {
  1008. return db[id][value] || {
  1009. name: this.valToName(id, value),
  1010. value: value
  1011. };
  1012. }
  1013. return db[id][value];
  1014. };
  1015. Common.prototype.linkageAdd = function (id, val) {
  1016. var dl = $('dl[xid="' + id + '"]');
  1017. dl.find('.xm-select-active').removeClass('xm-select-active');
  1018. var vs = val.value.split('/');
  1019. var pid = void 0,
  1020. li = void 0,
  1021. index = 0;
  1022. var lis = [];
  1023. do {
  1024. pid = vs[index];
  1025. li = dl.find('.xm-select-linkage-group' + (index + 1) + ' li[xm-value="' + pid + '"]');
  1026. li[0] && lis.push(li);
  1027. index++;
  1028. } while (li.length && pid != undefined);
  1029. if (lis.length == vs.length) {
  1030. $.each(lis, function (idx, item) {
  1031. item.addClass('xm-select-this');
  1032. });
  1033. }
  1034. };
  1035. Common.prototype.linkageDel = function (id, val) {
  1036. var dl = $('dl[xid="' + id + '"]');
  1037. var vs = val.value.split('/');
  1038. var pid = void 0,
  1039. li = void 0,
  1040. index = vs.length - 1;
  1041. do {
  1042. pid = vs[index];
  1043. li = dl.find('.xm-select-linkage-group' + (index + 1) + ' li[xm-value="' + pid + '"]');
  1044. if (!li.parent().next().find('li[pid=' + pid + '].xm-select-this').length) {
  1045. li.removeClass('xm-select-this');
  1046. }
  1047. index--;
  1048. } while (li.length && pid != undefined);
  1049. };
  1050. Common.prototype.valToName = function (id, val) {
  1051. var dl = $('dl[xid="' + id + '"]');
  1052. var vs = (val + "").split('/');
  1053. if (!vs.length) {
  1054. return null;
  1055. }
  1056. var names = [];
  1057. $.each(vs, function (idx, item) {
  1058. var name = dl.find('.xm-select-linkage-group' + (idx + 1) + ' li[xm-value="' + item + '"] span').text();
  1059. names.push(name);
  1060. });
  1061. return names.length == vs.length ? names.join('/') : null;
  1062. };
  1063. Common.prototype.commonHandler = function (key, label) {
  1064. if (!label || !label[0]) {
  1065. return;
  1066. }
  1067. this.checkHideSpan(key, label);
  1068. //计算input的提示语
  1069. this.changePlaceHolder(label);
  1070. //计算高度
  1071. this.retop(label.parents('.' + FORM_SELECT));
  1072. this.calcLabelLeft(label, 0, true);
  1073. //表单默认值
  1074. this.setHidnVal(key, label);
  1075. //title值
  1076. label.parents('.' + FORM_TITLE + ' .' + NAME).attr('title', data[key].values.map(function (val) {
  1077. return val.name;
  1078. }).join(','));
  1079. };
  1080. Common.prototype.initVal = function (id) {
  1081. var _this13 = this;
  1082. var target = {};
  1083. if (id) {
  1084. target[id] = data[id];
  1085. } else {
  1086. target = data;
  1087. }
  1088. $.each(target, function (key, val) {
  1089. var values = val.values,
  1090. div = $('dl[xid="' + key + '"]').parent(),
  1091. label = div.find('.' + LABEL),
  1092. dl = div.find('dl');
  1093. dl.find('dd.' + THIS).removeClass(THIS);
  1094. var _vals = values.concat([]);
  1095. _vals.concat([]).forEach(function (item, index) {
  1096. _this13.addLabel(key, label, item);
  1097. dl.find('dd[lay-value="' + item.value + '"]').addClass(THIS);
  1098. });
  1099. if (val.config.radio) {
  1100. _vals.length && values.push(_vals[_vals.length - 1]);
  1101. }
  1102. _this13.commonHandler(key, label);
  1103. });
  1104. };
  1105. Common.prototype.setHidnVal = function (key, label) {
  1106. if (!label || !label[0]) {
  1107. return;
  1108. }
  1109. label.parents('.' + PNAME).find('.' + HIDE_INPUT).val(data[key].values.map(function (val) {
  1110. return val.value;
  1111. }).join(','));
  1112. };
  1113. Common.prototype.handlerLabel = function (id, dd, isAdd, oval, notOn) {
  1114. var div = $('[xid="' + id + '"]').prev().find('.' + LABEL),
  1115. val = dd && this.getItem(id, dd),
  1116. vals = data[id].values,
  1117. on = data[id].config.on || events.on[id],
  1118. endOn = data[id].config.endOn || events.endOn[id];
  1119. if (oval) {
  1120. val = oval;
  1121. }
  1122. var fs = data[id];
  1123. if (isAdd && fs.config.max && fs.values.length >= fs.config.max) {
  1124. var maxTipsFun = events.maxTips[id] || data[id].config.maxTips;
  1125. maxTipsFun && maxTipsFun(id, vals.concat([]), val, fs.config.max);
  1126. return;
  1127. }
  1128. if (!notOn) {
  1129. if (on && on instanceof Function && on(id, vals.concat([]), val, isAdd, dd && dd.hasClass(DISABLED)) == false) {
  1130. return;
  1131. }
  1132. }
  1133. var dl = $('dl[xid="' + id + '"]');
  1134. isAdd ? (dd && dd[0] ? (dd.addClass(THIS), dd.removeClass(TEMP)) : dl.find('.xm-select-linkage')[0] && this.linkageAdd(id, val), this.addLabel(id, div, val), vals.push(val)) : (dd && dd[0] ? dd.removeClass(THIS) : dl.find('.xm-select-linkage')[0] && this.linkageDel(id, val), this.delLabel(id, div, val), this.remove(vals, val));
  1135. if (!div[0]) return;
  1136. //单选选完后直接关闭选择域
  1137. if (fs.config.radio) {
  1138. this.changeShow(div, false);
  1139. }
  1140. //移除表单验证的红色边框
  1141. div.parents('.' + FORM_TITLE).prev().removeClass('layui-form-danger');
  1142. //清空搜索值
  1143. fs.config.clearInput && this.clearInput(id);
  1144. this.commonHandler(id, div);
  1145. !notOn && endOn && endOn instanceof Function && endOn(id, vals.concat([]), val, isAdd, dd && dd.hasClass(DISABLED));
  1146. };
  1147. Common.prototype.addLabel = function (id, div, val) {
  1148. if (!val) return;
  1149. var tips = 'fsw="' + NAME + '"';
  1150. var _ref = [$('<span ' + tips + ' value="' + val.value + '"><font ' + tips + '>' + val.name + '</font></span>'), $('<i ' + tips + ' class="xm-iconfont icon-close"></i>')],
  1151. $label = _ref[0],
  1152. $close = _ref[1];
  1153. $label.append($close);
  1154. //如果是radio模式
  1155. var fs = data[id];
  1156. if (fs.config.radio) {
  1157. fs.values.length = 0;
  1158. $('dl[xid="' + id + '"]').find('dd.' + THIS + ':not([lay-value="' + val.value + '"])').removeClass(THIS);
  1159. div.find('span').remove();
  1160. }
  1161. //如果是固定高度
  1162. div.find('input').css('width', '50px');
  1163. div.find('input').before($label);
  1164. };
  1165. Common.prototype.delLabel = function (id, div, val) {
  1166. if (!val) return;
  1167. div.find('span[value="' + val.value + '"]:first').remove();
  1168. };
  1169. Common.prototype.checkHideSpan = function (id, div) {
  1170. var parentHeight = div.parents('.' + NAME)[0].offsetHeight + 5;
  1171. div.find('span.xm-span-hide').removeClass('xm-span-hide');
  1172. div.find('span[style]').remove();
  1173. var count = data[id].config.showCount;
  1174. div.find('span').each(function (index, item) {
  1175. if (index >= count) {
  1176. $(item).addClass('xm-span-hide');
  1177. }
  1178. });
  1179. var prefix = div.find('span:eq(' + count + ')');
  1180. prefix[0] && prefix.before($('<span style="padding-right: 6px;" fsw="' + NAME + '"> + ' + (div.find('span').length - count) + '</span>'));
  1181. };
  1182. Common.prototype.retop = function (div) {
  1183. //计算dl显示的位置
  1184. var dl = div.find('dl'),
  1185. top = div.offset().top + div.outerHeight() + 5 - $win.scrollTop(),
  1186. dlHeight = dl.outerHeight();
  1187. var up = div.hasClass('layui-form-selectup') || dl.css('top').indexOf('-') != -1 || top + dlHeight > $win.height() && top >= dlHeight;
  1188. div = div.find('.' + NAME);
  1189. var fs = data[dl.attr('xid')];
  1190. var base = dl.parents('.layui-form-pane')[0] && dl.prev()[0].clientHeight > 38 ? 14 : 10;
  1191. if (fs && fs.config.direction == 'up' || up) {
  1192. up = true;
  1193. if (fs && fs.config.direction == 'down') {
  1194. up = false;
  1195. }
  1196. }
  1197. var reHeight = div[0].offsetTop + div.height() + base;
  1198. if (up) {
  1199. dl.css({
  1200. top: 'auto',
  1201. bottom: reHeight + 3 + 'px'
  1202. });
  1203. } else {
  1204. dl.css({
  1205. top: reHeight + 'px',
  1206. bottom: 'auto'
  1207. });
  1208. }
  1209. };
  1210. Common.prototype.changeShow = function (children, isShow) {
  1211. //显示于隐藏
  1212. $('.layui-form-selected').removeClass('layui-form-selected');
  1213. var top = children.parents('.' + FORM_SELECT),
  1214. realShow = top.hasClass(FORM_SELECTED),
  1215. id = top.find('dl').attr('xid');
  1216. $('.' + PNAME + ' .' + FORM_SELECT).not(top).removeClass(FORM_SELECTED);
  1217. if (isShow) {
  1218. this.retop(top);
  1219. top.addClass(FORM_SELECTED);
  1220. top.find('.' + INPUT).focus();
  1221. var searchUrl = surl;
  1222. if (searchUrl.indexOf('{') != -1) {
  1223. this.triggerSearch(top, true);
  1224. }
  1225. if (!top.find('dl dd[lay-value]:not(.' + FORM_SELECT_TIPS + ')').length) {
  1226. top.find('dl .' + FORM_NONE).addClass(FORM_EMPTY);
  1227. }
  1228. } else {
  1229. top.removeClass(FORM_SELECTED);
  1230. this.clearInput(id);
  1231. top.find('dl .' + FORM_EMPTY).removeClass(FORM_EMPTY);
  1232. top.find('dl dd.' + DD_HIDE).removeClass(DD_HIDE);
  1233. top.find('dl dd.' + TEMP).remove();
  1234. //计算ajax数据是否为空, 然后重新请求数据
  1235. if (id && data[id] && data[id].config.isEmpty) {
  1236. this.triggerSearch(top);
  1237. }
  1238. this.changePlaceHolder(top.find('.' + LABEL));
  1239. }
  1240. if (isShow != realShow) {
  1241. var openFun = data[id].config.opened || events.opened[id];
  1242. isShow && openFun && openFun instanceof Function && openFun(id);
  1243. var closeFun = data[id].config.closed || events.closed[id];
  1244. !isShow && closeFun && closeFun instanceof Function && closeFun(id);
  1245. }
  1246. };
  1247. Common.prototype.changePlaceHolder = function (div) {
  1248. //显示于隐藏提示语
  1249. //调整pane模式下的高度
  1250. var title = div.parents('.' + FORM_TITLE);
  1251. title[0] || (title = div.parents('dl').prev());
  1252. if (!title[0]) {
  1253. return;
  1254. }
  1255. var id = div.parents('.' + PNAME).find('dl[xid]').attr('xid');
  1256. if (data[id] && data[id].config.height) {//既然固定高度了, 那就看着办吧
  1257. } else {
  1258. var height = title.find('.' + NAME)[0].clientHeight;
  1259. //title.css('height', (height > 36 ? height + 4 : height) + 'px');
  1260. //如果是layui pane模式, 处理label的高度
  1261. var label = title.parents('.' + PNAME).parent().prev();
  1262. if (label.is('.layui-form-label') && title.parents('.layui-form-pane')[0]) {
  1263. height = height > 36 ? height + 4 : height;
  1264. //title.css('height', height + 'px');
  1265. label.css({
  1266. height: height + 2 + 'px',
  1267. lineHeight: height - 18 + 'px'
  1268. });
  1269. }
  1270. }
  1271. var input = title.find('.' + TDIV + ' input'),
  1272. isShow = !div.find('span:last')[0] && !title.find('.' + INPUT).val();
  1273. if (isShow) {
  1274. var ph = input.attr('back');
  1275. input.removeAttr('back');
  1276. input.attr('placeholder', ph);
  1277. } else {
  1278. var _ph = input.attr('placeholder');
  1279. input.removeAttr('placeholder');
  1280. input.attr('back', _ph);
  1281. }
  1282. };
  1283. Common.prototype.indexOf = function (arr, val) {
  1284. for (var i = 0; i < arr.length; i++) {
  1285. if (arr[i].value == val || arr[i].value == (val ? val.value : val) || arr[i] == val || JSON.stringify(arr[i]) == JSON.stringify(val)) {
  1286. return i;
  1287. }
  1288. }
  1289. return -1;
  1290. };
  1291. Common.prototype.remove = function (arr, val) {
  1292. var idx = this.indexOf(arr, val ? val.value : val);
  1293. if (idx > -1) {
  1294. arr.splice(idx, 1);
  1295. return true;
  1296. }
  1297. return false;
  1298. };
  1299. Common.prototype.selectAll = function (id, isOn, skipDis) {
  1300. var _this14 = this;
  1301. var dl = $('[xid="' + id + '"]');
  1302. if (!dl[0]) {
  1303. return;
  1304. }
  1305. if (dl.find('.xm-select-linkage')[0]) {
  1306. return;
  1307. }
  1308. dl.find('dd[lay-value]:not(.' + FORM_SELECT_TIPS + '):not(.' + THIS + ')' + (skipDis ? ':not(.' + DISABLED + ')' : '')).each(function (index, item) {
  1309. item = $(item);
  1310. var val = _this14.getItem(id, item);
  1311. _this14.handlerLabel(id, dl.find('dd[lay-value="' + val.value + '"]'), true, val, !isOn);
  1312. });
  1313. };
  1314. Common.prototype.removeAll = function (id, isOn, skipDis) {
  1315. var _this15 = this;
  1316. var dl = $('[xid="' + id + '"]');
  1317. if (!dl[0]) {
  1318. return;
  1319. }
  1320. if (dl.find('.xm-select-linkage')[0]) {
  1321. //针对多级联动的处理
  1322. data[id].values.concat([]).forEach(function (item, idx) {
  1323. var vs = item.value.split('/');
  1324. var pid = void 0,
  1325. li = void 0,
  1326. index = 0;
  1327. do {
  1328. pid = vs[index++];
  1329. li = dl.find('.xm-select-linkage-group' + index + ':not(.xm-select-linkage-hide) li[xm-value="' + pid + '"]');
  1330. li.click();
  1331. } while (li.length && pid != undefined);
  1332. });
  1333. return;
  1334. }
  1335. data[id].values.concat([]).forEach(function (item, index) {
  1336. if (skipDis && dl.find('dd[lay-value="' + item.value + '"]').hasClass(DISABLED)) {} else {
  1337. _this15.handlerLabel(id, dl.find('dd[lay-value="' + item.value + '"]'), false, item, !isOn);
  1338. }
  1339. });
  1340. };
  1341. Common.prototype.reverse = function (id, isOn, skipDis) {
  1342. var _this16 = this;
  1343. var dl = $('[xid="' + id + '"]');
  1344. if (!dl[0]) {
  1345. return;
  1346. }
  1347. if (dl.find('.xm-select-linkage')[0]) {
  1348. return;
  1349. }
  1350. dl.find('dd[lay-value]:not(.' + FORM_SELECT_TIPS + ')' + (skipDis ? ':not(.' + DISABLED + ')' : '')).each(function (index, item) {
  1351. item = $(item);
  1352. var val = _this16.getItem(id, item);
  1353. _this16.handlerLabel(id, dl.find('dd[lay-value="' + val.value + '"]'), !item.hasClass(THIS), val, !isOn);
  1354. });
  1355. };
  1356. Common.prototype.skin = function (id) {
  1357. var skins = ['default', 'primary', 'normal', 'warm', 'danger'];
  1358. var skin = skins[Math.floor(Math.random() * skins.length)];
  1359. $('dl[xid="' + id + '"]').parents('.' + PNAME).find('.' + FORM_SELECT).attr('xm-select-skin', skin);
  1360. this.check(id) && this.commonHandler(id, $('dl[xid="' + id + '"]').parents('.' + PNAME).find('.' + LABEL));
  1361. };
  1362. Common.prototype.getPosition = function (e) {
  1363. var x = 0,
  1364. y = 0;
  1365. while (e != null) {
  1366. x += e.offsetLeft;
  1367. y += e.offsetTop;
  1368. e = e.offsetParent;
  1369. }
  1370. return { x: x, y: y };
  1371. };
  1372. Common.prototype.onreset = function () {
  1373. //监听reset按钮, 然后重置多选
  1374. $(document).on('click', '[type=reset]', function (e) {
  1375. $(e.target).parents('form').find('.' + PNAME + ' dl[xid]').each(function (index, item) {
  1376. var id = item.getAttribute('xid'),
  1377. dl = $(item),
  1378. dd = void 0,
  1379. temp = {};
  1380. common.removeAll(id);
  1381. data[id].config.init.forEach(function (val, idx) {
  1382. if (val && (!temp[val] || data[id].config.repeat) && (dd = dl.find('dd[lay-value="' + val.value + '"]'))[0]) {
  1383. common.handlerLabel(id, dd, true);
  1384. temp[val] = 1;
  1385. }
  1386. });
  1387. });
  1388. });
  1389. };
  1390. Common.prototype.bindEvent = function (name, id, fun) {
  1391. if (id && id instanceof Function) {
  1392. fun = id;
  1393. id = null;
  1394. }
  1395. if (fun && fun instanceof Function) {
  1396. if (!id) {
  1397. $.each(data, function (id, val) {
  1398. data[id] ? data[id].config[name] = fun : events[name][id] = fun;
  1399. });
  1400. } else {
  1401. data[id] ? (data[id].config[name] = fun, delete events[name][id]) : events[name][id] = fun;
  1402. }
  1403. }
  1404. };
  1405. Common.prototype.check = function (id, notAutoRender) {
  1406. if ($('dl[xid="' + id + '"]').length) {
  1407. return true;
  1408. } else if ($('select[xm-select="' + id + '"]').length) {
  1409. if (!notAutoRender) {
  1410. this.render(id, $('select[xm-select="' + id + '"]'));
  1411. return true;
  1412. }
  1413. } else {
  1414. delete data[id];
  1415. return false;
  1416. }
  1417. };
  1418. Common.prototype.render = function (id, select) {
  1419. common.init(select);
  1420. common.one($('dl[xid="' + id + '"]').parents('.' + PNAME));
  1421. common.initVal(id);
  1422. };
  1423. Common.prototype.log = function (obj) {
  1424. console.log(obj);
  1425. };
  1426. var Select4 = function Select4() {
  1427. this.v = v;
  1428. this.render();
  1429. };
  1430. var common = new Common();
  1431. Select4.prototype.value = function (id, type, isAppend) {
  1432. if (typeof id != 'string') {
  1433. return [];
  1434. }
  1435. var fs = data[id];
  1436. if (!common.check(id)) {
  1437. return [];
  1438. }
  1439. if (typeof type == 'string' || type == undefined) {
  1440. var arr = fs.values.concat([]) || [];
  1441. if (type == 'val') {
  1442. return arr.map(function (val) {
  1443. return val.value;
  1444. });
  1445. }
  1446. if (type == 'valStr') {
  1447. return arr.map(function (val) {
  1448. return val.value;
  1449. }).join(',');
  1450. }
  1451. if (type == 'name') {
  1452. return arr.map(function (val) {
  1453. return val.name;
  1454. });
  1455. }
  1456. if (type == 'nameStr') {
  1457. return arr.map(function (val) {
  1458. return val.name;
  1459. }).join(',');
  1460. }
  1461. return arr;
  1462. }
  1463. if (common.isArray(type)) {
  1464. var dl = $('[xid="' + id + '"]'),
  1465. temp = {},
  1466. dd = void 0,
  1467. isAdd = true;
  1468. if (isAppend == false) {
  1469. //删除传入的数组
  1470. isAdd = false;
  1471. } else if (isAppend == true) {
  1472. //追加模式
  1473. isAdd = true;
  1474. } else {
  1475. //删除原有的数据
  1476. common.removeAll(id);
  1477. }
  1478. if (isAdd) {
  1479. fs.values.forEach(function (val, index) {
  1480. temp[val.value] = 1;
  1481. });
  1482. }
  1483. type.forEach(function (val, index) {
  1484. if (val && (!temp[val] || fs.config.repeat)) {
  1485. if ((dd = dl.find('dd[lay-value="' + val + '"]'))[0]) {
  1486. common.handlerLabel(id, dd, isAdd, null, true);
  1487. temp[val] = 1;
  1488. } else {
  1489. var name = common.valToName(id, val);
  1490. if (name) {
  1491. common.handlerLabel(id, dd, isAdd, common.getItem(id, val), true);
  1492. temp[val] = 1;
  1493. }
  1494. }
  1495. }
  1496. });
  1497. }
  1498. };
  1499. Select4.prototype.on = function (id, fun, isEnd) {
  1500. common.bindEvent(isEnd ? 'endOn' : 'on', id, fun);
  1501. return this;
  1502. };
  1503. Select4.prototype.filter = function (id, fun) {
  1504. common.bindEvent('filter', id, fun);
  1505. return this;
  1506. };
  1507. Select4.prototype.maxTips = function (id, fun) {
  1508. common.bindEvent('maxTips', id, fun);
  1509. return this;
  1510. };
  1511. Select4.prototype.opened = function (id, fun) {
  1512. common.bindEvent('opened', id, fun);
  1513. return this;
  1514. };
  1515. Select4.prototype.closed = function (id, fun) {
  1516. common.bindEvent('closed', id, fun);
  1517. return this;
  1518. };
  1519. Select4.prototype.config = function (id, config, isJson) {
  1520. if (id && (typeof id === 'undefined' ? 'undefined' : _typeof(id)) == 'object') {
  1521. isJson = config == true;
  1522. config = id;
  1523. id = null;
  1524. }
  1525. if (config && (typeof config === 'undefined' ? 'undefined' : _typeof(config)) == 'object') {
  1526. if (isJson) {
  1527. config.header || (config.header = {});
  1528. config.header['Content-Type'] = 'application/json; charset=UTF-8';
  1529. config.dataType = 'json';
  1530. }
  1531. id ? (ajaxs[id] = $.extend(true, {}, ajaxs[id] || ajax, config), !common.check(id) && this.render(id), data[id] && config.direction && (data[id].config.direction = config.direction), data[id] && config.clearInput && (data[id].config.clearInput = true), config.searchUrl && data[id] && common.triggerSearch($('.' + PNAME + ' dl[xid="' + id + '"]').parents('.' + FORM_SELECT), true)) : ($.extend(true, ajax, config), $.each(ajaxs, function (key, item) {
  1532. $.extend(true, item, config);
  1533. }));
  1534. }
  1535. return this;
  1536. };
  1537. Select4.prototype.render = function (id, options) {
  1538. var _ref2;
  1539. if (id && (typeof id === 'undefined' ? 'undefined' : _typeof(id)) == 'object') {
  1540. options = id;
  1541. id = null;
  1542. }
  1543. var config = options ? (_ref2 = {
  1544. init: options.init,
  1545. disabled: options.disabled,
  1546. max: options.max,
  1547. isSearch: options.isSearch,
  1548. searchUrl: options.searchUrl,
  1549. isCreate: options.isCreate,
  1550. radio: options.radio,
  1551. skin: options.skin,
  1552. direction: options.direction,
  1553. height: options.height,
  1554. formname: options.formname,
  1555. layverify: options.layverify,
  1556. layverType: options.layverType,
  1557. showCount: options.showCount,
  1558. placeholder: options.placeholder,
  1559. create: options.create,
  1560. filter: options.filter,
  1561. maxTips: options.maxTips,
  1562. on: options.on
  1563. }, _defineProperty(_ref2, 'on', options.on), _defineProperty(_ref2, 'opened', options.opened), _defineProperty(_ref2, 'closed', options.closed), _defineProperty(_ref2, 'template', options.template), _defineProperty(_ref2, 'clearInput', options.clearInput), _ref2) : {};
  1564. options && options.searchType != undefined && (config.searchType = options.searchType == 'dl' ? 1 : 0);
  1565. if (id) {
  1566. fsConfigs[id] = {};
  1567. $.extend(fsConfigs[id], data[id] ? data[id].config : {}, config);
  1568. } else {
  1569. $.extend(fsConfig, config);
  1570. }
  1571. ($('select[' + NAME + '="' + id + '"]')[0] ? $('select[' + NAME + '="' + id + '"]') : $('select[' + NAME + ']')).each(function (index, select) {
  1572. var sid = select.getAttribute(NAME);
  1573. common.render(sid, select);
  1574. setTimeout(function () {
  1575. return common.setHidnVal(sid, $('select[xm-select="' + sid + '"] + div.' + PNAME + ' .' + LABEL));
  1576. }, 10);
  1577. });
  1578. return this;
  1579. };
  1580. Select4.prototype.disabled = function (id) {
  1581. var target = {};
  1582. id ? common.check(id) && (target[id] = data[id]) : target = data;
  1583. $.each(target, function (key, val) {
  1584. $('dl[xid="' + key + '"]').prev().addClass(DIS);
  1585. });
  1586. return this;
  1587. };
  1588. Select4.prototype.undisabled = function (id) {
  1589. var target = {};
  1590. id ? common.check(id) && (target[id] = data[id]) : target = data;
  1591. $.each(target, function (key, val) {
  1592. $('dl[xid="' + key + '"]').prev().removeClass(DIS);
  1593. });
  1594. return this;
  1595. };
  1596. Select4.prototype.data = function (id, type, config) {
  1597. if (!id || !type || !config) {
  1598. common.log('id: ' + id + ' param error !!!');
  1599. return this;
  1600. }
  1601. if (!common.check(id)) {
  1602. common.log('id: ' + id + ' not render !!!');
  1603. return this;
  1604. }
  1605. this.value(id, []);
  1606. this.config(id, config);
  1607. if (type == 'local') {
  1608. common.renderData(id, config.arr, config.linkage == true, config.linkageWidth ? config.linkageWidth : '100');
  1609. } else if (type == 'server') {
  1610. common.ajax(id, config.url, config.keyword, config.linkage == true, config.linkageWidth ? config.linkageWidth : '100');
  1611. }
  1612. return this;
  1613. };
  1614. Select4.prototype.btns = function (id, btns, config) {
  1615. if (id && common.isArray(id)) {
  1616. btns = id;
  1617. id = null;
  1618. }
  1619. if (!btns || !common.isArray(btns)) {
  1620. return this;
  1621. };
  1622. var target = {};
  1623. id ? common.check(id) && (target[id] = data[id]) : target = data;
  1624. btns = btns.map(function (obj) {
  1625. if (typeof obj == 'string') {
  1626. if (obj == 'select') {
  1627. return quickBtns[0];
  1628. }
  1629. if (obj == 'remove') {
  1630. return quickBtns[1];
  1631. }
  1632. if (obj == 'reverse') {
  1633. return quickBtns[2];
  1634. }
  1635. if (obj == 'skin') {
  1636. return quickBtns[3];
  1637. }
  1638. }
  1639. return obj;
  1640. });
  1641. $.each(target, function (key, val) {
  1642. val.config.btns = btns;
  1643. var dd = $('dl[xid="' + key + '"]').find('.' + FORM_SELECT_TIPS + ':first');
  1644. if (btns.length) {
  1645. var show = config && config.show && (config.show == 'name' || config.show == 'icon') ? config.show : '';
  1646. var html = common.renderBtns(key, show, config && config.space ? config.space : '30px');
  1647. dd.html(html);
  1648. } else {
  1649. var pcInput = dd.parents('.' + FORM_SELECT).find('.' + TDIV + ' input');
  1650. var _html = pcInput.attr('placeholder') || pcInput.attr('back');
  1651. dd.html(_html);
  1652. dd.removeAttr('style');
  1653. }
  1654. });
  1655. return this;
  1656. };
  1657. Select4.prototype.search = function (id, val) {
  1658. if (id && common.check(id)) {
  1659. ajaxs[id] = $.extend(true, {}, ajaxs[id] || ajax, {
  1660. first: true,
  1661. searchVal: val
  1662. });
  1663. common.triggerSearch($('dl[xid="' + id + '"]').parents('.' + FORM_SELECT), true);
  1664. }
  1665. return this;
  1666. };
  1667. Select4.prototype.replace = function (id, type, config) {
  1668. var _this17 = this;
  1669. if (!id || !type || !config) {
  1670. common.log('id: ' + id + ' param error !!!');
  1671. return this;
  1672. }
  1673. if (!common.check(id, true)) {
  1674. common.log('id: ' + id + ' not render !!!');
  1675. return this;
  1676. }
  1677. var oldVals = this.value(id, 'val');
  1678. this.value(id, []);
  1679. this.config(id, config);
  1680. if (type == 'local') {
  1681. common.renderData(id, config.arr, config.linkage == true, config.linkageWidth ? config.linkageWidth : '100', false, true);
  1682. this.value(id, oldVals, true);
  1683. } else if (type == 'server') {
  1684. common.ajax(id, config.url, config.keyword, config.linkage == true, config.linkageWidth ? config.linkageWidth : '100', false, function (id) {
  1685. _this17.value(id, oldVals, true);
  1686. }, true);
  1687. }
  1688. };
  1689. return new Select4();
  1690. });