formselects.js 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820
  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. if (searchUrl.indexOf('{') != -1) {
  406. var start = searchUrl.split('{');
  407. var end = start[1].split('}');
  408. searchUrl = start[0] + end[1];
  409. if (end[0].indexOf(',')) {
  410. var param = end[0].split(',');
  411. } else {
  412. var param = [];
  413. param[0] = end[0];
  414. }
  415. for (var i in param) {
  416. if (typeof(param[i]) == 'string') {
  417. var e = $('.update_'+param[i]);
  418. if (e.length > 1) {
  419. e.each(function() {
  420. if ($(this).get(0).checked) {
  421. ajaxData[param[i]] = $(this).val();
  422. }
  423. })
  424. } else {
  425. ajaxData[param[i]] = e.val();
  426. }
  427. }
  428. }
  429. }
  430. //是否需要对ajax添加随机时间
  431. //ajaxData['_'] = Date.now();
  432. $.ajax({
  433. type: ajaxConfig.type,
  434. headers: ajaxConfig.header,
  435. url: searchUrl,
  436. data: ajaxConfig.dataType == 'json' ? JSON.stringify(ajaxData) : ajaxData,
  437. success: function success(res) {
  438. if (typeof res == 'string') {
  439. res = JSON.parse(res);
  440. }
  441. ajaxConfig.beforeSuccess && ajaxConfig.beforeSuccess instanceof Function && (res = ajaxConfig.beforeSuccess(id, searchUrl, inputValue, res));
  442. if (_this5.isArray(res)) {
  443. var newRes = {};
  444. newRes[ajaxConfig.response.statusName] = ajaxConfig.response.statusCode;
  445. newRes[ajaxConfig.response.msgName] = "";
  446. newRes[ajaxConfig.response.dataName] = res;
  447. res = newRes;
  448. }
  449. if (res[ajaxConfig.response.statusName] != ajaxConfig.response.statusCode) {
  450. reElem.find('dd.' + FORM_NONE).addClass(FORM_EMPTY).text(res[ajaxConfig.response.msgName]);
  451. } else {
  452. reElem.find('dd.' + FORM_NONE).removeClass(FORM_EMPTY);
  453. _this5.renderData(id, res[ajaxConfig.response.dataName], isLinkage, linkageWidth, isSearch, isReplace);
  454. data[id].config.isEmpty = res[ajaxConfig.response.dataName].length == 0;
  455. }
  456. successCallback && successCallback(id);
  457. ajaxConfig.success && ajaxConfig.success instanceof Function && ajaxConfig.success(id, searchUrl, inputValue, res);
  458. },
  459. error: function error(err) {
  460. reElem.find('dd[lay-value]:not(.' + FORM_SELECT_TIPS + ')').remove();
  461. reElem.find('dd.' + FORM_NONE).addClass(FORM_EMPTY).text('服务异常');
  462. ajaxConfig.error && ajaxConfig.error instanceof Function && ajaxConfig.error(id, searchUrl, inputValue, err);
  463. }
  464. });
  465. };
  466. Common.prototype.renderData = function (id, dataArr, linkage, linkageWidth, isSearch, isReplace) {
  467. var _this6 = this;
  468. if (linkage) {
  469. //渲染多级联动
  470. this.renderLinkage(id, dataArr, linkageWidth);
  471. return;
  472. }
  473. if (isReplace) {
  474. this.renderReplace(id, dataArr);
  475. return;
  476. }
  477. var reElem = $('.' + PNAME + ' dl[xid="' + id + '"]').parents('.' + FORM_SELECT);
  478. var ajaxConfig = ajaxs[id] ? ajaxs[id] : ajax;
  479. var pcInput = reElem.find('.' + TDIV + ' input');
  480. dataArr = this.exchangeData(id, dataArr);
  481. var values = [];
  482. reElem.find('dl').html(this.renderSelect(id, pcInput.attr('placeholder') || pcInput.attr('back'), dataArr.map(function (item) {
  483. var itemVal = $.extend({}, item, {
  484. innerHTML: item[ajaxConfig.keyName],
  485. value: item[ajaxConfig.keyVal],
  486. sel: item[ajaxConfig.keySel],
  487. disabled: item[ajaxConfig.keyDis],
  488. type: item.type,
  489. name: item[ajaxConfig.keyName]
  490. });
  491. if (itemVal.sel) {
  492. values.push(itemVal);
  493. }
  494. return itemVal;
  495. })));
  496. var label = reElem.find('.' + LABEL);
  497. var dl = reElem.find('dl[xid]');
  498. if (isSearch) {
  499. //如果是远程搜索, 这里需要判重
  500. var oldVal = data[id].values;
  501. oldVal.forEach(function (item, index) {
  502. dl.find('dd[lay-value="' + item.value + '"]').addClass(THIS);
  503. });
  504. values.forEach(function (item, index) {
  505. if (_this6.indexOf(oldVal, item) == -1) {
  506. _this6.addLabel(id, label, item);
  507. dl.find('dd[lay-value="' + item.value + '"]').addClass(THIS);
  508. oldVal.push(item);
  509. }
  510. });
  511. } else {
  512. values.forEach(function (item, index) {
  513. _this6.addLabel(id, label, item);
  514. dl.find('dd[lay-value="' + item.value + '"]').addClass(THIS);
  515. });
  516. data[id].values = values;
  517. }
  518. this.commonHandler(id, label);
  519. };
  520. Common.prototype.renderLinkage = function (id, dataArr, linkageWidth) {
  521. var result = [],
  522. index = 0,
  523. temp = { "0": dataArr },
  524. ajaxConfig = ajaxs[id] ? ajaxs[id] : ajax;
  525. db[id] = {};
  526. var _loop = function _loop() {
  527. var group = result[index++] = [],
  528. _temp = temp;
  529. temp = {};
  530. $.each(_temp, function (pid, arr) {
  531. $.each(arr, function (idx, item) {
  532. var val = {
  533. pid: pid,
  534. name: item[ajaxConfig.keyName],
  535. value: item[ajaxConfig.keyVal]
  536. };
  537. db[id][val.value] = $.extend(item, val);
  538. group.push(val);
  539. var children = item[ajaxConfig.keyChildren];
  540. if (children && children.length) {
  541. temp[val.value] = children;
  542. }
  543. });
  544. });
  545. };
  546. do {
  547. _loop();
  548. } while (Object.getOwnPropertyNames(temp).length);
  549. var reElem = $('.' + PNAME + ' dl[xid="' + id + '"]').parents('.' + FORM_SELECT);
  550. var html = ['<div class="xm-select-linkage">'];
  551. $.each(result, function (idx, arr) {
  552. 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' : '') + '">'];
  553. $.each(arr, function (idx2, item) {
  554. var span = '<li title="' + item.name + '" pid="' + item.pid + '" xm-value="' + item.value + '"><span>' + item.name + '</span></li>';
  555. groupDiv.push(span);
  556. });
  557. groupDiv.push('</div>');
  558. html = html.concat(groupDiv);
  559. });
  560. html.push('<div style="clear: both; height: 288px;"></div>');
  561. html.push('</div>');
  562. reElem.find('dl').html(html.join(''));
  563. reElem.find('.' + INPUT).css('display', 'none'); //联动暂时不支持搜索
  564. };
  565. Common.prototype.renderReplace = function (id, dataArr) {
  566. var _this7 = this;
  567. var dl = $('.' + PNAME + ' dl[xid="' + id + '"]');
  568. var ajaxConfig = ajaxs[id] ? ajaxs[id] : ajax;
  569. dataArr = this.exchangeData(id, dataArr);
  570. db[id] = dataArr;
  571. var html = dataArr.map(function (item) {
  572. var itemVal = $.extend({}, item, {
  573. innerHTML: item[ajaxConfig.keyName],
  574. value: item[ajaxConfig.keyVal],
  575. sel: item[ajaxConfig.keySel],
  576. disabled: item[ajaxConfig.keyDis],
  577. type: item.type,
  578. name: item[ajaxConfig.keyName]
  579. });
  580. return _this7.createDD(id, itemVal);
  581. }).join('');
  582. dl.find('dd:not(.' + FORM_SELECT_TIPS + '),dt:not([style])').remove();
  583. dl.find('dt[style]').after($(html));
  584. };
  585. Common.prototype.exchangeData = function (id, arr) {
  586. //这里处理树形结构
  587. var ajaxConfig = ajaxs[id] ? ajaxs[id] : ajax;
  588. var childrenName = ajaxConfig['keyChildren'];
  589. var disabledName = ajaxConfig['keyDis'];
  590. db[id] = {};
  591. var result = this.getChildrenList(arr, childrenName, disabledName, [], false);
  592. return result;
  593. };
  594. Common.prototype.getChildrenList = function (arr, childrenName, disabledName, pid, disabled) {
  595. var result = [],
  596. offset = 0;
  597. for (var a = 0; a < arr.length; a++) {
  598. var item = arr[a];
  599. if (item.type && item.type == 'optgroup') {
  600. result.push(item);
  601. continue;
  602. } else {
  603. offset++;
  604. }
  605. var parentIds = pid.concat([]);
  606. parentIds.push(offset - 1 + '_E');
  607. item[FORM_TEAM_PID] = JSON.stringify(parentIds);
  608. item[disabledName] = item[disabledName] || disabled;
  609. result.push(item);
  610. var child = item[childrenName];
  611. if (child && common.isArray(child) && child.length) {
  612. item['XM_TREE_FOLDER'] = true;
  613. var pidArr = parentIds.concat([]);
  614. var childResult = this.getChildrenList(child, childrenName, disabledName, pidArr, item[disabledName]);
  615. result = result.concat(childResult);
  616. }
  617. }
  618. return result;
  619. };
  620. Common.prototype.create = function (id, isCreate, inputValue) {
  621. if (isCreate && inputValue) {
  622. var fs = data[id],
  623. dl = $('[xid="' + id + '"]'),
  624. tips = dl.find('dd.' + FORM_SELECT_TIPS + '.' + FORM_DL_INPUT),
  625. tdd = null,
  626. temp = dl.find('dd.' + TEMP);
  627. dl.find('dd:not(.' + FORM_SELECT_TIPS + '):not(.' + TEMP + ')').each(function (index, item) {
  628. if (inputValue == $(item).find('span').attr('name')) {
  629. tdd = item;
  630. }
  631. });
  632. if (!tdd) {
  633. //如果不存在, 则创建
  634. var val = fs.config.create(id, inputValue);
  635. if (temp[0]) {
  636. temp.attr('lay-value', val);
  637. temp.find('span').text(inputValue);
  638. temp.find('span').attr("name", inputValue);
  639. temp.removeClass(DD_HIDE);
  640. } else {
  641. tips.after($(this.createDD(id, {
  642. name: inputValue,
  643. innerHTML: inputValue,
  644. value: val
  645. }, TEMP + ' ' + CREATE_LONG)));
  646. }
  647. }
  648. } else {
  649. $('[xid=' + id + '] dd.' + TEMP).remove();
  650. }
  651. };
  652. Common.prototype.createDD = function (id, item, clz) {
  653. var ajaxConfig = ajaxs[id] ? ajaxs[id] : ajax;
  654. var name = $.trim(item.innerHTML);
  655. db[id][item.value] = $(item).is('option') ? item = function () {
  656. var resultItem = {};
  657. resultItem[ajaxConfig.keyName] = name;
  658. resultItem[ajaxConfig.keyVal] = item.value;
  659. resultItem[ajaxConfig.keyDis] = item.disabled;
  660. return resultItem;
  661. }() : item;
  662. var template = data[id].config.template(id, item);
  663. var pid = item[FORM_TEAM_PID];
  664. pid ? pid = JSON.parse(pid) : pid = [-1];
  665. var attr = pid[0] == -1 ? '' : 'tree-id="' + pid.join('-') + '" tree-folder="' + !!item['XM_TREE_FOLDER'] + '"';
  666. 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>';
  667. };
  668. Common.prototype.createQuickBtn = function (obj, right) {
  669. 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>';
  670. };
  671. Common.prototype.renderBtns = function (id, show, right) {
  672. var _this8 = this;
  673. var quickBtn = [];
  674. var dl = $('dl[xid="' + id + '"]');
  675. quickBtn.push('<div class="' + CZ_GROUP + '" show="' + show + '" style="max-width: ' + (dl.prev().width() - 54) + 'px;">');
  676. $.each(data[id].config.btns, function (index, item) {
  677. quickBtn.push(_this8.createQuickBtn(item, right));
  678. });
  679. quickBtn.push('</div>');
  680. quickBtn.push(this.createQuickBtn({ icon: 'xm-iconfont icon-caidan', name: '' }));
  681. return quickBtn.join('');
  682. };
  683. Common.prototype.renderSelect = function (id, tips, select) {
  684. var _this9 = this;
  685. db[id] = {};
  686. var arr = [];
  687. if (data[id].config.btns.length) {
  688. setTimeout(function () {
  689. var dl = $('dl[xid="' + id + '"]');
  690. dl.parents('.' + FORM_SELECT).attr(SEARCH_TYPE, data[id].config.searchType);
  691. dl.find('.' + CZ_GROUP).css('max-width', dl.prev().width() - 54 + 'px');
  692. }, 10);
  693. 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(''));
  694. } else {
  695. arr.push('<dd lay-value="" class="' + FORM_SELECT_TIPS + '">' + tips + '</dd>');
  696. }
  697. if (this.isArray(select)) {
  698. $(select).each(function (index, item) {
  699. if (item) {
  700. if (item.type && item.type === 'optgroup') {
  701. arr.push('<dt>' + item.name + '</dt>');
  702. } else {
  703. arr.push(_this9.createDD(id, item));
  704. }
  705. }
  706. });
  707. } else {
  708. $(select).find('*').each(function (index, item) {
  709. if (item.tagName.toLowerCase() == 'option' && index == 0 && !item.value) {
  710. return;
  711. }
  712. if (item.tagName.toLowerCase() === 'optgroup') {
  713. arr.push('<dt>' + item.label + '</dt>');
  714. } else {
  715. arr.push(_this9.createDD(id, item));
  716. }
  717. });
  718. }
  719. arr.push('<dt style="display:none;"> </dt>');
  720. arr.push('<dd class="' + FORM_SELECT_TIPS + ' ' + FORM_NONE + ' ' + (arr.length === 2 ? FORM_EMPTY : '') + '">\u6CA1\u6709\u9009\u9879</dd>');
  721. return arr.join('');
  722. };
  723. Common.prototype.on = function () {
  724. var _this10 = this;
  725. //事件绑定
  726. this.one();
  727. $(document).on('click', function (e) {
  728. if (!$(e.target).parents('.' + FORM_TITLE)[0]) {
  729. //清空input中的值
  730. $('.' + PNAME + ' dl .' + DD_HIDE).removeClass(DD_HIDE);
  731. $('.' + PNAME + ' dl dd.' + FORM_EMPTY).removeClass(FORM_EMPTY);
  732. $('.' + PNAME + ' dl dd.' + TEMP).remove();
  733. $.each(data, function (key, fs) {
  734. _this10.clearInput(key);
  735. if (!fs.values.length) {
  736. _this10.changePlaceHolder($('div[FS_ID="' + key + '"] .' + LABEL));
  737. }
  738. });
  739. }
  740. $('.' + PNAME + ' .' + FORM_SELECTED).each(function (index, item) {
  741. _this10.changeShow($(item).find('.' + FORM_TITLE), false);
  742. });
  743. });
  744. };
  745. Common.prototype.calcLabelLeft = function (label, w, call) {
  746. var pos = this.getPosition(label[0]);
  747. pos.y = pos.x + label[0].clientWidth;
  748. var left = label[0].offsetLeft;
  749. if (!label.find('span').length) {
  750. left = 0;
  751. } else if (call) {
  752. //校正归位
  753. var span = label.find('span:last');
  754. span.css('display') == 'none' ? span = span.prev()[0] : span = span[0];
  755. var spos = this.getPosition(span);
  756. spos.y = spos.x + span.clientWidth;
  757. if (spos.y > pos.y) {
  758. left = left - (spos.y - pos.y) - 5;
  759. } else {
  760. left = 0;
  761. }
  762. } else {
  763. if (w < 0) {
  764. var _span = label.find(':last');
  765. _span.css('display') == 'none' ? _span = _span.prev()[0] : _span = _span[0];
  766. var _spos = this.getPosition(_span);
  767. _spos.y = _spos.x + _span.clientWidth;
  768. if (_spos.y > pos.y) {
  769. left -= 10;
  770. }
  771. } else {
  772. if (left < 0) {
  773. left += 10;
  774. }
  775. if (left > 0) {
  776. left = 0;
  777. }
  778. }
  779. }
  780. label.css('left', left + 'px');
  781. };
  782. Common.prototype.one = function (target) {
  783. var _this11 = this;
  784. //一次性事件绑定
  785. $(target ? target : document).off('click', '.' + FORM_TITLE).on('click', '.' + FORM_TITLE, function (e) {
  786. var othis = $(e.target),
  787. title = othis.is(FORM_TITLE) ? othis : othis.parents('.' + FORM_TITLE),
  788. dl = title.next(),
  789. id = dl.attr('xid');
  790. //清空非本select的input val
  791. $('dl[xid]').not(dl).each(function (index, item) {
  792. _this11.clearInput($(item).attr('xid'));
  793. });
  794. $('dl[xid]').not(dl).find('dd.' + DD_HIDE).removeClass(DD_HIDE);
  795. //如果是disabled select
  796. if (title.hasClass(DIS)) {
  797. return false;
  798. }
  799. //如果点击的是右边的三角或者只读的input
  800. if (othis.is('.' + SANJIAO) || othis.is('.' + INPUT + '[readonly]')) {
  801. _this11.changeShow(title, !title.parents('.' + FORM_SELECT).hasClass(FORM_SELECTED));
  802. return false;
  803. }
  804. //如果点击的是input的右边, focus一下
  805. if (title.find('.' + INPUT + ':not(readonly)')[0]) {
  806. var input = title.find('.' + INPUT),
  807. epos = { x: e.pageX, y: e.pageY },
  808. pos = _this11.getPosition(title[0]),
  809. width = title.width();
  810. while (epos.x > pos.x) {
  811. if ($(document.elementFromPoint(epos.x, epos.y)).is(input)) {
  812. input.focus();
  813. _this11.changeShow(title, true);
  814. return false;
  815. }
  816. epos.x -= 50;
  817. }
  818. }
  819. //如果点击的是可搜索的input
  820. if (othis.is('.' + INPUT)) {
  821. _this11.changeShow(title, true);
  822. return false;
  823. }
  824. //如果点击的是x按钮
  825. if (othis.is('i[fsw="' + NAME + '"]')) {
  826. var val = _this11.getItem(id, othis),
  827. dd = dl.find('dd[lay-value=\'' + val.value + '\']');
  828. if (dd.hasClass(DISABLED)) {
  829. //如果是disabled状态, 不可选, 不可删
  830. return false;
  831. }
  832. _this11.handlerLabel(id, dd, false, val);
  833. return false;
  834. }
  835. _this11.changeShow(title, !title.parents('.' + FORM_SELECT).hasClass(FORM_SELECTED));
  836. return false;
  837. });
  838. $(target ? target : document).off('click', 'dl.' + DL).on('click', 'dl.' + DL, function (e) {
  839. var othis = $(e.target);
  840. if (othis.is('.' + LINKAGE) || othis.parents('.' + LINKAGE)[0]) {
  841. //linkage的处理
  842. othis = othis.is('li') ? othis : othis.parents('li[xm-value]');
  843. var _group = othis.parents('.xm-select-linkage-group'),
  844. _id = othis.parents('dl').attr('xid');
  845. if (!_id) {
  846. return false;
  847. }
  848. //激活li
  849. _group.find('.xm-select-active').removeClass('xm-select-active');
  850. othis.addClass('xm-select-active');
  851. //激活下一个group, 激活前显示对应数据
  852. _group.nextAll('.xm-select-linkage-group').addClass('xm-select-linkage-hide');
  853. var nextGroup = _group.next('.xm-select-linkage-group');
  854. nextGroup.find('li').addClass('xm-select-linkage-hide');
  855. nextGroup.find('li[pid="' + othis.attr('xm-value') + '"]').removeClass('xm-select-linkage-hide');
  856. //如果没有下一个group, 或没有对应的值
  857. if (!nextGroup[0] || nextGroup.find('li:not(.xm-select-linkage-hide)').length == 0) {
  858. var vals = [],
  859. index = 0,
  860. isAdd = !othis.hasClass('xm-select-this');
  861. if (data[_id].config.radio) {
  862. othis.parents('.xm-select-linkage').find('.xm-select-this').removeClass('xm-select-this');
  863. }
  864. do {
  865. vals[index++] = {
  866. name: othis.find('span').text(),
  867. value: othis.attr('xm-value')
  868. };
  869. othis = othis.parents('.xm-select-linkage-group').prev().find('li[xm-value="' + othis.attr('pid') + '"]');
  870. } while (othis.length);
  871. vals.reverse();
  872. var val = {
  873. name: vals.map(function (item) {
  874. return item.name;
  875. }).join('/'),
  876. value: vals.map(function (item) {
  877. return item.value;
  878. }).join('/')
  879. };
  880. _this11.handlerLabel(_id, null, isAdd, val);
  881. } else {
  882. nextGroup.removeClass('xm-select-linkage-hide');
  883. }
  884. return false;
  885. }
  886. if (othis.is('dl')) {
  887. return false;
  888. }
  889. if (othis.is('dt')) {
  890. othis.nextUntil('dt').each(function (index, item) {
  891. item = $(item);
  892. if (item.hasClass(DISABLED) || item.hasClass(THIS)) {} else {
  893. item.find('i:not(.icon-expand)').click();
  894. }
  895. });
  896. return false;
  897. }
  898. var dd = othis.is('dd') ? othis : othis.parents('dd');
  899. var id = dd.parent('dl').attr('xid');
  900. if (dd.hasClass(DISABLED)) {
  901. //被禁用选项的处理
  902. return false;
  903. }
  904. //菜单功效
  905. if (othis.is('i.icon-caidan')) {
  906. var opens = [],
  907. closes = [];
  908. othis.parents('dl').find('dd[tree-folder="true"]').each(function (index, item) {
  909. $(item).attr('xm-tree-hidn') == undefined ? opens.push(item) : closes.push(item);
  910. });
  911. var arr = closes.length ? closes : opens;
  912. arr.forEach(function (item) {
  913. return item.click();
  914. });
  915. return false;
  916. }
  917. //树状结构的选择
  918. var treeId = dd.attr('tree-id');
  919. if (treeId) {
  920. //忽略右边的图标
  921. if (othis.is('i:not(.icon-expand)')) {
  922. _this11.handlerLabel(id, dd, !dd.hasClass(THIS));
  923. return false;
  924. }
  925. var ajaxConfig = ajaxs[id] || ajax;
  926. var treeConfig = ajaxConfig.tree;
  927. var childrens = dd.nextAll('dd[tree-id^="' + treeId + '"]');
  928. if (childrens && childrens.length) {
  929. var len = childrens[0].clientHeight;
  930. 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) {
  931. return $(item).attr('tree-id').split('-').length - 1 == treeId.split('-').length;
  932. }));
  933. childrens.animate({
  934. height: len
  935. }, 150);
  936. return false;
  937. } else {
  938. if (treeConfig.nextClick && treeConfig.nextClick instanceof Function) {
  939. treeConfig.nextClick(id, _this11.getItem(id, dd), function (res) {
  940. if (!res || !res.length) {
  941. _this11.handlerLabel(id, dd, !dd.hasClass(THIS));
  942. } else {
  943. dd.attr('tree-folder', 'true');
  944. var ddChilds = [];
  945. res.forEach(function (item, idx) {
  946. item.innerHTML = item[ajaxConfig.keyName];
  947. item[FORM_TEAM_PID] = JSON.stringify(treeId.split('-').concat([idx]));
  948. ddChilds.push(_this11.createDD(id, item));
  949. db[id][item[ajaxConfig.keyVal]] = item;
  950. });
  951. dd.after(ddChilds.join(''));
  952. }
  953. });
  954. return false;
  955. }
  956. }
  957. }
  958. if (dd.hasClass(FORM_SELECT_TIPS)) {
  959. //tips的处理
  960. var btn = othis.is('.' + CZ) ? othis : othis.parents('.' + CZ);
  961. if (!btn[0]) {
  962. return false;
  963. }
  964. var method = btn.attr('method');
  965. var obj = data[id].config.btns.filter(function (bean) {
  966. return bean.name == method;
  967. })[0];
  968. obj && obj.click && obj.click instanceof Function && obj.click(id, _this11);
  969. return false;
  970. }
  971. _this11.handlerLabel(id, dd, !dd.hasClass(THIS));
  972. return false;
  973. });
  974. };
  975. Common.prototype.addTreeHeight = function (dd, len) {
  976. var _this12 = this;
  977. var treeId = dd.attr('tree-id');
  978. var childrens = dd.nextAll('dd[tree-id^="' + treeId + '"]');
  979. if (childrens.length) {
  980. dd.append('<i class="xm-iconfont icon-expand"></i>');
  981. dd.attr('xm-tree-hidn', len);
  982. childrens.each(function (index, item) {
  983. var that = $(item);
  984. _this12.addTreeHeight(that, len);
  985. });
  986. }
  987. };
  988. var db = {};
  989. Common.prototype.getItem = function (id, value) {
  990. if (value instanceof $) {
  991. if (value.is('i[fsw="' + NAME + '"]')) {
  992. var span = value.parent();
  993. return db[id][value] || {
  994. name: span.find('font').text(),
  995. value: span.attr('value')
  996. };
  997. }
  998. var val = value.attr('lay-value');
  999. return !db[id][val] ? db[id][val] = {
  1000. name: value.find('span[name]').attr('name'),
  1001. value: val
  1002. } : db[id][val];
  1003. } else if (typeof value == 'string' && value.indexOf('/') != -1) {
  1004. return db[id][value] || {
  1005. name: this.valToName(id, value),
  1006. value: value
  1007. };
  1008. }
  1009. return db[id][value];
  1010. };
  1011. Common.prototype.linkageAdd = function (id, val) {
  1012. var dl = $('dl[xid="' + id + '"]');
  1013. dl.find('.xm-select-active').removeClass('xm-select-active');
  1014. var vs = val.value.split('/');
  1015. var pid = void 0,
  1016. li = void 0,
  1017. index = 0;
  1018. var lis = [];
  1019. do {
  1020. pid = vs[index];
  1021. li = dl.find('.xm-select-linkage-group' + (index + 1) + ' li[xm-value="' + pid + '"]');
  1022. li[0] && lis.push(li);
  1023. index++;
  1024. } while (li.length && pid != undefined);
  1025. if (lis.length == vs.length) {
  1026. $.each(lis, function (idx, item) {
  1027. item.addClass('xm-select-this');
  1028. });
  1029. }
  1030. };
  1031. Common.prototype.linkageDel = function (id, val) {
  1032. var dl = $('dl[xid="' + id + '"]');
  1033. var vs = val.value.split('/');
  1034. var pid = void 0,
  1035. li = void 0,
  1036. index = vs.length - 1;
  1037. do {
  1038. pid = vs[index];
  1039. li = dl.find('.xm-select-linkage-group' + (index + 1) + ' li[xm-value="' + pid + '"]');
  1040. if (!li.parent().next().find('li[pid=' + pid + '].xm-select-this').length) {
  1041. li.removeClass('xm-select-this');
  1042. }
  1043. index--;
  1044. } while (li.length && pid != undefined);
  1045. };
  1046. Common.prototype.valToName = function (id, val) {
  1047. var dl = $('dl[xid="' + id + '"]');
  1048. var vs = (val + "").split('/');
  1049. if (!vs.length) {
  1050. return null;
  1051. }
  1052. var names = [];
  1053. $.each(vs, function (idx, item) {
  1054. var name = dl.find('.xm-select-linkage-group' + (idx + 1) + ' li[xm-value="' + item + '"] span').text();
  1055. names.push(name);
  1056. });
  1057. return names.length == vs.length ? names.join('/') : null;
  1058. };
  1059. Common.prototype.commonHandler = function (key, label) {
  1060. if (!label || !label[0]) {
  1061. return;
  1062. }
  1063. this.checkHideSpan(key, label);
  1064. //计算input的提示语
  1065. this.changePlaceHolder(label);
  1066. //计算高度
  1067. this.retop(label.parents('.' + FORM_SELECT));
  1068. this.calcLabelLeft(label, 0, true);
  1069. //表单默认值
  1070. this.setHidnVal(key, label);
  1071. //title值
  1072. label.parents('.' + FORM_TITLE + ' .' + NAME).attr('title', data[key].values.map(function (val) {
  1073. return val.name;
  1074. }).join(','));
  1075. };
  1076. Common.prototype.initVal = function (id) {
  1077. var _this13 = this;
  1078. var target = {};
  1079. if (id) {
  1080. target[id] = data[id];
  1081. } else {
  1082. target = data;
  1083. }
  1084. $.each(target, function (key, val) {
  1085. var values = val.values,
  1086. div = $('dl[xid="' + key + '"]').parent(),
  1087. label = div.find('.' + LABEL),
  1088. dl = div.find('dl');
  1089. dl.find('dd.' + THIS).removeClass(THIS);
  1090. var _vals = values.concat([]);
  1091. _vals.concat([]).forEach(function (item, index) {
  1092. _this13.addLabel(key, label, item);
  1093. dl.find('dd[lay-value="' + item.value + '"]').addClass(THIS);
  1094. });
  1095. if (val.config.radio) {
  1096. _vals.length && values.push(_vals[_vals.length - 1]);
  1097. }
  1098. _this13.commonHandler(key, label);
  1099. });
  1100. };
  1101. Common.prototype.setHidnVal = function (key, label) {
  1102. if (!label || !label[0]) {
  1103. return;
  1104. }
  1105. label.parents('.' + PNAME).find('.' + HIDE_INPUT).val(data[key].values.map(function (val) {
  1106. return val.value;
  1107. }).join(','));
  1108. };
  1109. Common.prototype.handlerLabel = function (id, dd, isAdd, oval, notOn) {
  1110. var div = $('[xid="' + id + '"]').prev().find('.' + LABEL),
  1111. val = dd && this.getItem(id, dd),
  1112. vals = data[id].values,
  1113. on = data[id].config.on || events.on[id],
  1114. endOn = data[id].config.endOn || events.endOn[id];
  1115. if (oval) {
  1116. val = oval;
  1117. }
  1118. var fs = data[id];
  1119. if (isAdd && fs.config.max && fs.values.length >= fs.config.max) {
  1120. var maxTipsFun = events.maxTips[id] || data[id].config.maxTips;
  1121. maxTipsFun && maxTipsFun(id, vals.concat([]), val, fs.config.max);
  1122. return;
  1123. }
  1124. if (!notOn) {
  1125. if (on && on instanceof Function && on(id, vals.concat([]), val, isAdd, dd && dd.hasClass(DISABLED)) == false) {
  1126. return;
  1127. }
  1128. }
  1129. var dl = $('dl[xid="' + id + '"]');
  1130. 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));
  1131. if (!div[0]) return;
  1132. //单选选完后直接关闭选择域
  1133. if (fs.config.radio) {
  1134. this.changeShow(div, false);
  1135. }
  1136. //移除表单验证的红色边框
  1137. div.parents('.' + FORM_TITLE).prev().removeClass('layui-form-danger');
  1138. //清空搜索值
  1139. fs.config.clearInput && this.clearInput(id);
  1140. this.commonHandler(id, div);
  1141. !notOn && endOn && endOn instanceof Function && endOn(id, vals.concat([]), val, isAdd, dd && dd.hasClass(DISABLED));
  1142. };
  1143. Common.prototype.addLabel = function (id, div, val) {
  1144. if (!val) return;
  1145. var tips = 'fsw="' + NAME + '"';
  1146. var _ref = [$('<span ' + tips + ' value="' + val.value + '"><font ' + tips + '>' + val.name + '</font></span>'), $('<i ' + tips + ' class="xm-iconfont icon-close"></i>')],
  1147. $label = _ref[0],
  1148. $close = _ref[1];
  1149. $label.append($close);
  1150. //如果是radio模式
  1151. var fs = data[id];
  1152. if (fs.config.radio) {
  1153. fs.values.length = 0;
  1154. $('dl[xid="' + id + '"]').find('dd.' + THIS + ':not([lay-value="' + val.value + '"])').removeClass(THIS);
  1155. div.find('span').remove();
  1156. }
  1157. //如果是固定高度
  1158. div.find('input').css('width', '50px');
  1159. div.find('input').before($label);
  1160. };
  1161. Common.prototype.delLabel = function (id, div, val) {
  1162. if (!val) return;
  1163. div.find('span[value="' + val.value + '"]:first').remove();
  1164. };
  1165. Common.prototype.checkHideSpan = function (id, div) {
  1166. var parentHeight = div.parents('.' + NAME)[0].offsetHeight + 5;
  1167. div.find('span.xm-span-hide').removeClass('xm-span-hide');
  1168. div.find('span[style]').remove();
  1169. var count = data[id].config.showCount;
  1170. div.find('span').each(function (index, item) {
  1171. if (index >= count) {
  1172. $(item).addClass('xm-span-hide');
  1173. }
  1174. });
  1175. var prefix = div.find('span:eq(' + count + ')');
  1176. prefix[0] && prefix.before($('<span style="padding-right: 6px;" fsw="' + NAME + '"> + ' + (div.find('span').length - count) + '</span>'));
  1177. };
  1178. Common.prototype.retop = function (div) {
  1179. //计算dl显示的位置
  1180. var dl = div.find('dl'),
  1181. top = div.offset().top + div.outerHeight() + 5 - $win.scrollTop(),
  1182. dlHeight = dl.outerHeight();
  1183. var up = div.hasClass('layui-form-selectup') || dl.css('top').indexOf('-') != -1 || top + dlHeight > $win.height() && top >= dlHeight;
  1184. div = div.find('.' + NAME);
  1185. var fs = data[dl.attr('xid')];
  1186. var base = dl.parents('.layui-form-pane')[0] && dl.prev()[0].clientHeight > 38 ? 14 : 10;
  1187. if (fs && fs.config.direction == 'up' || up) {
  1188. up = true;
  1189. if (fs && fs.config.direction == 'down') {
  1190. up = false;
  1191. }
  1192. }
  1193. var reHeight = div[0].offsetTop + div.height() + base;
  1194. if (up) {
  1195. dl.css({
  1196. top: 'auto',
  1197. bottom: reHeight + 3 + 'px'
  1198. });
  1199. } else {
  1200. dl.css({
  1201. top: reHeight + 'px',
  1202. bottom: 'auto'
  1203. });
  1204. }
  1205. };
  1206. Common.prototype.changeShow = function (children, isShow) {
  1207. //显示于隐藏
  1208. $('.layui-form-selected').removeClass('layui-form-selected');
  1209. var top = children.parents('.' + FORM_SELECT),
  1210. realShow = top.hasClass(FORM_SELECTED),
  1211. id = top.find('dl').attr('xid');
  1212. $('.' + PNAME + ' .' + FORM_SELECT).not(top).removeClass(FORM_SELECTED);
  1213. if (isShow) {
  1214. this.retop(top);
  1215. top.addClass(FORM_SELECTED);
  1216. top.find('.' + INPUT).focus();
  1217. this.triggerSearch(top, true);
  1218. if (!top.find('dl dd[lay-value]:not(.' + FORM_SELECT_TIPS + ')').length) {
  1219. top.find('dl .' + FORM_NONE).addClass(FORM_EMPTY);
  1220. }
  1221. } else {
  1222. top.removeClass(FORM_SELECTED);
  1223. this.clearInput(id);
  1224. top.find('dl .' + FORM_EMPTY).removeClass(FORM_EMPTY);
  1225. top.find('dl dd.' + DD_HIDE).removeClass(DD_HIDE);
  1226. top.find('dl dd.' + TEMP).remove();
  1227. //计算ajax数据是否为空, 然后重新请求数据
  1228. if (id && data[id] && data[id].config.isEmpty) {
  1229. this.triggerSearch(top);
  1230. }
  1231. this.changePlaceHolder(top.find('.' + LABEL));
  1232. }
  1233. if (isShow != realShow) {
  1234. var openFun = data[id].config.opened || events.opened[id];
  1235. isShow && openFun && openFun instanceof Function && openFun(id);
  1236. var closeFun = data[id].config.closed || events.closed[id];
  1237. !isShow && closeFun && closeFun instanceof Function && closeFun(id);
  1238. }
  1239. };
  1240. Common.prototype.changePlaceHolder = function (div) {
  1241. //显示于隐藏提示语
  1242. //调整pane模式下的高度
  1243. var title = div.parents('.' + FORM_TITLE);
  1244. title[0] || (title = div.parents('dl').prev());
  1245. if (!title[0]) {
  1246. return;
  1247. }
  1248. var id = div.parents('.' + PNAME).find('dl[xid]').attr('xid');
  1249. if (data[id] && data[id].config.height) {//既然固定高度了, 那就看着办吧
  1250. } else {
  1251. var height = title.find('.' + NAME)[0].clientHeight;
  1252. title.css('height', (height > 36 ? height + 4 : height) + 'px');
  1253. //如果是layui pane模式, 处理label的高度
  1254. var label = title.parents('.' + PNAME).parent().prev();
  1255. if (label.is('.layui-form-label') && title.parents('.layui-form-pane')[0]) {
  1256. height = height > 36 ? height + 4 : height;
  1257. title.css('height', height + 'px');
  1258. label.css({
  1259. height: height + 2 + 'px',
  1260. lineHeight: height - 18 + 'px'
  1261. });
  1262. }
  1263. }
  1264. var input = title.find('.' + TDIV + ' input'),
  1265. isShow = !div.find('span:last')[0] && !title.find('.' + INPUT).val();
  1266. if (isShow) {
  1267. var ph = input.attr('back');
  1268. input.removeAttr('back');
  1269. input.attr('placeholder', ph);
  1270. } else {
  1271. var _ph = input.attr('placeholder');
  1272. input.removeAttr('placeholder');
  1273. input.attr('back', _ph);
  1274. }
  1275. };
  1276. Common.prototype.indexOf = function (arr, val) {
  1277. for (var i = 0; i < arr.length; i++) {
  1278. if (arr[i].value == val || arr[i].value == (val ? val.value : val) || arr[i] == val || JSON.stringify(arr[i]) == JSON.stringify(val)) {
  1279. return i;
  1280. }
  1281. }
  1282. return -1;
  1283. };
  1284. Common.prototype.remove = function (arr, val) {
  1285. var idx = this.indexOf(arr, val ? val.value : val);
  1286. if (idx > -1) {
  1287. arr.splice(idx, 1);
  1288. return true;
  1289. }
  1290. return false;
  1291. };
  1292. Common.prototype.selectAll = function (id, isOn, skipDis) {
  1293. var _this14 = this;
  1294. var dl = $('[xid="' + id + '"]');
  1295. if (!dl[0]) {
  1296. return;
  1297. }
  1298. if (dl.find('.xm-select-linkage')[0]) {
  1299. return;
  1300. }
  1301. dl.find('dd[lay-value]:not(.' + FORM_SELECT_TIPS + '):not(.' + THIS + ')' + (skipDis ? ':not(.' + DISABLED + ')' : '')).each(function (index, item) {
  1302. item = $(item);
  1303. var val = _this14.getItem(id, item);
  1304. _this14.handlerLabel(id, dl.find('dd[lay-value="' + val.value + '"]'), true, val, !isOn);
  1305. });
  1306. };
  1307. Common.prototype.removeAll = function (id, isOn, skipDis) {
  1308. var _this15 = this;
  1309. var dl = $('[xid="' + id + '"]');
  1310. if (!dl[0]) {
  1311. return;
  1312. }
  1313. if (dl.find('.xm-select-linkage')[0]) {
  1314. //针对多级联动的处理
  1315. data[id].values.concat([]).forEach(function (item, idx) {
  1316. var vs = item.value.split('/');
  1317. var pid = void 0,
  1318. li = void 0,
  1319. index = 0;
  1320. do {
  1321. pid = vs[index++];
  1322. li = dl.find('.xm-select-linkage-group' + index + ':not(.xm-select-linkage-hide) li[xm-value="' + pid + '"]');
  1323. li.click();
  1324. } while (li.length && pid != undefined);
  1325. });
  1326. return;
  1327. }
  1328. data[id].values.concat([]).forEach(function (item, index) {
  1329. if (skipDis && dl.find('dd[lay-value="' + item.value + '"]').hasClass(DISABLED)) {} else {
  1330. _this15.handlerLabel(id, dl.find('dd[lay-value="' + item.value + '"]'), false, item, !isOn);
  1331. }
  1332. });
  1333. };
  1334. Common.prototype.reverse = function (id, isOn, skipDis) {
  1335. var _this16 = this;
  1336. var dl = $('[xid="' + id + '"]');
  1337. if (!dl[0]) {
  1338. return;
  1339. }
  1340. if (dl.find('.xm-select-linkage')[0]) {
  1341. return;
  1342. }
  1343. dl.find('dd[lay-value]:not(.' + FORM_SELECT_TIPS + ')' + (skipDis ? ':not(.' + DISABLED + ')' : '')).each(function (index, item) {
  1344. item = $(item);
  1345. var val = _this16.getItem(id, item);
  1346. _this16.handlerLabel(id, dl.find('dd[lay-value="' + val.value + '"]'), !item.hasClass(THIS), val, !isOn);
  1347. });
  1348. };
  1349. Common.prototype.skin = function (id) {
  1350. var skins = ['default', 'primary', 'normal', 'warm', 'danger'];
  1351. var skin = skins[Math.floor(Math.random() * skins.length)];
  1352. $('dl[xid="' + id + '"]').parents('.' + PNAME).find('.' + FORM_SELECT).attr('xm-select-skin', skin);
  1353. this.check(id) && this.commonHandler(id, $('dl[xid="' + id + '"]').parents('.' + PNAME).find('.' + LABEL));
  1354. };
  1355. Common.prototype.getPosition = function (e) {
  1356. var x = 0,
  1357. y = 0;
  1358. while (e != null) {
  1359. x += e.offsetLeft;
  1360. y += e.offsetTop;
  1361. e = e.offsetParent;
  1362. }
  1363. return { x: x, y: y };
  1364. };
  1365. Common.prototype.onreset = function () {
  1366. //监听reset按钮, 然后重置多选
  1367. $(document).on('click', '[type=reset]', function (e) {
  1368. $(e.target).parents('form').find('.' + PNAME + ' dl[xid]').each(function (index, item) {
  1369. var id = item.getAttribute('xid'),
  1370. dl = $(item),
  1371. dd = void 0,
  1372. temp = {};
  1373. common.removeAll(id);
  1374. data[id].config.init.forEach(function (val, idx) {
  1375. if (val && (!temp[val] || data[id].config.repeat) && (dd = dl.find('dd[lay-value="' + val.value + '"]'))[0]) {
  1376. common.handlerLabel(id, dd, true);
  1377. temp[val] = 1;
  1378. }
  1379. });
  1380. });
  1381. });
  1382. };
  1383. Common.prototype.bindEvent = function (name, id, fun) {
  1384. if (id && id instanceof Function) {
  1385. fun = id;
  1386. id = null;
  1387. }
  1388. if (fun && fun instanceof Function) {
  1389. if (!id) {
  1390. $.each(data, function (id, val) {
  1391. data[id] ? data[id].config[name] = fun : events[name][id] = fun;
  1392. });
  1393. } else {
  1394. data[id] ? (data[id].config[name] = fun, delete events[name][id]) : events[name][id] = fun;
  1395. }
  1396. }
  1397. };
  1398. Common.prototype.check = function (id, notAutoRender) {
  1399. if ($('dl[xid="' + id + '"]').length) {
  1400. return true;
  1401. } else if ($('select[xm-select="' + id + '"]').length) {
  1402. if (!notAutoRender) {
  1403. this.render(id, $('select[xm-select="' + id + '"]'));
  1404. return true;
  1405. }
  1406. } else {
  1407. delete data[id];
  1408. return false;
  1409. }
  1410. };
  1411. Common.prototype.render = function (id, select) {
  1412. common.init(select);
  1413. common.one($('dl[xid="' + id + '"]').parents('.' + PNAME));
  1414. common.initVal(id);
  1415. };
  1416. Common.prototype.log = function (obj) {
  1417. console.log(obj);
  1418. };
  1419. var Select4 = function Select4() {
  1420. this.v = v;
  1421. this.render();
  1422. };
  1423. var common = new Common();
  1424. Select4.prototype.value = function (id, type, isAppend) {
  1425. if (typeof id != 'string') {
  1426. return [];
  1427. }
  1428. var fs = data[id];
  1429. if (!common.check(id)) {
  1430. return [];
  1431. }
  1432. if (typeof type == 'string' || type == undefined) {
  1433. var arr = fs.values.concat([]) || [];
  1434. if (type == 'val') {
  1435. return arr.map(function (val) {
  1436. return val.value;
  1437. });
  1438. }
  1439. if (type == 'valStr') {
  1440. return arr.map(function (val) {
  1441. return val.value;
  1442. }).join(',');
  1443. }
  1444. if (type == 'name') {
  1445. return arr.map(function (val) {
  1446. return val.name;
  1447. });
  1448. }
  1449. if (type == 'nameStr') {
  1450. return arr.map(function (val) {
  1451. return val.name;
  1452. }).join(',');
  1453. }
  1454. return arr;
  1455. }
  1456. if (common.isArray(type)) {
  1457. var dl = $('[xid="' + id + '"]'),
  1458. temp = {},
  1459. dd = void 0,
  1460. isAdd = true;
  1461. if (isAppend == false) {
  1462. //删除传入的数组
  1463. isAdd = false;
  1464. } else if (isAppend == true) {
  1465. //追加模式
  1466. isAdd = true;
  1467. } else {
  1468. //删除原有的数据
  1469. common.removeAll(id);
  1470. }
  1471. if (isAdd) {
  1472. fs.values.forEach(function (val, index) {
  1473. temp[val.value] = 1;
  1474. });
  1475. }
  1476. type.forEach(function (val, index) {
  1477. if (val && (!temp[val] || fs.config.repeat)) {
  1478. if ((dd = dl.find('dd[lay-value="' + val + '"]'))[0]) {
  1479. common.handlerLabel(id, dd, isAdd, null, true);
  1480. temp[val] = 1;
  1481. } else {
  1482. var name = common.valToName(id, val);
  1483. if (name) {
  1484. common.handlerLabel(id, dd, isAdd, common.getItem(id, val), true);
  1485. temp[val] = 1;
  1486. }
  1487. }
  1488. }
  1489. });
  1490. }
  1491. };
  1492. Select4.prototype.on = function (id, fun, isEnd) {
  1493. common.bindEvent(isEnd ? 'endOn' : 'on', id, fun);
  1494. return this;
  1495. };
  1496. Select4.prototype.filter = function (id, fun) {
  1497. common.bindEvent('filter', id, fun);
  1498. return this;
  1499. };
  1500. Select4.prototype.maxTips = function (id, fun) {
  1501. common.bindEvent('maxTips', id, fun);
  1502. return this;
  1503. };
  1504. Select4.prototype.opened = function (id, fun) {
  1505. common.bindEvent('opened', id, fun);
  1506. return this;
  1507. };
  1508. Select4.prototype.closed = function (id, fun) {
  1509. common.bindEvent('closed', id, fun);
  1510. return this;
  1511. };
  1512. Select4.prototype.config = function (id, config, isJson) {
  1513. if (id && (typeof id === 'undefined' ? 'undefined' : _typeof(id)) == 'object') {
  1514. isJson = config == true;
  1515. config = id;
  1516. id = null;
  1517. }
  1518. if (config && (typeof config === 'undefined' ? 'undefined' : _typeof(config)) == 'object') {
  1519. if (isJson) {
  1520. config.header || (config.header = {});
  1521. config.header['Content-Type'] = 'application/json; charset=UTF-8';
  1522. config.dataType = 'json';
  1523. }
  1524. 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) {
  1525. $.extend(true, item, config);
  1526. }));
  1527. }
  1528. return this;
  1529. };
  1530. Select4.prototype.render = function (id, options) {
  1531. var _ref2;
  1532. if (id && (typeof id === 'undefined' ? 'undefined' : _typeof(id)) == 'object') {
  1533. options = id;
  1534. id = null;
  1535. }
  1536. var config = options ? (_ref2 = {
  1537. init: options.init,
  1538. disabled: options.disabled,
  1539. max: options.max,
  1540. isSearch: options.isSearch,
  1541. searchUrl: options.searchUrl,
  1542. isCreate: options.isCreate,
  1543. radio: options.radio,
  1544. skin: options.skin,
  1545. direction: options.direction,
  1546. height: options.height,
  1547. formname: options.formname,
  1548. layverify: options.layverify,
  1549. layverType: options.layverType,
  1550. showCount: options.showCount,
  1551. placeholder: options.placeholder,
  1552. create: options.create,
  1553. filter: options.filter,
  1554. maxTips: options.maxTips,
  1555. on: options.on
  1556. }, _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) : {};
  1557. options && options.searchType != undefined && (config.searchType = options.searchType == 'dl' ? 1 : 0);
  1558. if (id) {
  1559. fsConfigs[id] = {};
  1560. $.extend(fsConfigs[id], data[id] ? data[id].config : {}, config);
  1561. } else {
  1562. $.extend(fsConfig, config);
  1563. }
  1564. ($('select[' + NAME + '="' + id + '"]')[0] ? $('select[' + NAME + '="' + id + '"]') : $('select[' + NAME + ']')).each(function (index, select) {
  1565. var sid = select.getAttribute(NAME);
  1566. common.render(sid, select);
  1567. setTimeout(function () {
  1568. return common.setHidnVal(sid, $('select[xm-select="' + sid + '"] + div.' + PNAME + ' .' + LABEL));
  1569. }, 10);
  1570. });
  1571. return this;
  1572. };
  1573. Select4.prototype.disabled = function (id) {
  1574. var target = {};
  1575. id ? common.check(id) && (target[id] = data[id]) : target = data;
  1576. $.each(target, function (key, val) {
  1577. $('dl[xid="' + key + '"]').prev().addClass(DIS);
  1578. });
  1579. return this;
  1580. };
  1581. Select4.prototype.undisabled = function (id) {
  1582. var target = {};
  1583. id ? common.check(id) && (target[id] = data[id]) : target = data;
  1584. $.each(target, function (key, val) {
  1585. $('dl[xid="' + key + '"]').prev().removeClass(DIS);
  1586. });
  1587. return this;
  1588. };
  1589. Select4.prototype.data = function (id, type, config) {
  1590. if (!id || !type || !config) {
  1591. common.log('id: ' + id + ' param error !!!');
  1592. return this;
  1593. }
  1594. if (!common.check(id)) {
  1595. common.log('id: ' + id + ' not render !!!');
  1596. return this;
  1597. }
  1598. this.value(id, []);
  1599. this.config(id, config);
  1600. if (type == 'local') {
  1601. common.renderData(id, config.arr, config.linkage == true, config.linkageWidth ? config.linkageWidth : '100');
  1602. } else if (type == 'server') {
  1603. common.ajax(id, config.url, config.keyword, config.linkage == true, config.linkageWidth ? config.linkageWidth : '100');
  1604. }
  1605. return this;
  1606. };
  1607. Select4.prototype.btns = function (id, btns, config) {
  1608. if (id && common.isArray(id)) {
  1609. btns = id;
  1610. id = null;
  1611. }
  1612. if (!btns || !common.isArray(btns)) {
  1613. return this;
  1614. };
  1615. var target = {};
  1616. id ? common.check(id) && (target[id] = data[id]) : target = data;
  1617. btns = btns.map(function (obj) {
  1618. if (typeof obj == 'string') {
  1619. if (obj == 'select') {
  1620. return quickBtns[0];
  1621. }
  1622. if (obj == 'remove') {
  1623. return quickBtns[1];
  1624. }
  1625. if (obj == 'reverse') {
  1626. return quickBtns[2];
  1627. }
  1628. if (obj == 'skin') {
  1629. return quickBtns[3];
  1630. }
  1631. }
  1632. return obj;
  1633. });
  1634. $.each(target, function (key, val) {
  1635. val.config.btns = btns;
  1636. var dd = $('dl[xid="' + key + '"]').find('.' + FORM_SELECT_TIPS + ':first');
  1637. if (btns.length) {
  1638. var show = config && config.show && (config.show == 'name' || config.show == 'icon') ? config.show : '';
  1639. var html = common.renderBtns(key, show, config && config.space ? config.space : '30px');
  1640. dd.html(html);
  1641. } else {
  1642. var pcInput = dd.parents('.' + FORM_SELECT).find('.' + TDIV + ' input');
  1643. var _html = pcInput.attr('placeholder') || pcInput.attr('back');
  1644. dd.html(_html);
  1645. dd.removeAttr('style');
  1646. }
  1647. });
  1648. return this;
  1649. };
  1650. Select4.prototype.search = function (id, val) {
  1651. if (id && common.check(id)) {
  1652. ajaxs[id] = $.extend(true, {}, ajaxs[id] || ajax, {
  1653. first: true,
  1654. searchVal: val
  1655. });
  1656. common.triggerSearch($('dl[xid="' + id + '"]').parents('.' + FORM_SELECT), true);
  1657. }
  1658. return this;
  1659. };
  1660. Select4.prototype.replace = function (id, type, config) {
  1661. var _this17 = this;
  1662. if (!id || !type || !config) {
  1663. common.log('id: ' + id + ' param error !!!');
  1664. return this;
  1665. }
  1666. if (!common.check(id, true)) {
  1667. common.log('id: ' + id + ' not render !!!');
  1668. return this;
  1669. }
  1670. var oldVals = this.value(id, 'val');
  1671. this.value(id, []);
  1672. this.config(id, config);
  1673. if (type == 'local') {
  1674. common.renderData(id, config.arr, config.linkage == true, config.linkageWidth ? config.linkageWidth : '100', false, true);
  1675. this.value(id, oldVals, true);
  1676. } else if (type == 'server') {
  1677. common.ajax(id, config.url, config.keyword, config.linkage == true, config.linkageWidth ? config.linkageWidth : '100', false, function (id) {
  1678. _this17.value(id, oldVals, true);
  1679. }, true);
  1680. }
  1681. };
  1682. return new Select4();
  1683. });