|
@@ -789,8 +789,358 @@ class AjaxSend {
|
|
|
option.dataTable = $(that.domObj.find("#" + elementId)[0]).DataTable(table_data);
|
|
|
return option.dataTable;
|
|
|
}
|
|
|
+
|
|
|
+ *
|
|
|
+ *渲染时列显示与隐藏
|
|
|
+ * @param {*} option
|
|
|
+ * @return {*}
|
|
|
+ * @memberof AjaxSend
|
|
|
+ */
|
|
|
+ public DataTables_check_visible(option) {
|
|
|
+ let ajaxSend = this;
|
|
|
+ let that = option.that, elementId = option.elementId, url = option.url, searchInfo = option.searchInfo,
|
|
|
+ displayTitle = option.displayTitle, displayField = option.displayField, beforeTrClickEvent = option.beforeTrClickEvent,
|
|
|
+ afterTrClickEvent = option.afterTrClickEvent, drawEvent = option.drawEvent, errmassage = option.errmassage,
|
|
|
+ nullmessage = option.nullmessage,title = option.exportTitle, extentDisplayTitle = option.extentDisplayTitle,
|
|
|
+ extentDisplayContent = option.extentDisplayContent,serachCallBack = option.serachCallBack,testData=option.testData;
|
|
|
+ let isCheck = null;
|
|
|
+ if (option.isCheck != undefined || option.isCheck != null) {
|
|
|
+ isCheck = option.isCheck
|
|
|
+ } else {
|
|
|
+ isCheck = true;
|
|
|
+ }
|
|
|
+ let requestMethod = null;
|
|
|
+ let contentType = "application/x-www-form-urlencoded"
|
|
|
+ if (option.requestMethod != undefined || option.requestMethod != null) {
|
|
|
+ requestMethod = option.requestMethod;
|
|
|
+ contentType = "application/json;charset=utf-8";
|
|
|
+ } else {
|
|
|
+ requestMethod = "GET";
|
|
|
+ }
|
|
|
+ let classThis = this;
|
|
|
+ if (option.dataTable) {
|
|
|
+ option.dataTable.destroy();
|
|
|
+ }
|
|
|
+
|
|
|
+ let tableThead_th
|
|
|
+ tableThead_th = '<th title="本页全选" width="50"><input type="checkbox" class="AllCheck" /></th>';
|
|
|
+ for (let e of displayTitle) {
|
|
|
+ tableThead_th += '<th title="' + e + '">' + e + '</th>';
|
|
|
+ }
|
|
|
+ if (extentDisplayTitle && extentDisplayTitle.length > 0) {
|
|
|
+ for (let el of extentDisplayTitle) {
|
|
|
+ tableThead_th += '<th title="' + el + '">' + el + '</th>';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ that.domObj.find("#" + elementId).empty().append("<thead><tr>" + tableThead_th + "</tr></thead>");
|
|
|
+
|
|
|
+ let columns = [];
|
|
|
+ columns.push({ "data": "input" })
|
|
|
+ for (let e of displayField) {
|
|
|
+ columns.push({ "data": e.name ,"visible": e.visible})
|
|
|
+ }
|
|
|
+ if (extentDisplayContent && extentDisplayContent.length > 0) {
|
|
|
+ for (let el of extentDisplayContent) {
|
|
|
+ columns.push({ "data": el.field })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let table_data = {
|
|
|
+ dom: 't' +
|
|
|
+ ' <"row"' +
|
|
|
+ ' <" information"ri>' +
|
|
|
+ ' <" length-changing"l>' +
|
|
|
+ ' <" pull-right pagination"p>' +
|
|
|
+ ' <" turnToolbar">' +
|
|
|
+ ' <" Bfrtip">' +
|
|
|
+ ' >' +
|
|
|
+ "<'row_datable_export'<'col-md-12'B>>",
|
|
|
+ buttons: [{
|
|
|
+ extend: 'excelHtml5',
|
|
|
+ title: title,
|
|
|
+ customize: function (xlsx) {
|
|
|
+ var sheet = xlsx.xl.worksheets['sheet1.xml'];
|
|
|
+ },
|
|
|
+ exportOptions: {
|
|
|
+ format: {
|
|
|
+ body: function (data, row, column, node) {
|
|
|
+ if (data.indexOf("singleCheckBox") != -1) {
|
|
|
+ return (row + 1);
|
|
|
+ } else if(data.indexOf("infoWrite") != -1){
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return node.textContent
|
|
|
+ }
|
|
|
+ },
|
|
|
+ header: function (data, column, node) {
|
|
|
+ if (data.indexOf("AllCheck") != -1) {
|
|
|
+ return "序号";
|
|
|
+ } else if(data == "详情"){
|
|
|
+ return ""
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return data
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }],
|
|
|
+ language: {
|
|
|
+ "lengthMenu": "每页_MENU_条",
|
|
|
+ "zeroRecords": "未查询到任何记录",
|
|
|
+ "info": "共 _TOTAL_ 条",
|
|
|
+ "infoEmpty": "",
|
|
|
+ "infoFiltered": "",
|
|
|
+ "processing": "查询中,请稍等...",
|
|
|
+ "paginate": {
|
|
|
+ "first": "首页",
|
|
|
+ "last": "尾页",
|
|
|
+ "next": ">",
|
|
|
+ "previous": "<"
|
|
|
+ },
|
|
|
+ "search": "搜索: ",
|
|
|
+ },
|
|
|
+ pagingType: "simple",
|
|
|
+ paging: true,
|
|
|
+ scrollCollapse: false,
|
|
|
+ processing: true,
|
|
|
+ scrollX: true,
|
|
|
+ scrollY: "calc(100% - 50px)",
|
|
|
+ ordering: false,
|
|
|
+ lengthMenu: [10, 50, 100, 1000,100000],
|
|
|
+ drawCallback: function (settings) {
|
|
|
+ $(settings.nTableWrapper).find(".AllCheck").prop('checked', false);
|
|
|
+ $(settings.nTable).off('click', "tbody tr").on('click', "tbody tr", function (e) {
|
|
|
+ let dom = $(e.currentTarget).find(".currentTableData");
|
|
|
+ let index = parseInt(dom.attr("index"));
|
|
|
+ if (option.dataTable.aExtentData && option.dataTable.aExtentData.currentAllData && option.dataTable.aExtentData.currentAllData.length == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let clickData = option.dataTable.aExtentData.currentAllData[index];
|
|
|
+ if (beforeTrClickEvent && !beforeTrClickEvent(clickData)) {
|
|
|
+ return;
|
|
|
+ };
|
|
|
+ if (option.dataTable.aExtentData && option.dataTable.aExtentData.currentTableData && option.dataTable.aExtentData.currentTableData.id && clickData.id == option.dataTable.aExtentData.currentTableData.id) {
|
|
|
+ return;
|
|
|
+ } else {
|
|
|
+ option.dataTable.aExtentData.currentTableData = clickData;
|
|
|
+ }
|
|
|
+ $(settings.nTable).find("tbody tr.active").removeClass("active");
|
|
|
+ $(e.currentTarget).addClass("active");
|
|
|
+ if (afterTrClickEvent && !afterTrClickEvent()) {
|
|
|
+ return;
|
|
|
+ };
|
|
|
+ });
|
|
|
+ if (drawEvent) {
|
|
|
+ drawEvent();
|
|
|
+ }
|
|
|
+
|
|
|
+ let dom = $(settings.nTableWrapper);
|
|
|
+ dom.find(".row_datable_export").attr("style", "display:none");
|
|
|
+ let addPosi = dom.find(".previous");
|
|
|
+ let pagehtml = '<li class="addPageInfo"><span>第' + (settings._iDisplayStart / settings._iDisplayLength + 1) + '页/共' + Math.ceil(settings._iRecordsDisplay / settings._iDisplayLength) + '页</span></li>';
|
|
|
+ addPosi.after(pagehtml);
|
|
|
+
|
|
|
+ let turnAddPosi = dom.find('.turnToolbar');
|
|
|
+ let turnpagehtml = '<input type="number" class="addPageIndexInput" value="' + (settings._iDisplayStart / settings._iDisplayLength + 1) + '" /> <button type="button" class="btn btn-sm btn-default addPageIndexButton">跳转</button>'
|
|
|
+ turnAddPosi.empty().append(turnpagehtml);
|
|
|
+ turnAddPosi.find('.addPageIndexButton').off().click(e => {
|
|
|
+ let pageInfo = option.dataTable.page.info();
|
|
|
+ let pageIndex = (turnAddPosi.find('.addPageIndexInput').val());
|
|
|
+ if (pageIndex > 0 && pageIndex <= pageInfo.pages) {
|
|
|
+ option.dataTable.deafultPageIndex = pageIndex;
|
|
|
+ option.dataTable.ajax.reload();
|
|
|
+ } else {
|
|
|
+ option.dataTable.deafultPageIndex = -10;
|
|
|
+ that.toast.show("跳转页数超过查询范围请重新设置!");
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ dom.find('.AllCheck').off().click(e => {
|
|
|
+ let currentDom = $(e.currentTarget)[0];
|
|
|
+ if (currentDom["checked"]) {
|
|
|
+ dom.find(".singleCheckBox").prop('checked', true);
|
|
|
+ } else {
|
|
|
+ dom.find(".singleCheckBox").prop('checked', false);
|
|
|
+ };
|
|
|
+ classThis.DataTables_check_getCheck(option.dataTable, dom);
|
|
|
+ });
|
|
|
+
|
|
|
+ dom.find('.singleCheckBox').off().click(e => {
|
|
|
+ let currentDom = dom.find(".singleCheckBox:checked");
|
|
|
+ let currentAllDom = dom.find(".singleCheckBox");
|
|
|
+ if (currentDom.length == currentAllDom.length) {
|
|
|
+ dom.find(".AllCheck").prop('checked', true);
|
|
|
+ } else {
|
|
|
+ dom.find(".AllCheck").prop('checked', false);
|
|
|
+ }
|
|
|
+ classThis.DataTables_check_getCheck(option.dataTable, dom);
|
|
|
+ });
|
|
|
+ if (!isCheck) {
|
|
|
+ dom.find(".singleCheckBox").parent('td').attr('style', 'display:none');
|
|
|
+ dom.find(".AllCheck").parent('th').attr('style', 'display:none')
|
|
|
+ }
|
|
|
+ }.bind(that),
|
|
|
+ serverSide: true,
|
|
|
+ ajax: {
|
|
|
+ headers: that.header,
|
|
|
+ type: requestMethod,
|
|
|
+ data: function (e) {
|
|
|
+ let start = (e['start'] / e['length']) + 1;
|
|
|
+ if (option.dataTable && option.dataTable.deafultPageIndex && option.dataTable.deafultPageIndex != -10) {
|
|
|
+ start = parseInt(option.dataTable.deafultPageIndex);
|
|
|
+ option.dataTable.context[0]._iDisplayStart = (start - 1) * option.dataTable.context[0]._iDisplayLength
|
|
|
+ option.dataTable.deafultPageIndex = -10;
|
|
|
+ }
|
|
|
+ let searchData = null;
|
|
|
+ if (that.searchInfo) {
|
|
|
+ that.searchInfo.current = start || that.config.pagenumber;
|
|
|
+ that.searchInfo.size = e['length'] || that.config.pagesize;
|
|
|
+ searchData = that.searchInfo;
|
|
|
+ } else {
|
|
|
+ searchInfo.current = start || that.config.pagenumber;
|
|
|
+ searchInfo.size = e['length'] || that.config.pagesize;
|
|
|
+ searchData = searchInfo;
|
|
|
+ }
|
|
|
+ if (requestMethod == "POST") {
|
|
|
+ let data = JSON.stringify(searchData);
|
|
|
+ searchData = data;
|
|
|
+ }
|
|
|
+ return searchData;
|
|
|
+ },
|
|
|
+ url: that.apiRoot + url,
|
|
|
+ dataType: "json",
|
|
|
+ contentType: contentType,
|
|
|
+ async: true,
|
|
|
+ error: function (e) {
|
|
|
+ that.loadWait.hide();
|
|
|
+ let title = '查询失败!';
|
|
|
+ if (errmassage) {
|
|
|
+ title = errmassage;
|
|
|
+ }
|
|
|
+ that.toast.show(title);
|
|
|
+ console.error(e);
|
|
|
+ },
|
|
|
+ dataSrc: function (results) {
|
|
|
+ that.AppX.runtimeConfig.map.infoWindow.hide();
|
|
|
+
|
|
|
+ if(testData){
|
|
|
+ results=testData;
|
|
|
+ }
|
|
|
+ if (results.code == 1) {
|
|
|
+ var value = results;
|
|
|
+ if (serachCallBack) {
|
|
|
+ serachCallBack(results);
|
|
|
+ }
|
|
|
+ results = {};
|
|
|
+ option.dataTable.aExtentData = {};
|
|
|
+ option.dataTable.aExtentData.currentAllData = value.result.records;
|
|
|
+
|
|
|
+ value.recordsFiltered = value.result.total;
|
|
|
+ results.data = [];
|
|
|
+ if (value.result.records.length == 0) {
|
|
|
+ let title = '未查询到数据!';
|
|
|
+ if (nullmessage) {
|
|
|
+ title = nullmessage;
|
|
|
+ }
|
|
|
+ that.toast.show(title);
|
|
|
+ that.loadWait.hide();
|
|
|
+ that.AppX.runtimeConfig.loadMask.hide();
|
|
|
+ that.AppX.runtimeConfig.loadFulldMask.hide();
|
|
|
+ return results.data;
|
|
|
+ };
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+ $.each(value.result.records, function (i, item) {
|
|
|
+ let itemData = {};
|
|
|
+ for (let e of displayField) {
|
|
|
+
|
|
|
+ if (e.name.indexOf('_special_') != -1) {
|
|
|
+
|
|
|
+ if (e.name.indexOf('EquipmentOperationLedger') != -1) {
|
|
|
+ let dataInfo = "";
|
|
|
+ if (item['content']) {
|
|
|
+ item['content'].forEach(a => {
|
|
|
+ dataInfo += (ajaxSend.verificationHelper.setNullAndUndefined(a.name) + ":" + ajaxSend.verificationHelper.setNullAndUndefined(a.names) + ";")
|
|
|
+ })
|
|
|
+ }
|
|
|
+ dataInfo = ajaxSend.verificationHelper.setNullAndUndefined(dataInfo);
|
|
|
+ itemData[e.name] = "<span title='" + dataInfo + "'>" + dataInfo + "</span>";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ else if (e.name.indexOf('/') == -1) {
|
|
|
+ let dataInfo = ajaxSend.verificationHelper.setNullAndUndefined(item[e.name]);
|
|
|
+
|
|
|
+ if (typeof (dataInfo) == "number") {
|
|
|
+
|
|
|
+ if (dataInfo % 1 != 0) {
|
|
|
+ dataInfo = dataInfo.toFixed(2);
|
|
|
+ } else {
|
|
|
+ dataInfo = dataInfo;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ itemData[e.name] = "<span title='" + dataInfo + "'>" + dataInfo + "</span>";
|
|
|
+ }
|
|
|
+
|
|
|
+ else {
|
|
|
+ let fieldArr = e.name.split('/');
|
|
|
+
|
|
|
+ let fileld1 = fieldArr[0];
|
|
|
+
|
|
|
+ let fileld2 = fieldArr[1];
|
|
|
+ let dataList = item[fileld1];
|
|
|
+ if (dataList) {
|
|
|
+ let dataItem = null;
|
|
|
+
|
|
|
+ if (dataList instanceof Array) {
|
|
|
+ if (dataList.length > 0) {
|
|
|
+ dataItem = dataList[0]
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (dataList != "") {
|
|
|
+ dataItem = dataList;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ let dataInfo = null;
|
|
|
+ if (dataItem) {
|
|
|
+ dataInfo = ajaxSend.verificationHelper.setNullAndUndefined(dataItem[fileld2]);
|
|
|
+ } else {
|
|
|
+ dataInfo = ajaxSend.verificationHelper.setNullAndUndefined(undefined);
|
|
|
+ }
|
|
|
+ itemData[e.name] = "<span title='" + dataInfo + "'>" + dataInfo + "</span>";
|
|
|
+ } else {
|
|
|
+ itemData[e.name] = "<span title='" + ajaxSend.verificationHelper.setNullAndUndefined(undefined) + "'>" + ajaxSend.verificationHelper.setNullAndUndefined(undefined) + "</span>";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ itemData["input"] = "<input class='singleCheckBox currentTableData' type='checkbox' index='" + i + "'>";
|
|
|
+ if (extentDisplayContent && extentDisplayContent.length > 0) {
|
|
|
+ for (let el of extentDisplayContent) {
|
|
|
+ itemData[el.field] = el.fieldContent
|
|
|
+ }
|
|
|
+ }
|
|
|
+ results.data.push(itemData);
|
|
|
+ });
|
|
|
+ that.loadWait.hide();
|
|
|
+ that.AppX.runtimeConfig.loadMask.hide();
|
|
|
+ that.AppX.runtimeConfig.loadFulldMask.hide();
|
|
|
+ return results.data;
|
|
|
+ } else {
|
|
|
+ that.toast.show(results.message);
|
|
|
+ console.error(results.message);
|
|
|
+ that.loadWait.hide();
|
|
|
+ that.AppX.runtimeConfig.loadMask.hide();
|
|
|
+ that.AppX.runtimeConfig.loadFulldMask.hide();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ columns: columns,
|
|
|
+ };
|
|
|
+ option.dataTable = $(that.domObj.find("#" + elementId)[0]).DataTable(table_data);
|
|
|
+ return option.dataTable;
|
|
|
+ }
|
|
|
|
|
|
* 本方法将在option.dataTable对象中加入当前选中列表的数据(option.dataTable.aExtentData.currentTableData)和所有查询的数据(option.dataTable.aExtentData.currentAllData)
|
|
|
* 选中的行的类名中将加入active用来改变选中行的颜色
|