queryForm.js 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222
  1. const query = function getQueryForm(data) {
  2. {
  3. this.el = data.el || '#form_div';
  4. this.form = data.form;
  5. this.method = data.method || 'get';
  6. this.url = data.url || getPathname();
  7. this.condition = data.condition;
  8. this.paginations = [50, 100, 200, 500] || data.paginations;
  9. this.keydownfun = data.keydownfun || undefined;
  10. this.selectChange = data.selectChange || undefined;
  11. this.searchClick = data.searchClick || undefined;
  12. this.selectfun = data.selectfun || undefined;
  13. this._onsubmit = data._onsubmit || undefined;
  14. this.keydownSearch = data.keydownSearch || true;
  15. this.selectChangeSearch = data.selectChangeSearch || true;
  16. this.tip = data.tip || '';
  17. this.nextPage = nextPage;
  18. this.pervPage = pervPage;
  19. this.goPage =goPage;
  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. map.value.forEach(function (value) {
  36. form.append("<input type='checkbox' name='" + key + "' value='" + value + "' checked='checked' >");
  37. })
  38. }
  39. }
  40. for (let key in this.param){
  41. form.append("<input type='text' name='" + key + "' value='" + this.param[key] + "'>");
  42. }
  43. if (_this.method !== 'get') {
  44. form.append("<input type='hidden' name='_token' value='" + $('meta[name="csrf-token"]').attr('content') + "'>");
  45. form.append("<input type='hidden' name='_method' value='" + _this.method + "'>");
  46. form.attr('action', _this.url);
  47. }
  48. _hidden_div.html('');
  49. _hidden_div.append(form);
  50. form.submit();
  51. }
  52. }
  53. let _this = this;
  54. let _parentNode = null;
  55. let _data = {};
  56. let _form = [];
  57. let _table = null;
  58. let _clearTr = null;
  59. let _pagination = null;
  60. let _baseData = data;
  61. let _searchBtn = null;
  62. let _hidden_div = null;
  63. let _parentNode_top = null;
  64. let _page = '';
  65. this.init = function () {
  66. _parentNode = $(_this.el);
  67. _form = $("<div ></div>");
  68. _table = $("<table class='table table-sm table-bordered m-0 position-static' style='background: rgb(255, 255, 255);'></table>");
  69. fillTable();
  70. switchData();
  71. addHiedDiv();
  72. rendererSearchForm();
  73. visibleClearBtn();
  74. parentNodeFloat();
  75. inputKeyDown();
  76. selectChange();
  77. createTip();
  78. $('[data-toggle="tooltip"]').tooltip({'trigger': 'hover'})
  79. }
  80. // form fixed
  81. function parentNodeFloat() {
  82. _parentNode_top = _parentNode.offset().top;
  83. let height = _parentNode.height();
  84. window.onscroll = function () {
  85. let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
  86. if (scrollTop > _parentNode_top) {
  87. _form.addClass('fixed-top');
  88. _parentNode.height(height);
  89. } else {
  90. _form.removeClass('fixed-top');
  91. }
  92. }
  93. }
  94. // add hide div (on submit form )
  95. function addHiedDiv() {
  96. _parentNode.append(_form.append(_table));
  97. _hidden_div = $('<div></div>');
  98. _hidden_div.hide();
  99. $("body").append(_hidden_div);
  100. }
  101. // fill table
  102. function fillTable() {
  103. _table.html('');
  104. _table.append(crateClearBtn());
  105. _table.append(createPagination());
  106. _baseData.condition.forEach(function (conditions, index, arrays) {
  107. let tr = $("<tr></tr>");
  108. conditions.forEach(function (condition, index, array) {
  109. let td = $("<td style='width: 260px'></td>");
  110. if ([null, '', undefined].includes(condition.type) && ![null, undefined].includes(condition.name)) {
  111. condition.type = 'input';
  112. }
  113. if (['dataTime_dataTime', 'input_input'].includes(condition.type)) {
  114. td = $("<td style='width: 330px'</td>")
  115. } else if (['select_multiple_select', 'time', 'dataTime_select'].includes(condition.type)) {
  116. td = $("<td style='width: 280px'</td>");
  117. } else if (['time', 'dataTime_select'].includes(condition.type)) {
  118. td = $("<td style='width: 320px'</td>");
  119. }
  120. td.append(createModule(condition));
  121. tr.append(td);
  122. })
  123. _table.append(tr);
  124. if (arrays.length === index + 1) {
  125. let td = $("<td ></td>");
  126. tr.append(td.append(createSearchBt()));
  127. }
  128. })
  129. $.cookie.raw = true;
  130. $.cookie.json = true;
  131. setTableWidth();
  132. }
  133. function setTableWidth() {
  134. let max_width = 0;
  135. _baseData.condition.forEach(function (conditions, xindex, xarrays) {
  136. let _width = 0;
  137. conditions.forEach(function (condition, index, array) {
  138. if (['input', 'select', 'dataTime', 'input_select'].includes(condition.type)) {
  139. _width += 260;
  140. } else if (['dataTime_dataTime', 'input_input'].includes(condition.type)) {
  141. _width += 330;
  142. } else if (['select_multiple_select','search_select'].includes(condition.type)) {
  143. _width += 280;
  144. } else if (['checkbox'].includes(condition.type)) {
  145. _width += 260;
  146. } else if (['time', 'dataTime_select'].includes(condition.type)) {
  147. _width += 320;
  148. } else if ([undefined, null, ''].includes(condition)) {
  149. _width += 260;
  150. }
  151. if (index === array.length - 1 && xindex === xarrays.length - 1) {
  152. _width += 260;
  153. }
  154. if (max_width < _width) {
  155. max_width = _width;
  156. }
  157. })
  158. })
  159. _parentNode.css('min-width', 1920 - 30)
  160. _parentNode.css('max-width', (max_width || window.screen.availWidth) - 30);
  161. _table.css('width', max_width + 'px');
  162. }
  163. // 清空过滤条件按钮
  164. function crateClearBtn() {
  165. let clearbtn = $("<button type='button' class='btn btn-warning text-dark '>清除过滤条件</button>");
  166. clearbtn.click(function () {
  167. clearData();
  168. visibleClearBtn();
  169. })
  170. let tr = $("<tr ><td colspan='10'></td></tr>");
  171. tr.find('td').append(clearbtn);
  172. _clearTr = tr;
  173. return tr;
  174. }
  175. // create SearchBtn
  176. function createSearchBt() {
  177. _searchBtn = $("<span class='btn btn-sm btn-outline-dark ml-1' >按条件搜索</span>");
  178. let div = $("<div class='form-inline'></div>");
  179. div.append(_searchBtn);
  180. _searchBtn.click(function () {
  181. if (controlJsType(_this.searchClick, 'fun')) {
  182. _this.searchClick();
  183. }
  184. if (controlJsType(_this._onsubmit, 'fun')) {
  185. _this._onsubmit();
  186. }else{
  187. _this.onsubmit();
  188. }
  189. })
  190. return div;
  191. }
  192. // create _pagination
  193. function createPagination() {
  194. _pagination = $("<select id='paginate' 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 = _data[condition.name].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 (!select_div.is(':focus')) {
  508. ul_div.hide();
  509. }
  510. }, 1000);
  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. return div;
  523. }
  524. // checkbox
  525. function getCheckBox(condition) {
  526. let div1 = $("<div class='form-inline'></div>")
  527. condition.data.forEach(function (map, index) {
  528. let div = $('<div class="custom-control custom-control-inline custom-checkbox"></div>');
  529. let checkbox = $("<input type='checkbox' name='" + condition.name + "' class='custom-control-input' id='" + condition.name + index + "' value='" + map.name + "' >");
  530. let label = $("<label class='custom-control-label text-left font-weight-norma' for='" + condition.name + index + "'>" + map.value + "</label>")
  531. div1.append(div.append(checkbox).append(label));
  532. checkbox.click(function () {
  533. let value = [];
  534. $.each($("input:checkbox[name='" + condition.name + "']:checked"), function () {
  535. value.push($(this).val());
  536. })
  537. let dom = {name: condition.name, type: 'checkbox', value: value, mold: 'check'};
  538. modifyData(dom);
  539. });
  540. })
  541. return div1;
  542. }
  543. // fill select
  544. function fillSelectOption(select, data, placeholder = '') {
  545. select.html('');
  546. if (![undefined, null].includes(placeholder)) {
  547. let option = $("<option value></option>");
  548. if ('' === placeholder) {
  549. option = $("<option value>" + '全部' + placeholder + "</option>");
  550. } else {
  551. option = $("<option value>" + placeholder + "</option>");
  552. }
  553. select.append(option);
  554. }
  555. data.forEach(function (map) {
  556. let option = $("<option value='" + map.name + "'>" + map.value + "</optio>");
  557. select.append(option);
  558. })
  559. if (data !== undefined) {
  560. }
  561. }
  562. // fill multiple select ul
  563. function fillMultipleSelectOption(ul, data, name) {
  564. ul.html('');
  565. data.forEach(function (map) {
  566. let span = $("<span style='cursor:default'>" + map.value + "</span>");
  567. let li = $("<li class='list-group-item pt-0 pb-0' value='" + map.name + "'></li>");
  568. li.append(span);
  569. ul.append(li);
  570. li.click(function () {
  571. let value = li.attr('value');
  572. let dom_data = _data[name].value;
  573. if (controlJsType(dom_data, ['undefined', 'null', 'string'])) {
  574. dom_data = [dom_data];
  575. }
  576. if (dom_data.includes(value)) {
  577. dom_data.splice(dom_data.indexOf(value), 1);
  578. } else {
  579. dom_data.push(value);
  580. dom_data = arrDuplicate(dom_data);
  581. }
  582. let dom = {
  583. name: ul.attr('name'),
  584. type: 'select_multiple_select',
  585. value: dom_data,
  586. select: dom_data,
  587. mold: 'select_multiple_select'
  588. };
  589. modifyData(dom);
  590. redenerUl(ul);
  591. isMultiple(name);
  592. _this.onsubmit();
  593. })
  594. })
  595. }
  596. function isMultiple(name) {
  597. let label = $('#' + name + '_lab');
  598. let select = $('#' + name + '_sel');
  599. let dom_data = _data[name].value;
  600. if (dom_data.length === 1 ) {
  601. select.show();
  602. select.val(dom_data[0]);
  603. label.hide();
  604. }else if(controlJsType(dom_data,'string')){
  605. select.show();
  606. select.val(dom_data);
  607. label.hide();
  608. } else if (dom_data.length >= 2) {
  609. select.hide();
  610. label.show();
  611. }
  612. }
  613. // modify _data
  614. function modifyData(dom) {
  615. _data[dom.name].mold = dom.mold;
  616. _data[dom.name].value = dom.value;
  617. _data[dom.name].select = dom.value;
  618. redenerSearchFormOnData(dom.name, dom.value, dom.mold);
  619. }
  620. // save search on cookie
  621. function saveSearchOnCookie() {
  622. let saveData = {};
  623. for (const key in _data) {
  624. if (!['', null, undefined].includes(_data[key].value)) {
  625. if (controlJsType(_data[key].value, 'array') && _data[key].value.length === 0) {
  626. //console.log(key);
  627. continue;
  628. }
  629. saveData[key] = {
  630. value: _data[key].value,
  631. mold: _data[key].mold,
  632. }
  633. }
  634. }
  635. if (!_this.page) {
  636. saveData['page'] = _this.page;
  637. }
  638. saveCookie(saveData);
  639. }
  640. // hour_minute
  641. function verifyTime(time) {
  642. setTimeout(function () {
  643. time.value = time.value.replace(':', ':');
  644. time.value = time.value.replace(/[a-zA-Z]/, '');
  645. time.value = time.value.replace(/[^\d^\:]/, '');
  646. time.value = time.value.replace(/\:\:/, ':');
  647. time.value = time.value.replace(/^([\d]{1})([\s]{1})/, "$1:");
  648. time.value = time.value.replace(/^([\d]{1})([\d]{1})([\s]{1})/, "$1$2:");
  649. time.value = time.value.replace(/^([\d]{1})([\d]{1})([\d]{1})/, "$1$2:$3");
  650. time.value = time.value.replace(/^([\d]{1})([\d]{1})([\d]{1})([\d]{1})(.*?)/, "$1$2$3$4");
  651. time.value = time.value.replace(/^([\d]{1})([\d]{1})([\d]{1})([\d]{1})/, "$1$2:$3$4");
  652. time.value = time.value.replace(/^([\d]{1})([\d]{1}):([\d]{1})([\d]{1})([\s\S]{1})/, "$1$2:$3$4");
  653. time.value = time.value.replace(/^([\d]{1})([\d]{1}):([\D]{1,99})/, "$1$2:");
  654. time.value = time.value.replace(/^([\d]{1})([\d]{1})([\d]{1})\./, "$1:$2$3");
  655. time.value = time.value.replace(/^([\d]{1})\.([\d]{1})([\d]{1})/, "$1:$2$3");
  656. time.value = time.value.replace(/^([\d]{1})([\d]{2})([\S\s]{1,99})/, "$1$2:$3");
  657. time.value = time.value.replace(/^([\d]{1}):([\d]{2})([\S\s]{1,99})/, "$1:$2");
  658. time.value = time.value.replace(/^([\d])/, "$1");
  659. time.value = time.value.replace(/^([1])([\d]{1})/, "$1$2");
  660. time.value = time.value.replace(/^([3-9])([\d]{1})/, "2$2");
  661. time.value = time.value.replace(/^([2-9]{1})([4-9]{1})/, "$13");
  662. time.value = time.value.replace(/^([\d]{1})([\d]{1}):([6-9]{1})/, "$1$2:5");
  663. time.value = time.value.replace(/^([\d]{1})([\d]{1})$/, "$1$2:");
  664. }, 10);
  665. }
  666. // array duplicate
  667. function arrDuplicate(arr) {
  668. let res = [];
  669. let obj = {};
  670. for (let i = 0; i < arr.length; i++) {
  671. if ([undefined, null, ''].includes(arr[i])) {
  672. continue;
  673. }
  674. if (!obj[arr[i]]) {
  675. obj[arr[i]] = 1;
  676. res.push(arr[i]);
  677. }
  678. }
  679. return res;
  680. }
  681. // get search data
  682. function getSearchData(type = 'array') {
  683. let data = {};
  684. if (type === 'array') {
  685. for (let key in _data) {
  686. if (_data[key].value !== undefined && _data[key].value !== '') {
  687. data[key] = _data[key].value
  688. }
  689. }
  690. } else if (type === 'string') {
  691. data = '';
  692. for (let key in _data) {
  693. if (![undefined, null, ''].includes(_data[key].value)) {
  694. let value = _data[key].value;
  695. if (controlJsType(value, 'string')) {
  696. data = data + "&" + key + "=" + value;
  697. } else if (controlJsType(value, 'array')) {
  698. value.forEach(function (val) {
  699. data = data + "&" + key + "=" + val;
  700. });
  701. }
  702. }
  703. }
  704. }
  705. return data;
  706. }
  707. // renderer input
  708. function rendererSearchFormOnInput(key, value, mold) {
  709. if ([undefined, null, ''].includes(value)) {
  710. $(_form).find("input[name='" + key + "']").val('');
  711. $(_form).find("input[name='" + key + "']").removeClass('bg-warning');
  712. } else {
  713. $(_form).find("input[name='" + key + "']").val(value);
  714. $(_form).find("input[name='" + key + "']").addClass('bg-warning');
  715. }
  716. }
  717. // renderer select
  718. function rendererSearchFormOnSelect(key, value, mold) {
  719. if ([undefined, null, ''].includes(value)) {
  720. $(_form).find("select[name='" + key + "']").val('').removeClass('bg-warning');
  721. if (key === 'paginate') {
  722. $(_form).find("select[name='" + key + "']").val(_this.paginations[0]).removeClass('bg-warning');
  723. }
  724. } else {
  725. $(_form).find("select[name='" + key + "']").val(value);
  726. //console.log(value === _this.paginations[0]);
  727. if (key === 'paginate' && value == _this.paginations[0]) {
  728. return;
  729. }
  730. $(_form).find("select[name='" + key + "']").addClass('bg-warning');
  731. }
  732. }
  733. // renderer check
  734. function rendererSearchFormOnCheck(key, value, mold) {
  735. if ([undefined, null, ''].includes(value)) {
  736. $(_form).find("input[name='" + key + "']").prop("checked", false).removeClass('bg-warning');
  737. } else {
  738. if (controlJsType(value, 'array')) {
  739. value.forEach(function (_value) {
  740. $(_form).find("input[name='" + key + "'][value='" + _value + "']").prop("checked", true).addClass('bg-warning');
  741. })
  742. } else if (controlJsType(value, 'string')) {
  743. $(_form).find("input[name='" + key + "'][value='" + value + "']").prop("checked", true).addClass('bg-warning');
  744. }
  745. }
  746. }
  747. // redener multiple select input
  748. function rendererSearchFormOnMultipleSelect(key, value, mold) {
  749. let ul = $(_form).find("ul[name='" + key + "']");
  750. if ([undefined, null, ''].includes(value) || (controlJsType(value, 'array') && value.length === 0)) {
  751. $(_form).find("input[name='" + key + "_tip']").removeClass('bg-warning');
  752. ul.addClass('bg-warning');
  753. } else if (!!value) {
  754. $(_form).find("input[name='" + key + "_tip']").addClass('bg-warning');
  755. ul.addClass('bg-warning');
  756. } else if (controlJsType(value, 'array') && value.length >= 1) {
  757. $(_form).find("input[name='" + key + "_tip']").addClass('bg-warning');
  758. ul.addClass('bg-warning');
  759. }
  760. redenerUl(ul);
  761. }
  762. // redener multiple select ul
  763. function redenerUl(ul) {
  764. let name = ul.attr('name');
  765. let select = _data[name].select;
  766. if ([null, undefined].includes(select)) {
  767. _data[name].select = [];
  768. select = [];
  769. }
  770. let lis = ul.find('li');
  771. if ([null, undefined, ''].includes(lis)) {
  772. return;
  773. } else {
  774. lis.get().forEach(function (dom) {
  775. if (select.includes($(dom).attr('value'))) {
  776. dom.style.backgroundColor = "#4AA0E6";
  777. $(dom).addClass('active');
  778. } else {
  779. dom.style.backgroundColor = "#FFFFFF";
  780. $(dom).removeClass('active');
  781. }
  782. })
  783. isMultiple(name);
  784. }
  785. }
  786. function rendererSearchFormOnTime(key, value, mold) {
  787. if ([undefined, null, ''].includes(value)) {
  788. $(_form).find("input[name='+key+']").val(value.substring(0, 10)).addClass('bg-warning');
  789. if (value.length > 11 + 5) {
  790. $(_form).find("input[name='" + key + "_tim']").val(value.substring(11, 5));
  791. }
  792. } else {
  793. $(_form).find("input[name='+key+']").val("").removeClass('bg-warning');
  794. $(_form).find("input[name='" + key + "_tim']").val("");
  795. }
  796. }
  797. function visibleClearBtn() {
  798. let bool = false;
  799. for (const key in _data) {
  800. if (key === 'paginate') {
  801. if ((key === 'paginate' && _data[key].value !== _this.paginations[0])) {
  802. bool = true;
  803. }
  804. } else {
  805. if (![undefined, null, ''].includes(_data[key].value)) {
  806. bool = true;
  807. }
  808. }
  809. }
  810. if (bool) {
  811. _clearTr.show();
  812. } else {
  813. _clearTr.hide();
  814. }
  815. }
  816. function inputKeyDown() {
  817. $(_form).find('input').keydown(function (e) {
  818. if (e.keyCode === 13) {
  819. if (_this.keydownSearch) {
  820. _this.onsubmit()
  821. }
  822. if (controlJsType(_this.keydownfun, 'fun')) {
  823. _this.keydownfun();
  824. }
  825. }
  826. });
  827. $(_form).find("input[type='date']").change(function (e) {
  828. if (_this.keydownSearch) {
  829. _this.onsubmit()
  830. }
  831. if (controlJsType(_this.keydownfun, 'fun')) {
  832. _this.keydownfun();
  833. }
  834. });
  835. }
  836. function selectChange() {
  837. $(_form).find('select').change(function () {
  838. _this.onsubmit();
  839. })
  840. }
  841. function redenerSearchFormOnData(key, value, mold) {
  842. if (mold === 'input') {
  843. rendererSearchFormOnInput(key, value, mold);
  844. } else if (mold === 'select') {
  845. rendererSearchFormOnSelect(key, value, mold);
  846. } else if (mold === 'check') {
  847. rendererSearchFormOnCheck(key, value, mold);
  848. } else if (mold === 'select_multiple_select') {
  849. rendererSearchFormOnMultipleSelect(key, value, mold);
  850. } else if (mold === 'time') {
  851. rendererSearchFormOnTime(key, value, mold);
  852. }
  853. }
  854. // 数据转换
  855. function switchData() {
  856. _this.condition.forEach(function (conditions) {
  857. conditions.forEach(function (condition) {
  858. if (['input', 'select', 'dataTime', 'search_select', 'time', 'select_multiple_select','checkbox'].includes(condition.type)) {
  859. if (!condition.select) {
  860. condition.select = '';
  861. }
  862. let data = {
  863. name: condition.name,
  864. type: condition.type,
  865. value: condition.value,
  866. select: condition.select,
  867. mold: ['input', 'dataTime'].includes(condition.type) ? 'input' : condition.type
  868. }
  869. if (condition.type === 'search_select') {
  870. data.mold = 'select';
  871. }
  872. _data[condition.name] = data;
  873. } else if (['dataTime_dataTime', 'input_input', 'input_select', 'dataTime_select'].includes(condition.type)) {
  874. let types = condition.type.split("_");
  875. if (!condition.select) {
  876. condition.select = ['', ''];
  877. }
  878. if (!condition.value) {
  879. condition.value = ['', ''];
  880. }
  881. condition.name.forEach(function (_name, index) {
  882. let data = {
  883. name: _name,
  884. type: types[index],
  885. value: condition.value[index],
  886. select: condition.select[index],
  887. mold: ['input', 'dataTime'].includes(types[index]) ? 'input' : types[index]
  888. }
  889. _data[_name] = data;
  890. })
  891. }
  892. })
  893. })
  894. }
  895. // redererSearchForm on cookie
  896. function rendererSearchForm() {
  897. let url = document.referrer;
  898. let partt = /(Edit\/)|(\/eidt)|(eidt\/)/i;
  899. if (url.search(partt) > 0) {
  900. rendererOptionOnCookie();
  901. } else {
  902. rendererOptionOnUrl();
  903. }
  904. }
  905. function rendererOptionOnCookie() {
  906. //console.log('rendererSearchFromOnCookie');
  907. let data = fetchCookie();
  908. if (data === undefined) {
  909. return;
  910. }
  911. data = JSON.parse(data);
  912. for (let key in data) {
  913. _data[key].value = data[key].value;
  914. _data[key].mold = data[key].mold;
  915. _data[key].select = data[key].select;
  916. }
  917. rendererSearchFormOn_data();
  918. }
  919. function rendererOptionOnUrl() {
  920. if (!window.location.search) {
  921. return;
  922. }
  923. searchOptionToUrlsearch();
  924. rendererSearchFormOn_data();
  925. }
  926. function rendererSearchFormOn_data() {
  927. // console.log('rendererSearchFormOn_data', _data);
  928. for (let key in _data) {
  929. let value = _data[key].value, type = _data[key].type, mold = _data[key].mold;
  930. _data[key].select = value;
  931. if (['input', 'dataTime'].includes(mold)) {
  932. rendererSearchFormOnInput(key, value, mold);
  933. } else if (['select'].includes(mold)) {
  934. rendererSearchFormOnSelect(key, value, mold);
  935. } else if (['checkbox'].includes(mold)) {
  936. rendererSearchFormOnCheck(key, value, mold);
  937. } else if (['select_multiple_select'].includes(mold)) {
  938. if (controlJsType(value, ['array', 'string'])) {
  939. let ul = $(_form).find("ul[name='" + key + "']");
  940. redenerUl(ul);
  941. rendererSearchFormOnMultipleSelect(key, value, mold);
  942. }
  943. } else if (['time'].includes(type) && value !== undefined) {
  944. $(_form).find("input[name='" + key + "']").val(value.substr(0, 10));
  945. $(_form).find("input[id='" + key + "_min']").val(value.substr(11, value.length));
  946. }
  947. /* if (['input', 'dataTime', 'input_input', 'dataTime_dataTime'].includes(type)) {
  948. rendererSearchFormOnInput(key,value,mold);
  949. } else if (['select', 'input_select', 'dataTime_select'].includes(type)) {
  950. if (mold === 'select') {
  951. rendererSearchFormOnSelect(key,value,mold)
  952. } else if (mold === 'input') {
  953. rendererSearchFormOnInput(key,value,mold);
  954. } else if (mold === 'dataTime') {
  955. rendererSearchFormOnInput(key,value,mold);
  956. }
  957. } else if (['input_select_text'].includes(type)) {
  958. if (mold === 'input') {
  959. rendererSearchFormOnInput(key,value,mold);
  960. } else if (mold === 'select') {
  961. rendererSearchFormOnSelect(key,value,mold)
  962. }
  963. } else if (['checkbox'].includes(type)) {
  964. if (controlJsType(value, 'array')) {
  965. value.forEach(function (map) {
  966. $(_form).find("input[type='checkbox'][name='" + key + "'][value='" + map + "']").attr("checked", true);
  967. })
  968. }
  969. } else if (['select_multiple_select'].includes(type)) {
  970. if (controlJsType(value, ['array','string']) ) {
  971. let ul = $(_form).find("ul[name='" + key + "']");
  972. redenerUl(ul);
  973. rendererSearchFormOnMultipleSelect(key,value,mold);
  974. }
  975. } else if (['time'].includes(type) && value !== undefined) {
  976. $(_form).find("input[name='"+key+"']").val(value.substr(0,10));
  977. $(_form).find("input[id='"+key+"_min']").val(value.substr(11,value.length));
  978. }*/
  979. }
  980. if ([undefined, null, ''].includes(data['paginate'])) {
  981. return;
  982. }
  983. if ([undefined, null, ''].includes(data['paginate'].value)) {
  984. $(_form).find("select[name='paginate']").val(_this.paginations[0]);
  985. } else {
  986. $(_form).find("select[name='paginate']").val(data['paginate'].value);
  987. }
  988. }
  989. // url path on search form option renderer
  990. function searchOptionToUrlsearch() {
  991. let data = window.location.search;
  992. data = decodeURIComponent(data);
  993. if (!!data) {
  994. data = (data.substr(1)).split('&');
  995. data = convertArrayToObj(data);
  996. for (const key in data) {
  997. if(!data[key] || _this.param[key]){
  998. continue;
  999. }
  1000. if (key === 'paginate') {
  1001. _data[key] = {
  1002. name: key,
  1003. value: data[key],
  1004. type: 'select',
  1005. mold: 'select'
  1006. }
  1007. } else if (key === 'page') {
  1008. _page = data[key];
  1009. } else {
  1010. _data[key].value = data[key];
  1011. }
  1012. // console.log('key', key, typeof key);
  1013. }
  1014. }
  1015. }
  1016. // cookie -> data
  1017. function set_dataOnCookie() {
  1018. let data = fetchCookie();
  1019. data = JSON.parse(data);
  1020. if (!data) {
  1021. return;
  1022. }
  1023. for (const key in data) {
  1024. if (!!data[key]) {
  1025. _data[key].value = data[key].value;
  1026. }
  1027. }
  1028. }
  1029. // array - > object
  1030. function convertArrayToObj(arr) {
  1031. if (!arr || !controlJsType(arr, 'array')) {
  1032. return {};
  1033. } else if (controlJsType(arr, 'array') && arr.length > 0) {
  1034. let data = {};
  1035. arr.forEach(function (map) {
  1036. let arr = map.split('='), key = arr[0], value = arr[1];
  1037. if (!data[key]) {
  1038. data[key] = value;
  1039. } else {
  1040. if (controlJsType(data[key], 'string')) {
  1041. data[key] = [data[key], value];
  1042. } else if (controlJsType(data[key], 'array')) {
  1043. data[key].push(value);
  1044. }
  1045. }
  1046. })
  1047. return data;
  1048. }
  1049. }
  1050. // paginate
  1051. function pervPage() {
  1052. let obj = getSearchData();
  1053. _page = getPage();
  1054. if(!obj['paginate']){
  1055. obj['paginate'] = 50;
  1056. }
  1057. if(Number(_page)>1){
  1058. _page= Number(_page)-1;
  1059. }else{
  1060. _page = 1;
  1061. }
  1062. return getSearchUri(obj);
  1063. }
  1064. function nextPage() {
  1065. let obj = getSearchData();
  1066. _page = getPage();
  1067. if(!_page){_page=1;}
  1068. if(_page){
  1069. _page = Number(_page)+ 1;
  1070. }
  1071. if(!obj['paginate']){
  1072. obj['paginate'] = 50;
  1073. }
  1074. return getSearchUri(obj);
  1075. }
  1076. function goPage(page){
  1077. let obj = getSearchData();
  1078. _page = page;
  1079. return getSearchUri(obj);
  1080. }
  1081. function getSearchObj() {
  1082. let data = window.location.search;
  1083. data = decodeURIComponent(data);
  1084. if(!data){
  1085. return {};
  1086. }
  1087. let saveData = {};
  1088. data = data.substr(1).split('&');
  1089. data.forEach(function (map) {
  1090. let arr = map.split('='),key = arr[0],value = arr[1];
  1091. if(!!value){
  1092. if (!saveData[key]) {
  1093. saveData[key] = value;
  1094. } else {
  1095. if (controlJsType(data[key], 'string')) {
  1096. saveData[key] = [saveData[key] , value];
  1097. } else if (controlJsType(data[key], 'array')) {
  1098. saveData[key].push(value);
  1099. }
  1100. }
  1101. }
  1102. })
  1103. return saveData;
  1104. }
  1105. function getPage(){
  1106. return getSearchObj()['page'];
  1107. }
  1108. function getSearchUri(obj){
  1109. let string = "?";
  1110. let param = _this.param;
  1111. for (const key in param) {
  1112. if(controlJsType(param[key],['string','number'])){
  1113. string+= key + "=" + param[key]+'&';
  1114. }else if( controlJsType(param[key],'array')&&param[key].length > 0){
  1115. param[key].forEach(function(value){
  1116. string+=key + "=" + value+'&';
  1117. })
  1118. }
  1119. }
  1120. for (const key in obj) {
  1121. if(controlJsType(obj[key],['string','number'])){
  1122. string+= key + "=" + obj[key]+'&';
  1123. }else if( controlJsType(obj[key],'array')&&obj[key].length > 0){
  1124. obj[key].forEach(function(value){
  1125. string+=key + "=" + value+'&';
  1126. })
  1127. }
  1128. }
  1129. if(_page){
  1130. string+='page='+_page;
  1131. }
  1132. return window.location.pathname +string;
  1133. }
  1134. };