StatForm.js 20 KB

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