queryForm.js 49 KB

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