queryForm.js 50 KB

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