StatForm.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. MWF.xApplication.Execution = MWF.xApplication.Execution || {};
  2. MWF.xDesktop.requireApp("Template", "MPopupForm", null, false);
  3. MWF.xDesktop.requireApp("Template", "MForm", null, false);
  4. MWF.xDesktop.requireApp("Execution", "WorkForm", null, false);
  5. MWF.xApplication.Execution.StatForm = new Class({
  6. Extends: MPopupForm,
  7. Implements: [Options, Events],
  8. options: {
  9. //"centerWorkId" : "fc44be47-7271-469f-8f04-deebdb71d3e6",
  10. "style": "default",
  11. "width": "90%",
  12. "height": "90%",
  13. "hasTop": true,
  14. "hasIcon": false,
  15. "hasBottom": true,
  16. "title": "",
  17. "draggable": false,
  18. "closeAction": true,
  19. "isNew": false,
  20. "isEdited": true
  21. },
  22. initialize: function (explorer, actions, data, options) {
  23. this.setOptions(options);
  24. this.explorer = explorer;
  25. this.app = explorer.app;
  26. this.lp = this.app.lp.statForm;
  27. this.actions = this.app.restActions;
  28. this.path = "/x_component_Execution/$StatForm/";
  29. this.cssPath = this.path + this.options.style + "/css.wcss";
  30. this._loadCss();
  31. this.options.title = this.lp.title;
  32. this.data = data || {};
  33. this.actions = actions;
  34. },
  35. load: function () {
  36. this.centerWorkId = this.options.centerWorkId;
  37. this.centerWorkData = {};
  38. this.getCenterWork(this.centerWorkId);
  39. if (this.options.isNew) {
  40. this.create();
  41. } else if (this.options.isEdited) {
  42. this.edit();
  43. } else {
  44. this.open();
  45. }
  46. this.resizeWindow();
  47. this.app.addEvent("resize", function(){
  48. this.resizeWindow();
  49. }.bind(this));
  50. },
  51. resizeWindow: function(){
  52. var size = this.formNode.getSize();
  53. var rW = this.formTopContentNode.getWidth();
  54. this.formTopTextNode.setStyles({"width":(size.x-rW-200)+"px"});
  55. },
  56. //*****************common function**************************************
  57. getCenterWork: function(centerWorkId){
  58. this.actions.getMainTask(centerWorkId,function(json){
  59. this.centerWorkData = json.data;
  60. }.bind(this),function(xhr,text,error){
  61. this.showErrorMsg(xhr,text,error)
  62. }.bind(this),false)
  63. },
  64. //*****************common function**************************************
  65. createTopNode: function () {
  66. if (!this.formTopNode) {
  67. this.formTopNode = new Element("div.formTopNode", {
  68. "styles": this.css.formTopNode
  69. }).inject(this.formNode);
  70. this.formTopIconNode = new Element("div", {
  71. "styles": this.css.formTopIconNode
  72. }).inject(this.formTopNode);
  73. this.formTopTextNode = new Element("div.formTopTextNode", {
  74. "styles": this.css.formTopTextNode,
  75. "text": this.centerWorkData.title ? this.centerWorkData.title: this.options.title
  76. }).inject(this.formTopNode);
  77. if (this.options.closeAction) {
  78. this.formTopCloseActionNode = new Element("div.formTopCloseActionNode", {"styles": this.css.formTopCloseActionNode}).inject(this.formTopNode);
  79. this.formTopCloseActionNode.addEvent("click", function () {
  80. this.close()
  81. }.bind(this))
  82. }
  83. this.formTopContentNode = new Element("div.formTopContentNode", {
  84. "styles": this.css.formTopContentNode
  85. }).inject(this.formTopNode);
  86. this._createTopContent();
  87. }
  88. },
  89. _createTopContent: function () {
  90. if(this.centerWorkData.title){
  91. var html = "<span style='font-size:14px;'>"+this.lp.topTitle.drafter+":</span>" +
  92. " <span style='font-size:14px;'>"+this.centerWorkData.creatorName.split("@")[0]+"</span>"+
  93. " <span style='font-size:14px;margin-left:10px;'>"+this.lp.topTitle.department+":</span>"+
  94. " <span style='font-size:14px;'>"+this.centerWorkData.creatorUnitName.split("@")[0]+"</span>"+
  95. " <span style='font-size:14px;margin-left:10px;'>"+this.lp.topTitle.createTime+":</span>"+
  96. " <span style='font-size:14px;'>"+this.centerWorkData.createTime.split(" ")[0]+"</span>";
  97. this.formTopContentNode.set("html", html);
  98. }
  99. },
  100. _createTableContent: function (data) {
  101. this.createWeeklyList();
  102. //this.createStatView();
  103. },
  104. createWeeklyList: function(){
  105. this.weeklyContentDiv = new Element("div.weeklyContentDiv", {
  106. "styles": this.css.weeklyContentDiv
  107. }).inject(this.formTableArea);
  108. var weeklyTitleDiv = new Element("div.weeklyTitleDiv", {
  109. "styles": this.css.weeklyTitleDiv,
  110. "text": this.lp.weeklyTitle
  111. }).inject(this.weeklyContentDiv);
  112. this.weeklyListDiv = new Element("div.weeklyListDiv", {
  113. "styles": this.css.weeklyListDiv
  114. }).inject(this.weeklyContentDiv);
  115. this.loadWeeklyList();
  116. },
  117. loadWeeklyList: function(){
  118. var filterData = {
  119. "centerId":this.centerWorkData.id,
  120. "order":"DESC"
  121. };
  122. this.actions.getStatDateList(filterData,function(json){
  123. if(json.type == "success"){
  124. this.weeklyData = json.data
  125. }
  126. }.bind(this),
  127. function(xhr,text,error){
  128. this.showErrorMsg(xhr,text,error)
  129. }.bind(this),false
  130. );
  131. if(!this.weeklyData || this.weeklyData.length==0){
  132. var weeklyListLi = new Element("li.weeklyListLi",{
  133. "styles":this.css.weeklyListLi,
  134. "text": "未生成汇报统计"
  135. }).inject(this.weeklyListDiv);
  136. return false;
  137. }
  138. this.weeklyData.each(function(d,i){
  139. var weeklyListLi = new Element("li.weeklyListLi",{
  140. "styles":this.css.weeklyListLi,
  141. "text": d.datetime,
  142. "title": d.reportCycle
  143. }).inject(this.weeklyListDiv);
  144. weeklyListLi.addEvents({
  145. "click":function(){
  146. this.weeklyListDiv.getElements("li").setStyles({"background-color":"","color":""});
  147. weeklyListLi.setStyles({"background-color":"#3c76c1","color":"#ffffff"});
  148. this.displayDateStat(d);
  149. this.currentWeeklyLi = weeklyListLi;
  150. this.currentWeeklyData = d;
  151. }.bind(this),
  152. "mouseover":function(){
  153. weeklyListLi.setStyles({"border":"1px solid #3c76c1"})
  154. }.bind(this),
  155. "mouseout":function(){
  156. weeklyListLi.setStyles({"border":""})
  157. }.bind(this)
  158. });
  159. if(i==0){
  160. this.currentWeeklyLi = weeklyListLi;
  161. }
  162. }.bind(this));
  163. //var sendData = {}
  164. //sendData.centerId = this.centerWorkId
  165. //sendData.reportCycle = "每周统计"
  166. //this.actions.getStatListForCenterWork(sendData,function(json){
  167. // if(json.data){
  168. // this.weeklyData = json.data;
  169. // }
  170. //}.bind(this),function(xhr,text,error) {
  171. // this.showErrorMsg(xhr,text,error)
  172. //}.bind(this),false)
  173. //if(!this.weeklyData) return false;
  174. //this.weeklyData.each(function(d,index){
  175. // //alert(JSON.stringify(d))
  176. // if(d.week){
  177. // var statDate = d.statisticTime.split(" ")[0]
  178. // var weeklyListLi = new Element("li.weeklyListLi",{
  179. // "styles":this.css.weeklyListLi,
  180. // "text": statDate
  181. // }).inject(this.weeklyListDiv);
  182. // weeklyListLi.addEvents({
  183. // "click":function(){
  184. // this.weeklyListDiv.getElements("li").setStyles({"background-color":"","color":""})
  185. // weeklyListLi.setStyles({"background-color":"#3c76c1","color":"#ffffff"})
  186. // this.createStatView(d.id);
  187. // this.currentWeeklyLi = weeklyListLi
  188. // this.currentWeeklyData = d;
  189. // }.bind(this),
  190. // "mouseover":function(){
  191. // weeklyListLi.setStyles({"border":"1px solid #3c76c1"})
  192. // }.bind(this),
  193. // "mouseout":function(){
  194. // weeklyListLi.setStyles({"border":""})
  195. // }.bind(this)
  196. // })
  197. // if(index==0){
  198. // this.currentWeeklyLi = weeklyListLi;
  199. // }
  200. // }
  201. //}.bind(this))
  202. if(this.currentWeeklyLi) this.currentWeeklyLi.click()
  203. },
  204. createStatView : function(d){
  205. if(this.statViewDiv) this.statViewDiv.destroy();
  206. this.statViewDiv = new Element("div.statViewDiv", {
  207. "styles": this.css.statViewDiv
  208. }).inject(this.formTableArea);
  209. var statViewTitleDiv = new Element("div.statViewTitleDiv", {
  210. "styles": this.css.statViewTitleDiv,
  211. "text": this.lp.statViewTitle
  212. }).inject(this.statViewDiv);
  213. this.statViewListDiv = new Element("div.statViewListDiv", {
  214. "styles": this.css.statViewListDiv
  215. }).inject(this.statViewDiv);
  216. this.loadStatView(d)
  217. },
  218. displayDateStat: function(d,id){
  219. if(this.statViewListDiv) this.statViewListDiv.empty();
  220. if(d){
  221. var filterData = {
  222. "statisticTimeFlag": d.datetime,
  223. "centerId":this.centerWorkData.id
  224. };
  225. if(this.statViewListDiv) this.statViewListDiv.set("text","loading...");
  226. this.actions.getStatDate(filterData,function(json){
  227. if(json.type == "success"){
  228. this.dateStatData = json.data;
  229. this.displayDateStatTable()
  230. }
  231. }.bind(this),
  232. function(xhr,text,error){
  233. this.showErrorMsg(xhr,text,error)
  234. }.bind(this),true
  235. )
  236. }
  237. },
  238. displayDateStatTable:function(){
  239. if(this.dateStatData){
  240. if(this.statViewListDiv) this.statViewListDiv.destroy();
  241. this.statViewListDiv = new Element("div.statViewListDiv", {
  242. "styles": this.css.statViewListDiv
  243. }).inject(this.formTableArea);
  244. //var y = this.formTableArea.getSize().y - this.weeklyContentDiv.getSize().y
  245. //alert(y)
  246. //this.statViewListDiv.setStyles({"height":(y-50)+"px"})
  247. this.statTable = new Element("table.statTable",{
  248. "styles":this.css.statTable
  249. }).inject(this.statViewListDiv);
  250. //this.statTable.set("border","1")
  251. this.statHeadTr = new Element("tr.statHeadTr",{
  252. "styles":this.css.statHeadTr
  253. }).inject(this.statTable);
  254. for(var o in this.lp.statTable){
  255. var statHeadTd = new Element("td.statHeadTd",{
  256. "styles": this.css.statHeadTd,
  257. "text":this.lp.statTable[o]
  258. }).inject(this.statHeadTr);
  259. }
  260. this.dateStatData.each(function(d,i){
  261. if(d.contents && d.contents.length>0){
  262. d.contents.each(function(dd,ii){
  263. var baseTr = new Element("tr.baseTr").inject(this.statTable);
  264. for(var o in this.lp.statTable){
  265. //if(o!="order"){
  266. var val = "";
  267. if(o=="opinions") {
  268. if(dd[o]){
  269. dd[o].each(function(ddd){
  270. val = val + ddd.processorName.split("@")[0] + ":\n"+ ddd.opinion +"\n"
  271. })
  272. }
  273. }else if(o == "responsibilityUnitName"){
  274. val = dd[o];
  275. val = val.split("@")[0];
  276. }else{
  277. if(dd[o])val = dd[o]
  278. }
  279. var baseTd = new Element("td.dateStatBaseTd",{
  280. "styles": this.css.dateStatBaseTd,
  281. "html": val.length>50?val.substring(0,50)+"...":val,
  282. "title":val
  283. }).inject(baseTr);
  284. if(o=="serialNumber"){
  285. baseTd.setStyles({"width":"35px","text-align":"center"})
  286. }
  287. if(o=="responsibilityUnitName"){
  288. baseTd.setStyles({"width":"87px"});
  289. val = val.split("@")[0]
  290. }
  291. if(o=="workDetail"){
  292. }
  293. }
  294. }.bind(this))
  295. }
  296. }.bind(this))
  297. }
  298. },
  299. loadStatView: function(d){
  300. this.statTable = new Element("table.statTable",{
  301. "styles":this.css.statTable
  302. }).inject(this.statViewListDiv);
  303. //this.statTable.set("border","1")
  304. this.statHeadTr = new Element("tr.statHeadTr",{
  305. "styles":this.css.statHeadTr
  306. }).inject(this.statTable);
  307. for(var o in this.lp.statTable){
  308. var statHeadTd = new Element("td.statHeadTd",{
  309. "styles": this.css.statHeadTd,
  310. "text":this.lp.statTable[o]
  311. }).inject(this.statHeadTr);
  312. }
  313. if(!parentWorkId) parentWorkId = "(0)";
  314. this.actions.getStatByWorkId(id,parentWorkId,function(json){
  315. json.data.each(function(d,index){
  316. var statBodyTr = new Element("tr.statBodyTr",{
  317. "styles": this.css.statBodyTr
  318. }).inject(this.statTable);
  319. var statBodyTd = new Element("td.statBodyTd",{
  320. "styles": this.css.statBodyTd,
  321. "text":(index+1),
  322. "id": d.workId
  323. }).inject(statBodyTr);
  324. statBodyTd.setStyles({"width":"35px","text-align":"center"});
  325. for(var o in this.lp.statTable){
  326. if(o!="order"){
  327. var val = "";
  328. if(o=="opinions") {
  329. if(d[o]){
  330. d[o].each(function(dd){
  331. val = val + dd.processorName.split("@")[0] + ":<br>"+ dd.opinion +"<br>"
  332. })
  333. }
  334. }else{
  335. val = d[o]
  336. }
  337. statBodyTd = new Element("td.statBodyTd",{
  338. "styles": this.css.statBodyTd,
  339. "html": val.length>50?val.substring(0,50)+"...":val,
  340. "title":val
  341. }).inject(statBodyTr);
  342. if(o=="organizationName"){
  343. statBodyTd.setStyles({"width":"87px"})
  344. }
  345. if(o=="workDetail"){
  346. //statBodyTd.setStyles({"cursor":"pointer","color":"#3d77c1","text-decoration":"underline"})
  347. statBodyTd.addEvents({
  348. "click":function(){
  349. this.loadSubStat(id, d.workId,statBodyTr);
  350. //this.actions.getStatByWorkId(id, d.workId,function(json){
  351. //
  352. //}.bind(this),function(xhr,text,error){
  353. // this.showErrorMsg(xhr,text,error)
  354. //}.bind(this),false)
  355. }.bind(this)
  356. })
  357. }
  358. }
  359. }
  360. }.bind(this))
  361. }.bind(this),function(xhr,text,error){
  362. this.showErrorMsg(xhr,text,error)
  363. }.bind(this),false)
  364. },
  365. loadSubStat:function(id,parentWorkId,position){
  366. var curPosition = position.getElementById(parentWorkId).get("text");
  367. this.actions.getStatByWorkId(id,parentWorkId,function(json){
  368. this.subStatData = json.data;
  369. json.data.each(function(d,index){
  370. if(document.getElementById(d.workId)) {
  371. return false;
  372. }
  373. var statBodyTr = new Element("tr.statBodyTr",{
  374. "styles": this.css.statBodyTr
  375. }).inject(position,"after");
  376. var statBodyTd = new Element("td.statBodyTd",{
  377. "styles": this.css.statBodyTd,
  378. "text":curPosition + "."+(this.subStatData.length-index),
  379. "id": d.workId
  380. }).inject(statBodyTr);
  381. for(var o in this.lp.statTable){
  382. if(o!="order"){
  383. var val = "";
  384. if(o=="opinions") {
  385. if(d[o]){
  386. d[o].each(function(dd){
  387. val = val + dd.processorName.split("@")[0] + ":<br>"+ dd.opinion +"<br>"
  388. })
  389. }
  390. }else{
  391. val = d[o]
  392. }
  393. statBodyTd = new Element("td.statBodyTd",{
  394. "styles": this.css.statBodyTd,
  395. "html": val.length>50?val.substring(1,50)+"...":val,
  396. "title":val
  397. }).inject(statBodyTr);
  398. if(o=="workDetail"){
  399. //statBodyTd.setStyles({"cursor":"pointer","color":"#3d77c1","text-decoration":"underline"})
  400. statBodyTd.addEvents({
  401. "click":function(){
  402. this.loadSubStat(id, d.workId);
  403. }.bind(this)
  404. })
  405. }
  406. }
  407. }
  408. }.bind(this))
  409. }.bind(this),function(xhr,text,error){
  410. this.showErrorMsg(xhr,text,error)
  411. }.bind(this),false
  412. )
  413. },
  414. _createBottomContent: function () {
  415. if(this.formBottomNode) this.formBottomNode.empty();
  416. this.closeActionNode = new Element("div.closeActionNode", {
  417. "styles": this.css.formActionNode,
  418. "text": this.lp.actions.close
  419. }).inject(this.formBottomNode);
  420. this.closeActionNode.addEvents({
  421. click:function(){
  422. this.close()
  423. }.bind(this)
  424. });
  425. this.exportActionNode = new Element("div.exportActionNode", {
  426. "styles": this.css.formActionNode,
  427. "text": this.lp.actions.export
  428. }).inject(this.formBottomNode);
  429. this.exportActionNode.addEvents({
  430. click:function(){
  431. var sendData = {};
  432. sendData.centerId = this.centerWorkId;
  433. sendData.statisticTimeFlag = this.currentWeeklyData.datetime;
  434. sendData.reportCycle = this.currentWeeklyData.reportCycle;
  435. this.actions.exportByCenterWork(sendData,function(json){
  436. if(json.data && json.data.id){
  437. var address = this.actions.action.address;
  438. var url = address + "/jaxrs/export/statisticreportcontent/"+json.data.id+"/stream"
  439. window.open(url)
  440. }
  441. }.bind(this),
  442. function(xhr,text,error){
  443. this.showErrorMsg(xhr,text,error)
  444. }.bind(this),false)
  445. }.bind(this)
  446. })
  447. },
  448. showErrorMsg: function(xhr,text,error){
  449. var errorText = error;
  450. if (xhr) errorMessage = xhr.responseText;
  451. var e = JSON.parse(errorMessage);
  452. if (e.message) {
  453. this.app.notice(e.message, "error");
  454. } else {
  455. this.app.notice(errorText, "error");
  456. }
  457. }
  458. });