formselects.js 73 KB

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