截流自动化的商城平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

formSelects-v4.js 57KB

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