ReportShow.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. function CreateReportShow(x,y,width,height,pageHeight)
  2. {
  3. //列表控件
  4. listView = new ht.widget.ListView();
  5. //listView.setCheckMode(true);
  6. var SelectTime="";
  7. listView.onDataClicked=function(data)//选择某个数据
  8. {
  9. if(!data)
  10. return;
  11. SelectTime=data.a('Name');
  12. }
  13. //布局控件
  14. borderPaneDayReport = new ht.widget.BorderPane();
  15. borderPaneDayReport.setLeftView(listView, 180);
  16. //表格控件
  17. var ReportDiv=document.createElement("div");
  18. var ReportDivChild=document.createElement("div");
  19. ReportDiv.appendChild(ReportDivChild);
  20. ReportDivChild.className="sample-turtorial";
  21. var reportWidth=width-180;
  22. var reportHeight=(height)*document.documentElement.clientHeight /pageHeight-28;
  23. ReportDivChild.style='width:'+reportWidth+'px; height:'+reportHeight+'px;border: 1px solid gray;';
  24. ReportSpread =new GC.Spread.Sheets.Workbook(ReportDivChild, { sheetCount: 1 });
  25. //表格加入布局
  26. //borderPaneDayReport.setRightView(ReportDiv,width-180);
  27. borderPaneDayReport.setCenterView(ReportDiv);
  28. var NodeStartTimeDiv=document.createElement("div");
  29. 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>';
  30. document.body.appendChild(NodeStartTimeDiv);
  31. var NodeEndTimeDiv=document.createElement("div");
  32. 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>';
  33. document.body.appendChild(NodeEndTimeDiv);
  34. toolbar = new ht.widget.Toolbar();
  35. borderPaneDayReport.setTopView(toolbar);
  36. //按钮
  37. lookButton1=new ht.widget.Button();
  38. lookButton1.setWidth(40);
  39. lookButton1.setLabel("查看");
  40. lookButton1.setBorderColor("#4682B4");
  41. lookButton1.setBackground("#4682B4");
  42. lookButton1.setLabelColor("#FFFAF0");
  43. lookButton1.onClicked= function(e)
  44. {
  45. SetTimeSelectDivValue(NodeStartTimeDiv,SelectTime,"date");
  46. var tempEndTime1=new Date(Date.parse(SelectTime));
  47. tempEndTime1.setDate(tempEndTime1.getDate()+1);
  48. SetTimeSelectDivValue(NodeEndTimeDiv,tempEndTime1.toString(),"date");
  49. }
  50. downloadButton1=new ht.widget.Button();
  51. downloadButton1.setWidth(40);
  52. downloadButton1.setLabel("导出");
  53. downloadButton1.setBorderColor("#4682B4");
  54. downloadButton1.setBackground("#4682B4");
  55. downloadButton1.setLabelColor("#FFFAF0");
  56. lookButton2=new ht.widget.Button();
  57. lookButton2.setWidth(40);
  58. lookButton2.setLabel("查询");
  59. lookButton2.setBorderColor("#4682B4");
  60. lookButton2.setBackground("#4682B4");
  61. lookButton2.setLabelColor("#FFFAF0");
  62. downloadButton2=new ht.widget.Button();
  63. downloadButton2.setWidth(40);
  64. downloadButton2.setLabel("导出");
  65. downloadButton2.setBorderColor("#4682B4");
  66. downloadButton2.setBackground("#4682B4");
  67. downloadButton2.setLabelColor("#FFFAF0");
  68. toolbar.getSelectBackground = function(item){ return '#3D97D0'; };
  69. toolbar.setItems([
  70. {
  71. id: 'text',
  72. label: '',
  73. icon: 'image/search.png',
  74. textField: {
  75. width: 80
  76. }
  77. },
  78. {
  79. label: '',
  80. element:lookButton1
  81. },
  82. {
  83. label: '',
  84. element:downloadButton1
  85. },
  86. {
  87. id: 'nation',
  88. label: '开始时间 ',
  89. },
  90. {
  91. id: 'nation',
  92. label: ' ',
  93. element: NodeStartTimeDiv
  94. },
  95. {
  96. id: 'nation',
  97. label: '结束时间 ',
  98. },
  99. {
  100. id: 'nation',
  101. label: ' ',
  102. element: NodeEndTimeDiv
  103. },
  104. {
  105. label: '',
  106. element:lookButton2
  107. },
  108. {
  109. label: '',
  110. element:downloadButton2
  111. },
  112. ]);
  113. toolbar.getItemById('text').element.getElement().onkeyup = function(e){
  114. listView.invalidateModel();
  115. };
  116. //时间选择控件 初始化时间
  117. (function (elem, timeValue, type) {
  118. timeValue = getRelativeDate(timeValue, type);
  119. laydate.render({
  120. elem: elem,
  121. type: type,
  122. value: timeValue,
  123. done: function(value, date){
  124. setTimeout(function () {
  125. ;
  126. }, 100)
  127. }
  128. });
  129. ;
  130. })(NodeStartTimeDiv, '2017-09-21', 'date');
  131. //时间选择控件 初始化时间
  132. SetTimeSelectDivValue(NodeEndTimeDiv, '2017-01-01', 'date');
  133. //建立一个websocket链接
  134. var socket = new WebSocket('ws://localhost:10087/Command');
  135. // 打开Socket
  136. socket.onopen = function(event)
  137. {
  138. console.log('web socket connceted!',event);
  139. //请求报表js数据
  140. var obj=new CommandObj();
  141. obj.method="GetReportJsFile";
  142. obj.parm1="day";
  143. var objStr=JSON.stringify(obj);
  144. socket.send(objStr);
  145. //请求报表生成日期列表
  146. socket.send("{\"method\":\"GetHaveSaveDayList\"}");
  147. };
  148. // 监听消息
  149. socket.onmessage = function(event)
  150. {
  151. console.log('Client received a message',event);
  152. var receiveObj=JSON.parse(event.data);
  153. if(receiveObj.method=="GetHaveSaveDayList")
  154. {
  155. var dayList=JSON.parse(receiveObj.obj);
  156. dayList.forEach(function(val,index,arr)
  157. {
  158. AddListViewElem(listView,val);
  159. });
  160. }
  161. else if(receiveObj.method=="GetReportJsFile")
  162. {
  163. var jsObj=JSON.parse(receiveObj.obj);
  164. importJSON(ReportSpread,jsObj);
  165. }
  166. };
  167. // 监听Socket的关闭
  168. socket.onclose = function(event) {
  169. console.log('Client notified socket has closed',event);
  170. };
  171. listView.setRowHeight(30);
  172. //添加列表中的数据
  173. //AddListViewElem(listView);
  174. /*products.forEach(function(product){
  175. var data = new ht.Data();
  176. data.a(product);
  177. listView.dm().add(data);
  178. }); */
  179. listView.enableToolTip();
  180. listView.getLabel = function(data){
  181. return data.a('ProductName') + ' - $' + data.a('UnitPrice').toFixed(2);
  182. };
  183. ht.Default.setImage('productIcon', {
  184. width: 50,
  185. height: 50,
  186. clip: function(g, width, height) {
  187. g.beginPath();
  188. g.arc(width/2, height/2, Math.min(width, height)/2-3, 0, Math.PI * 2, true);
  189. g.clip();
  190. },
  191. comps: [
  192. {
  193. type: 'image',
  194. stretch: 'uniform',
  195. rect: [0, 0, 50, 50],
  196. name: {func: function(data){return data.a('ProductId');}}
  197. }
  198. ]
  199. });
  200. listView.drawRowBackground = function(g, data, selected, xx, yy, widthb, heightb){
  201. if(this.isSelected(data)){
  202. g.fillStyle = '#87A6CB';
  203. }
  204. else if(this.getRowIndex(data) % 2 === 0){
  205. g.fillStyle = '#F1F4F7';
  206. }
  207. else{
  208. g.fillStyle = '#FAFAFA';
  209. }
  210. g.beginPath();
  211. g.rect(xx, yy, widthb, heightb);
  212. g.fill();
  213. };
  214. listView.setIndent(60);
  215. //listView.getIcon = function(data){
  216. // return 'productIcon';
  217. // };
  218. listView.enableToolTip();
  219. listView.getLabel = function(data){
  220. return data.a('Name');
  221. };
  222. listView.getToolTip = function(e){
  223. var data = this.getDataAt(e);
  224. if(data)
  225. {
  226. return '<span style="color:#3D97D0">ProductId:&nbsp;</span>' + data.a('ProductId') + '<br>' +
  227. '<span style="color:#3D97D0">ProductName:&nbsp;</span>' + data.a('ProductName') + '<br>' +
  228. '<span style="color:#3D97D0">QuantityPerUnit:&nbsp;</span>' + data.a('QuantityPerUnit') + '<br>' +
  229. '<span style="color:#3D97D0">Description:&nbsp;</span>' + data.a('Description');
  230. }
  231. return null;
  232. };
  233. sortFunc = function(d1, d2){
  234. return d1.a('UnitPrice') - d2.a('UnitPrice');
  235. };
  236. listView.setSortFunc(sortFunc);
  237. listView.setVisibleFunc(function(data){
  238. var text = toolbar.v('text');
  239. if(text){
  240. return data.a('Name').toLowerCase().indexOf(text.toLowerCase()) >= 0;
  241. }
  242. return true;
  243. });
  244. var borderPaneRealNode = new ht.HtmlNode();
  245. borderPaneRealNode.setScalable(false);
  246. borderPaneRealNode.s({
  247. '2d.selectable': true,
  248. '2d.movable': false
  249. });
  250. borderPaneRealNode.setHtml(borderPaneDayReport);
  251. borderPaneRealNode.setPosition({
  252. x: x,
  253. y: y
  254. });
  255. borderPaneRealNode.setWidth(width);
  256. borderPaneRealNode.setHeight(height);
  257. borderPaneRealNode.setPadding(0);
  258. /*startSubscribe();*/
  259. /*getSnapshotCallback();*/
  260. return borderPaneRealNode;
  261. };
  262. //添加列表控件的数据
  263. function AddListViewElem(listView,obj)
  264. {
  265. var data = new ht.Data();
  266. data.a(obj);
  267. listView.dm().add(data);
  268. }
  269. //导入报表的json数据
  270. function importJSON (spread,jsonData)
  271. {
  272. ApplyCustomFunc(spread);
  273. spread.fromJSON(jsonData);
  274. ApplyCustomFunc(spread);
  275. var json = spread.toJSON();
  276. spread.fromJSON(json);
  277. var sheet = spread.getSheet(0);
  278. sheet.options.colHeaderVisible=false;
  279. sheet.options.rowHeaderVisible=false;
  280. spread.options.newTabVisible=false;
  281. spread.options.tabStripVisible=false;
  282. spread.options.showHorizontalScrollbar=true;
  283. ResetFormular(spread);
  284. }
  285. //设置时间选择控件的时间
  286. function SetTimeSelectDivValue(elem, timeValue, type)
  287. {
  288. timeValue = getRelativeDate(timeValue, type);
  289. laydate.render({
  290. elem: elem,
  291. type: type,
  292. value: timeValue,
  293. done: function(value, date){
  294. setTimeout(function () {
  295. ;
  296. }, 100)
  297. }
  298. });
  299. ;
  300. }
  301. function CommandObj()
  302. {
  303. var method="";
  304. var parm1="";
  305. }
  306. function ReceiveObj()
  307. {
  308. var method="";
  309. var obj="";
  310. }