123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472 |
-
- 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 = '<div id ="NodeStartTimeDiv" class = "dateTimePicker" style = "width:100px,height:10px,font-size:10.66664px;background-color:rgba(255,255,255,1);border-color:rgba(0,0,0,1);color:rgba(0,0,0,1);"></div>';
- document.body.appendChild(NodeStartTimeDiv);
-
- var NodeEndTimeDiv=document.createElement("div");
- NodeEndTimeDiv.innerHTML = '<div id ="NodeEndTimeDiv" class = "dateTimePicker" style = "width:100px,height:10px,font-size:10.66664px;background-color:rgba(255,255,255,1);border-color:rgba(0,0,0,1);color:rgba(0,0,0,1);"></div>';
- 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 '<span style="color:#3D97D0">ProductId: </span>' + data.a('ProductId') + '<br>' +
- '<span style="color:#3D97D0">ProductName: </span>' + data.a('ProductName') + '<br>' +
- '<span style="color:#3D97D0">QuantityPerUnit: </span>' + data.a('QuantityPerUnit') + '<br>' +
- '<span style="color:#3D97D0">Description: </span>' + 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);
- });
- }
|