queryForm.js 50 KB

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