queryForm.js 50 KB

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