|
|
@@ -1,8 +1,6 @@
|
|
|
-//let cookie = require('jquery.cookie');
|
|
|
-
|
|
|
const query = function getQueryForm(data) {
|
|
|
{
|
|
|
- this.el = data.el || '#from_div';
|
|
|
+ this.el = data.el || '#form_div';
|
|
|
this.form = data.form;
|
|
|
this.method = data.method || 'get';
|
|
|
this.url = data.url || getPathname();
|
|
|
@@ -12,15 +10,19 @@ const query = function getQueryForm(data) {
|
|
|
this.selectChange = data.selectChange || undefined;
|
|
|
this.searchClick = data.searchClick || undefined;
|
|
|
this.selectfun = data.selectfun || undefined;
|
|
|
- this._onsubmit = data._onsubmit || true;
|
|
|
+ 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.nextPage = nextPage;
|
|
|
+ this.pervPage = pervPage;
|
|
|
+ this.getSearchData = getSearchData;
|
|
|
+ this.autoSubmit = (data.autoSubmit === false) ? false : true ;
|
|
|
// 提交表单
|
|
|
this.onsubmit = function () {
|
|
|
+ if(!this.autoSubmit){
|
|
|
+ return;
|
|
|
+ }
|
|
|
saveSearchOnCookie();
|
|
|
let form = $("<form method=" + _this.method + " ></form>");
|
|
|
for (const key in _data) {
|
|
|
@@ -49,7 +51,7 @@ const query = function getQueryForm(data) {
|
|
|
let _data = {};
|
|
|
let _form = [];
|
|
|
let _table = null;
|
|
|
- let _clearBtn = null;
|
|
|
+ let _clearTr = null;
|
|
|
let _pagination = null;
|
|
|
let _baseData = data;
|
|
|
let _searchBtn = null;
|
|
|
@@ -138,11 +140,11 @@ const query = function getQueryForm(data) {
|
|
|
conditions.forEach(function (condition, index, array) {
|
|
|
if (['input', 'select', 'dataTime', 'input_select'].includes(condition.type)) {
|
|
|
_width += 260;
|
|
|
- } else if (['dataTime_DataTime', 'input_input'].includes(condition.type)) {
|
|
|
+ } else if (['dataTime_dataTime', 'input_input'].includes(condition.type)) {
|
|
|
_width += 330;
|
|
|
} else if (['select_multiple_select','search_select'].includes(condition.type)) {
|
|
|
_width += 280;
|
|
|
- } else if (['check'].includes(condition.type)) {
|
|
|
+ } else if (['checkbox'].includes(condition.type)) {
|
|
|
_width += 260;
|
|
|
} else if (['time', 'dataTime_select'].includes(condition.type)) {
|
|
|
_width += 320;
|
|
|
@@ -165,15 +167,14 @@ const query = function getQueryForm(data) {
|
|
|
|
|
|
// 清空过滤条件按钮
|
|
|
function crateClearBtn() {
|
|
|
- let label = $("<label class='col-form-label col-sm-2 p-0'></label>");
|
|
|
- _clearBtn = $("<span class='btn btn-warning text-dark invisible'>清除过滤条件</span>");
|
|
|
- _clearBtn.click(function () {
|
|
|
+ let clearbtn = $("<button type='button' class='btn btn-warning text-dark '>清除过滤条件</button>");
|
|
|
+ clearbtn.click(function () {
|
|
|
clearData();
|
|
|
visibleClearBtn();
|
|
|
})
|
|
|
- let tr = $("<tr ><td colspan='10' style='height: 45px'></td></tr>");
|
|
|
- tr.find('td').append(label);
|
|
|
- label.append(_clearBtn);
|
|
|
+ let tr = $("<tr ><td colspan='10'></td></tr>");
|
|
|
+ tr.find('td').append(clearbtn);
|
|
|
+ _clearTr = tr;
|
|
|
return tr;
|
|
|
}
|
|
|
|
|
|
@@ -183,14 +184,14 @@ const query = function getQueryForm(data) {
|
|
|
let div = $("<div class='form-inline'></div>");
|
|
|
div.append(_searchBtn);
|
|
|
_searchBtn.click(function () {
|
|
|
-
|
|
|
if (controlJsType(_this.searchClick, 'fun')) {
|
|
|
_this.searchClick();
|
|
|
}
|
|
|
- if (_this._onsubmit) {
|
|
|
+ if (controlJsType(_this._onsubmit, 'fun')) {
|
|
|
+ _this._onsubmit();
|
|
|
+ }else{
|
|
|
_this.onsubmit();
|
|
|
}
|
|
|
- _this.onsubmit();
|
|
|
})
|
|
|
return div;
|
|
|
}
|
|
|
@@ -306,7 +307,7 @@ const query = function getQueryForm(data) {
|
|
|
|
|
|
// 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 + "' data-toggle='tooltip' data-placement='top' >");
|
|
|
+ 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.on('input', function () {
|
|
|
let dom = {name: condition.name, type: 'input', value: this.value, mold: 'input'}
|
|
|
@@ -364,7 +365,7 @@ const query = function getQueryForm(data) {
|
|
|
// 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: 100px;' data-toggle='tooltip' data-placement='top' >");
|
|
|
+ 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);
|
|
|
@@ -381,7 +382,7 @@ const query = function getQueryForm(data) {
|
|
|
|
|
|
// datTime
|
|
|
function getDataTime(condition) {
|
|
|
- let dataTime = $("<input type='date' class='form-control form-control-sm' name='" + condition.name + "' style='max-width: 200px' data-toggle='tooltip' data-placement='top' title='" + condition.tip + "' style='width: 200px'>");
|
|
|
+ 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'>");
|
|
|
dataTime.attr('title', controlJsType(condition.tip, 'undefined') ? '' : condition.tip);
|
|
|
dataTime.bind('input propertychange', function () {
|
|
|
let dom = {name: condition.name, type: 'dataTime', value: this.value, mold: 'dataTime'};
|
|
|
@@ -411,8 +412,8 @@ const query = function getQueryForm(data) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- let value = ['null', 'undefined', ''].includes(dataTime.val()) ? '' : dataTime + ' ' + min.val();
|
|
|
- // let value = dataTime.value !== '' ? dataTime.value + ' ' + (min.value === '' ? '00:00' : min. value) : '';
|
|
|
+ let value = ['null', 'undefined', ''].includes(dataTime.val()) ? '' : dataTime.val() + ' ' + min.val();
|
|
|
+ //let value = dataTime.value !== '' ? dataTime.value + ' ' + (min.value === '' ? '00:00' : min. value) : '';
|
|
|
let dom = {name: condition.name, type: 'time', value: value, mold: 'time'};
|
|
|
modifyData(dom);
|
|
|
})
|
|
|
@@ -464,7 +465,7 @@ const query = function getQueryForm(data) {
|
|
|
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' >");
|
|
|
dataTime.attr('title', controlJsType(condition.tip[0], 'undefined') ? '' : condition.tip[0]);
|
|
|
|
|
|
- let select = $("<select name='" + condition.name[1] + "' class='form-control form-control-sm ' data-toggle='tooltip' data-placement='top' style='max-width: 75px'></select>");
|
|
|
+ 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)
|
|
|
@@ -559,7 +560,7 @@ const query = function getQueryForm(data) {
|
|
|
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' for='" + condition.name + index + "'>" + map.value + "</label>")
|
|
|
+ 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 = [];
|
|
|
@@ -586,7 +587,7 @@ const query = function getQueryForm(data) {
|
|
|
select.append(option);
|
|
|
}
|
|
|
data.forEach(function (map) {
|
|
|
- let option = $("<option value='" + map.name + "'>" + map.value + "</optio>");
|
|
|
+ let option = $("<option value='" + map.value + "'>" + map.name + "</optio>");
|
|
|
select.append(option);
|
|
|
})
|
|
|
if (data !== undefined) {
|
|
|
@@ -661,7 +662,7 @@ const query = function getQueryForm(data) {
|
|
|
for (const key in _data) {
|
|
|
if (!['', null, undefined].includes(_data[key].value)) {
|
|
|
if (controlJsType(_data[key].value, 'array') && _data[key].value.length === 0) {
|
|
|
- console.log(key);
|
|
|
+ //console.log(key);
|
|
|
continue;
|
|
|
}
|
|
|
saveData[key] = {
|
|
|
@@ -720,7 +721,7 @@ const query = function getQueryForm(data) {
|
|
|
}
|
|
|
|
|
|
// get search data
|
|
|
- this.getSearchData = function (type = 'array') {
|
|
|
+ function getSearchData(type = 'array') {
|
|
|
let data = {};
|
|
|
if (type === 'array') {
|
|
|
for (let key in _data) {
|
|
|
@@ -766,7 +767,7 @@ const query = function getQueryForm(data) {
|
|
|
}
|
|
|
} else {
|
|
|
$(_form).find("select[name='" + key + "']").val(value);
|
|
|
- console.log(value === _this.paginations[0]);
|
|
|
+ //console.log(value === _this.paginations[0]);
|
|
|
if (key === 'paginate' && value == _this.paginations[0]) {
|
|
|
return;
|
|
|
}
|
|
|
@@ -856,10 +857,10 @@ const query = function getQueryForm(data) {
|
|
|
}
|
|
|
}
|
|
|
if (bool) {
|
|
|
- _clearBtn.addClass('visible').removeClass('invisible');
|
|
|
+ _clearTr.show();
|
|
|
|
|
|
} else {
|
|
|
- _clearBtn.addClass('invisible').removeClass('visible');
|
|
|
+ _clearTr.hide();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -909,7 +910,7 @@ const query = function getQueryForm(data) {
|
|
|
function switchData() {
|
|
|
_this.condition.forEach(function (conditions) {
|
|
|
conditions.forEach(function (condition) {
|
|
|
- if (['input', 'select', 'dataTime', 'search_select', 'time', 'select_multiple_select'].includes(condition.type)) {
|
|
|
+ if (['input', 'select', 'dataTime', 'search_select', 'time', 'select_multiple_select','checkbox'].includes(condition.type)) {
|
|
|
if (!condition.select) {
|
|
|
condition.select = '';
|
|
|
}
|
|
|
@@ -959,7 +960,7 @@ const query = function getQueryForm(data) {
|
|
|
}
|
|
|
|
|
|
function rendererOptionOnCookie() {
|
|
|
- console.log('rendererSearchFromOnCookie');
|
|
|
+ //console.log('rendererSearchFromOnCookie');
|
|
|
let data = fetchCookie();
|
|
|
if (data === undefined) {
|
|
|
return;
|
|
|
@@ -982,7 +983,7 @@ const query = function getQueryForm(data) {
|
|
|
}
|
|
|
|
|
|
function rendererSearchFormOn_data() {
|
|
|
- console.log('rendererSearchFormOn_data', _data);
|
|
|
+ // console.log('rendererSearchFormOn_data', _data);
|
|
|
|
|
|
for (let key in _data) {
|
|
|
let value = _data[key].value, type = _data[key].type, mold = _data[key].mold;
|
|
|
@@ -1056,6 +1057,9 @@ const query = function getQueryForm(data) {
|
|
|
data = (data.substr(1)).split('&');
|
|
|
data = convertArrayToObj(data);
|
|
|
for (const key in data) {
|
|
|
+ if(!data[key]){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
if (key === 'paginate') {
|
|
|
_data[key] = {
|
|
|
name: key,
|
|
|
@@ -1068,7 +1072,7 @@ const query = function getQueryForm(data) {
|
|
|
} else {
|
|
|
_data[key].value = data[key];
|
|
|
}
|
|
|
- console.log('key', key, typeof key);
|
|
|
+ // console.log('key', key, typeof key);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1111,7 +1115,7 @@ const query = function getQueryForm(data) {
|
|
|
|
|
|
// paginate
|
|
|
function pervPage() {
|
|
|
- let obj = getSearchObj();
|
|
|
+ let obj = getSearchData();
|
|
|
if(!!obj['page'] && obj['page']>1){
|
|
|
obj['page'] = obj['page']-1;
|
|
|
}
|
|
|
@@ -1119,7 +1123,7 @@ const query = function getQueryForm(data) {
|
|
|
}
|
|
|
|
|
|
function nextPage() {
|
|
|
- let obj = getSearchObj();
|
|
|
+ let obj = getSearchData();
|
|
|
if(!!obj['page'] ){
|
|
|
obj['page'] = obj['page']+1;
|
|
|
}else{
|
|
|
@@ -1159,7 +1163,7 @@ const query = function getQueryForm(data) {
|
|
|
function getSearchUri(obj){
|
|
|
let string = "?";
|
|
|
for (const key in obj) {
|
|
|
- if(controlJsType(obj[key],'string')){
|
|
|
+ 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){
|
|
|
@@ -1171,5 +1175,3 @@ const query = function getQueryForm(data) {
|
|
|
}
|
|
|
|
|
|
};
|
|
|
-
|
|
|
-//module.exports = query;
|