queryForm.js 49 KB

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