queryForm.js 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177
  1. const query = function getQueryForm(data) {
  2. {
  3. this.el = data.el || '#form_div';
  4. this.form = data.form;
  5. this.method = data.method || 'get';
  6. this.url = data.url || getPathname();
  7. this.condition = data.condition;
  8. this.paginations = [50, 100, 200, 500] || data.paginations;
  9. this.keydownfun = data.keydownfun || undefined;
  10. this.selectChange = data.selectChange || undefined;
  11. this.searchClick = data.searchClick || undefined;
  12. this.selectfun = data.selectfun || undefined;
  13. this._onsubmit = data._onsubmit || undefined;
  14. this.keydownSearch = data.keydownSearch || true;
  15. this.selectChangeSearch = data.selectChangeSearch || true;
  16. this.tip = data.tip || '';
  17. this.nextPage = nextPage;
  18. this.pervPage = pervPage;
  19. this.getSearchData = getSearchData;
  20. this.autoSubmit = (data.autoSubmit === false) ? false : true ;
  21. // 提交表单
  22. this.onsubmit = function () {
  23. if(!this.autoSubmit){
  24. return;
  25. }
  26. saveSearchOnCookie();
  27. let form = $("<form method=" + _this.method + " ></form>");
  28. for (const key in _data) {
  29. let map = _data[key];
  30. if (["string", "number"].includes(fetchJsType(map.value)) && map.value !== '') {
  31. form.append("<input name='" + key + "' value='" + map.value + "'>")
  32. } else if ('array' === fetchJsType(map.value)) {
  33. map.value.forEach(function (value) {
  34. form.append("<input type='checkbox' name='" + key + "' value='" + value + "' checked='checked' >");
  35. })
  36. }
  37. }
  38. if (_this.method !== 'get') {
  39. form.append("<input type='hidden' name='_token' value='" + $('meta[name="csrf-token"]').attr('content') + "'>");
  40. form.append("<input type='hidden' name='_method' value='" + _this.method + "'>");
  41. form.attr('action', _this.url);
  42. }
  43. _hidden_div.html('');
  44. _hidden_div.append(form);
  45. form.submit();
  46. }
  47. }
  48. let _this = this;
  49. let _parentNode = null;
  50. let _data = {};
  51. let _form = [];
  52. let _table = null;
  53. let _clearTr = null;
  54. let _pagination = null;
  55. let _baseData = data;
  56. let _searchBtn = null;
  57. let _hidden_div = null;
  58. let _parentNode_top = null;
  59. let _page = '';
  60. this.init = function () {
  61. _parentNode = $(_this.el);
  62. _form = $("<div ></div>");
  63. _table = $("<table class='table table-sm table-bordered m-0 position-static' style='background: rgb(255, 255, 255);'></table>");
  64. fillTable();
  65. switchData();
  66. addHiedDiv();
  67. rendererSearchForm();
  68. visibleClearBtn();
  69. parentNodeFloat();
  70. inputKeyDown();
  71. selectChange();
  72. createTip();
  73. $('[data-toggle="tooltip"]').tooltip({'trigger': 'hover'})
  74. }
  75. // form fixed
  76. function parentNodeFloat() {
  77. _parentNode_top = _parentNode.offset().top;
  78. let height = _parentNode.height();
  79. window.onscroll = function () {
  80. let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
  81. if (scrollTop > _parentNode_top) {
  82. _form.addClass('fixed-top');
  83. _parentNode.height(height);
  84. } else {
  85. _form.removeClass('fixed-top');
  86. }
  87. }
  88. }
  89. // add hide div (on submit form )
  90. function addHiedDiv() {
  91. _parentNode.append(_form.append(_table));
  92. _hidden_div = $('<div></div>');
  93. _hidden_div.hide();
  94. $("body").append(_hidden_div);
  95. }
  96. // fill table
  97. function fillTable() {
  98. _table.html('');
  99. _table.append(crateClearBtn());
  100. _table.append(createPagination());
  101. _baseData.condition.forEach(function (conditions, index, arrays) {
  102. let tr = $("<tr></tr>");
  103. conditions.forEach(function (condition, index, array) {
  104. let td = $("<td style='width: 260px'></td>");
  105. if ([null, '', undefined].includes(condition.type) && ![null, undefined].includes(condition.name)) {
  106. condition.type = 'input';
  107. }
  108. if (['dataTime_dataTime', 'input_input'].includes(condition.type)) {
  109. td = $("<td style='width: 330px'</td>")
  110. } else if (['select_multiple_select', 'time', 'dataTime_select'].includes(condition.type)) {
  111. td = $("<td style='width: 280px'</td>");
  112. } else if (['time', 'dataTime_select'].includes(condition.type)) {
  113. td = $("<td style='width: 320px'</td>");
  114. }
  115. td.append(createModule(condition));
  116. tr.append(td);
  117. })
  118. _table.append(tr);
  119. if (arrays.length === index + 1) {
  120. let td = $("<td ></td>");
  121. tr.append(td.append(createSearchBt()));
  122. }
  123. })
  124. $.cookie.raw = true;
  125. $.cookie.json = true;
  126. setTableWidth();
  127. }
  128. function setTableWidth() {
  129. let max_width = 0;
  130. _baseData.condition.forEach(function (conditions, xindex, xarrays) {
  131. let _width = 0;
  132. conditions.forEach(function (condition, index, array) {
  133. if (['input', 'select', 'dataTime', 'input_select'].includes(condition.type)) {
  134. _width += 260;
  135. } else if (['dataTime_dataTime', 'input_input'].includes(condition.type)) {
  136. _width += 330;
  137. } else if (['select_multiple_select','search_select'].includes(condition.type)) {
  138. _width += 280;
  139. } else if (['checkbox'].includes(condition.type)) {
  140. _width += 260;
  141. } else if (['time', 'dataTime_select'].includes(condition.type)) {
  142. _width += 320;
  143. } else if ([undefined, null, ''].includes(condition)) {
  144. _width += 260;
  145. }
  146. if (index === array.length - 1 && xindex === xarrays.length - 1) {
  147. _width += 260;
  148. }
  149. if (max_width < _width) {
  150. max_width = _width;
  151. }
  152. })
  153. })
  154. _parentNode.css('min-width', 1920 - 30)
  155. _parentNode.css('max-width', (max_width || window.screen.availWidth) - 30);
  156. _table.css('width', max_width + 'px');
  157. }
  158. // 清空过滤条件按钮
  159. function crateClearBtn() {
  160. let clearbtn = $("<button type='button' class='btn btn-warning text-dark '>清除过滤条件</button>");
  161. clearbtn.click(function () {
  162. clearData();
  163. visibleClearBtn();
  164. })
  165. let tr = $("<tr ><td colspan='10'></td></tr>");
  166. tr.find('td').append(clearbtn);
  167. _clearTr = tr;
  168. return tr;
  169. }
  170. // create SearchBtn
  171. function createSearchBt() {
  172. _searchBtn = $("<span class='btn btn-sm btn-outline-dark ml-1' >按条件搜索</span>");
  173. let div = $("<div class='form-inline'></div>");
  174. div.append(_searchBtn);
  175. _searchBtn.click(function () {
  176. if (controlJsType(_this.searchClick, 'fun')) {
  177. _this.searchClick();
  178. }
  179. if (controlJsType(_this._onsubmit, 'fun')) {
  180. _this._onsubmit();
  181. }else{
  182. _this.onsubmit();
  183. }
  184. })
  185. return div;
  186. }
  187. // create _pagination
  188. function createPagination() {
  189. _pagination = $("<select id='paginate' name='paginate' class='form-control form-control-sm' style='vertical-align: middle; max-width: 150px;'></select>");
  190. let tr = $("<tr ><td colspan='10'><div class='col p-0' style='height: 100%'></div></td></tr>");
  191. tr.find('div').append(_pagination);
  192. _this.paginations.forEach(function (map) {
  193. let option = $("<option value='" + map + "'>每页显示" + map + "</option>");
  194. _pagination.append(option);
  195. })
  196. _pagination.change(function () {
  197. let dom = {name: 'paginate', type: 'select', value: _pagination.val(), mold: 'select'};
  198. _data['paginate'] = dom;
  199. modifyData(dom);
  200. _data['paginate'] = dom;
  201. _this.onsubmit();
  202. })
  203. return tr;
  204. }
  205. // create Tip
  206. function createTip() {
  207. let data = fetchCookie();
  208. let search = window.location.search;
  209. if (!data || !search) {
  210. return;
  211. }
  212. let cookies = JSON.parse(data);
  213. if (!cookies['success_tip']) {
  214. return;
  215. }
  216. if (!cookies['success_tip'] && !!_this.tip) {
  217. cookies['success_tip'].value = _this.tip;
  218. cookies['success_tip'].count = 1;
  219. _data['page'].value = _page;
  220. saveCookie(cookies);
  221. set_dataOnCookie();
  222. _this.onsubmit();
  223. // 重定向
  224. } else if (!cookies['success_tip'] && cookies['success_tip'].count === 1) {
  225. let tip = $("<div class='alert alert-success h1'></div>")
  226. let tipdiv = $("<div style='max-width: " + window.screen.availWidth + "px'>" + cookies['success_tip'].value + "</div>").append(tip);
  227. _form.append(tipdiv);
  228. cookies['success_tip'] = '';
  229. saveCookie(cookies);
  230. }
  231. }
  232. // 数据清空
  233. function clearData() {
  234. saveCookie({});
  235. window.location.href = _this.url;
  236. }
  237. // 存cookie
  238. function saveCookie(data) {
  239. $.cookie(getPathname(), data, {expires: 1});
  240. }
  241. // 取cookie
  242. function fetchCookie() {
  243. return $.cookie(getPathname());
  244. }
  245. // 获取路径
  246. function getPathname() {
  247. return window.location.pathname;
  248. }
  249. // 获取js对象类型types.call
  250. function fetchJsType(JsObj) {
  251. let types = Object.prototype.toString;
  252. let obj = types.call(JsObj);
  253. return (obj === "[object Number]" && 'number')
  254. || (obj === "[object Boolean]" && 'boolean')
  255. || (obj === "[object String]" && 'string')
  256. || (obj === "[object Array]" && 'array')
  257. || (obj === "[object Function]" && 'fun')
  258. || (obj === "[object Object]" && 'object')
  259. || (obj === "[object Null]" && 'null')
  260. || (obj === "[object Undefined]" && 'undefined');
  261. }
  262. // 判断js类型
  263. function controlJsType(JsObj, type) {
  264. if (fetchJsType(type) === 'array') {
  265. return type.includes(fetchJsType(JsObj));
  266. } else if (fetchJsType(type) === 'string') {
  267. return fetchJsType(JsObj) === type;
  268. } else {
  269. return JsObj === type;
  270. }
  271. }
  272. // create Module
  273. function createModule(condition) {
  274. let type = condition.type;
  275. return (['input', '', null].includes(type) && getInput(condition))
  276. || (type === "select" && getSelect(condition))
  277. || (type === "search_select" && getSearchSelect(condition))
  278. || (type === "input_select" && getInputSelect(condition))
  279. || (type === "dataTime" && getDataTime(condition))
  280. || (type === "time" && getTime(condition))
  281. || (type === "input_input" && getInputInput(condition))
  282. || (type === "dataTime_dataTime" && getDataTimeDataTime(condition))
  283. || (type === "dataTime_select" && getDataTimeSelect(condition))
  284. || (type === "select_multiple_select" && getSelectMultipleSelect(condition))
  285. || (type === "checkbox" && getCheckBox(condition));
  286. }
  287. // input
  288. function getInput(condition) {
  289. let input = $("<input name='" + condition.name + "' class='form-control form-control-sm' style='vertical-align: middle; max-width: 200px;' placeholder='" + condition.placeholder + "' autocomplete='off' data-toggle='tooltip' data-placement='top' >");
  290. input.attr('title', condition.tip === undefined ? '' : condition.tip);
  291. input.on('input', function () {
  292. let dom = {name: condition.name, type: 'input', value: this.value, mold: 'input'}
  293. modifyData(dom)
  294. });
  295. return input;
  296. }
  297. // select
  298. function getSelect(condition) {
  299. let select = $("<select name='" + condition.name + "' class='form-control form-control-sm' style='max-width: 200px;' data-toggle='tooltip' data-placement='top'></select>")
  300. select.attr('title', condition.tip === undefined ? '' : condition.tip);
  301. let tip = $("<option value class='text-secondary'>" + condition.placeholder + "</option>")
  302. select.append(tip);
  303. condition.data.forEach(function (map) {
  304. let option = $("<option value='" + map.name + "' class='text-secondary'>" + map.value + "</option>")
  305. select.append(option);
  306. })
  307. select.on('change', function () {
  308. let dom = {name: condition.name, type: 'select', value: this.value, mold: 'select'}
  309. modifyData(dom)
  310. })
  311. return select;
  312. }
  313. // search_select
  314. function getSearchSelect(condition) {
  315. let div = $("<div class='form-inline'></div>");
  316. let input = $("<input class='form-control form-control-sm' placeholder='" + condition.placeholder[0] + "' style='width: 70px;' autocomplete='off' data-toggle='tooltip' data-placement='top'>");
  317. input.attr('title', controlJsType(condition.tip[0], 'undefined') ? '输入关键词快速定位下拉列表,回车确定' : condition.tip[0]);
  318. let select = $("<select class='form-control form-control-sm ml-2' name='" + condition.name + "' style='min-width: 120px;max-width: 150px;' data-toggle='tooltip' data-placement='top' data-toggle='tooltip' data-placement='top'></select>");
  319. select.attr('title', controlJsType(condition.tip[1], 'undefined') ? '' : condition.tip[1]);
  320. let placeholder = '';
  321. if (controlJsType(condition.placeholder, 'array') && !['', undefined, null].includes(condition.placeholder[1])) {
  322. placeholder = condition.placeholder[1];
  323. }
  324. fillSelectOption(select, condition.data, placeholder);
  325. input.bind('input propertychange', function () {
  326. let value = this.value;
  327. let data = condition.data.filter(function (map) {
  328. return map.value.includes(value);
  329. })
  330. fillSelectOption(select, data || condition.data);
  331. select.val(_data[condition.name].select);
  332. })
  333. select.change(function () {
  334. let dom = {name: condition.name, type: 'input_select', value: this.value, mold: 'select'};
  335. modifyData(dom);
  336. })
  337. return div.append(input).append(select);
  338. }
  339. // input_select
  340. function getInputSelect(condition) {
  341. let div = $("<div class='form-inline'></div>");
  342. let input = $("<input class='form-control form-control-sm' name='" + condition.name[0] + "' placeholder='" + condition.placeholder[0] + "' autocomplete='off' style='max-width: 120px;' data-toggle='tooltip' data-placement='top' >");
  343. input.attr('title', controlJsType(condition.tip[0], 'undefined') ? '' : condition.tip[0]);
  344. let select = $("<select class='form-control form-control-sm ml-2' name='" + condition.name[1] + "' style='max-width: 200px;' title='" + condition.tip[1] + "''>");
  345. fillSelectOption(select, condition.data);
  346. input.bind('input propertychange', function () {
  347. let dom = {name: this.name, type: 'input_select_longtext', value: this.value, mold: 'input'};
  348. modifyData(dom);
  349. })
  350. select.change(function () {
  351. let dom = {name: this.name, type: 'input_select_longtext', value: this.value, mold: 'select'};
  352. modifyData(dom);
  353. })
  354. return div.append(input).append(select);
  355. }
  356. // datTime
  357. function getDataTime(condition) {
  358. let dataTime = $("<input type='date' class='form-control form-control-sm' name='" + condition.name + "' style='max-width: 150px' data-toggle='tooltip' data-placement='top' title='" + condition.tip + "' style='width: 200px'>");
  359. dataTime.attr('title', controlJsType(condition.tip, 'undefined') ? '' : condition.tip);
  360. dataTime.bind('input propertychange', function () {
  361. let dom = {name: condition.name, type: 'dataTime', value: this.value, mold: 'dataTime'};
  362. modifyData(dom);
  363. })
  364. return dataTime;
  365. }
  366. // time
  367. function getTime(condition) {
  368. let div = $("<div class='form-inline'></div>");
  369. let dataTime = $("<input type='date' class='form-control form-control-sm' name='" + condition.name + "' style='width:150px' data-toggle='tooltip' data-placement='top' >");
  370. dataTime.attr('title', controlJsType(condition.tip[0], 'undefined') ? '' : condition.tip[0]);
  371. let min = $("<input id='" + condition.name + "_min' class='form-control form-control-sm ml-2' style='max-width: 100px;' placeholder='00:00' data-toggle='tooltip' data-placement='top' >");
  372. min.attr('title', controlJsType(condition.tip[1], 'undefined') ? '' : condition.tip[1]);
  373. dataTime.bind('input propertychange', function () {
  374. let value = this.value !== '' ? this.value + ' ' + ([null, undefined, ''].includes(min.value) ? '00:00' : min.value) : '';
  375. let dom = {name: condition.name, type: 'time', value: value, mold: 'time'};
  376. modifyData(dom);
  377. })
  378. min.bind('input propertychange', function () {
  379. verifyTime(this);
  380. })
  381. min.bind('input propertychange', function () {
  382. if (['null', 'undefined', ''].includes(dataTime.val())) {
  383. return;
  384. }
  385. let value = ['null', 'undefined', ''].includes(dataTime.val()) ? '' : dataTime.val() + ' ' + min.val();
  386. //let value = dataTime.value !== '' ? dataTime.value + ' ' + (min.value === '' ? '00:00' : min. value) : '';
  387. let dom = {name: condition.name, type: 'time', value: value, mold: 'time'};
  388. modifyData(dom);
  389. })
  390. return div.append(dataTime).append(min);
  391. }
  392. // input_input
  393. function getInputInput(condition) {
  394. let div = $("<div class='form-inline'></div>");
  395. let input1 = $("<input name='" + condition.name[0] + "' class='form-control form-control-sm' style='vertical-align: middle; max-width: 150px;' placeholder='" + condition.placeholder[0] + "' data-toggle='tooltip' data-placement='top' title='" + condition.tip[0] + "'>");
  396. input1.attr('title', controlJsType(condition.tip[0], 'undefined') ? '' : condition.tip[0]);
  397. let input2 = $("<input name='" + condition.name[1] + "' class='form-control form-control-sm ml-2' style='vertical-align: middle; max-width: 150px;' placeholder='" + condition.placeholder[1] + "' data-toggle='tooltip' data-placement='top' title='" + condition.tip[1] + "'>");
  398. input2.attr('title', controlJsType(condition.tip[1], 'undefined') ? '' : condition.tip[1]);
  399. input1.bind('input propertychange', function () {
  400. let dom = {name: this.name, type: 'input_input', value: this.value, mold: 'input'};
  401. modifyData(dom);
  402. })
  403. input2.bind('input propertychange', function () {
  404. let dom = {name: this.name, type: 'input_input', value: this.value, mold: 'input'};
  405. modifyData(dom);
  406. })
  407. return div.append(input1).append(input2);
  408. }
  409. // dataTime_dataTime
  410. function getDataTimeDataTime(condition) {
  411. let div = $("<div class='form-inline'></div>");
  412. let dataTime1 = $("<input type='date' class='form-control form-control-sm' name='" + condition.name[0] + "' style='width: 150px' data-toggle='tooltip' data-placement='top' >");
  413. dataTime1.attr('title', controlJsType(condition.tip[0], 'undefined') ? '' : condition.tip[0]);
  414. let dataTime2 = $("<input type='date' class='form-control form-control-sm ml-2' name='" + condition.name[1] + "' style='width: 150px;' data-toggle='tooltip' data-placement='top' >");
  415. dataTime2.attr('title', controlJsType(condition.tip[1], 'undefined') ? '' : condition.tip[1]);
  416. dataTime1.bind('input propertychange', function () {
  417. let dom = {name: this.name, type: 'dataTime_dataTime', value: this.value, mold: 'dataTime'};
  418. modifyData(dom);
  419. })
  420. dataTime2.bind('input propertychange', function () {
  421. let dom = {name: this.name, type: 'dataTime_dataTime', value: this.value, mold: 'dataTime'};
  422. modifyData(dom);
  423. })
  424. return div.append(dataTime1).append(dataTime2);
  425. }
  426. // dataTime_select
  427. function getDataTimeSelect(condition) {
  428. let div = $("<div class='form-inline'></div>");
  429. let dataTime = $("<input type='date' class='form-control form-control-sm' name='" + condition.name[0] + "' style='max-width: 150px;' data-toggle='tooltip' data-placement='top' >");
  430. dataTime.attr('title', controlJsType(condition.tip[0], 'undefined') ? '' : condition.tip[0]);
  431. let select = $("<select name='" + condition.name[1] + "' class='form-control form-control-sm ml-2' data-toggle='tooltip' data-placement='top' style='max-width: 100px'></select>");
  432. select.attr('title', controlJsType(condition.tip[1], 'undefined') ? '' : condition.tip[1]);
  433. fillSelectOption(select, condition.data)
  434. dataTime.bind('input propertychange', function () {
  435. let dom = {name: this.name, type: 'dataTime_select', value: this.value, mold: 'dataTime'};
  436. modifyData(dom);
  437. })
  438. select.change(function () {
  439. let dom = {name: this.name, type: 'dataTime_select', value: this.value, mold: 'select'};
  440. modifyData(dom);
  441. })
  442. return div.append(dataTime).append(select);
  443. }
  444. // select_multiple_select
  445. function getSelectMultipleSelect(condition) {
  446. let div = $("<div class='form-inline' style='position: relative'></div>");
  447. let select = $("<select class='form-control form-control-sm' name='" + condition.name + "_sel' id='" + condition.name + "_sel' style='vertical-align: middle; width: 100px;' data-toggle='tooltip' data-placement='top' ></select>");
  448. let label = $("<label id='" + condition.name + "_lab' style='vertical-align: middle; width: 100px' >(多选)</label>").hide();
  449. let select_div = $("<div ></div>");
  450. select.attr('title', controlJsType(condition.tip[0], 'undefined') ? '' : condition.tip[0]);
  451. let placeholder = controlJsType(condition.placeholder[0], 'undefined') ? '' : condition.placeholder[0];
  452. fillSelectOption(select, condition.data, placeholder);
  453. let input = $("<input name='" + condition.name + "_tip' class='form-control form-control-sm ml-2' style='max-width: 150px' data-toggle='tooltip' data-placement='top'>");
  454. input.attr('title', controlJsType(condition.tip[1], 'undefined') ? '' : condition.tip[1]);
  455. input.attr('placeholder', controlJsType(condition.placeholder[1], 'undefined') ? '' : condition.placeholder[1])
  456. let ul_div = $("<div class='pl-0' style='position: absolute;left: 100px;top:25px; max-height: 150px; overflow-y: scroll; border: 1px solid rgb(221, 221, 221); border-radius: 5px; text-align: center; transform: scale(0.9);z-index:1' tabindex='1'></div>");
  457. let ul = $("<ul name='" + condition.name + "' class='list-group pl-0 m-0 p-0 bg-white' style='list-style-type: none;width: 150px;top:35px; z-index: 100' ></ul>");
  458. select_div.append(input).append(ul_div.append(ul));
  459. div.append(select).append(label).append(select_div);
  460. fillMultipleSelectOption(ul, condition.data, condition.name);
  461. input.bind('input propertychange', function () {
  462. let value = this.value;
  463. if (value === '') {
  464. fillMultipleSelectOption(ul, _data[condition.name].data, condition.name);
  465. redenerUl(ul);
  466. return;
  467. }
  468. let select = _data[condition.name].select;
  469. if ([undefined, null, ''].includes(select)) {
  470. select = [];
  471. }
  472. let select_data = _data[condition.name].data.filter(function (map) {
  473. return map.value.includes(value) || select.includes(map.name);
  474. })
  475. fillMultipleSelectOption(ul, select_data, condition.name);
  476. redenerUl(ul);
  477. })
  478. select.change(function () {
  479. let dom = {
  480. name: condition.name,
  481. type: 'select_multiple_select',
  482. value: [this.value]
  483. }
  484. modifyData(dom);
  485. redenerUl(ul);
  486. })
  487. input.focus(function () {
  488. ul_div.show();
  489. })
  490. input.blur(function () {
  491. setTimeout(function () {
  492. if (!select_div.is(':focus')) {
  493. ul_div.hide();
  494. }
  495. }, 1000);
  496. })
  497. select_div.focus(function () {
  498. ul_div.show();
  499. })
  500. select_div.blur(function () {
  501. ul_div.hide();
  502. })
  503. ul_div.blur(function () {
  504. ul_div.hide();
  505. })
  506. ul_div.hide();
  507. return div;
  508. }
  509. // checkbox
  510. function getCheckBox(condition) {
  511. let div1 = $("<div class='form-inline'></div>")
  512. condition.data.forEach(function (map, index) {
  513. let div = $('<div class="custom-control custom-control-inline custom-checkbox"></div>');
  514. let checkbox = $("<input type='checkbox' name='" + condition.name + "' class='custom-control-input' id='" + condition.name + index + "' value='" + map.name + "' >");
  515. let label = $("<label class='custom-control-label text-left font-weight-norma' for='" + condition.name + index + "'>" + map.value + "</label>")
  516. div1.append(div.append(checkbox).append(label));
  517. checkbox.click(function () {
  518. let value = [];
  519. $.each($("input:checkbox[name='" + condition.name + "']:checked"), function () {
  520. value.push($(this).val());
  521. })
  522. let dom = {name: condition.name, type: 'checkbox', value: value, mold: 'check'};
  523. modifyData(dom);
  524. });
  525. })
  526. return div1;
  527. }
  528. // fill select
  529. function fillSelectOption(select, data, placeholder = '') {
  530. select.html('');
  531. if (![undefined, null].includes(placeholder)) {
  532. let option = $("<option value></option>");
  533. if ('' === placeholder) {
  534. option = $("<option value>" + '全部' + placeholder + "</option>");
  535. } else {
  536. option = $("<option value>" + placeholder + "</option>");
  537. }
  538. select.append(option);
  539. }
  540. data.forEach(function (map) {
  541. let option = $("<option value='" + map.value + "'>" + map.name + "</optio>");
  542. select.append(option);
  543. })
  544. if (data !== undefined) {
  545. }
  546. }
  547. // fill multiple select ul
  548. function fillMultipleSelectOption(ul, data, name) {
  549. ul.html('');
  550. data.forEach(function (map) {
  551. let span = $("<span style='cursor:default'>" + map.value + "</span>");
  552. let li = $("<li class='list-group-item pt-0 pb-0' value='" + map.name + "'></li>");
  553. li.append(span);
  554. ul.append(li);
  555. li.click(function () {
  556. let value = li.attr('value');
  557. let dom_data = _data[name].value;
  558. if (controlJsType(dom_data, ['undefined', 'null', 'string'])) {
  559. dom_data = [dom_data];
  560. }
  561. if (dom_data.includes(value)) {
  562. dom_data.splice(dom_data.indexOf(value), 1);
  563. } else {
  564. dom_data.push(value);
  565. dom_data = arrDuplicate(dom_data);
  566. }
  567. let dom = {
  568. name: ul.attr('name'),
  569. type: 'select_multiple_select',
  570. value: dom_data,
  571. select: dom_data,
  572. mold: 'select_multiple_select'
  573. };
  574. modifyData(dom);
  575. redenerUl(ul);
  576. isMultiple(name);
  577. _this.onsubmit();
  578. })
  579. })
  580. }
  581. function isMultiple(name) {
  582. let label = $('#' + name + '_lab');
  583. let select = $('#' + name + '_sel');
  584. let dom_data = _data[name].value;
  585. if (dom_data.length === 1 ) {
  586. select.show();
  587. select.val(dom_data[0]);
  588. label.hide();
  589. }else if(controlJsType(dom_data,'string')){
  590. select.show();
  591. select.val(dom_data);
  592. label.hide();
  593. } else if (dom_data.length >= 2) {
  594. select.hide();
  595. label.show();
  596. }
  597. }
  598. // modify _data
  599. function modifyData(dom) {
  600. _data[dom.name].mold = dom.mold;
  601. _data[dom.name].value = dom.value;
  602. _data[dom.name].select = dom.value;
  603. redenerSearchFormOnData(dom.name, dom.value, dom.mold);
  604. }
  605. // save search on cookie
  606. function saveSearchOnCookie() {
  607. let saveData = {};
  608. for (const key in _data) {
  609. if (!['', null, undefined].includes(_data[key].value)) {
  610. if (controlJsType(_data[key].value, 'array') && _data[key].value.length === 0) {
  611. //console.log(key);
  612. continue;
  613. }
  614. saveData[key] = {
  615. value: _data[key].value,
  616. mold: _data[key].mold,
  617. }
  618. }
  619. }
  620. if (!_this.page) {
  621. saveData['page'] = _this.page;
  622. }
  623. saveCookie(saveData);
  624. }
  625. // hour_minute
  626. function verifyTime(time) {
  627. setTimeout(function () {
  628. time.value = time.value.replace(':', ':');
  629. time.value = time.value.replace(/[a-zA-Z]/, '');
  630. time.value = time.value.replace(/[^\d^\:]/, '');
  631. time.value = time.value.replace(/\:\:/, ':');
  632. time.value = time.value.replace(/^([\d]{1})([\s]{1})/, "$1:");
  633. time.value = time.value.replace(/^([\d]{1})([\d]{1})([\s]{1})/, "$1$2:");
  634. time.value = time.value.replace(/^([\d]{1})([\d]{1})([\d]{1})/, "$1$2:$3");
  635. time.value = time.value.replace(/^([\d]{1})([\d]{1})([\d]{1})([\d]{1})(.*?)/, "$1$2$3$4");
  636. time.value = time.value.replace(/^([\d]{1})([\d]{1})([\d]{1})([\d]{1})/, "$1$2:$3$4");
  637. time.value = time.value.replace(/^([\d]{1})([\d]{1}):([\d]{1})([\d]{1})([\s\S]{1})/, "$1$2:$3$4");
  638. time.value = time.value.replace(/^([\d]{1})([\d]{1}):([\D]{1,99})/, "$1$2:");
  639. time.value = time.value.replace(/^([\d]{1})([\d]{1})([\d]{1})\./, "$1:$2$3");
  640. time.value = time.value.replace(/^([\d]{1})\.([\d]{1})([\d]{1})/, "$1:$2$3");
  641. time.value = time.value.replace(/^([\d]{1})([\d]{2})([\S\s]{1,99})/, "$1$2:$3");
  642. time.value = time.value.replace(/^([\d]{1}):([\d]{2})([\S\s]{1,99})/, "$1:$2");
  643. time.value = time.value.replace(/^([\d])/, "$1");
  644. time.value = time.value.replace(/^([1])([\d]{1})/, "$1$2");
  645. time.value = time.value.replace(/^([3-9])([\d]{1})/, "2$2");
  646. time.value = time.value.replace(/^([2-9]{1})([4-9]{1})/, "$13");
  647. time.value = time.value.replace(/^([\d]{1})([\d]{1}):([6-9]{1})/, "$1$2:5");
  648. time.value = time.value.replace(/^([\d]{1})([\d]{1})$/, "$1$2:");
  649. }, 10);
  650. }
  651. // array duplicate
  652. function arrDuplicate(arr) {
  653. let res = [];
  654. let obj = {};
  655. for (let i = 0; i < arr.length; i++) {
  656. if ([undefined, null, ''].includes(arr[i])) {
  657. continue;
  658. }
  659. if (!obj[arr[i]]) {
  660. obj[arr[i]] = 1;
  661. res.push(arr[i]);
  662. }
  663. }
  664. return res;
  665. }
  666. // get search data
  667. function getSearchData(type = 'array') {
  668. let data = {};
  669. if (type === 'array') {
  670. for (let key in _data) {
  671. if (_data[key].value !== undefined && _data[key].value !== '') {
  672. data[key] = _data[key].value
  673. }
  674. }
  675. } else if (type === 'string') {
  676. data = '';
  677. for (let key in _data) {
  678. if (![undefined, null, ''].includes(_data[key].value)) {
  679. let value = _data[key].value;
  680. if (controlJsType(value, 'string')) {
  681. data = data + "&" + key + "=" + value;
  682. } else if (controlJsType(value, 'array')) {
  683. value.forEach(function (val) {
  684. data = data + "&" + key + "=" + val;
  685. });
  686. }
  687. }
  688. }
  689. }
  690. return data;
  691. }
  692. // renderer input
  693. function rendererSearchFormOnInput(key, value, mold) {
  694. if ([undefined, null, ''].includes(value)) {
  695. $(_form).find("input[name='" + key + "']").val('');
  696. $(_form).find("input[name='" + key + "']").removeClass('bg-warning');
  697. } else {
  698. $(_form).find("input[name='" + key + "']").val(value);
  699. $(_form).find("input[name='" + key + "']").addClass('bg-warning');
  700. }
  701. }
  702. // renderer select
  703. function rendererSearchFormOnSelect(key, value, mold) {
  704. if ([undefined, null, ''].includes(value)) {
  705. $(_form).find("select[name='" + key + "']").val('').removeClass('bg-warning');
  706. if (key === 'paginate') {
  707. $(_form).find("select[name='" + key + "']").val(_this.paginations[0]).removeClass('bg-warning');
  708. }
  709. } else {
  710. $(_form).find("select[name='" + key + "']").val(value);
  711. //console.log(value === _this.paginations[0]);
  712. if (key === 'paginate' && value == _this.paginations[0]) {
  713. return;
  714. }
  715. $(_form).find("select[name='" + key + "']").addClass('bg-warning');
  716. }
  717. }
  718. // renderer check
  719. function rendererSearchFormOnCheck(key, value, mold) {
  720. if ([undefined, null, ''].includes(value)) {
  721. $(_form).find("input[name='" + key + "']").prop("checked", false).removeClass('bg-warning');
  722. } else {
  723. if (controlJsType(value, 'array')) {
  724. value.forEach(function (_value) {
  725. $(_form).find("input[name='" + key + "'][value='" + _value + "']").prop("checked", true).addClass('bg-warning');
  726. })
  727. } else if (controlJsType(value, 'string')) {
  728. $(_form).find("input[name='" + key + "'][value='" + value + "']").prop("checked", true).addClass('bg-warning');
  729. }
  730. }
  731. }
  732. // redener multiple select input
  733. function rendererSearchFormOnMultipleSelect(key, value, mold) {
  734. let ul = $(_form).find("ul[name='" + key + "']");
  735. if ([undefined, null, ''].includes(value) || (controlJsType(value, 'array') && value.length === 0)) {
  736. $(_form).find("input[name='" + key + "_tip']").removeClass('bg-warning');
  737. ul.addClass('bg-warning');
  738. } else if (!!value) {
  739. $(_form).find("input[name='" + key + "_tip']").addClass('bg-warning');
  740. ul.addClass('bg-warning');
  741. } else if (controlJsType(value, 'array') && value.length >= 1) {
  742. $(_form).find("input[name='" + key + "_tip']").addClass('bg-warning');
  743. ul.addClass('bg-warning');
  744. }
  745. redenerUl(ul);
  746. }
  747. // redener multiple select ul
  748. function redenerUl(ul) {
  749. let name = ul.attr('name');
  750. let select = _data[name].select;
  751. if ([null, undefined].includes(select)) {
  752. _data[name].select = [];
  753. select = [];
  754. }
  755. let lis = ul.find('li');
  756. if ([null, undefined, ''].includes(lis)) {
  757. return;
  758. } else {
  759. lis.get().forEach(function (dom) {
  760. if (select.includes($(dom).attr('value'))) {
  761. dom.style.backgroundColor = "#4AA0E6";
  762. $(dom).addClass('active');
  763. } else {
  764. dom.style.backgroundColor = "#FFFFFF";
  765. $(dom).removeClass('active');
  766. }
  767. })
  768. isMultiple(name);
  769. }
  770. }
  771. function rendererSearchFormOnTime(key, value, mold) {
  772. if ([undefined, null, ''].includes(value)) {
  773. $(_form).find("input[name='+key+']").val(value.substring(0, 10)).addClass('bg-warning');
  774. if (value.length > 11 + 5) {
  775. $(_form).find("input[name='" + key + "_tim']").val(value.substring(11, 5));
  776. }
  777. } else {
  778. $(_form).find("input[name='+key+']").val("").removeClass('bg-warning');
  779. $(_form).find("input[name='" + key + "_tim']").val("");
  780. }
  781. }
  782. function visibleClearBtn() {
  783. let bool = false;
  784. for (const key in _data) {
  785. if (key === 'paginate') {
  786. if ((key === 'paginate' && _data[key].value !== _this.paginations[0])) {
  787. bool = true;
  788. }
  789. } else {
  790. if (![undefined, null, ''].includes(_data[key].value)) {
  791. bool = true;
  792. }
  793. }
  794. }
  795. if (bool) {
  796. _clearTr.show();
  797. } else {
  798. _clearTr.hide();
  799. }
  800. }
  801. function inputKeyDown() {
  802. $(_form).find('input').keydown(function (e) {
  803. if (e.keyCode === 13) {
  804. if (_this.keydownSearch) {
  805. _this.onsubmit()
  806. }
  807. if (controlJsType(_this.keydownfun, 'fun')) {
  808. _this.keydownfun();
  809. }
  810. }
  811. });
  812. $(_form).find("input[type='date']").change(function (e) {
  813. if (_this.keydownSearch) {
  814. _this.onsubmit()
  815. }
  816. if (controlJsType(_this.keydownfun, 'fun')) {
  817. _this.keydownfun();
  818. }
  819. });
  820. }
  821. function selectChange() {
  822. $(_form).find('select').change(function () {
  823. _this.onsubmit();
  824. })
  825. }
  826. function redenerSearchFormOnData(key, value, mold) {
  827. if (mold === 'input') {
  828. rendererSearchFormOnInput(key, value, mold);
  829. } else if (mold === 'select') {
  830. rendererSearchFormOnSelect(key, value, mold);
  831. } else if (mold === 'check') {
  832. rendererSearchFormOnCheck(key, value, mold);
  833. } else if (mold === 'select_multiple_select') {
  834. rendererSearchFormOnMultipleSelect(key, value, mold);
  835. } else if (mold === 'time') {
  836. rendererSearchFormOnTime(key, value, mold);
  837. }
  838. }
  839. // 数据转换
  840. function switchData() {
  841. _this.condition.forEach(function (conditions) {
  842. conditions.forEach(function (condition) {
  843. if (['input', 'select', 'dataTime', 'search_select', 'time', 'select_multiple_select','checkbox'].includes(condition.type)) {
  844. if (!condition.select) {
  845. condition.select = '';
  846. }
  847. let data = {
  848. name: condition.name,
  849. type: condition.type,
  850. value: condition.value,
  851. select: condition.select,
  852. mold: ['input', 'dataTime'].includes(condition.type) ? 'input' : condition.type
  853. }
  854. if (condition.type === 'search_select') {
  855. data.mold = 'select';
  856. }
  857. _data[condition.name] = data;
  858. } else if (['dataTime_dataTime', 'input_input', 'input_select', 'dataTime_select'].includes(condition.type)) {
  859. let types = condition.type.split("_");
  860. if (!condition.select) {
  861. condition.select = ['', ''];
  862. }
  863. if (!condition.value) {
  864. condition.value = ['', ''];
  865. }
  866. condition.name.forEach(function (_name, index) {
  867. let data = {
  868. name: _name,
  869. type: types[index],
  870. value: condition.value[index],
  871. select: condition.select[index],
  872. mold: ['input', 'dataTime'].includes(types[index]) ? 'input' : types[index]
  873. }
  874. _data[_name] = data;
  875. })
  876. }
  877. })
  878. })
  879. }
  880. // redererSearchForm on cookie
  881. function rendererSearchForm() {
  882. let url = document.referrer;
  883. let partt = /(Edit\/)|(\/eidt)|(eidt\/)/i;
  884. if (url.search(partt) > 0) {
  885. rendererOptionOnCookie();
  886. } else {
  887. rendererOptionOnUrl();
  888. }
  889. }
  890. function rendererOptionOnCookie() {
  891. //console.log('rendererSearchFromOnCookie');
  892. let data = fetchCookie();
  893. if (data === undefined) {
  894. return;
  895. }
  896. data = JSON.parse(data);
  897. for (let key in data) {
  898. _data[key].value = data[key].value;
  899. _data[key].mold = data[key].mold;
  900. _data[key].select = data[key].select;
  901. }
  902. rendererSearchFormOn_data();
  903. }
  904. function rendererOptionOnUrl() {
  905. if (!window.location.search) {
  906. return;
  907. }
  908. searchOptionToUrlsearch();
  909. rendererSearchFormOn_data();
  910. }
  911. function rendererSearchFormOn_data() {
  912. // console.log('rendererSearchFormOn_data', _data);
  913. for (let key in _data) {
  914. let value = _data[key].value, type = _data[key].type, mold = _data[key].mold;
  915. _data[key].select = value;
  916. if (['input', 'dataTime'].includes(mold)) {
  917. rendererSearchFormOnInput(key, value, mold);
  918. } else if (['select'].includes(mold)) {
  919. rendererSearchFormOnSelect(key, value, mold);
  920. } else if (['checkbox'].includes(mold)) {
  921. rendererSearchFormOnCheck(key, value, mold);
  922. } else if (['select_multiple_select'].includes(mold)) {
  923. if (controlJsType(value, ['array', 'string'])) {
  924. let ul = $(_form).find("ul[name='" + key + "']");
  925. redenerUl(ul);
  926. rendererSearchFormOnMultipleSelect(key, value, mold);
  927. }
  928. } else if (['time'].includes(type) && value !== undefined) {
  929. $(_form).find("input[name='" + key + "']").val(value.substr(0, 10));
  930. $(_form).find("input[id='" + key + "_min']").val(value.substr(11, value.length));
  931. }
  932. /* if (['input', 'dataTime', 'input_input', 'dataTime_dataTime'].includes(type)) {
  933. rendererSearchFormOnInput(key,value,mold);
  934. } else if (['select', 'input_select', 'dataTime_select'].includes(type)) {
  935. if (mold === 'select') {
  936. rendererSearchFormOnSelect(key,value,mold)
  937. } else if (mold === 'input') {
  938. rendererSearchFormOnInput(key,value,mold);
  939. } else if (mold === 'dataTime') {
  940. rendererSearchFormOnInput(key,value,mold);
  941. }
  942. } else if (['input_select_text'].includes(type)) {
  943. if (mold === 'input') {
  944. rendererSearchFormOnInput(key,value,mold);
  945. } else if (mold === 'select') {
  946. rendererSearchFormOnSelect(key,value,mold)
  947. }
  948. } else if (['checkbox'].includes(type)) {
  949. if (controlJsType(value, 'array')) {
  950. value.forEach(function (map) {
  951. $(_form).find("input[type='checkbox'][name='" + key + "'][value='" + map + "']").attr("checked", true);
  952. })
  953. }
  954. } else if (['select_multiple_select'].includes(type)) {
  955. if (controlJsType(value, ['array','string']) ) {
  956. let ul = $(_form).find("ul[name='" + key + "']");
  957. redenerUl(ul);
  958. rendererSearchFormOnMultipleSelect(key,value,mold);
  959. }
  960. } else if (['time'].includes(type) && value !== undefined) {
  961. $(_form).find("input[name='"+key+"']").val(value.substr(0,10));
  962. $(_form).find("input[id='"+key+"_min']").val(value.substr(11,value.length));
  963. }*/
  964. }
  965. if ([undefined, null, ''].includes(data['paginate'])) {
  966. return;
  967. }
  968. if ([undefined, null, ''].includes(data['paginate'].value)) {
  969. $(_form).find("select[name='paginate']").val(_this.paginations[0]);
  970. } else {
  971. $(_form).find("select[name='paginate']").val(data['paginate'].value);
  972. }
  973. }
  974. // url path on search form option renderer
  975. function searchOptionToUrlsearch() {
  976. let data = window.location.search;
  977. data = decodeURIComponent(data);
  978. if (!!data) {
  979. data = (data.substr(1)).split('&');
  980. data = convertArrayToObj(data);
  981. for (const key in data) {
  982. if(!data[key]){
  983. continue;
  984. }
  985. if (key === 'paginate') {
  986. _data[key] = {
  987. name: key,
  988. value: data[key],
  989. type: 'select',
  990. mold: 'select'
  991. }
  992. } else if (key === 'page') {
  993. _page = data[key];
  994. } else {
  995. _data[key].value = data[key];
  996. }
  997. // console.log('key', key, typeof key);
  998. }
  999. }
  1000. }
  1001. // cookie -> data
  1002. function set_dataOnCookie() {
  1003. let data = fetchCookie();
  1004. data = JSON.parse(data);
  1005. if (!data) {
  1006. return;
  1007. }
  1008. for (const key in data) {
  1009. if (!!data[key]) {
  1010. _data[key].value = data[key].value;
  1011. }
  1012. }
  1013. }
  1014. // array - > object
  1015. function convertArrayToObj(arr) {
  1016. if (!arr || !controlJsType(arr, 'array')) {
  1017. return {};
  1018. } else if (controlJsType(arr, 'array') && arr.length > 0) {
  1019. let data = {};
  1020. arr.forEach(function (map) {
  1021. let arr = map.split('='), key = arr[0], value = arr[1];
  1022. if (!data[key]) {
  1023. data[key] = value;
  1024. } else {
  1025. if (controlJsType(data[key], 'string')) {
  1026. data[key] = [data[key], value];
  1027. } else if (controlJsType(data[key], 'array')) {
  1028. data[key].push(value);
  1029. }
  1030. }
  1031. })
  1032. return data;
  1033. }
  1034. }
  1035. // paginate
  1036. function pervPage() {
  1037. let obj = getSearchData();
  1038. if(!!obj['page'] && obj['page']>1){
  1039. obj['page'] = obj['page']-1;
  1040. }
  1041. return getSearchUri(obj);
  1042. }
  1043. function nextPage() {
  1044. let obj = getSearchData();
  1045. if(!!obj['page'] ){
  1046. obj['page'] = obj['page']+1;
  1047. }else{
  1048. obj['page'] = 2;
  1049. }
  1050. if(!obj['paginate']){
  1051. obj['paginate'] = 50;
  1052. }
  1053. return getSearchUri(obj);
  1054. }
  1055. function getSearchObj() {
  1056. let data = window.location.search;
  1057. data = decodeURIComponent(data);
  1058. if(!data){
  1059. return {};
  1060. }
  1061. let saveData = {};
  1062. data = data.substr(1).split('&');
  1063. data.forEach(function (map) {
  1064. let arr = map.split('&'),key = arr[0],value = arr[1];
  1065. if(!!value){
  1066. if (!saveData[key]) {
  1067. saveData[key] = value;
  1068. } else {
  1069. if (controlJsType(data[key], 'string')) {
  1070. saveData[key] = [saveData[key] , value];
  1071. } else if (controlJsType(data[key], 'array')) {
  1072. saveData[key].push(value);
  1073. }
  1074. }
  1075. }
  1076. })
  1077. return saveData;
  1078. }
  1079. function getSearchUri(obj){
  1080. let string = "?";
  1081. for (const key in obj) {
  1082. if(controlJsType(obj[key],['string','number'])){
  1083. string+= key + "=" + obj[key]+'&';
  1084. }else if( controlJsType(obj[key],'array')&&obj[key].length > 0){
  1085. obj[key].forEach(function(value){
  1086. string+=key + "=" + value+'&';
  1087. })
  1088. }
  1089. }
  1090. return string;
  1091. }
  1092. };