queryForm.js 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235
  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.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 (!select_div.is(':focus')) {
  507. ul_div.hide();
  508. }
  509. }, 1000);
  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. return div;
  522. }
  523. // checkbox
  524. function getCheckBox(condition) {
  525. let div1 = $("<div class='form-inline'></div>")
  526. condition.data.forEach(function (map, index) {
  527. let div = $('<div class="custom-control custom-control-inline custom-checkbox"></div>');
  528. let checkbox = $("<input type='checkbox' name='" + condition.name + "' class='custom-control-input' id='" + condition.name + index + "' value='" + map.name + "' >");
  529. let label = $("<label class='custom-control-label text-left font-weight-norma' for='" + condition.name + index + "'>" + map.value + "</label>")
  530. div1.append(div.append(checkbox).append(label));
  531. checkbox.click(function () {
  532. let value = [];
  533. $.each($("input:checkbox[name='" + condition.name + "']:checked"), function () {
  534. value.push($(this).val());
  535. })
  536. let dom = {name: condition.name, type: 'checkbox', value: value, mold: 'check'};
  537. modifyData(dom);
  538. });
  539. })
  540. return div1;
  541. }
  542. // fill select
  543. function fillSelectOption(select, data, placeholder = '') {
  544. select.html('');
  545. if (![undefined, null].includes(placeholder)) {
  546. let option = $("<option value></option>");
  547. if ('' === placeholder) {
  548. option = $("<option value>" + '全部' + placeholder + "</option>");
  549. } else {
  550. option = $("<option value>" + placeholder + "</option>");
  551. }
  552. select.append(option);
  553. }
  554. data.forEach(function (map) {
  555. let option = $("<option value='" + map.name + "'>" + map.value + "</optio>");
  556. select.append(option);
  557. })
  558. if (data !== undefined) {
  559. }
  560. }
  561. // fill multiple select ul
  562. function fillMultipleSelectOption(ul, data, name) {
  563. ul.html('');
  564. data.forEach(function (map) {
  565. let span = $("<span style='cursor:default'>" + map.value + "</span>");
  566. let li = $("<li class='list-group-item pt-0 pb-0' value='" + map.name + "'></li>");
  567. li.append(span);
  568. ul.append(li);
  569. li.click(function () {
  570. let value = li.attr('value');
  571. let dom_data = _data[name].value;
  572. if (controlJsType(dom_data, ['undefined', 'null', 'string'])) {
  573. dom_data = [dom_data];
  574. }
  575. if (dom_data.includes(value)) {
  576. dom_data.splice(dom_data.indexOf(value), 1);
  577. } else {
  578. dom_data.push(value);
  579. dom_data = arrDuplicate(dom_data);
  580. }
  581. let dom = {
  582. name: ul.attr('name'),
  583. type: 'select_multiple_select',
  584. value: dom_data,
  585. select: dom_data,
  586. mold: 'select_multiple_select'
  587. };
  588. modifyData(dom);
  589. redenerUl(ul);
  590. isMultiple(ul.attr('name'));
  591. _this.onsubmit();
  592. })
  593. })
  594. }
  595. function isMultiple(name) {
  596. let label = $('#' + name + '_lab');
  597. let select = $('#' + name + '_sel');
  598. let dom_data = _data[name].data;
  599. console.log(_data[name],_data);
  600. console.log(dom_data);
  601. console.log(name);
  602. if (dom_data.length === 1 ) {
  603. select.show();
  604. select.val(dom_data[0]);
  605. label.hide();
  606. }else if(controlJsType(dom_data,'string')){
  607. select.show();
  608. select.val(dom_data);
  609. label.hide();
  610. } else if (dom_data.length >= 2) {
  611. select.hide();
  612. label.show();
  613. }
  614. }
  615. // modify _data
  616. function modifyData(dom) {
  617. _data[dom.name].mold = dom.mold;
  618. _data[dom.name].value = dom.value;
  619. _data[dom.name].select = dom.value;
  620. redenerSearchFormOnData(dom.name, dom.value, dom.mold);
  621. }
  622. // save search on cookie
  623. function saveSearchOnCookie() {
  624. let saveData = {};
  625. for (const key in _data) {
  626. if (!['', null, undefined].includes(_data[key].value)) {
  627. if (controlJsType(_data[key].value, 'array') && _data[key].value.length === 0) {
  628. //console.log(key);
  629. continue;
  630. }
  631. saveData[key] = {
  632. value: _data[key].value,
  633. mold: _data[key].mold,
  634. }
  635. }
  636. }
  637. if (!_this.page) {
  638. saveData['page'] = _this.page;
  639. }
  640. saveCookie(saveData);
  641. }
  642. // hour_minute
  643. function verifyTime(time) {
  644. setTimeout(function () {
  645. time.value = time.value.replace(':', ':');
  646. time.value = time.value.replace(/[a-zA-Z]/, '');
  647. time.value = time.value.replace(/[^\d^\:]/, '');
  648. time.value = time.value.replace(/\:\:/, ':');
  649. time.value = time.value.replace(/^([\d]{1})([\s]{1})/, "$1:");
  650. time.value = time.value.replace(/^([\d]{1})([\d]{1})([\s]{1})/, "$1$2:");
  651. time.value = time.value.replace(/^([\d]{1})([\d]{1})([\d]{1})/, "$1$2:$3");
  652. time.value = time.value.replace(/^([\d]{1})([\d]{1})([\d]{1})([\d]{1})(.*?)/, "$1$2$3$4");
  653. time.value = time.value.replace(/^([\d]{1})([\d]{1})([\d]{1})([\d]{1})/, "$1$2:$3$4");
  654. time.value = time.value.replace(/^([\d]{1})([\d]{1}):([\d]{1})([\d]{1})([\s\S]{1})/, "$1$2:$3$4");
  655. time.value = time.value.replace(/^([\d]{1})([\d]{1}):([\D]{1,99})/, "$1$2:");
  656. time.value = time.value.replace(/^([\d]{1})([\d]{1})([\d]{1})\./, "$1:$2$3");
  657. time.value = time.value.replace(/^([\d]{1})\.([\d]{1})([\d]{1})/, "$1:$2$3");
  658. time.value = time.value.replace(/^([\d]{1})([\d]{2})([\S\s]{1,99})/, "$1$2:$3");
  659. time.value = time.value.replace(/^([\d]{1}):([\d]{2})([\S\s]{1,99})/, "$1:$2");
  660. time.value = time.value.replace(/^([\d])/, "$1");
  661. time.value = time.value.replace(/^([1])([\d]{1})/, "$1$2");
  662. time.value = time.value.replace(/^([3-9])([\d]{1})/, "2$2");
  663. time.value = time.value.replace(/^([2-9]{1})([4-9]{1})/, "$13");
  664. time.value = time.value.replace(/^([\d]{1})([\d]{1}):([6-9]{1})/, "$1$2:5");
  665. time.value = time.value.replace(/^([\d]{1})([\d]{1})$/, "$1$2:");
  666. }, 10);
  667. }
  668. // array duplicate
  669. function arrDuplicate(arr) {
  670. let res = [];
  671. let obj = {};
  672. for (let i = 0; i < arr.length; i++) {
  673. if ([undefined, null, ''].includes(arr[i])) {
  674. continue;
  675. }
  676. if (!obj[arr[i]]) {
  677. obj[arr[i]] = 1;
  678. res.push(arr[i]);
  679. }
  680. }
  681. return res;
  682. }
  683. // get search data
  684. function getSearchData(type = 'array') {
  685. let data = {};
  686. if (type === 'array') {
  687. for (let key in _data) {
  688. if (_data[key].value !== undefined && _data[key].value !== '') {
  689. data[key] = _data[key].value
  690. }
  691. }
  692. } else if (type === 'string') {
  693. data = '';
  694. for (let key in _data) {
  695. if (![undefined, null, ''].includes(_data[key].value)) {
  696. let value = _data[key].value;
  697. if (controlJsType(value, 'string')) {
  698. data = data + "&" + key + "=" + value;
  699. } else if (controlJsType(value, 'array')) {
  700. value.forEach(function (val) {
  701. data = data + "&" + key + "=" + val;
  702. });
  703. }
  704. }
  705. }
  706. }
  707. return data;
  708. }
  709. // renderer input
  710. function rendererSearchFormOnInput(key, value, mold) {
  711. if ([undefined, null, ''].includes(value)) {
  712. $(_form).find("input[name='" + key + "']").val('');
  713. $(_form).find("input[name='" + key + "']").removeClass('bg-warning');
  714. } else {
  715. $(_form).find("input[name='" + key + "']").val(value);
  716. $(_form).find("input[name='" + key + "']").addClass('bg-warning');
  717. }
  718. }
  719. // renderer select
  720. function rendererSearchFormOnSelect(key, value, mold) {
  721. if ([undefined, null, ''].includes(value)) {
  722. $(_form).find("select[name='" + key + "']").val('').removeClass('bg-warning');
  723. if (key === 'paginate') {
  724. $(_form).find("select[name='" + key + "']").val(_this.paginations[0]).removeClass('bg-warning');
  725. }
  726. } else {
  727. $(_form).find("select[name='" + key + "']").val(value);
  728. //console.log(value === _this.paginations[0]);
  729. if (key === 'paginate' && value == _this.paginations[0]) {
  730. return;
  731. }
  732. $(_form).find("select[name='" + key + "']").addClass('bg-warning');
  733. }
  734. }
  735. // renderer check
  736. function rendererSearchFormOnCheck(key, value, mold) {
  737. if ([undefined, null, ''].includes(value)) {
  738. $(_form).find("input[name='" + key + "']").prop("checked", false).removeClass('bg-warning');
  739. } else {
  740. if (controlJsType(value, 'array')) {
  741. value.forEach(function (_value) {
  742. $(_form).find("input[name='" + key + "'][value='" + _value + "']").prop("checked", true).addClass('bg-warning');
  743. })
  744. } else if (controlJsType(value, 'string')) {
  745. $(_form).find("input[name='" + key + "'][value='" + value + "']").prop("checked", true).addClass('bg-warning');
  746. }
  747. }
  748. }
  749. // redener multiple select input
  750. function rendererSearchFormOnMultipleSelect(key, value, mold) {
  751. let ul = $(_form).find("ul[name='" + key + "']");
  752. if ([undefined, null, ''].includes(value) || (controlJsType(value, 'array') && value.length === 0)) {
  753. $(_form).find("input[name='" + key + "_tip']").removeClass('bg-warning');
  754. ul.addClass('bg-warning');
  755. } else if (!!value) {
  756. $(_form).find("input[name='" + key + "_tip']").addClass('bg-warning');
  757. ul.addClass('bg-warning');
  758. } else if (controlJsType(value, 'array') && value.length >= 1) {
  759. $(_form).find("input[name='" + key + "_tip']").addClass('bg-warning');
  760. ul.addClass('bg-warning');
  761. }
  762. redenerUl(ul);
  763. }
  764. // redener multiple select ul
  765. function redenerUl(ul) {
  766. let name = ul.attr('name');
  767. let select = _data[name].select;
  768. if ([null, undefined].includes(select)) {
  769. _data[name].select = [];
  770. select = [];
  771. }
  772. let lis = ul.find('li');
  773. if ([null, undefined, ''].includes(lis)) {
  774. return;
  775. } else {
  776. lis.get().forEach(function (dom) {
  777. if (select.includes($(dom).attr('value'))) {
  778. dom.style.backgroundColor = "#4AA0E6";
  779. $(dom).addClass('active');
  780. } else {
  781. dom.style.backgroundColor = "#FFFFFF";
  782. $(dom).removeClass('active');
  783. }
  784. })
  785. isMultiple(ul.attr('name'));
  786. }
  787. }
  788. function rendererSearchFormOnTime(key, value, mold) {
  789. if ([undefined, null, ''].includes(value)) {
  790. $(_form).find("input[name='+key+']").val(value.substring(0, 10)).addClass('bg-warning');
  791. if (value.length > 11 + 5) {
  792. $(_form).find("input[name='" + key + "_tim']").val(value.substring(11, 5));
  793. }
  794. } else {
  795. $(_form).find("input[name='+key+']").val("").removeClass('bg-warning');
  796. $(_form).find("input[name='" + key + "_tim']").val("");
  797. }
  798. }
  799. function visibleClearBtn() {
  800. let bool = false;
  801. for (const key in _data) {
  802. if (key === 'paginate') {
  803. if ((key === 'paginate' && _data[key].value !== _this.paginations[0])) {
  804. bool = true;
  805. }
  806. } else {
  807. if (![undefined, null, ''].includes(_data[key].value)) {
  808. bool = true;
  809. }
  810. }
  811. }
  812. if (bool) {
  813. _clearTr.show();
  814. } else {
  815. _clearTr.hide();
  816. }
  817. }
  818. function inputKeyDown() {
  819. $(_form).find('input').keydown(function (e) {
  820. if (e.keyCode === 13) {
  821. if (_this.keydownSearch) {
  822. _this.onsubmit()
  823. }
  824. if (controlJsType(_this.keydownfun, 'fun')) {
  825. _this.keydownfun();
  826. }
  827. }
  828. });
  829. $(_form).find("input[type='date']").change(function (e) {
  830. if (_this.keydownSearch) {
  831. _this.onsubmit()
  832. }
  833. if (controlJsType(_this.keydownfun, 'fun')) {
  834. _this.keydownfun();
  835. }
  836. });
  837. }
  838. function selectChange() {
  839. $(_form).find('select').change(function () {
  840. _this.onsubmit();
  841. })
  842. }
  843. function redenerSearchFormOnData(key, value, mold) {
  844. if (mold === 'input') {
  845. rendererSearchFormOnInput(key, value, mold);
  846. } else if (mold === 'select') {
  847. rendererSearchFormOnSelect(key, value, mold);
  848. } else if (mold === 'check') {
  849. rendererSearchFormOnCheck(key, value, mold);
  850. } else if (mold === 'select_multiple_select') {
  851. rendererSearchFormOnMultipleSelect(key, value, mold);
  852. } else if (mold === 'time') {
  853. rendererSearchFormOnTime(key, value, mold);
  854. }
  855. }
  856. // 数据转换
  857. function switchData() {
  858. _this.condition.forEach(function (conditions) {
  859. conditions.forEach(function (condition) {
  860. if (['input', 'select', 'dataTime', 'search_select', 'time', 'select_multiple_select','checkbox'].includes(condition.type)) {
  861. if (!condition.select) {
  862. condition.select = '';
  863. }
  864. let data = {
  865. name: condition.name,
  866. type: condition.type,
  867. value: condition.value,
  868. select: condition.select,
  869. mold: ['input', 'dataTime'].includes(condition.type) ? 'input' : condition.type,
  870. data:condition.data
  871. }
  872. if (condition.type === 'search_select') {
  873. data.mold = 'select';
  874. }
  875. _data[condition.name] = data;
  876. } else if (['dataTime_dataTime', 'input_input', 'input_select', 'dataTime_select'].includes(condition.type)) {
  877. let types = condition.type.split("_");
  878. if (!condition.select) {
  879. condition.select = ['', ''];
  880. }
  881. if (!condition.value) {
  882. condition.value = ['', ''];
  883. }
  884. condition.name.forEach(function (_name, index) {
  885. let data = {
  886. name: _name,
  887. type: types[index],
  888. value: condition.value[index],
  889. select: condition.select[index],
  890. mold: ['input', 'dataTime'].includes(types[index]) ? 'input' : types[index]
  891. }
  892. _data[_name] = data;
  893. })
  894. }
  895. })
  896. })
  897. }
  898. // redererSearchForm on cookie
  899. function rendererSearchForm() {
  900. let url = document.referrer;
  901. let partt = /(Edit\/)|(\/eidt)|(eidt\/)/i;
  902. if (url.search(partt) > 0) {
  903. rendererOptionOnCookie();
  904. } else {
  905. rendererOptionOnUrl();
  906. }
  907. }
  908. function rendererOptionOnCookie() {
  909. //console.log('rendererSearchFromOnCookie');
  910. let data = fetchCookie();
  911. if (data === undefined) {
  912. return;
  913. }
  914. data = JSON.parse(data);
  915. for (let key in data) {
  916. _data[key].value = data[key].value;
  917. _data[key].mold = data[key].mold;
  918. _data[key].select = data[key].select;
  919. }
  920. rendererSearchFormOn_data();
  921. }
  922. function rendererOptionOnUrl() {
  923. if (!window.location.search) {
  924. return;
  925. }
  926. searchOptionToUrlsearch();
  927. rendererSearchFormOn_data();
  928. }
  929. function rendererSearchFormOn_data() {
  930. // console.log('rendererSearchFormOn_data', _data);
  931. for (let key in _data) {
  932. let value = _data[key].value, type = _data[key].type, mold = _data[key].mold;
  933. _data[key].select = value;
  934. if (['input', 'dataTime'].includes(mold)) {
  935. rendererSearchFormOnInput(key, value, mold);
  936. } else if (['select'].includes(mold)) {
  937. rendererSearchFormOnSelect(key, value, mold);
  938. } else if (['checkbox'].includes(mold)) {
  939. rendererSearchFormOnCheck(key, value, mold);
  940. } else if (['select_multiple_select'].includes(mold)) {
  941. if (controlJsType(value, ['array', 'string'])) {
  942. let ul = $(_form).find("ul[name='" + key + "']");
  943. redenerUl(ul);
  944. rendererSearchFormOnMultipleSelect(key, value, mold);
  945. }
  946. } else if (['time'].includes(type) && value !== undefined) {
  947. $(_form).find("input[name='" + key + "']").val(value.substr(0, 10));
  948. $(_form).find("input[id='" + key + "_min']").val(value.substr(11, value.length));
  949. }
  950. /* if (['input', 'dataTime', 'input_input', 'dataTime_dataTime'].includes(type)) {
  951. rendererSearchFormOnInput(key,value,mold);
  952. } else if (['select', 'input_select', 'dataTime_select'].includes(type)) {
  953. if (mold === 'select') {
  954. rendererSearchFormOnSelect(key,value,mold)
  955. } else if (mold === 'input') {
  956. rendererSearchFormOnInput(key,value,mold);
  957. } else if (mold === 'dataTime') {
  958. rendererSearchFormOnInput(key,value,mold);
  959. }
  960. } else if (['input_select_text'].includes(type)) {
  961. if (mold === 'input') {
  962. rendererSearchFormOnInput(key,value,mold);
  963. } else if (mold === 'select') {
  964. rendererSearchFormOnSelect(key,value,mold)
  965. }
  966. } else if (['checkbox'].includes(type)) {
  967. if (controlJsType(value, 'array')) {
  968. value.forEach(function (map) {
  969. $(_form).find("input[type='checkbox'][name='" + key + "'][value='" + map + "']").attr("checked", true);
  970. })
  971. }
  972. } else if (['select_multiple_select'].includes(type)) {
  973. if (controlJsType(value, ['array','string']) ) {
  974. let ul = $(_form).find("ul[name='" + key + "']");
  975. redenerUl(ul);
  976. rendererSearchFormOnMultipleSelect(key,value,mold);
  977. }
  978. } else if (['time'].includes(type) && value !== undefined) {
  979. $(_form).find("input[name='"+key+"']").val(value.substr(0,10));
  980. $(_form).find("input[id='"+key+"_min']").val(value.substr(11,value.length));
  981. }*/
  982. }
  983. if ([undefined, null, ''].includes(data['paginate'])) {
  984. return;
  985. }
  986. if ([undefined, null, ''].includes(data['paginate'].value)) {
  987. $(_form).find("select[name='paginate']").val(_this.paginations[0]);
  988. } else {
  989. $(_form).find("select[name='paginate']").val(data['paginate'].value);
  990. }
  991. }
  992. // url path on search form option renderer
  993. function searchOptionToUrlsearch() {
  994. let data = window.location.search;
  995. data = decodeURIComponent(data);
  996. if (!!data) {
  997. data = (data.substr(1)).split('&');
  998. data = convertArrayToObj(data);
  999. for (const key in data) {
  1000. if(!data[key] || _this.param[key]){
  1001. continue;
  1002. }
  1003. if (key === 'paginate') {
  1004. _data[key] = {
  1005. name: key,
  1006. value: data[key],
  1007. type: 'select',
  1008. mold: 'select'
  1009. }
  1010. } else if (key === 'page') {
  1011. _page = data[key];
  1012. } else if(_data[key].type === 'select_multiple_select' && !data[key]){
  1013. _data[key].value = data[key].split(',');
  1014. }else {
  1015. _data[key].value = data[key];
  1016. }
  1017. // console.log('key', key, typeof key);
  1018. }
  1019. }
  1020. }
  1021. // cookie -> data
  1022. function set_dataOnCookie() {
  1023. let data = fetchCookie();
  1024. data = JSON.parse(data);
  1025. if (!data) {
  1026. return;
  1027. }
  1028. for (const key in data) {
  1029. if (!!data[key]) {
  1030. _data[key].value = data[key].value;
  1031. }
  1032. }
  1033. }
  1034. // array - > object
  1035. function convertArrayToObj(arr) {
  1036. if (!arr || !controlJsType(arr, 'array')) {
  1037. return {};
  1038. } else if (controlJsType(arr, 'array') && arr.length > 0) {
  1039. let data = {};
  1040. arr.forEach(function (map) {
  1041. let arr = map.split('='), key = arr[0], value = arr[1];
  1042. if (!data[key]) {
  1043. data[key] = value;
  1044. } else {
  1045. if (controlJsType(data[key], 'string')) {
  1046. data[key] = [data[key], value];
  1047. } else if (controlJsType(data[key], 'array')) {
  1048. data[key].push(value);
  1049. }
  1050. }
  1051. })
  1052. return data;
  1053. }
  1054. }
  1055. // paginate
  1056. function pervPage() {
  1057. let obj = getSearchData();
  1058. if(!!obj['page'] && obj['page']>1){
  1059. obj['page'] = obj['page']-1;
  1060. }
  1061. return getSearchUri(obj);
  1062. }
  1063. function nextPage() {
  1064. let obj = getSearchData();
  1065. if(!!obj['page'] ){
  1066. obj['page'] = obj['page']+1;
  1067. }else{
  1068. obj['page'] = 2;
  1069. }
  1070. if(!obj['paginate']){
  1071. obj['paginate'] = 50;
  1072. }
  1073. return getSearchUri(obj);
  1074. }
  1075. function getSearchObj() {
  1076. let data = window.location.search;
  1077. data = decodeURIComponent(data);
  1078. if(!data){
  1079. return {};
  1080. }
  1081. let saveData = {};
  1082. data = data.substr(1).split('&');
  1083. data.forEach(function (map) {
  1084. let arr = map.split('&'),key = arr[0],value = arr[1];
  1085. if(!!value){
  1086. if (!saveData[key]) {
  1087. saveData[key] = value;
  1088. } else {
  1089. if (controlJsType(data[key], 'string')) {
  1090. saveData[key] = [saveData[key] , value];
  1091. } else if (controlJsType(data[key], 'array')) {
  1092. saveData[key].push(value);
  1093. }
  1094. }
  1095. }
  1096. })
  1097. return saveData;
  1098. }
  1099. function getPage(){
  1100. return getSearchObj()['page'];
  1101. }
  1102. // paginate
  1103. function pervPage() {
  1104. let obj = getSearchData();
  1105. _page = getPage();
  1106. if(!obj['paginate']){
  1107. obj['paginate'] = 50;
  1108. }
  1109. if(Number(_page)>1){
  1110. _page= Number(_page)-1;
  1111. }else{
  1112. _page = 1;
  1113. }
  1114. return getSearchUri(obj);
  1115. }
  1116. function nextPage() {
  1117. let obj = getSearchData();
  1118. _page = getPage();
  1119. if(!_page){_page=1;}
  1120. if(_page){
  1121. _page = Number(_page)+ 1;
  1122. }
  1123. if(!obj['paginate']){
  1124. obj['paginate'] = 50;
  1125. }
  1126. return getSearchUri(obj);
  1127. }
  1128. function goPage(page){
  1129. let obj = getSearchData();
  1130. _page = page;
  1131. return getSearchUri(obj);
  1132. }
  1133. function getSearchUri(obj){
  1134. let string = "?";
  1135. for (const key in obj) {
  1136. if(controlJsType(obj[key],['string','number'])){
  1137. string+= key + "=" + obj[key]+'&';
  1138. }else if( controlJsType(obj[key],'array')&&obj[key].length > 0){
  1139. obj[key].forEach(function(value){
  1140. string+=key + "=" + value+'&';
  1141. })
  1142. }
  1143. }
  1144. return string;
  1145. }
  1146. };