GoldenDayReportShow.js.bak 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. 
  2. StartTime="2017-1-1";
  3. EndTime="2017-1-1";
  4. ReportFileName="day";
  5. function CreateDayMonthReportShow(x,y,width,height,pageHeight,jsonFileNameData,dayMonth)
  6. {
  7. //列表控件
  8. listView = new ht.widget.ListView();
  9. //listView.setCheckMode(true);
  10. var SelectTime="";
  11. listView.onDataClicked=function(data)//选择某个数据
  12. {
  13. if(!data)
  14. return;
  15. SelectTime=data.a('Name');
  16. }
  17. //布局控件
  18. borderPaneDayReport = new ht.widget.BorderPane();
  19. borderPaneDayReport.setLeftView(listView, 180);
  20. //表格控件
  21. var ReportDiv=document.createElement("div");
  22. var ReportDivChild=document.createElement("div");
  23. ReportDiv.appendChild(ReportDivChild);
  24. ReportDivChild.className="sample-turtorial";
  25. var reportWidth=width-180;
  26. var reportHeight=(height)*document.documentElement.clientHeight /pageHeight-28;
  27. ReportDivChild.style='width:'+reportWidth+'px; height:'+reportHeight+'px;border: 1px solid gray;';
  28. ReportSpread =new GC.Spread.Sheets.Workbook(ReportDivChild, { sheetCount: 1 });
  29. importJSON(ReportSpread,jsonFileNameData );
  30. //表格加入布局
  31. //borderPaneDayReport.setRightView(ReportDiv,width-180);
  32. borderPaneDayReport.setCenterView(ReportDiv);
  33. var NodeStartTimeDiv=document.createElement("div");
  34. 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>';
  35. document.body.appendChild(NodeStartTimeDiv);
  36. var NodeEndTimeDiv=document.createElement("div");
  37. 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>';
  38. document.body.appendChild(NodeEndTimeDiv);
  39. toolbar = new ht.widget.Toolbar();
  40. borderPaneDayReport.setTopView(toolbar);
  41. //按钮
  42. //报表查看
  43. lookButton1=new ht.widget.Button();
  44. lookButton1.setWidth(40);
  45. lookButton1.setLabel("查看");
  46. lookButton1.setBorderColor("#4682B4");
  47. lookButton1.setBackground("#4682B4");
  48. lookButton1.setLabelColor("#FFFAF0");
  49. lookButton1.onClicked= function(e)
  50. {
  51. SetTimeSelectDivValue(NodeStartTimeDiv,SelectTime,"date");
  52. var tempEndTime1=new Date(Date.parse(SelectTime));
  53. tempEndTime1.setDate(tempEndTime1.getDate()+1);
  54. SetTimeSelectDivValue(NodeEndTimeDiv,tempEndTime1.toString(),"date");
  55. StartTime=NodeStartTimeDiv.innerText+" 0:0:0";
  56. EndTime=NodeEndTimeDiv.innerText+" 0:0:0";;
  57. ReportSpread.resumeCalcService();
  58. }
  59. //报表直接导出
  60. downloadButton1=new ht.widget.Button();
  61. downloadButton1.setWidth(40);
  62. downloadButton1.setLabel("导出");
  63. downloadButton1.setBorderColor("#4682B4");
  64. downloadButton1.setBackground("#4682B4");
  65. downloadButton1.setLabelColor("#FFFAF0");
  66. downloadButton1.onClicked= function(e)
  67. {
  68. SetTimeSelectDivValue(NodeStartTimeDiv,SelectTime,"date");
  69. var tempEndTime1=new Date(Date.parse(SelectTime));
  70. tempEndTime1.setDate(tempEndTime1.getDate()+1);
  71. SetTimeSelectDivValue(NodeEndTimeDiv,tempEndTime1.toString(),"date");
  72. StartTime=NodeStartTimeDiv.innerText+" 0:0:0";
  73. EndTime=NodeEndTimeDiv.innerText+" 0:0:0";;
  74. ReportSpread.resumeCalcService();
  75. SpreadExport(ReportSpread,ReportFileName);
  76. }
  77. //报表查询
  78. lookButton2=new ht.widget.Button();
  79. lookButton2.setWidth(40);
  80. lookButton2.setLabel("查询");
  81. lookButton2.setBorderColor("#4682B4");
  82. lookButton2.setBackground("#4682B4");
  83. lookButton2.setLabelColor("#FFFAF0");
  84. lookButton2.onClicked= function(e)
  85. {
  86. StartTime=NodeStartTimeDiv.innerText+" 0:0:0";
  87. EndTime=NodeEndTimeDiv.innerText+" 0:0:0";;
  88. ReportSpread.resumeCalcService();
  89. }
  90. //报表导出
  91. downloadButton2=new ht.widget.Button();
  92. downloadButton2.setWidth(40);
  93. downloadButton2.setLabel("导出");
  94. downloadButton2.setBorderColor("#4682B4");
  95. downloadButton2.setBackground("#4682B4");
  96. downloadButton2.setLabelColor("#FFFAF0");
  97. downloadButton2.onClicked= function(e)
  98. {
  99. StartTime=NodeStartTimeDiv.innerText+" 0:0:0";
  100. EndTime=NodeEndTimeDiv.innerText+" 0:0:0";
  101. ReportSpread.resumeCalcService();
  102. SpreadExport(ReportSpread,ReportFileName);
  103. }
  104. //数据补抽
  105. var recaluBtn=new ht.widget.Button();
  106. recaluBtn.setWidth(80);
  107. recaluBtn.setLabel("数据补抽");
  108. recaluBtn.setBorderColor("#4682B4");
  109. recaluBtn.setBackground("#4682B4");
  110. recaluBtn.setLabelColor("#FFFAF0");
  111. recaluBtn.onClicked= function(e)
  112. {
  113. StartTime=NodeStartTimeDiv.innerText+" 0:0:0";
  114. EndTime=NodeEndTimeDiv.innerText+" 0:0:0";
  115. var obj=new CommandObj();
  116. obj.method="HisDataReGet";
  117. obj.parm1=StartTime;
  118. obj.parm2=EndTime;
  119. var objStr=JSON.stringify(obj);
  120. socket.send(objStr);
  121. }
  122. var progressBtn=new ht.widget.Button();
  123. progressBtn.setWidth(100);
  124. progressBtn.setLabel("进度:");
  125. progressBtn.setBorderColor("#4682B4");
  126. progressBtn.setBackground("#4682B4");
  127. progressBtn.setLabelColor("#FFFAF0");
  128. toolbar.getSelectBackground = function(item){ return '#3D97D0'; };
  129. toolbar.setItems([
  130. {
  131. id: 'text',
  132. label: '',
  133. icon: 'image/search.png',
  134. textField: {
  135. width: 80
  136. }
  137. },
  138. {
  139. label: '',
  140. element:lookButton1
  141. },
  142. {
  143. label: '',
  144. element:downloadButton1
  145. },
  146. {
  147. id: 'nation',
  148. label: '开始时间 ',
  149. },
  150. {
  151. id: 'nation',
  152. label: ' ',
  153. element: NodeStartTimeDiv
  154. },
  155. {
  156. id: 'nation',
  157. label: '结束时间 ',
  158. },
  159. {
  160. id: 'nation',
  161. label: ' ',
  162. element: NodeEndTimeDiv
  163. },
  164. {
  165. label: '',
  166. element:lookButton2
  167. },
  168. {
  169. label: '',
  170. element:downloadButton2
  171. },
  172. {
  173. label: '',
  174. element:recaluBtn
  175. },
  176. {
  177. label: '',
  178. element:progressBtn
  179. },
  180. ]);
  181. toolbar.getItemById('text').element.getElement().onkeyup = function(e){
  182. listView.invalidateModel();
  183. };
  184. //时间选择控件 初始化时间
  185. (function (elem, timeValue, type) {
  186. timeValue = getRelativeDate(timeValue, type);
  187. laydate.render({
  188. elem: elem,
  189. type: type,
  190. value: timeValue,
  191. done: function(value, date){
  192. setTimeout(function () {
  193. ;
  194. }, 100)
  195. }
  196. });
  197. ;
  198. })(NodeStartTimeDiv, '2017-01-01', 'date');
  199. //时间选择控件 初始化时间
  200. SetTimeSelectDivValue(NodeEndTimeDiv, '2017-01-01', 'date');
  201. //建立一个websocket链接
  202. //var socket = new WebSocket('ws://192.168.0.141:10087/Command');
  203. var socket = new WebSocket('ws://'+webServiceIP+':10087/Command');
  204. // 打开Socket
  205. socket.onopen = function(event)
  206. {
  207. console.log('web socket connceted!',event);
  208. //请求报表js数据
  209. var obj=new CommandObj();
  210. obj.method="GetReportJsFile";
  211. obj.parm1="day";
  212. var objStr=JSON.stringify(obj);
  213. socket.send(objStr);
  214. //请求报表生成日期列表
  215. socket.send("{\"method\":\"GetHaveSaveDayList\"}");
  216. };
  217. // 监听消息
  218. socket.onmessage = function(event)
  219. {
  220. console.log('Client received a message',event);
  221. var receiveObj=JSON.parse(event.data);
  222. if(receiveObj.method=="GetHaveSaveDayList")
  223. {
  224. var dayList=JSON.parse(receiveObj.obj);
  225. listView.dm().clear();
  226. dayList.forEach(function(val,index,arr)
  227. {
  228. AddListViewElem(listView,val);
  229. });
  230. listView.setSortFunc(sortFunc);
  231. }
  232. else if(receiveObj.method=="GetReportJsFile")
  233. {
  234. //var jsObj=JSON.parse(receiveObj.obj);
  235. // importJSON(ReportSpread,jsObj);
  236. }
  237. else if(receiveObj.method=="HisDataReGet")
  238. {
  239. var jsObj=receiveObj.obj;
  240. progressBtn.setLabel("进度:"+jsObj);
  241. }
  242. };
  243. // 监听Socket的关闭
  244. socket.onclose = function(event) {
  245. console.log('Client notified socket has closed',event);
  246. };
  247. listView.setRowHeight(30);
  248. //添加列表中的数据
  249. //AddListViewElem(listView);
  250. /*products.forEach(function(product){
  251. var data = new ht.Data();
  252. data.a(product);
  253. listView.dm().add(data);
  254. }); */
  255. listView.enableToolTip();
  256. listView.getLabel = function(data){
  257. return data.a('ProductName') + ' - $' + data.a('UnitPrice').toFixed(2);
  258. };
  259. ht.Default.setImage('productIcon', {
  260. width: 50,
  261. height: 50,
  262. clip: function(g, width, height) {
  263. g.beginPath();
  264. g.arc(width/2, height/2, Math.min(width, height)/2-3, 0, Math.PI * 2, true);
  265. g.clip();
  266. },
  267. comps: [
  268. {
  269. type: 'image',
  270. stretch: 'uniform',
  271. rect: [0, 0, 50, 50],
  272. name: {func: function(data){return data.a('ProductId');}}
  273. }
  274. ]
  275. });
  276. listView.drawRowBackground = function(g, data, selected, xx, yy, widthb, heightb){
  277. if(this.isSelected(data)){
  278. g.fillStyle = '#87A6CB';
  279. }
  280. else if(this.getRowIndex(data) % 2 === 0){
  281. g.fillStyle = '#F1F4F7';
  282. }
  283. else{
  284. g.fillStyle = '#FAFAFA';
  285. }
  286. g.beginPath();
  287. g.rect(xx, yy, widthb, heightb);
  288. g.fill();
  289. };
  290. listView.setIndent(60);
  291. //listView.getIcon = function(data){
  292. // return 'productIcon';
  293. // };
  294. listView.enableToolTip();
  295. listView.getLabel = function(data){
  296. return data.a('Name');
  297. };
  298. listView.getToolTip = function(e){
  299. var data = this.getDataAt(e);
  300. if(data)
  301. {
  302. return '<span style="color:#3D97D0">ProductId:&nbsp;</span>' + data.a('ProductId') + '<br>' +
  303. '<span style="color:#3D97D0">ProductName:&nbsp;</span>' + data.a('ProductName') + '<br>' +
  304. '<span style="color:#3D97D0">QuantityPerUnit:&nbsp;</span>' + data.a('QuantityPerUnit') + '<br>' +
  305. '<span style="color:#3D97D0">Description:&nbsp;</span>' + data.a('Description');
  306. }
  307. return null;
  308. };
  309. sortFunc = function(d1, d2)
  310. {
  311. var str1= d1.a('Name');
  312. var str2= d2.a('Name');
  313. var strInt1=str1.replace('-','');
  314. strInt1=strInt1.replace('-','');
  315. var strInt2=str2.replace('-','');
  316. strInt2=strInt2.replace('-','');
  317. return parseInt(strInt2)-parseInt(strInt1);
  318. };
  319. listView.setSortFunc(sortFunc);
  320. listView.setVisibleFunc(function(data){
  321. var text = toolbar.v('text');
  322. if(text){
  323. return data.a('Name').toLowerCase().indexOf(text.toLowerCase()) >= 0;
  324. }
  325. return true;
  326. });
  327. var borderPaneRealNode = new ht.HtmlNode();
  328. borderPaneRealNode.setScalable(false);
  329. borderPaneRealNode.s({
  330. '2d.selectable': true,
  331. '2d.movable': false
  332. });
  333. borderPaneRealNode.setHtml(borderPaneDayReport);
  334. borderPaneRealNode.setPosition({
  335. x: x,
  336. y: y
  337. });
  338. borderPaneRealNode.setWidth(width);
  339. borderPaneRealNode.setHeight(height);
  340. borderPaneRealNode.setPadding(0);
  341. /*startSubscribe();*/
  342. /*getSnapshotCallback();*/
  343. return borderPaneRealNode;
  344. };
  345. //添加列表控件的数据
  346. function AddListViewElem(listView,obj)
  347. {
  348. var data = new ht.Data();
  349. data.a(obj);
  350. listView.dm().add(data);
  351. }
  352. //导入报表的json数据
  353. function importJSON (spread,jsonData)
  354. {
  355. ApplyCustomFunc(spread);
  356. spread.fromJSON(jsonData);
  357. ApplyCustomFunc(spread);
  358. var json = spread.toJSON();
  359. spread.fromJSON(json);
  360. var sheet = spread.getSheet(0);
  361. sheet.options.colHeaderVisible=false;
  362. sheet.options.rowHeaderVisible=false;
  363. spread.options.newTabVisible=false;
  364. spread.options.tabStripVisible=false;
  365. spread.options.showHorizontalScrollbar=true;
  366. ResetFormular(spread);
  367. }
  368. //设置时间选择控件的时间
  369. function SetTimeSelectDivValue(elem, timeValue, type)
  370. {
  371. timeValue = getRelativeDate(timeValue, type);
  372. laydate.render({
  373. elem: elem,
  374. type: type,
  375. value: timeValue,
  376. done: function(value, date){
  377. setTimeout(function () {
  378. ;
  379. }, 100)
  380. }
  381. });
  382. ;
  383. }
  384. function CommandObj()
  385. {
  386. var method="";
  387. var parm1="";
  388. var parm2="";
  389. }
  390. function ReceiveObj()
  391. {
  392. var method="";
  393. var obj="";
  394. }
  395. function SpreadExport(spread,exportfileName)
  396. {
  397. var fileName =exportfileName + (+new Date()) + '.xlsx';
  398. if (fileName.substr(-5, 5) !== '.xlsx') {
  399. fileName += '.xlsx';
  400. }
  401. var json = spread.toJSON();
  402. sheet1=spread.getActiveSheet();
  403. var spread2 = new GC.Spread.Sheets.Workbook();
  404. spread2.fromJSON(json);
  405. var sheet2 = spread2.getActiveSheet();
  406. var array = sheet1.getArray(0,0,sheet1.getRowCount(),sheet1.getColumnCount(),false);
  407. sheet2.clear(0,0,sheet2.getRowCount(),sheet2.getColumnCount(),GC.Spread.Sheets.SheetArea.viewport,GC.Spread.Sheets.StorageType.data);
  408. sheet2.setArray(0,0,array,false);
  409. json = spread2.toJSON();
  410. // here is excel IO API
  411. excelIo = new GC.Spread.Excel.IO();
  412. excelIo.save(json, function (blob) {
  413. saveAs(blob, fileName);
  414. }, function (e) {
  415. // process error
  416. alert(e.message);
  417. });
  418. }