queryForm.js 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212
  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;
  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) ? false : true ;
  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 (['dataTime_dataTime', 'input_input'].includes(condition.type)) {
  113. td = $("<td style='width: 330px'</td>")
  114. } else if (['select_multiple_select', 'time', 'dataTime_select'].includes(condition.type)) {
  115. td = $("<td style='width: 280px'</td>");
  116. } else if (['time', 'dataTime_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', 'dataTime', 'input_select'].includes(condition.type)) {
  138. _width += 260;
  139. } else if (['dataTime_dataTime', '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', 'dataTime_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 === "dataTime" && getDataTime(condition))
  295. || (type === "time" && getTime(condition))
  296. || (type === "input_input" && getInputInput(condition))
  297. || (type === "dataTime_dataTime" && getDataTimeDataTime(condition))
  298. || (type === "dataTime_select" && getDataTimeSelect(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 getDataTime(condition) {
  373. let dataTime = $("<input type='date' class='form-control form-control-sm' name='" + condition.name + "' style='max-width: 150px' data-toggle='tooltip' data-placement='top' title='" + condition.tip + "' style='width: 200px'>");
  374. dataTime.attr('title', controlJsType(condition.tip, 'undefined') ? '' : condition.tip);
  375. dataTime.bind('input propertychange', function () {
  376. let dom = {name: condition.name, type: 'dataTime', value: this.value, mold: 'dataTime'};
  377. modifyData(dom);
  378. })
  379. return dataTime;
  380. }
  381. // time
  382. function getTime(condition) {
  383. let div = $("<div class='form-inline'></div>");
  384. let dataTime = $("<input type='date' class='form-control form-control-sm' name='" + condition.name + "' style='width:150px' data-toggle='tooltip' data-placement='top' >");
  385. dataTime.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. dataTime.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(dataTime.val())) {
  398. return;
  399. }
  400. let value = ['null', 'undefined', ''].includes(dataTime.val()) ? '' : dataTime.val() + ' ' + min.val();
  401. //let value = dataTime.value !== '' ? dataTime.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(dataTime).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. // dataTime_dataTime
  425. function getDataTimeDataTime(condition) {
  426. let div = $("<div class='form-inline'></div>");
  427. let dataTime1 = $("<input type='date' class='form-control form-control-sm' name='" + condition.name[0] + "' style='width: 150px' data-toggle='tooltip' data-placement='top' >");
  428. dataTime1.attr('title', controlJsType(condition.tip[0], 'undefined') ? '' : condition.tip[0]);
  429. let dataTime2 = $("<input type='date' class='form-control form-control-sm ml-2' name='" + condition.name[1] + "' style='width: 150px;' data-toggle='tooltip' data-placement='top' >");
  430. dataTime2.attr('title', controlJsType(condition.tip[1], 'undefined') ? '' : condition.tip[1]);
  431. dataTime1.bind('input propertychange', function () {
  432. let dom = {name: this.name, type: 'dataTime_dataTime', value: this.value, mold: 'dataTime'};
  433. modifyData(dom);
  434. })
  435. dataTime2.bind('input propertychange', function () {
  436. let dom = {name: this.name, type: 'dataTime_dataTime', value: this.value, mold: 'dataTime'};
  437. modifyData(dom);
  438. })
  439. return div.append(dataTime1).append(dataTime2);
  440. }
  441. // dataTime_select
  442. function getDataTimeSelect(condition) {
  443. let div = $("<div class='form-inline'></div>");
  444. let dataTime = $("<input type='date' class='form-control form-control-sm' name='" + condition.name[0] + "' style='max-width: 150px;' data-toggle='tooltip' data-placement='top' >");
  445. dataTime.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. dataTime.bind('input propertychange', function () {
  450. let dom = {name: this.name, type: 'dataTime_select', value: this.value, mold: 'dataTime'};
  451. modifyData(dom);
  452. })
  453. select.change(function () {
  454. let dom = {name: this.name, type: 'dataTime_select', value: this.value, mold: 'select'};
  455. modifyData(dom);
  456. })
  457. return div.append(dataTime).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. }
  630. // save search on cookie
  631. function saveSearchOnCookie() {
  632. let saveData = {};
  633. for (const key in _data) {
  634. if (!['', null, undefined].includes(_data[key].value)) {
  635. if (controlJsType(_data[key].value, 'array') && _data[key].value.length === 0) {
  636. continue;
  637. }
  638. saveData[key] = {
  639. value: _data[key].value,
  640. mold: _data[key].mold,
  641. }
  642. }
  643. }
  644. if (!_this.page) {
  645. saveData['page'] = _this.page;
  646. }
  647. saveCookie(saveData);
  648. }
  649. // hour_minute
  650. function verifyTime(time) {
  651. setTimeout(function () {
  652. time.value = time.value.replace(':', ':');
  653. time.value = time.value.replace(/[a-zA-Z]/, '');
  654. time.value = time.value.replace(/[^\d^\:]/, '');
  655. time.value = time.value.replace(/\:\:/, ':');
  656. time.value = time.value.replace(/^([\d]{1})([\s]{1})/, "$1:");
  657. time.value = time.value.replace(/^([\d]{1})([\d]{1})([\s]{1})/, "$1$2:");
  658. time.value = time.value.replace(/^([\d]{1})([\d]{1})([\d]{1})/, "$1$2:$3");
  659. time.value = time.value.replace(/^([\d]{1})([\d]{1})([\d]{1})([\d]{1})(.*?)/, "$1$2$3$4");
  660. time.value = time.value.replace(/^([\d]{1})([\d]{1})([\d]{1})([\d]{1})/, "$1$2:$3$4");
  661. time.value = time.value.replace(/^([\d]{1})([\d]{1}):([\d]{1})([\d]{1})([\s\S]{1})/, "$1$2:$3$4");
  662. time.value = time.value.replace(/^([\d]{1})([\d]{1}):([\D]{1,99})/, "$1$2:");
  663. time.value = time.value.replace(/^([\d]{1})([\d]{1})([\d]{1})\./, "$1:$2$3");
  664. time.value = time.value.replace(/^([\d]{1})\.([\d]{1})([\d]{1})/, "$1:$2$3");
  665. time.value = time.value.replace(/^([\d]{1})([\d]{2})([\S\s]{1,99})/, "$1$2:$3");
  666. time.value = time.value.replace(/^([\d]{1}):([\d]{2})([\S\s]{1,99})/, "$1:$2");
  667. time.value = time.value.replace(/^([\d])/, "$1");
  668. time.value = time.value.replace(/^([1])([\d]{1})/, "$1$2");
  669. time.value = time.value.replace(/^([3-9])([\d]{1})/, "2$2");
  670. time.value = time.value.replace(/^([2-9]{1})([4-9]{1})/, "$13");
  671. time.value = time.value.replace(/^([\d]{1})([\d]{1}):([6-9]{1})/, "$1$2:5");
  672. time.value = time.value.replace(/^([\d]{1})([\d]{1})$/, "$1$2:");
  673. }, 10);
  674. }
  675. // array duplicate
  676. function arrDuplicate(arr) {
  677. let res = [];
  678. let obj = {};
  679. for (let i = 0; i < arr.length; i++) {
  680. if ([undefined, null, ''].includes(arr[i])) {
  681. continue;
  682. }
  683. if (!obj[arr[i]]) {
  684. obj[arr[i]] = 1;
  685. res.push(arr[i]);
  686. }
  687. }
  688. return res;
  689. }
  690. // get search data
  691. function getSearchData(type = 'array') {
  692. let data = {};
  693. if (type === 'array') {
  694. for (let key in _data) {
  695. if (_data[key].value !== undefined && _data[key].value !== '') {
  696. data[key] = _data[key].value
  697. }
  698. }
  699. } else if (type === 'string') {
  700. data = '';
  701. for (let key in _data) {
  702. if (![undefined, null, ''].includes(_data[key].value)) {
  703. let value = _data[key].value;
  704. if (controlJsType(value, 'string')) {
  705. data = data + "&" + key + "=" + value;
  706. } else if (controlJsType(value, 'array')) {
  707. value.forEach(function (val) {
  708. data = data + "&" + key + "=" + val;
  709. });
  710. }
  711. }
  712. }
  713. }
  714. return data;
  715. }
  716. // renderer input
  717. function rendererSearchFormOnInput(key, value, mold) {
  718. if ([undefined, null, ''].includes(value)) {
  719. $(_form).find("input[name='" + key + "']").val('');
  720. $(_form).find("input[name='" + key + "']").removeClass('bg-warning');
  721. } else {
  722. $(_form).find("input[name='" + key + "']").val(value);
  723. $(_form).find("input[name='" + key + "']").addClass('bg-warning');
  724. }
  725. }
  726. // renderer select
  727. function rendererSearchFormOnSelect(key, value, mold) {
  728. if ([undefined, null, ''].includes(value)) {
  729. $(_form).find("select[name='" + key + "']").val('').removeClass('bg-warning');
  730. if (key === 'paginate') {
  731. $(_form).find("select[name='" + key + "']").val(_this.paginations[0]).removeClass('bg-warning');
  732. }
  733. } else {
  734. $(_form).find("select[name='" + key + "']").val(value);
  735. if (key === 'paginate' && value == _this.paginations[0]) {
  736. return;
  737. }
  738. $(_form).find("select[name='" + key + "']").addClass('bg-warning');
  739. }
  740. }
  741. // renderer check
  742. function rendererSearchFormOnCheck(key, value, mold) {
  743. if ([undefined, null, ''].includes(value)) {
  744. $(_form).find("input[name='" + key + "']").prop("checked", false).removeClass('bg-warning');
  745. } else {
  746. if (controlJsType(value, 'array')) {
  747. value.forEach(function (_value) {
  748. $(_form).find("input[name='" + key + "'][value='" + _value + "']").prop("checked", true).addClass('bg-warning');
  749. })
  750. } else if (controlJsType(value, 'string')) {
  751. $(_form).find("input[name='" + key + "'][value='" + value + "']").prop("checked", true).addClass('bg-warning');
  752. }
  753. }
  754. }
  755. // redener multiple select input
  756. function rendererSearchFormOnMultipleSelect(key, value, mold) {
  757. let ul = $(_form).find("ul[name='" + key + "']");
  758. if ([undefined, null, ''].includes(value) || (controlJsType(value, 'array') && value.length === 0)) {
  759. $(_form).find("input[name='" + key + "_tip']").removeClass('bg-warning');
  760. ul.addClass('bg-warning');
  761. } else if (!!value) {
  762. $(_form).find("input[name='" + key + "_tip']").addClass('bg-warning');
  763. ul.addClass('bg-warning');
  764. } else if (controlJsType(value, 'array') && value.length >= 1) {
  765. $(_form).find("input[name='" + key + "_tip']").addClass('bg-warning');
  766. ul.addClass('bg-warning');
  767. }
  768. redenerUl(ul);
  769. }
  770. // redener multiple select ul
  771. function redenerUl(ul) {
  772. let name = ul.attr('name');
  773. let select = _data[name].select;
  774. if ([null, undefined].includes(select)) {
  775. _data[name].select = [];
  776. select = [];
  777. }
  778. let lis = ul.find('li');
  779. if ([null, undefined, ''].includes(lis)) {
  780. return;
  781. } else {
  782. lis.get().forEach(function (dom) {
  783. if (select.includes($(dom).attr('value'))) {
  784. dom.style.backgroundColor = "#4AA0E6";
  785. $(dom).addClass('active');
  786. } else {
  787. dom.style.backgroundColor = "#FFFFFF";
  788. $(dom).removeClass('active');
  789. }
  790. })
  791. isMultiple(ul.attr('name'));
  792. }
  793. }
  794. function rendererSearchFormOnTime(key, value, mold) {
  795. if ([undefined, null, ''].includes(value)) {
  796. $(_form).find("input[name='+key+']").val(value.substring(0, 10)).addClass('bg-warning');
  797. if (value.length > 11 + 5) {
  798. $(_form).find("input[name='" + key + "_tim']").val(value.substring(11, 5));
  799. }
  800. } else {
  801. $(_form).find("input[name='+key+']").val("").removeClass('bg-warning');
  802. $(_form).find("input[name='" + key + "_tim']").val("");
  803. }
  804. }
  805. function visibleClearBtn() {
  806. let bool = false;
  807. for (const key in _data) {
  808. if (key === 'paginate') {
  809. if ((key === 'paginate' && _data[key].value !== _this.paginations[0])) {
  810. bool = true;
  811. }
  812. } else {
  813. if (![undefined, null, ''].includes(_data[key].value)) {
  814. if(controlJsType(_data[key].value,'array') && _data[key].value.length === 0 ){
  815. continue;
  816. }
  817. bool = true;
  818. }
  819. }
  820. }
  821. if (bool) {
  822. _clearTr.show();
  823. } else {
  824. _clearTr.hide();
  825. }
  826. }
  827. function inputKeyDown() {
  828. $(_form).find('input').keydown(function (e) {
  829. if (e.keyCode === 13) {
  830. if (_this.keydownSearch) {
  831. _this.onsubmit()
  832. }
  833. if (controlJsType(_this.keydownfun, 'fun')) {
  834. _this.keydownfun();
  835. }
  836. }
  837. });
  838. $(_form).find("input[type='date']").change(function (e) {
  839. if (_this.keydownSearch) {
  840. _this.onsubmit()
  841. }
  842. if (controlJsType(_this.keydownfun, 'fun')) {
  843. _this.keydownfun();
  844. }
  845. });
  846. }
  847. function selectChange() {
  848. $(_form).find('select').change(function () {
  849. _this.onsubmit();
  850. })
  851. }
  852. function redenerSearchFormOnData(key, value, mold) {
  853. if (mold === 'input') {
  854. rendererSearchFormOnInput(key, value, mold);
  855. } else if (mold === 'select') {
  856. rendererSearchFormOnSelect(key, value, mold);
  857. } else if (mold === 'check') {
  858. rendererSearchFormOnCheck(key, value, mold);
  859. } else if (mold === 'select_multiple_select') {
  860. rendererSearchFormOnMultipleSelect(key, value, mold);
  861. } else if (mold === 'time') {
  862. rendererSearchFormOnTime(key, value, mold);
  863. }
  864. }
  865. // 数据转换
  866. function switchData() {
  867. _this.condition.forEach(function (conditions) {
  868. conditions.forEach(function (condition) {
  869. if (['input', 'select', 'dataTime', 'search_select', 'time', 'select_multiple_select','checkbox'].includes(condition.type)) {
  870. if (!condition.select) {
  871. condition.select = '';
  872. }
  873. let data = {
  874. name: condition.name,
  875. type: condition.type,
  876. value: condition.value,
  877. select: condition.select,
  878. mold: ['input', 'dataTime'].includes(condition.type) ? 'input' : condition.type,
  879. data:condition.data
  880. }
  881. if (condition.type === 'search_select') {
  882. data.mold = 'select';
  883. }
  884. if(condition.type === 'select_multiple_select'){
  885. data.value = [];
  886. }
  887. _data[condition.name] = data;
  888. } else if (['dataTime_dataTime', 'input_input', 'input_select', 'dataTime_select'].includes(condition.type)) {
  889. let types = condition.type.split("_");
  890. if (!condition.select) {
  891. condition.select = ['', ''];
  892. }
  893. if (!condition.value) {
  894. condition.value = ['', ''];
  895. }
  896. condition.name.forEach(function (_name, index) {
  897. let data = {
  898. name: _name,
  899. type: types[index],
  900. value: condition.value[index],
  901. select: condition.select[index],
  902. mold: ['input', 'dataTime'].includes(types[index]) ? 'input' : types[index]
  903. }
  904. _data[_name] = data;
  905. })
  906. }
  907. })
  908. })
  909. }
  910. // redererSearchForm on cookie
  911. function rendererSearchForm() {
  912. let url = document.referrer;
  913. let partt = /(Edit\/)|(\/eidt)|(eidt\/)/i;
  914. if (url.search(partt) > 0) {
  915. rendererOptionOnCookie();
  916. } else {
  917. rendererOptionOnUrl();
  918. }
  919. }
  920. function rendererOptionOnCookie() {
  921. let data = fetchCookie();
  922. if (data === undefined) {
  923. return;
  924. }
  925. data = JSON.parse(data);
  926. for (let key in data) {
  927. _data[key].value = data[key].value;
  928. _data[key].mold = data[key].mold;
  929. _data[key].select = data[key].select;
  930. }
  931. rendererSearchFormOn_data();
  932. }
  933. function rendererOptionOnUrl() {
  934. if (!window.location.search) {
  935. return;
  936. }
  937. searchOptionToUrlsearch();
  938. rendererSearchFormOn_data();
  939. }
  940. function rendererSearchFormOn_data() {
  941. for (let key in _data) {
  942. let value = _data[key].value, type = _data[key].type, mold = _data[key].mold;
  943. _data[key].select = value;
  944. if (['input', 'dataTime'].includes(mold)) {
  945. rendererSearchFormOnInput(key, value, mold);
  946. } else if (['select'].includes(mold)) {
  947. rendererSearchFormOnSelect(key, value, mold);
  948. } else if (['checkbox'].includes(mold)) {
  949. rendererSearchFormOnCheck(key, value, mold);
  950. } else if (['select_multiple_select'].includes(mold)) {
  951. if (controlJsType(value, ['array', 'string'])) {
  952. let ul = $(_form).find("ul[name='" + key + "']");
  953. redenerUl(ul);
  954. rendererSearchFormOnMultipleSelect(key, value, mold);
  955. }
  956. } else if (['time'].includes(type) && value !== undefined) {
  957. $(_form).find("input[name='" + key + "']").val(value.substr(0, 10));
  958. $(_form).find("input[id='" + key + "_min']").val(value.substr(11, value.length));
  959. }
  960. }
  961. if ([undefined, null, ''].includes(data['paginate'])) {
  962. return;
  963. }
  964. if ([undefined, null, ''].includes(data['paginate'].value)) {
  965. $(_form).find("select[name='paginate']").val(_this.paginations[0]);
  966. } else {
  967. $(_form).find("select[name='paginate']").val(data['paginate'].value);
  968. }
  969. }
  970. // url path on search form option renderer
  971. function searchOptionToUrlsearch() {
  972. let data = window.location.search;
  973. data = decodeURIComponent(data);
  974. if (!!data) {
  975. data = (data.substr(1)).split('&');
  976. data = convertArrayToObj(data);
  977. for (const key in data) {
  978. if(!data[key] || _this.param[key]){
  979. continue;
  980. }
  981. if (key === 'paginate') {
  982. _data[key] = {
  983. name: key,
  984. value: data[key],
  985. type: 'select',
  986. mold: 'select'
  987. }
  988. } else if (key === 'page') {
  989. _page = data[key];
  990. } else if(_data[key].type === 'select_multiple_select' ){
  991. if(!_data[key]){
  992. _data[key].value = [];
  993. }else{
  994. _data[key].value = data[key].split(',');
  995. }
  996. }else {
  997. _data[key].value = data[key];
  998. }
  999. }
  1000. }
  1001. }
  1002. // cookie -> data
  1003. function set_dataOnCookie() {
  1004. let data = fetchCookie();
  1005. data = JSON.parse(data);
  1006. if (!data) {
  1007. return;
  1008. }
  1009. for (const key in data) {
  1010. if (!!data[key]) {
  1011. _data[key].value = data[key].value;
  1012. }
  1013. }
  1014. }
  1015. // array - > object
  1016. function convertArrayToObj(arr) {
  1017. if (!arr || !controlJsType(arr, 'array')) {
  1018. return {};
  1019. } else if (controlJsType(arr, 'array') && arr.length > 0) {
  1020. let data = {};
  1021. arr.forEach(function (map) {
  1022. let arr = map.split('='), key = arr[0], value = arr[1];
  1023. if (!data[key]) {
  1024. data[key] = value;
  1025. } else {
  1026. if (controlJsType(data[key], 'string')) {
  1027. data[key] = [data[key], value];
  1028. } else if (controlJsType(data[key], 'array')) {
  1029. data[key].push(value);
  1030. }
  1031. }
  1032. })
  1033. return data;
  1034. }
  1035. }
  1036. // paginate
  1037. function pervPage() {
  1038. let obj = getSearchData();
  1039. if(!!obj['page'] && obj['page']>1){
  1040. obj['page'] = obj['page']-1;
  1041. }
  1042. return getSearchUri(obj);
  1043. }
  1044. function nextPage() {
  1045. let obj = getSearchData();
  1046. if(!!obj['page'] ){
  1047. obj['page'] = obj['page']+1;
  1048. }else{
  1049. obj['page'] = 2;
  1050. }
  1051. if(!obj['paginate']){
  1052. obj['paginate'] = 50;
  1053. }
  1054. return getSearchUri(obj);
  1055. }
  1056. function getSearchObj() {
  1057. let data = window.location.search;
  1058. data = decodeURIComponent(data);
  1059. if(!data){
  1060. return {};
  1061. }
  1062. let saveData = {};
  1063. data = data.substr(1).split('&');
  1064. data.forEach(function (map) {
  1065. let arr = map.split('&'),key = arr[0],value = arr[1];
  1066. if(!!value){
  1067. if (!saveData[key]) {
  1068. saveData[key] = value;
  1069. } else {
  1070. if (controlJsType(data[key], 'string')) {
  1071. saveData[key] = [saveData[key] , value];
  1072. } else if (controlJsType(data[key], 'array')) {
  1073. saveData[key].push(value);
  1074. }
  1075. }
  1076. }
  1077. })
  1078. return saveData;
  1079. }
  1080. function getPage(){
  1081. return getSearchObj()['page'];
  1082. }
  1083. // paginate
  1084. function pervPage() {
  1085. let obj = getSearchData();
  1086. _page = getPage();
  1087. if(!obj['paginate']){
  1088. obj['paginate'] = 50;
  1089. }
  1090. if(Number(_page)>1){
  1091. _page= Number(_page)-1;
  1092. }else{
  1093. _page = 1;
  1094. }
  1095. return getSearchUri(obj);
  1096. }
  1097. function nextPage() {
  1098. let obj = getSearchData();
  1099. _page = getPage();
  1100. if(!_page){_page=1;}
  1101. if(_page){
  1102. _page = Number(_page)+ 1;
  1103. }
  1104. if(!obj['paginate']){
  1105. obj['paginate'] = 50;
  1106. }
  1107. return getSearchUri(obj);
  1108. }
  1109. function goPage(page){
  1110. let obj = getSearchData();
  1111. _page = page;
  1112. return getSearchUri(obj);
  1113. }
  1114. function getSearchUri(obj){
  1115. let string = "?";
  1116. for (const key in obj) {
  1117. if(controlJsType(obj[key],['string','number'])){
  1118. string+= key + "=" + obj[key]+'&';
  1119. }else if( controlJsType(obj[key],'array')&&obj[key].length > 0){
  1120. obj[key].forEach(function(value){
  1121. string+=key + "=" + value+'&';
  1122. })
  1123. }
  1124. }
  1125. return string;
  1126. }
  1127. };