| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433 |
- const query = function getQueryForm(data) {
- {
- this.el = data.el || '#form_div';
- this.form = data.form;
- this.method = data.method || 'get';
- this.url = data.url || getPathname();
- this.condition = data.condition;
- this.paginations =data.paginations ? data.paginations : [50, 100, 200, 500,1000] ;
- this.isPaginations = data.isPaginations !== false;
- this.keydownfun = data.keydownfun || undefined;
- this.selectChange = data.selectChange || undefined;
- this.searchClick = data.searchClick || undefined;
- this.selectfun = data.selectfun || undefined;
- this._onsubmit = data._onsubmit || undefined;
- this.keydownSearch = data.keydownSearch || true;
- this.selectChangeSearch = data.selectChangeSearch || true;
- this.tip = data.tip || '';
- this.nextPage = nextPage;
- this.pervPage = pervPage;
- this.goPage = goPage;
- this.getSearchData = getSearchData;
- this.autoSubmit = (data.autoSubmit !== false) ;
- this.param = data.param || [];
- this.appendDom = data.appendDom || undefined;
- // 提交表单
- this.onsubmit = function () {
- if(!this.autoSubmit){
- return;
- }
- saveSearchOnCookie();
- let form = $("<form method='" + _this.method +"'></form>");
- for (const key in _data) {
- let map = _data[key];
- if(map['required'] == true && (map.value === '' || map.value===null || map.value === undefined))return;
- if (["string", "number"].includes(fetchJsType(map.value)) && map.value !== '') {
- // if(map.value){
- // let string = new String(map.value);
- // if(string.length > 1 ){
- // string = string.replace(/\+/g,',');
- // map.value = string
- // }
- // }
- //form.append("<input name='" + key + "' value='" + map.value.replace(" ","%20") + "'>");
- form.append("<input name='" + key + "' value='" + encodeURIComponent(map.value) + "'>")
- } else if ('array' === fetchJsType(map.value)) {
- let string = map.value.join(',');
- //form.append("<input name='" + key + "' value='" + string.replace(" ","%20") + "'>");
- form.append("<input name='" + key + "' value='" + encodeURIComponent(string) + "'>")
- }
- }
- for (let key in this.param){
- form.append("<input type='text' name='" + key + "' value='" + this.param[key] + "'>");
- }
- if (_this.method !== 'get') {
- form.append("<input type='hidden' name='_token' value='" + $('meta[name="csrf-token"]').attr('content') + "'>");
- form.append("<input type='hidden' name='_method' value='" + _this.method + "'>");
- form.attr('action', _this.url);
- }
- _hidden_div.html('');
- _hidden_div.append(form);
- form.submit();
- }
- }
- let _this = this;
- let _parentNode = null;
- let _data = {};
- let _form = [];
- let _table = null;
- let _clearTr = null;
- let _pagination = null;
- let _baseData = data;
- let _searchBtn = null;
- let _hidden_div = null;
- let _parentNode_top = null;
- let _page = '';
- this.init = function () {
- _parentNode = $(_this.el);
- _form = $("<div ></div>");
- _table = $("<table class='table table-sm table-bordered m-0 position-static' style='background: rgb(255, 255, 255);'></table>");
- fillTable();
- switchData();
- addHiedDiv();
- rendererSearchForm();
- visibleClearBtn();
- parentNodeFloat();
- inputKeyDown();
- selectChange();
- createTip();
- $('[data-toggle="tooltip"]').tooltip({'trigger': 'hover'})
- }
- // form fixed
- function parentNodeFloat() {
- _parentNode_top = _parentNode.offset().top;
- let height = _parentNode.height();
- let dom = _this.appendDom ? $("#"+_this.appendDom+"") : null;
- $(window).scroll(function(){
- let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
- if (scrollTop > _parentNode_top) {
- _form.addClass('fixed-top');
- _parentNode.height(height);
- if (dom){
- dom.css('position','fixed');
- dom.css('background','rgb(255, 255, 255)');
- dom.css('top',height);
- dom.css('z-index',1000);
- }
- } else {
- _form.removeClass('fixed-top');
- if (dom){
- dom.attr('style','');
- }
- }
- });
- }
- // add hide div (on submit form )
- function addHiedDiv() {
- _parentNode.append(_form.append(_table));
- _hidden_div = $('<div></div>');
- _hidden_div.hide();
- $("body").append(_hidden_div);
- }
- // fill table
- function fillTable() {
- _table.html('');
- _table.append(crateClearBtn());
- _table.append(createPagination());
- _baseData.condition.forEach(function (conditions, index, arrays) {
- let tr = $("<tr></tr>");
- conditions.forEach(function (condition, index, array) {
- let td = $("<td style='width: 260px'></td>");
- if ([null, '', undefined].includes(condition.type) && ![null, undefined].includes(condition.name)) {
- condition.type = 'input';
- }
- if (['dateTime_dateTime','dateTimeLocal', 'input_input'].includes(condition.type)) {
- td = $("<td style='width: 330px'</td>")
- } else if (['select_multiple_select', 'time', 'dateTime_select'].includes(condition.type)) {
- td = $("<td style='width: 280px'</td>");
- } else if (['time', 'dateTime_select'].includes(condition.type)) {
- td = $("<td style='width: 320px'</td>");
- }
- td.append(createModule(condition));
- tr.append(td);
- })
- _table.append(tr);
- if (arrays.length === index + 1) {
- let td = $("<td ></td>");
- tr.append(td.append(createSearchBt()));
- }
- })
- $.cookie.raw = true;
- $.cookie.json = true;
- setTableWidth();
- }
- function setTableWidth() {
- let max_width = 0;
- _baseData.condition.forEach(function (conditions, xindex, xarrays) {
- let _width = 0;
- conditions.forEach(function (condition, index, array) {
- if (['input','dateMonth', 'select', 'dateTime', 'input_select'].includes(condition.type)) {
- _width += 260;
- } else if (['dateTime_dateTime','dateTimeLocal', 'input_input'].includes(condition.type)) {
- _width += 330;
- } else if (['select_multiple_select','search_select'].includes(condition.type)) {
- _width += 280;
- } else if (['checkbox'].includes(condition.type)) {
- _width += 260;
- } else if (['time', 'dateTime_select'].includes(condition.type)) {
- _width += 320;
- } else if ([undefined, null, ''].includes(condition)) {
- _width += 260;
- }
- if (index === array.length - 1 && xindex === xarrays.length - 1) {
- _width += 260;
- }
- if (max_width < _width) {
- max_width = _width;
- }
- })
- })
- _parentNode.css('min-width', 1920 - 30)
- _parentNode.css('max-width', (max_width || window.screen.availWidth) - 30);
- _table.css('width', max_width + 'px');
- }
- // 清空筛选按钮
- function crateClearBtn() {
- let clearbtn = $("<button type='button' class='btn btn-warning text-dark '>清除筛选</button>");
- clearbtn.click(function () {
- clearData();
- visibleClearBtn();
- })
- let tr = $("<tr ><td colspan='10'></td></tr>");
- tr.find('td').append(clearbtn);
- _clearTr = tr;
- return tr;
- }
- // create SearchBtn
- function createSearchBt() {
- _searchBtn = $("<span class='btn btn-sm btn-outline-dark ml-1' >按条件搜索</span>");
- let div = $("<div class='form-inline'></div>");
- div.append(_searchBtn);
- _searchBtn.click(function () {
- if (controlJsType(_this.searchClick, 'fun')) {
- _this.searchClick();
- }
- if (controlJsType(_this._onsubmit, 'fun')) {
- _this._onsubmit();
- }else{
- _this.onsubmit();
- }
- })
- return div;
- }
- // create _pagination
- function createPagination() {
- let isPaginations = _this.isPaginations ? '' : 'hidden';
- _pagination = $("<select id='paginate' "+isPaginations+" name='paginate' class='form-control form-control-sm' style='vertical-align: middle; max-width: 150px;'></select>");
- let tr = $("<tr ><td colspan='10'><div class='col p-0' style='height: 100%'></div></td></tr>");
- tr.find('div').append(_pagination);
- _this.paginations.forEach(function (map) {
- let option = $("<option value='" + map + "'>每页显示" + map + "</option>");
- _pagination.append(option);
- })
- _pagination.change(function () {
- let dom = {name: 'paginate', type: 'select', value: _pagination.val(), mold: 'select'};
- _data['paginate'] = dom;
- modifyData(dom);
- _data['paginate'] = dom;
- _this.onsubmit();
- })
- return tr;
- }
- // create Tip
- function createTip() {
- let data = fetchCookie();
- let search = window.location.search;
- if (!data || !search) {
- return;
- }
- let cookies = JSON.parse(data);
- if (!cookies['success_tip']) {
- return;
- }
- if (!cookies['success_tip'] && !!_this.tip) {
- cookies['success_tip'].value = _this.tip;
- cookies['success_tip'].count = 1;
- _data['page'].value = _page;
- saveCookie(cookies);
- set_dataOnCookie();
- _this.onsubmit();
- // 重定向
- } else if (!cookies['success_tip'] && cookies['success_tip'].count === 1) {
- let tip = $("<div class='alert alert-success h1'></div>")
- let tipdiv = $("<div style='max-width: " + window.screen.availWidth + "px'>" + cookies['success_tip'].value + "</div>").append(tip);
- _form.append(tipdiv);
- cookies['success_tip'] = '';
- saveCookie(cookies);
- }
- }
- // 数据清空
- function clearData() {
- saveCookie({});
- let url=_this.url;
- if (_this.param !== []){
- url += "?";
- let i=0;
- for (let key in _this.param){
- if (i!==0) url += "&";
- url += key+"="+_this.param[key];
- i++;
- }
- }
- window.location.href = url;
- }
- // 存cookie
- function saveCookie(data) {
- $.cookie(getPathname(), data, {expires: 1});
- }
- // 取cookie
- function fetchCookie() {
- return $.cookie(getPathname());
- }
- // 获取路径
- function getPathname() {
- return window.location.pathname;
- }
- // 获取js对象类型types.call
- function fetchJsType(JsObj) {
- let types = Object.prototype.toString;
- let obj = types.call(JsObj);
- return (obj === "[object Number]" && 'number')
- || (obj === "[object Boolean]" && 'boolean')
- || (obj === "[object String]" && 'string')
- || (obj === "[object Array]" && 'array')
- || (obj === "[object Function]" && 'fun')
- || (obj === "[object Object]" && 'object')
- || (obj === "[object Null]" && 'null')
- || (obj === "[object Undefined]" && 'undefined');
- }
- // 判断js类型
- function controlJsType(JsObj, type) {
- if (fetchJsType(type) === 'array') {
- return type.includes(fetchJsType(JsObj));
- } else if (fetchJsType(type) === 'string') {
- return fetchJsType(JsObj) === type;
- } else {
- return JsObj === type;
- }
- }
- // create Module
- function createModule(condition) {
- let type = condition.type;
- return (['input', '', null].includes(type) && getInput(condition))
- || (type === "select" && getSelect(condition))
- || (type === "search_select" && getSearchSelect(condition))
- || (type === "input_select" && getInputSelect(condition))
- || (type === "dateTime" && getdateTime(condition))
- || (type === "dateTimeLocal" && getDateTimeLocal(condition))
- || (type === "dateMonth" && getDateMonth(condition))
- || (type === "time" && getTime(condition))
- || (type === "input_input" && getInputInput(condition))
- || (type === "dateTime_dateTime" && getdateTimedateTime(condition))
- || (type === "dateTime_select" && getdateTimeSelect(condition))
- || (type === "select_multiple_select" && getSelectMultipleSelect(condition))
- || (type === "checkbox" && getCheckBox(condition));
- }
- // dateMonth
- function getDateMonth(condition) {
- let dateMonth = $("<input name = '"+ condition.name +"' type='month' class='form-control form-control-sm' style='vertical-align: middle; max-width: 200px;' placeholder='" + condition.placeholder + "' autocomplete='off' data-toggle='tooltip' >");
- dateMonth.attr('title', condition.tip === undefined ? '' : condition.tip);
- dateMonth.blur(function(){
- modifyData({name: condition.name, type: 'dateMonth', value: this.value, mold: 'dateMonth'});
- });
- dateMonth.keypress(function(event){
- if(event.which === 13){
- modifyData({name: condition.name, type: 'input', value: this.value, mold: 'input'});
- }
- });
- return dateMonth;
- }
- // input
- function getInput(condition) {
- 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' >");
- input.attr('title', condition.tip === undefined ? '' : condition.tip);
- input.blur(function(){
- modifyData({name: condition.name, type: 'input', value: this.value, mold: 'input'});
- });
- input.keypress(function(event){
- if(event.which === 13)modifyData({name: condition.name, type: 'input', value: this.value, mold: 'input'});
- });
- return input;
- }
- // select
- function getSelect(condition) {
- let select = $("<select name='" + condition.name + "' class='form-control form-control-sm' style='max-width: 200px;' data-toggle='tooltip' data-placement='top'></select>")
- select.attr('title', condition.tip === undefined ? '' : condition.tip);
- let tip = $("<option value class='text-secondary'>" + condition.placeholder + "</option>")
- select.append(tip);
- condition.data.forEach(function (map) {
- let option = $("<option value='" + map.name + "' class='text-secondary'>" + map.value + "</option>")
- select.append(option);
- })
- select.on('change', function () {
- let dom = {name: condition.name, type: 'select', value: this.value, mold: 'select'}
- modifyData(dom)
- })
- return select;
- }
- // search_select
- function getSearchSelect(condition) {
- let div = $("<div class='form-inline'></div>");
- let input = $("<input class='form-control form-control-sm' placeholder='" + condition.placeholder[0] + "' style='width: 70px;' autocomplete='off' data-toggle='tooltip' data-placement='top'>");
- input.attr('title', controlJsType(condition.tip[0], 'undefined') ? '输入关键词快速定位下拉列表,回车确定' : condition.tip[0]);
- 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>");
- select.attr('title', controlJsType(condition.tip[1], 'undefined') ? '' : condition.tip[1]);
- let placeholder = '';
- if (controlJsType(condition.placeholder, 'array') && !['', undefined, null].includes(condition.placeholder[1])) {
- placeholder = condition.placeholder[1];
- }
- fillSelectOption(select, condition.data, placeholder);
- input.blur(function(){
- let value = this.value;
- let data = condition.data.filter(function (map) {
- return map.value.includes(value);
- });
- fillSelectOption(select, data || condition.data);
- select.val(_data[condition.name].select);
- });
- input.keypress(function(event){
- if(event.which === 13){
- let value = this.value;
- let data = condition.data.filter(function (map) {
- return map.value.includes(value);
- })
- fillSelectOption(select, data || condition.data);
- select.val(_data[condition.name].select);
- }
- });
- select.change(function () {
- modifyData({name: condition.name, type: 'input_select', value: this.value, mold: 'select'});
- })
- return div.append(input).append(select);
- }
- // input_select
- function getInputSelect(condition) {
- let div = $("<div class='form-inline'></div>");
- 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' >");
- input.attr('title', controlJsType(condition.tip[0], 'undefined') ? '' : condition.tip[0]);
- let select = $("<select class='form-control form-control-sm ml-2' name='" + condition.name[1] + "' style='max-width: 200px;' title='" + condition.tip[1] + "''>");
- fillSelectOption(select, condition.data);
- input.blur(function(){
- modifyData({name: this.name, type: 'input_select_longtext', value: this.value, mold: 'input'});
- });
- input.keypress(function(event){
- if(event.which === 13)modifyData({name: this.name, type: 'input_select_longtext', value: this.value, mold: 'input'});
- });
- select.change(function () {
- modifyData({name: this.name, type: 'input_select_longtext', value: this.value, mold: 'select'});
- })
- return div.append(input).append(select);
- }
- // dataTime
- function getdateTime(condition) {
- let dateTime = $("<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'>");
- dateTime.attr('title', controlJsType(condition.tip, 'undefined') ? '' : condition.tip);
- dateTime.bind('input propertychange', function () {
- modifyData({name: condition.name, type: 'dateTime', value: this.value, mold: 'dateTime'});
- });
- return dateTime;
- }
- //dateTimeLocal
- function getDateTimeLocal(condition) {
- let dateTimeLocal = $("<input name = '"+ condition.name +"' type='datetime-local' step='01' class='form-control form-control-sm' style='vertical-align: middle; max-width: 280px;' placeholder='" + condition.placeholder + "' autocomplete='off' data-toggle='tooltip' data-placement='top' >");
- dateTimeLocal.attr('title', condition.tip === undefined ? '' : condition.tip);
- dateTimeLocal.bind('input propertychange', function () {
- modifyData({name: condition.name, type: 'dateTimeLocal', value: this.value, mold: 'dateTimeLocal'});
- });
- return dateTimeLocal;
- }
- // time
- function getTime(condition) {
- let div = $("<div class='form-inline'></div>");
- let dateTime = $("<input type='date' class='form-control form-control-sm' name='" + condition.name + "' style='width:150px' data-toggle='tooltip' data-placement='top' >");
- dateTime.attr('title', controlJsType(condition.tip[0], 'undefined') ? '' : condition.tip[0]);
- 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' >");
- min.attr('title', controlJsType(condition.tip[1], 'undefined') ? '' : condition.tip[1]);
- dateTime.bind('input propertychange', function () {
- let value = this.value !== '' ? this.value + ' ' +(!!min.val() ? min.val() :'23:59' ) : '';
- modifyData( {name: condition.name, type: 'time', value: value, mold: 'time'});
- // modifyData({name: condition.name, type: 'dateTime', value: this.value, mold: 'dateTime'});
- });
- min.bind('input propertychange', function () {
- if (['null', 'undefined', ''].includes(dateTime.val()))return;
- let value = ['null', 'undefined', ''].includes(dateTime.val()) ? '' : dateTime.val() + ' ' + min.val();
- modifyData({name: condition.name, type: 'time', value: value, mold: 'time'});
- })
- return div.append(dateTime).append(min);
- }
- // input_input
- function getInputInput(condition) {
- let div = $("<div class='form-inline'></div>");
- 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] + "'>");
- input1.attr('title', controlJsType(condition.tip[0], 'undefined') ? '' : condition.tip[0]);
- 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] + "'>");
- input2.attr('title', controlJsType(condition.tip[1], 'undefined') ? '' : condition.tip[1]);
- input1.blur(function(){
- modifyData({name: this.name, type: 'input_input', value: this.value, mold: 'input'});
- });
- input1.keypress(function(event){
- if(event.which === 13)modifyData({name: this.name, type: 'input_input', value: this.value, mold: 'input'});
- });
- input2.blur(function(){
- modifyData({name: this.name, type: 'input_input', value: this.value, mold: 'input'});
- });
- input2.keypress(function(event){
- if(event.which === 13)modifyData({name: this.name, type: 'input_input', value: this.value, mold: 'input'});
- });
- return div.append(input1).append(input2);
- }
- // dateTime_dateTime
- function getdateTimedateTime(condition) {
- let div = $("<div class='form-inline'></div>");
- let dateTime1 = $("<input type='date' class='form-control form-control-sm' name='" + condition.name[0] + "' style='width: 150px' data-toggle='tooltip' data-placement='top' >");
- dateTime1.attr('title', controlJsType(condition.tip[0], 'undefined') ? '' : condition.tip[0]);
- let dateTime2 = $("<input type='date' class='form-control form-control-sm ml-2' name='" + condition.name[1] + "' style='width: 150px;' data-toggle='tooltip' data-placement='top' >");
- dateTime2.attr('title', controlJsType(condition.tip[1], 'undefined') ? '' : condition.tip[1]);
- dateTime1.bind('input propertychange', function () {
- let dom = {name: this.name, type: 'dateTime_dateTime', value: this.value, mold: 'dateTime'};
- modifyData(dom);
- })
- dateTime2.bind('input propertychange', function () {
- let dom = {name: this.name, type: 'dateTime_dateTime', value: this.value, mold: 'dateTime'};
- modifyData(dom);
- })
- return div.append(dateTime1).append(dateTime2);
- }
- // dateTime_select
- function getdateTimeSelect(condition) {
- let div = $("<div class='form-inline'></div>");
- let dateTime = $("<input type='date' class='form-control form-control-sm' name='" + condition.name[0] + "' style='max-width: 150px;' data-toggle='tooltip' data-placement='top' >");
- dateTime.attr('title', controlJsType(condition.tip[0], 'undefined') ? '' : condition.tip[0]);
- 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>");
- select.attr('title', controlJsType(condition.tip[1], 'undefined') ? '' : condition.tip[1]);
- fillSelectOption(select, condition.data)
- dateTime.bind('input propertychange', function () {
- modifyData( {name: this.name, type: 'dateTime_select', value: this.value, mold: 'dateTime'});
- })
- select.change(function () {
- modifyData({name: this.name, type: 'dateTime_select', value: this.value, mold: 'select'});
- })
- return div.append(dateTime).append(select);
- }
- // select_multiple_select
- function getSelectMultipleSelect(condition) {
- let div = $("<div class='form-inline' style='position: relative'></div>");
- 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>");
- let label = $("<label id='" + condition.name + "_lab' style='vertical-align: middle; width: 100px' >(多选)</label>").hide();
- let select_div = $("<div ></div>");
- select.attr('title', controlJsType(condition.tip[0], 'undefined') ? '' : condition.tip[0]);
- let placeholder = controlJsType(condition.placeholder[0], 'undefined') ? '' : condition.placeholder[0];
- fillSelectOption(select, condition.data, placeholder);
- 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'>");
- input.attr('title', controlJsType(condition.tip[1], 'undefined') ? '' : condition.tip[1]);
- input.attr('placeholder', controlJsType(condition.placeholder[1], 'undefined') ? '' : condition.placeholder[1])
- let ul_div = $("<div class='pl-0 tooltipTarget' 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>");
- 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>");
- let check = $("<input id='multipleCheckBox' type = 'checkbox' style='z-index:101;position:fixed;top:0;right: 0;border:1px green' >");
- let isMouseenterCheckBox = false;
- select_div.append(input).append(ul_div.append(ul).append(check));
- div.append(select).append(label).append(select_div);
- fillMultipleSelectOption(ul, condition.data, condition.name);
- check.click(function () {
- _data[condition.name].value = [];
- _data[condition.name].select = [];
- if (check[0].checked === true){
- condition.data.forEach(function (data) {
- _data[condition.name].value.push(data.name);
- if (_data[condition.name].select) _data[condition.name].select.push(data.name);
- else _data[condition.name].select = [data.name];
- });
- }else{
- let dom = {
- name: condition.name,
- mold: 'select_multiple_select',
- value: [],
- select:[],
- };
- modifyData(dom);
- }
- redenerUl(ul);
- });
- check.mouseleave(()=>{
- isMouseenterCheckBox = false;
- });
- check.mouseenter(()=>{
- isMouseenterCheckBox = true;
- });
- input.bind('input propertychange', function () {
- let value = this.value;
- if (value === '') {
- fillMultipleSelectOption(ul, _data[condition.name].data, condition.name);
- redenerUl(ul);
- return;
- }
- let select = _data[condition.name].select;
- if ([undefined, null, ''].includes(select)) {
- select = [];
- }
- let select_data = condition.data.filter(function (map) {
- return map.value.includes(value) || select.includes(map.name);
- })
- fillMultipleSelectOption(ul, select_data, condition.name);
- redenerUl(ul);
- });
- select.change(function () {
- let dom = {
- name: condition.name,
- mold: 'select_multiple_select',
- value: [this.value]
- }
- modifyData(dom);
- redenerUl(ul);
- })
- input.focus(function () {
- ul_div.show();
- })
- input.blur(function () {
- setTimeout(function () {
- if (!ul_div.is(':focus') && !check.is(':focus')) {
- ul_div.hide();
- }
- }, 100);
- })
- select_div.focus(function () {
- ul_div.show();
- })
- select_div.blur(function () {
- ul_div.hide();
- })
- /*ul_div.blur(function () {
- if (!isMouseenterCheckBox){
- ul_div.hide();
- }
- })*/
- ul_div.hide();
- ul_div.mouseleave(function () {
- if(_data[condition.name].value.length>0){
- _this.onsubmit();
- ul_div.hide();
- return;
- }
- if (!isMouseenterCheckBox){
- ul_div.hide();
- }
- });
- ul_div.mouseenter(function () {
- if(_data[condition.name].value.length>0){
- setTimeout(()=> {
- if (ul_div.is(':visible')){
- ul_div.attr("title","移出多选区域即可自动提交");
- ul_div.tooltip('show');
- }
- },1000);
- }
- });
- return div;
- }
- // checkbox
- function getCheckBox(condition) {
- let div1 = $("<div class='form-inline'></div>")
- condition.data.forEach(function (map, index) {
- let div = $('<div class="custom-control custom-control-inline custom-checkbox"></div>');
- let checkbox = $("<input type='checkbox' name='" + condition.name + "' class='custom-control-input' id='" + condition.name + index + "' value='" + map.name + "' >");
- let label = $("<label class='custom-control-label text-left font-weight-norma' for='" + condition.name + index + "'>" + map.value + "</label>")
- div1.append(div.append(checkbox).append(label));
- checkbox.click(function () {
- let value = [];
- $.each($("input:checkbox[name='" + condition.name + "']:checked"), function () {
- value.push($(this).val());
- })
- let dom = {name: condition.name, type: 'checkbox', value: value, mold: 'check'};
- modifyData(dom);
- _this.onsubmit();
- });
- })
- return div1;
- }
- // fill select
- function fillSelectOption(select, data, placeholder = '') {
- select.html('');
- if (![undefined, null].includes(placeholder)) {
- let option = $("<option value></option>");
- if ('' === placeholder) {
- option = $("<option value>" + '全部' + placeholder + "</option>");
- } else {
- option = $("<option value>" + placeholder + "</option>");
- }
- select.append(option);
- }
- data.forEach(function (map) {
- let option = $("<option value='" + map.name + "'>" + map.value + "</optio>");
- select.append(option);
- })
- if (data !== undefined) {
- }
- }
- // fill multiple select ul
- function fillMultipleSelectOption(ul, data, name) {
- ul.html('');
- data.forEach(function (map) {
- let span = $("<span style='cursor:default'>" + map.value + "</span>");
- let li = $("<li class='list-group-item pt-0 pb-0' value='" + map.name + "'></li>");
- li.append(span);
- ul.append(li);
- li.click(function () {
- let value = li.attr('value');
- let dom_data = _data[name].value;
- if(!dom_data){
- dom_data = [];
- }
- if (controlJsType(dom_data,'string')){
- dom_data = [dom_data];
- }
- if (dom_data.includes(value)) {
- dom_data.splice(dom_data.indexOf(value), 1);
- } else {
- dom_data.push(value);
- }
- dom_data = arrDuplicate(dom_data);
- let dom = {
- name: ul.attr('name'),
- type: 'select_multiple_select',
- value: dom_data,
- select: dom_data,
- mold: 'select_multiple_select'
- };
- modifyData(dom);
- redenerUl(ul);
- isMultiple(ul.attr('name'));
- })
- })
- }
- function isMultiple(name) {
- let label = $('#' + name + '_lab');
- let select = $('#' + name + '_sel');
- let dom_data = _data[name].value;
- if (dom_data && dom_data.length === 1 ) {
- select.show();
- select.val(dom_data[0]);
- label.hide();
- }else if(controlJsType(dom_data,'string')){
- select.show();
- select.val(dom_data);
- label.hide();
- } else if (dom_data.length >= 2) {
- select.hide();
- label.show();
- }
- }
- // modify _data
- function modifyData(dom) {
- _data[dom.name].mold = dom.mold;
- _data[dom.name].value = dom.value;
- _data[dom.name].select = dom.value;
- redenerSearchFormOnData(dom.name, dom.value, dom.mold);
- let killings=_data[dom.name].killings;
- if(killings){
- killings.forEach(function(targetName){
- _data[targetName].value= '';
- redenerSearchFormOnData(_data[targetName].name, '', _data[targetName].mold);
- })
- }
- /* rules 规则
- * son 子级元素 对象形式多传递 子级元素不存在时且 required_without_all_if 忽略列表内元素皆无值时使子级元素设置默认值
- * {son:{key:{required_without_all_if:[],default:''}}}
- * date_relevance 时间关联 对象形式传递 date为起终时间 relevance为关联元素name
- * killing为标记干掉哪种类型元素(enum('date','relevance')) default为relevance列表值,时间差存在于该值中才会去选中
- * {date_relevance:{date:['',''],relevance:'',killing:'',default:[]}}
- * */
- let rules = _data[dom.name].rules;
- if (rules && JSON.stringify(rules) !== '{}'){
- if (rules['son']){
- for (let key in rules['son']){
- if (!dom.value){
- redenerSearchFormOnData(_data[key].name, '', _data[key].mold);
- continue;
- }
- if (!_data[key].value){
- if (rules['son'][key].required_without_all_if && Array.isArray(rules['son'][key].required_without_all_if)){
- let sign = true;
- rules['son'][key].required_without_all_if.some(function (name) {
- if (_data[name].value){ sign=false; return true;}
- });
- if (sign) {
- _data[_data[key].name].mold = _data[key].mold;
- _data[_data[key].name].value = rules['son'][key].default;
- _data[_data[key].name].select = rules['son'][key].default;
- redenerSearchFormOnData(_data[key].name, rules['son'][key].default, _data[key].mold);
- }
- }
- }
- }
- }
- if (rules['date_relevance']){
- if (!rules['date_relevance']['date']
- || !Array.isArray(rules['date_relevance']['date'])
- || rules['date_relevance']['date'].length !== 2
- || !rules['date_relevance']['relevance']) return;
- let start = _data[rules['date_relevance']['date'][0]];
- let end = _data[rules['date_relevance']['date'][1]];
- let relevance = _data[rules['date_relevance']['relevance']];
- if (dom.name === rules['date_relevance']['relevance']){
- if (relevance.value){
- let today = getToday();
- let tarDate = getSubDate(getToday(),relevance.value);
- _data[end.name].value = today+" 23:59";
- _data[start.name].value = tarDate+" 00:00";
- /*redenerSearchFormOnData(end.name, tarDate+" 23:59", end.mold);
- redenerSearchFormOnData(start.name, tarDate+" 00:00", start.mold);*/
- }
- return;
- }
- if (!start.value || !end.value){
- if (rules['date_relevance']['killing'] === 'date'){
- _data[start.name].value = '';
- redenerSearchFormOnData(start.name, '', start.mold);
- _data[start.name].value = '';
- redenerSearchFormOnData(end.name, '', end.mold);
- }else{
- _data[relevance.name].value = '';
- redenerSearchFormOnData(relevance.name, '', relevance.mold);
- }
- }
- if (start.value && end.value){
- start.value = start.value.replace('+',' ');
- end.value = end.value.replace('+',' ');
- let diff = getDiffDay(start.value,end.value);
- if (rules['date_relevance']['default'] && rules['date_relevance']['default'].includes(diff)){
- _data[relevance.name].value = diff;
- redenerSearchFormOnData(relevance.name, diff, relevance.mold);}
- else {
- _data[relevance.name].value = '';
- redenerSearchFormOnData(relevance.name, '', relevance.mold);
- }
- }
- }
- }
- }
- function getDiffDay(startDate,endDate) {
- startDate = new Date(startDate);
- endDate = new Date(endDate);
- return Math.floor((endDate.getTime() - startDate.getTime())/(24*3600*1000));
- }
- function getSubDate(date,value) {
- date = new Date(date);
- date.setDate(date.getDate() - value);
- return dateFormat(date);
- }
- function getToday() {
- let myDate = new Date();
- return dateFormat(myDate);
- }
- function dateFormat(date) {
- let year=date.getFullYear();
- let month=(date.getMonth()+1)<10 ? '0'+(date.getMonth()+1) : date.getMonth()+1;
- let day=date.getDate()<10 ? '0'+date.getDate() : date.getDate();
- return year+"-"+month+"-"+day;
- }
- // save search on cookie
- function saveSearchOnCookie() {
- let saveData = {};
- for (const key in _data) {
- if (!['', null, undefined].includes(_data[key].value)) {
- if (controlJsType(_data[key].value, 'array') && _data[key].value.length === 0) {
- continue;
- }
- saveData[key] = {
- value: _data[key].value,
- mold: _data[key].mold,
- }
- }
- }
- if (!_this.page) {
- saveData['page'] = _this.page;
- }
- saveCookie(saveData);
- }
- // hour_minute
- function verifyTime(time) {
- setTimeout(function () {
- time.value = time.value.replace(':', ':');
- time.value = time.value.replace(/[a-zA-Z]/, '');
- time.value = time.value.replace(/[^\d^\:]/, '');
- time.value = time.value.replace(/\:\:/, ':');
- time.value = time.value.replace(/^([\d]{1})([\s]{1})/, "$1:");
- time.value = time.value.replace(/^([\d]{1})([\d]{1})([\s]{1})/, "$1$2:");
- time.value = time.value.replace(/^([\d]{1})([\d]{1})([\d]{1})/, "$1$2:$3");
- time.value = time.value.replace(/^([\d]{1})([\d]{1})([\d]{1})([\d]{1})(.*?)/, "$1$2$3$4");
- time.value = time.value.replace(/^([\d]{1})([\d]{1})([\d]{1})([\d]{1})/, "$1$2:$3$4");
- time.value = time.value.replace(/^([\d]{1})([\d]{1}):([\d]{1})([\d]{1})([\s\S]{1})/, "$1$2:$3$4");
- time.value = time.value.replace(/^([\d]{1})([\d]{1}):([\D]{1,99})/, "$1$2:");
- time.value = time.value.replace(/^([\d]{1})([\d]{1})([\d]{1})\./, "$1:$2$3");
- time.value = time.value.replace(/^([\d]{1})\.([\d]{1})([\d]{1})/, "$1:$2$3");
- time.value = time.value.replace(/^([\d]{1})([\d]{2})([\S\s]{1,99})/, "$1$2:$3");
- time.value = time.value.replace(/^([\d]{1}):([\d]{2})([\S\s]{1,99})/, "$1:$2");
- time.value = time.value.replace(/^([\d])/, "$1");
- time.value = time.value.replace(/^([1])([\d]{1})/, "$1$2");
- time.value = time.value.replace(/^([3-9])([\d]{1})/, "2$2");
- time.value = time.value.replace(/^([2-9]{1})([4-9]{1})/, "$13");
- time.value = time.value.replace(/^([\d]{1})([\d]{1}):([6-9]{1})/, "$1$2:5");
- time.value = time.value.replace(/^([\d]{1})([\d]{1})$/, "$1$2:");
- }, 10);
- }
- // array duplicate
- function arrDuplicate(arr) {
- let res = [];
- let obj = {};
- for (let i = 0; i < arr.length; i++) {
- if ([undefined, null, ''].includes(arr[i])) {
- continue;
- }
- if (!obj[arr[i]]) {
- obj[arr[i]] = 1;
- res.push(arr[i]);
- }
- }
- return res;
- }
- // get search data
- function getSearchData(type = 'array') {
- let data = {};
- if (type === 'array') {
- for (let key in _data) {
- if (_data[key].value !== undefined && _data[key].value !== '') {
- data[key] = _data[key].value
- }
- }
- } else if (type === 'string') {
- data = '';
- for (let key in _data) {
- if (![undefined, null, ''].includes(_data[key].value)) {
- let value = _data[key].value;
- if (controlJsType(value, 'string')) {
- data = data + "&" + key + "=" + value;
- } else if (controlJsType(value, 'array')) {
- value.forEach(function (val) {
- data = data + "&" + key + "=" + val;
- });
- }
- }
- }
- }
- return data;
- }
- // renderer input
- function rendererSearchFormOnInput(key, value, mold) {
- if ([undefined, null, ''].includes(value)) {
- $(_form).find("input[name='" + key + "']").val('');
- $(_form).find("input[name='" + key + "']").removeClass('bg-warning');
- } else {
- $(_form).find("input[name='" + key + "']").val(value);
- $(_form).find("input[name='" + key + "']").addClass('bg-warning');
- }
- }
- // renderer select
- function rendererSearchFormOnSelect(key, value, mold) {
- if ([undefined, null, ''].includes(value)) {
- $(_form).find("select[name='" + key + "']").val('').removeClass('bg-warning');
- if (key === 'paginate') {
- $(_form).find("select[name='" + key + "']").val(_this.paginations[0]).removeClass('bg-warning');
- }
- } else {
- $(_form).find("select[name='" + key + "']").val(value);
- if (key === 'paginate' && value == _this.paginations[0]) {
- return;
- }
- $(_form).find("select[name='" + key + "']").addClass('bg-warning');
- }
- }
- // renderer check
- function rendererSearchFormOnCheck(key, value, mold) {
- if ([undefined, null, ''].includes(value)) {
- $(_form).find("input[name='" + key + "']").prop("checked", false).removeClass('bg-warning');
- } else {
- if (controlJsType(value, 'array')) {
- value.forEach(function (_value) {
- $(_form).find("input[name='" + key + "'][value='" + _value + "']").prop("checked", true).addClass('bg-warning');
- })
- } else if (controlJsType(value, 'string')) {
- $(_form).find("input[name='" + key + "'][value='" + value + "']").prop("checked", true).addClass('bg-warning');
- }
- }
- }
- // redener multiple select input
- function rendererSearchFormOnMultipleSelect(key, value, mold) {
- let ul = $(_form).find("ul[name='" + key + "']");
- if ([undefined, null, ''].includes(value) || (controlJsType(value, 'array') && value.length === 0)) {
- $(_form).find("input[name='" + key + "_tip']").removeClass('bg-warning');
- ul.addClass('bg-warning');
- } else if (!!value) {
- $(_form).find("input[name='" + key + "_tip']").addClass('bg-warning');
- ul.addClass('bg-warning');
- } else if (controlJsType(value, 'array') && value.length >= 1) {
- $(_form).find("input[name='" + key + "_tip']").addClass('bg-warning');
- ul.addClass('bg-warning');
- }
- redenerUl(ul);
- }
- // redener multiple select ul
- function redenerUl(ul) {
- let name = ul.attr('name');
- let select = _data[name].select;
- if ([null, undefined].includes(select)) {
- _data[name].select = [];
- select = [];
- }
- let lis = ul.find('li');
- if ([null, undefined, ''].includes(lis)) {
- return;
- } else {
- lis.get().forEach(function (dom) {
- if (select.includes($(dom).attr('value'))) {
- dom.style.backgroundColor = "#4AA0E6";
- $(dom).addClass('active');
- } else {
- dom.style.backgroundColor = "#FFFFFF";
- $(dom).removeClass('active');
- }
- });
- if (lis.length === select.length) {
- $("#multipleCheckBox").prop("checked", true);
- }
- isMultiple(ul.attr('name'));
- }
- }
- function rendererSearchFormOnTime(key, value, mold) {
- if (![undefined, null, ''].includes(value)) {
- $(_form).find("input[name="+key+"]").val(value.substring(0, 10)).addClass('bg-warning');
- if (value.length > 11 + 5) {
- $(_form).find("input[name='" + key + "_tim']").val(value.substring(11, 5));
- }
- } else {
- $(_form).find("input[name="+key+"]").val("").removeClass('bg-warning');
- $(_form).find("input[name='" + key + "_tim']").val("");
- }
- }
- function visibleClearBtn() {
- let bool = false;
- for (const key in _data) {
- if (key === 'paginate') {
- if ((key === 'paginate' && _data[key].value !== _this.paginations[0])) {
- bool = true;
- }
- } else {
- if (![undefined, null, ''].includes(_data[key].value)) {
- if(controlJsType(_data[key].value,'array') && _data[key].value.length === 0 ){
- continue;
- }
- bool = true;
- }
- }
- }
- if (bool) {
- _clearTr.show();
- } else {
- _clearTr.hide();
- }
- }
- function inputKeyDown() {
- $(_form).find('input').keydown(function (e) {
- if (e.keyCode === 13) {
- setTimeout(function () {
- if (_this.keydownSearch) _this.onsubmit();
- if (controlJsType(_this.keydownfun, 'fun')) _this.keydownfun();
- },100);
- }
- });
- $(_form).find("input[type='date']").change(function (e) {
- setTimeout(function () {
- if (_this.keydownSearch)_this.onsubmit();
- if (controlJsType(_this.keydownfun, 'fun')) _this.keydownfun();
- },100);
- });
- }
- function selectChange() {
- $(_form).find('select').change(function () {
- _this.onsubmit();
- })
- }
- function redenerSearchFormOnData(key, value, mold) {
- if (mold === 'input' ||mold === 'dateTime' || mold === 'dateTimeLocal' || mold === 'dateMonth') {
- rendererSearchFormOnInput(key, value, mold);
- } else if (mold === 'select') {
- rendererSearchFormOnSelect(key, value, mold);
- } else if (mold === 'check') {
- rendererSearchFormOnCheck(key, value, mold);
- } else if (mold === 'select_multiple_select') {
- rendererSearchFormOnMultipleSelect(key, value, mold);
- } else if (mold === 'time') {
- rendererSearchFormOnTime(key, value, mold);
- }
- }
- // 数据转换
- function switchData() {
- _this.condition.forEach(function (conditions) {
- conditions.forEach(function (condition) {
- if (['input', 'select', 'dateTime','dateTimeLocal', 'dateMonth', 'search_select', 'time', 'select_multiple_select','checkbox'].includes(condition.type)) {
- if (!condition.select) {
- condition.select = '';
- }
- let data = {
- name: condition.name,
- type: condition.type,
- value: condition.value,
- select: condition.select,
- mold: ['input', 'dateTime'].includes(condition.type) ? 'input' : condition.type,
- data:condition.data,
- killings:condition.killings,
- rules:condition.rules,
- required:condition.required,
- }
- if (condition.type === 'search_select') {
- data.mold = 'select';
- }
- if(condition.type === 'select_multiple_select'){
- data.value = [];
- }
- _data[condition.name] = data;
- } else if (['dateTime_dateTime', 'input_input', 'input_select', 'dateTime_select'].includes(condition.type)) {
- let types = condition.type.split("_");
- if (!condition.select) {
- condition.select = ['', ''];
- }
- if (!condition.value) {
- condition.value = ['', ''];
- }
- condition.name.forEach(function (_name, index) {
- let data = {
- name: _name,
- type: types[index],
- value: condition.value[index],
- select: condition.select[index],
- mold: ['input', 'dateTime'].includes(types[index]) ? 'input' : types[index],
- killings:condition.killings,
- rules:condition.rules,
- required:condition.required,
- }
- if(condition.killings&&Array.isArray(condition.killings)){
- data.killings=condition.killings[index];
- }
- if(condition.rules&&Array.isArray(condition.rules)){
- data.rules=condition.rules[index];
- }
- _data[_name] = data;
- })
- }
- })
- })
- }
- // redererSearchForm on cookie
- function rendererSearchForm() {
- let url = document.referrer;
- let partt = /(Edit\/)|(\/eidt)|(eidt\/)/i;
- if (url.search(partt) > 0) {
- rendererOptionOnCookie();
- } else {
- rendererOptionOnUrl();
- }
- }
- function rendererOptionOnCookie() {
- let data = fetchCookie();
- if (data === undefined) {
- return;
- }
- data = JSON.parse(data);
- for (let key in data) {
- _data[key].value = data[key].value;
- _data[key].mold = data[key].mold;
- _data[key].select = data[key].select;
- }
- rendererSearchFormOn_data();
- }
- function rendererOptionOnUrl() {
- if (!window.location.search) {
- return;
- }
- searchOptionToUrlsearch();
- rendererSearchFormOn_data();
- }
- function rendererSearchFormOn_data() {
- for (let key in _data) {
- let value = _data[key].value, type = _data[key].type, mold = _data[key].mold;
- // if(value){
- // let string = new String(value);
- // if(string.length > 1 ){
- // string = string.replace(/\+/g,' ');
- // value = string
- // }
- // }
- _data[key].select = value;
- if (['input', 'dateTime', 'dateTimeLocal', 'dateMonth'].includes(mold)) {
- rendererSearchFormOnInput(key, value, mold);
- } else if (['select'].includes(mold)) {
- rendererSearchFormOnSelect(key, value, mold);
- } else if (['checkbox'].includes(mold)) {
- rendererSearchFormOnCheck(key, value, mold);
- } else if (['select_multiple_select'].includes(mold)) {
- if (controlJsType(value, ['array', 'string'])) {
- let ul = $(_form).find("ul[name='" + key + "']");
- redenerUl(ul);
- rendererSearchFormOnMultipleSelect(key, value, mold);
- }
- } else if (['time'].includes(type) && value !== undefined) {
- $(_form).find("input[name='" + key + "']").val(value.substr(0, 10)).addClass('bg-warning');
- $(_form).find("input[id='" + key + "_min']").val(value.substr(11, value.length));
- }
- }
- if ([undefined, null, ''].includes(data['paginate'])) {
- return;
- }
- if ([undefined, null, ''].includes(data['paginate'].value)) {
- $(_form).find("select[name='paginate']").val(_this.paginations[0]);
- } else {
- $(_form).find("select[name='paginate']").val(data['paginate'].value);
- }
- }
- // url path on search form option renderer
- function searchOptionToUrlsearch() {
- let data = (window.location.search);
- data = decodeURIComponent(decodeURIComponent(data));
- //data = decodeURIComponent(data).replace('%20'," ");
- if (!!data) {
- data = (data.substr(1)).split('&');
- data = convertArrayToObj(data);
- for (const key in data) {
- if(!data[key] || _this.param[key]){
- continue;
- }
- if (key === 'paginate') {
- _data[key] = {
- name: key,
- value: data[key],
- type: 'select',
- mold: 'select'
- }
- } else if (key === 'page') {
- _page = data[key];
- } else if(_data[key].type === 'select_multiple_select' ){
- if(!_data[key]){
- _data[key].value = [];
- }else{
- _data[key].value = data[key].split(',');
- }
- }else {
- _data[key].value = data[key];
- }
- }
- }
- }
- // cookie -> data
- function set_dataOnCookie() {
- let data = fetchCookie();
- data = JSON.parse(data);
- if (!data) {
- return;
- }
- for (const key in data) {
- if (!!data[key]) {
- _data[key].value = data[key].value;
- }
- }
- }
- // array - > object
- function convertArrayToObj(arr) {
- if (!arr || !controlJsType(arr, 'array')) {
- return {};
- } else if (controlJsType(arr, 'array') && arr.length > 0) {
- let data = {};
- arr.forEach(function (map) {
- let arr = map.split('='), key = arr[0], value = arr[1];
- if (!data[key]) {
- data[key] = value;
- } else {
- if (controlJsType(data[key], 'string')) {
- data[key] = [data[key], value];
- } else if (controlJsType(data[key], 'array')) {
- data[key].push(value);
- }
- }
- })
- return data;
- }
- }
- // paginate
- function pervPage() {
- let obj = getSearchData();
- if(!!obj['page'] && obj['page']>1){
- obj['page'] = obj['page']-1;
- }
- return getSearchUri(obj);
- }
- function nextPage() {
- let obj = getSearchData();
- if(!!obj['page'] ){
- obj['page'] = obj['page']+1;
- }else{
- obj['page'] = 2;
- }
- if(!obj['paginate']){
- obj['paginate'] = 50;
- }
- return getSearchUri(obj);
- }
- function getSearchObj() {
- let data = window.location.search;
- data = decodeURIComponent(data);
- if(!data){
- return {};
- }
- let saveData = {};
- data = data.substr(1).split('&');
- data.forEach(function (map) {
- let arr = map.split('&'),key = arr[0],value = arr[1];
- if(!!value){
- if (!saveData[key]) {
- saveData[key] = value;
- } else {
- if (controlJsType(data[key], 'string')) {
- saveData[key] = [saveData[key] , value];
- } else if (controlJsType(data[key], 'array')) {
- saveData[key].push(value);
- }
- }
- }
- })
- return saveData;
- }
- function getPage(){
- return getSearchObj()['page'];
- }
- // paginate
- function pervPage() {
- let obj = getSearchData();
- _page = getPage();
- if(!obj['paginate']){
- obj['paginate'] = 50;
- }
- if(Number(_page)>1){
- _page= Number(_page)-1;
- }else{
- _page = 1;
- }
- return getSearchUri(obj);
- }
- function nextPage() {
- let obj = getSearchData();
- _page = getPage();
- if(!_page){_page=1;}
- if(_page){
- _page = Number(_page)+ 1;
- }
- if(!obj['paginate']){
- obj['paginate'] = 50;
- }
- return getSearchUri(obj);
- }
- function goPage(page){
- let obj = getSearchData();
- _page = page;
- return getSearchUri(obj);
- }
- function getSearchUri(obj){
- let string = "?";
- for (const key in obj) {
- if(controlJsType(obj[key],['string','number'])){
- string+= key + "=" + obj[key]+'&';
- }else if( controlJsType(obj[key],'array')&&obj[key].length > 0){
- obj[key].forEach(function(value){
- string+=key + "=" + value+'&';
- })
- }
- }
- return string;
- }
- };
|