formselects.js 74 KB

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