StartTime="2017-1-1"; EndTime="2017-1-1"; ReportFileName="day"; function CreateDayMonthReportShow(x,y,width,height,pageHeight,jsonFileNameData,dayMonth) { //列表控件 listView = new ht.widget.ListView(); //listView.setCheckMode(true); var SelectTime=""; listView.onDataClicked=function(data)//选择某个数据 { if(!data) return; SelectTime=data.a('Name'); } //布局控件 borderPaneDayReport = new ht.widget.BorderPane(); borderPaneDayReport.setLeftView(listView, 180); //表格控件 var ReportDiv=document.createElement("div"); var ReportDivChild=document.createElement("div"); ReportDiv.appendChild(ReportDivChild); ReportDivChild.className="sample-turtorial"; var reportWidth=width-180; var reportHeight=(height)*document.documentElement.clientHeight /pageHeight-28; ReportDivChild.style='width:'+reportWidth+'px; height:'+reportHeight+'px;border: 1px solid gray;'; ReportSpread =new GC.Spread.Sheets.Workbook(ReportDivChild, { sheetCount: 1 }); importJSON(ReportSpread,jsonFileNameData ); //表格加入布局 //borderPaneDayReport.setRightView(ReportDiv,width-180); borderPaneDayReport.setCenterView(ReportDiv); var NodeStartTimeDiv=document.createElement("div"); NodeStartTimeDiv.innerHTML = '
'; document.body.appendChild(NodeStartTimeDiv); var NodeEndTimeDiv=document.createElement("div"); NodeEndTimeDiv.innerHTML = '
'; document.body.appendChild(NodeEndTimeDiv); toolbar = new ht.widget.Toolbar(); borderPaneDayReport.setTopView(toolbar); //按钮 //报表查看 lookButton1=new ht.widget.Button(); lookButton1.setWidth(40); lookButton1.setLabel("查看"); lookButton1.setBorderColor("#4682B4"); lookButton1.setBackground("#4682B4"); lookButton1.setLabelColor("#FFFAF0"); lookButton1.onClicked= function(e) { SetTimeSelectDivValue(NodeStartTimeDiv,SelectTime,"date"); var tempEndTime1=new Date(Date.parse(SelectTime)); tempEndTime1.setDate(tempEndTime1.getDate()+1); SetTimeSelectDivValue(NodeEndTimeDiv,tempEndTime1.toString(),"date"); StartTime=NodeStartTimeDiv.innerText+" 0:0:0"; EndTime=NodeEndTimeDiv.innerText+" 0:0:0";; ReportSpread.resumeCalcService(); } //报表直接导出 downloadButton1=new ht.widget.Button(); downloadButton1.setWidth(40); downloadButton1.setLabel("导出"); downloadButton1.setBorderColor("#4682B4"); downloadButton1.setBackground("#4682B4"); downloadButton1.setLabelColor("#FFFAF0"); downloadButton1.onClicked= function(e) { SetTimeSelectDivValue(NodeStartTimeDiv,SelectTime,"date"); var tempEndTime1=new Date(Date.parse(SelectTime)); tempEndTime1.setDate(tempEndTime1.getDate()+1); SetTimeSelectDivValue(NodeEndTimeDiv,tempEndTime1.toString(),"date"); StartTime=NodeStartTimeDiv.innerText+" 0:0:0"; EndTime=NodeEndTimeDiv.innerText+" 0:0:0";; ReportSpread.resumeCalcService(); SpreadExport(ReportSpread,ReportFileName); } //报表查询 lookButton2=new ht.widget.Button(); lookButton2.setWidth(40); lookButton2.setLabel("查询"); lookButton2.setBorderColor("#4682B4"); lookButton2.setBackground("#4682B4"); lookButton2.setLabelColor("#FFFAF0"); lookButton2.onClicked= function(e) { StartTime=NodeStartTimeDiv.innerText+" 0:0:0"; EndTime=NodeEndTimeDiv.innerText+" 0:0:0";; ReportSpread.resumeCalcService(); } //报表导出 downloadButton2=new ht.widget.Button(); downloadButton2.setWidth(40); downloadButton2.setLabel("导出"); downloadButton2.setBorderColor("#4682B4"); downloadButton2.setBackground("#4682B4"); downloadButton2.setLabelColor("#FFFAF0"); downloadButton2.onClicked= function(e) { StartTime=NodeStartTimeDiv.innerText+" 0:0:0"; EndTime=NodeEndTimeDiv.innerText+" 0:0:0"; ReportSpread.resumeCalcService(); SpreadExport(ReportSpread,ReportFileName); } //数据补抽 var recaluBtn=new ht.widget.Button(); recaluBtn.setWidth(80); recaluBtn.setLabel("数据补抽"); recaluBtn.setBorderColor("#4682B4"); recaluBtn.setBackground("#4682B4"); recaluBtn.setLabelColor("#FFFAF0"); recaluBtn.onClicked= function(e) { StartTime=NodeStartTimeDiv.innerText+" 0:0:0"; EndTime=NodeEndTimeDiv.innerText+" 0:0:0"; var obj=new CommandObj(); obj.method="HisDataReGet"; obj.parm1=StartTime; obj.parm2=EndTime; var objStr=JSON.stringify(obj); socket.send(objStr); } var progressBtn=new ht.widget.Button(); progressBtn.setWidth(100); progressBtn.setLabel("进度:"); progressBtn.setBorderColor("#4682B4"); progressBtn.setBackground("#4682B4"); progressBtn.setLabelColor("#FFFAF0"); toolbar.getSelectBackground = function(item){ return '#3D97D0'; }; toolbar.setItems([ { id: 'text', label: '', icon: 'image/search.png', textField: { width: 80 } }, { label: '', element:lookButton1 }, { label: '', element:downloadButton1 }, { id: 'nation', label: '开始时间 ', }, { id: 'nation', label: ' ', element: NodeStartTimeDiv }, { id: 'nation', label: '结束时间 ', }, { id: 'nation', label: ' ', element: NodeEndTimeDiv }, { label: '', element:lookButton2 }, { label: '', element:downloadButton2 }, { label: '', element:recaluBtn }, { label: '', element:progressBtn }, ]); toolbar.getItemById('text').element.getElement().onkeyup = function(e){ listView.invalidateModel(); }; //时间选择控件 初始化时间 (function (elem, timeValue, type) { timeValue = getRelativeDate(timeValue, type); laydate.render({ elem: elem, type: type, value: timeValue, done: function(value, date){ setTimeout(function () { ; }, 100) } }); ; })(NodeStartTimeDiv, '2017-01-01', 'date'); //时间选择控件 初始化时间 SetTimeSelectDivValue(NodeEndTimeDiv, '2017-01-01', 'date'); //建立一个websocket链接 //var socket = new WebSocket('ws://192.168.0.141:10087/Command'); var socket = new WebSocket('ws://'+webServiceIP+':10087/Command'); // 打开Socket socket.onopen = function(event) { console.log('web socket connceted!',event); //请求报表js数据 var obj=new CommandObj(); obj.method="GetReportJsFile"; obj.parm1="day"; var objStr=JSON.stringify(obj); socket.send(objStr); //请求报表生成日期列表 socket.send("{\"method\":\"GetHaveSaveDayList\"}"); }; // 监听消息 socket.onmessage = function(event) { console.log('Client received a message',event); var receiveObj=JSON.parse(event.data); if(receiveObj.method=="GetHaveSaveDayList") { var dayList=JSON.parse(receiveObj.obj); listView.dm().clear(); dayList.forEach(function(val,index,arr) { AddListViewElem(listView,val); }); listView.setSortFunc(sortFunc); } else if(receiveObj.method=="GetReportJsFile") { //var jsObj=JSON.parse(receiveObj.obj); // importJSON(ReportSpread,jsObj); } else if(receiveObj.method=="HisDataReGet") { var jsObj=receiveObj.obj; progressBtn.setLabel("进度:"+jsObj); } }; // 监听Socket的关闭 socket.onclose = function(event) { console.log('Client notified socket has closed',event); }; listView.setRowHeight(30); //添加列表中的数据 //AddListViewElem(listView); /*products.forEach(function(product){ var data = new ht.Data(); data.a(product); listView.dm().add(data); }); */ listView.enableToolTip(); listView.getLabel = function(data){ return data.a('ProductName') + ' - $' + data.a('UnitPrice').toFixed(2); }; ht.Default.setImage('productIcon', { width: 50, height: 50, clip: function(g, width, height) { g.beginPath(); g.arc(width/2, height/2, Math.min(width, height)/2-3, 0, Math.PI * 2, true); g.clip(); }, comps: [ { type: 'image', stretch: 'uniform', rect: [0, 0, 50, 50], name: {func: function(data){return data.a('ProductId');}} } ] }); listView.drawRowBackground = function(g, data, selected, xx, yy, widthb, heightb){ if(this.isSelected(data)){ g.fillStyle = '#87A6CB'; } else if(this.getRowIndex(data) % 2 === 0){ g.fillStyle = '#F1F4F7'; } else{ g.fillStyle = '#FAFAFA'; } g.beginPath(); g.rect(xx, yy, widthb, heightb); g.fill(); }; listView.setIndent(60); //listView.getIcon = function(data){ // return 'productIcon'; // }; listView.enableToolTip(); listView.getLabel = function(data){ return data.a('Name'); }; listView.getToolTip = function(e){ var data = this.getDataAt(e); if(data) { return 'ProductId: ' + data.a('ProductId') + '
' + 'ProductName: ' + data.a('ProductName') + '
' + 'QuantityPerUnit: ' + data.a('QuantityPerUnit') + '
' + 'Description: ' + data.a('Description'); } return null; }; sortFunc = function(d1, d2) { var str1= d1.a('Name'); var str2= d2.a('Name'); var strInt1=str1.replace('-',''); strInt1=strInt1.replace('-',''); var strInt2=str2.replace('-',''); strInt2=strInt2.replace('-',''); return parseInt(strInt2)-parseInt(strInt1); }; listView.setSortFunc(sortFunc); listView.setVisibleFunc(function(data){ var text = toolbar.v('text'); if(text){ return data.a('Name').toLowerCase().indexOf(text.toLowerCase()) >= 0; } return true; }); var borderPaneRealNode = new ht.HtmlNode(); borderPaneRealNode.setScalable(false); borderPaneRealNode.s({ '2d.selectable': true, '2d.movable': false }); borderPaneRealNode.setHtml(borderPaneDayReport); borderPaneRealNode.setPosition({ x: x, y: y }); borderPaneRealNode.setWidth(width); borderPaneRealNode.setHeight(height); borderPaneRealNode.setPadding(0); /*startSubscribe();*/ /*getSnapshotCallback();*/ return borderPaneRealNode; }; //添加列表控件的数据 function AddListViewElem(listView,obj) { var data = new ht.Data(); data.a(obj); listView.dm().add(data); } //导入报表的json数据 function importJSON (spread,jsonData) { ApplyCustomFunc(spread); spread.fromJSON(jsonData); ApplyCustomFunc(spread); var json = spread.toJSON(); spread.fromJSON(json); var sheet = spread.getSheet(0); sheet.options.colHeaderVisible=false; sheet.options.rowHeaderVisible=false; spread.options.newTabVisible=false; spread.options.tabStripVisible=false; spread.options.showHorizontalScrollbar=true; ResetFormular(spread); } //设置时间选择控件的时间 function SetTimeSelectDivValue(elem, timeValue, type) { timeValue = getRelativeDate(timeValue, type); laydate.render({ elem: elem, type: type, value: timeValue, done: function(value, date){ setTimeout(function () { ; }, 100) } }); ; } function CommandObj() { var method=""; var parm1=""; var parm2=""; } function ReceiveObj() { var method=""; var obj=""; } function SpreadExport(spread,exportfileName) { var fileName =exportfileName + (+new Date()) + '.xlsx'; if (fileName.substr(-5, 5) !== '.xlsx') { fileName += '.xlsx'; } var json = spread.toJSON(); sheet1=spread.getActiveSheet(); var spread2 = new GC.Spread.Sheets.Workbook(); spread2.fromJSON(json); var sheet2 = spread2.getActiveSheet(); var array = sheet1.getArray(0,0,sheet1.getRowCount(),sheet1.getColumnCount(),false); sheet2.clear(0,0,sheet2.getRowCount(),sheet2.getColumnCount(),GC.Spread.Sheets.SheetArea.viewport,GC.Spread.Sheets.StorageType.data); sheet2.setArray(0,0,array,false); json = spread2.toJSON(); // here is excel IO API excelIo = new GC.Spread.Excel.IO(); excelIo.save(json, function (blob) { saveAs(blob, fileName); }, function (e) { // process error alert(e.message); }); }