ImportForm.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. MWF.xApplication.Strategy = MWF.xApplication.Strategy || {};
  2. MWF.xDesktop.requireApp("Strategy", "Template", null, false);
  3. MWF.xDesktop.requireApp("Template", "MPopupForm", null, false);
  4. MWF.xDesktop.requireApp("Template", "MForm", null, false);
  5. MWF.xDesktop.requireApp("Template", "MDomItem", null, false);
  6. MWF.xDesktop.requireApp("Strategy","Attachment",null,false);
  7. MWF.xApplication.Strategy.ImportForm = new Class({
  8. Extends: MPopupForm,
  9. Implements: [Options, Events],
  10. options: {
  11. "style": "default",
  12. "width": "500",
  13. "height": "200",
  14. "hasTop": true,
  15. "hasIcon": false,
  16. "hasBottom": false,
  17. "title": "",
  18. "draggable": true,
  19. "maxAction":true,
  20. "closeAction": true
  21. },
  22. initialize: function (explorer, data, options, para) {
  23. this.setOptions(options);
  24. this.explorer = explorer;
  25. this.app = explorer.app;
  26. this.lp = this.app.lp.importForm;
  27. this.actions = this.app.restActions;
  28. this.path = "/x_component_Strategy/$ImportForm/";
  29. this.cssPath = this.path + this.options.style + "/css.wcss";
  30. if(this.options.from){
  31. this.cssPath = this.path + this.options.style + "/css_portal.wcss";
  32. }
  33. this._loadCss();
  34. this.options.title = this.lp.title;
  35. this.data = data || {};
  36. if(para) this.para = para;
  37. },
  38. load: function () {
  39. var now = new Date();
  40. this.thisYear = now.getFullYear();
  41. if (this.options.isNew) {
  42. this.create();
  43. } else if (this.options.isEdited) {
  44. this.edit();
  45. } else {
  46. this.open();
  47. }
  48. },
  49. createTopNode: function () {
  50. if (!this.formTopNode) {
  51. this.formTopNode = new Element("div.formTopNode", {
  52. "styles": this.css.formTopNode
  53. }).inject(this.formNode);
  54. this.formTopIconNode = new Element("div.formTopIconNode", {
  55. "styles": this.css.formTopIconNode
  56. }).inject(this.formTopNode);
  57. this.formTopTextNode = new Element("div", {
  58. "styles": this.css.formTopTextNode,
  59. "text": this.data.title ? this.data.title : this.lp.title
  60. }).inject(this.formTopNode);
  61. if (this.options.closeAction) {
  62. this.formTopCloseActionNode = new Element("div", {"styles": this.css.formTopCloseActionNode}).inject(this.formTopNode);
  63. this.formTopCloseActionNode.addEvent("click", function () {
  64. this.close();
  65. }.bind(this))
  66. }
  67. this._createTopContent();
  68. }
  69. },
  70. _createTopContent: function () {
  71. },
  72. _createTableContent: function () {
  73. //this.getData(
  74. // function(){
  75. // this.createTableInfo()
  76. // }.bind(this)
  77. //);
  78. this.createTableInfo();
  79. },
  80. getData:function(callback){
  81. if(!this.options.isNew){
  82. if(this.data.id){
  83. this.id = this.data.id;
  84. }else if(this.options.id){
  85. this.id = this.options.id;
  86. }
  87. this.actions.getMeasureById(this.id,function(json){
  88. if(json.type=="success"){
  89. this.data = json.data;
  90. this.formTopTextNode.set("text",this.data.measuresinfotitle);
  91. if(json.data.measuresinfoyear){
  92. this.currentYear = json.data.measuresinfoyear;
  93. }
  94. if(callback)callback();
  95. }
  96. }.bind(this));
  97. }else{
  98. if(callback)callback();
  99. }
  100. },
  101. createTableInfo:function(){
  102. this.templateDiv = new Element("div.templateDiv",{
  103. "styles":this.css.templateDiv
  104. }).inject(this.formTableArea);
  105. this.templateText = new Element("span.templateText",{
  106. "styles":this.css.templateText,
  107. "text":this.lp.template
  108. }).inject(this.templateDiv);
  109. this.templateText.addEvents({
  110. "click":function(){
  111. }.bind(this)
  112. });
  113. this.inputDiv = new Element("div.inputDiv",{
  114. "styles":this.css.inputDiv
  115. }).inject(this.formTableArea);
  116. this.input = new Element("input.input",{
  117. "styles":this.css.input,
  118. "type":"file",
  119. "name":"file"
  120. }).inject(this.inputDiv);
  121. this.sheetDiv = new Element("div.sheetDiv",{
  122. "styles":this.css.sheetDiv
  123. }).inject(this.formTableArea);
  124. this.sheetSel = new MDomItem(this.sheetDiv, {
  125. "text":"sheet页",
  126. "name":"sheet",
  127. "type":"MSelector",
  128. selectValue : "1,2,3,4,5,6,7,8,9,10",
  129. selectText : "1,2,3,4,5,6,7,8,9,10",
  130. "mSelectorOptions":{
  131. "width":"150px",
  132. "defaultOptionLp" : "请选择Sheet",
  133. "tooltipsOptions" : {
  134. axis: "y", //箭头在x轴还是y轴上展现
  135. position : { //node 固定的位置
  136. x : "auto", //x轴上left center right, auto 系统自动计算
  137. y : "auto" //y 轴上top middle bottom, auto 系统自动计算
  138. },
  139. event : "click", //事件类型,有target 时有效, mouseenter对应mouseleave,click 对应 container 的 click
  140. hiddenDelay : 200, //ms , 有target 且 事件类型为 mouseenter 时有效
  141. displayDelay : 0 //ms , 有target 且事件类型为 mouseenter 时有效
  142. }
  143. }
  144. } , null, this.app, this.css);
  145. this.sheetSel.load();
  146. this.importAction = new Element("div.importAction",{
  147. "styles":this.css.importAction,
  148. "text":this.lp.importAction
  149. }).inject(this.formTableArea);
  150. this.importAction.addEvents({
  151. "click":function(){
  152. var fileNode = this.inputDiv.getFirst();
  153. var files = fileNode.files;
  154. if(files.length) {
  155. for (var i = 0; i < files.length; i++) {
  156. var file = files.item(i);
  157. var formData = new FormData();
  158. formData.append('file', file);
  159. formData.append("year",this.data.year||"");
  160. formData.append("parentid",this.data.parentid||"");
  161. formData.append("sheetsequence",this.sheetSel.get("value")||"");
  162. this.actions.importMeasure(function(json) {
  163. if (json.data.isPersist){
  164. this.app.notice(json.data.describe, "success");
  165. this.fireEvent("importSave", json);
  166. this.close();
  167. }else{
  168. this.app.notice(json.data.describe, "error");
  169. var address = this.actions.action.address;
  170. var url = address+"/jaxrs/measuresimport/result/flag/"+json.data.flag;
  171. window.open(url);
  172. }
  173. }.bind(this),function(xhr,text,error){
  174. this.app.notice("导入失败","error");
  175. this.close();
  176. }.bind(this),formData,file);
  177. }
  178. }else{
  179. this.app.notice(this.lp.notice.fileEmpty,"error");
  180. }
  181. if(this.sheetSel.get("value")==""){
  182. this.app.notice(this.lp.notice.sheetEmpty,"error");
  183. //return;
  184. }
  185. }.bind(this)
  186. });
  187. this.closeAction = new Element("div.closeAction",{
  188. "styles":this.css.closeAction,
  189. "text":this.lp.importClose
  190. }).inject(this.formTableArea);
  191. this.closeAction.addEvents({
  192. "click":function(){
  193. this.close();
  194. }.bind(this)
  195. });
  196. /*if(this.uploadFileAreaNode) this.uploadFileAreaNode.destroy();
  197. this.uploadFileAreaNode = new Element("div");
  198. var html = "<input name=\"file\" type=\"file\" />";
  199. this.uploadFileAreaNode.set("html", html);
  200. this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  201. this.fileUploadNode.addEvent("change", function(){
  202. var files = fileNode.files;
  203. if (files.length){
  204. for (var i = 0; i < files.length; i++) {
  205. var file = files.item(i);
  206. var tmp = file.name.split(".");
  207. this.uploadFileName = file.name;
  208. if( tmp[tmp.length-1].toLowerCase() != "xls" && tmp[tmp.length-1].toLowerCase() != "xlsx" ){
  209. this.app.notice("请导入excel文件!","error");
  210. return;
  211. }
  212. var formData = new FormData();
  213. formData.append('file', file);
  214. this.app.createShade(null,"正在导入,请稍后.....");
  215. this.actions.importBaseWork(centerId,function(json){
  216. this.reloadTableContent(centerId);
  217. this.app.destroyShade()
  218. }.bind(this),function(xhr,text,error){
  219. this.showErrorMessage(xhr,text,error);
  220. this.app.destroyShade()
  221. }.bind(this),formData,file);
  222. //this.actions.importBaseWork(centerId,function(json){
  223. // this.reloadTableContent(centerId);
  224. // this.app.destroyShade()
  225. //}.bind(this),function(xhr,text,error){
  226. // this.showErrorMessage(xhr,text,error);
  227. // this.app.destroyShade()
  228. //}.bind(this),formData,file)
  229. }
  230. }
  231. }.bind(this));
  232. var fileNode = this.uploadFileAreaNode.getFirst();
  233. //alert(13)
  234. debugger;
  235. //alert(this.uploadFileAreaNode.get("html"))
  236. fileNode.click();
  237. //this.uploadFileAreaNode.destroy();*/
  238. },
  239. createShade: function(o,txtInfo){
  240. var defaultObj = this.content;
  241. var obj = o || defaultObj;
  242. var txt = txtInfo || "loading...";
  243. if(this.shadeDiv){ this.shadeDiv.destroy()}
  244. if(this["shadeTxtDiv"]) this["shadeTxtDiv"].destroy();
  245. this.shadeDiv = new Element("div.shadeDiv").inject(obj);
  246. this.inforDiv = new Element("div.inforDiv",{
  247. styles:{"height":"16px","display":"inline-block","position":"absolute","background-color":"#000000","border-radius":"3px","padding":"5px 10px"}
  248. }).inject(this.shadeDiv);
  249. this.loadImg = new Element("img.loadImg",{
  250. styles:{"width":"16px","height":"16px","float":"left"},
  251. src:this.path+"default/icon/loading.gif"
  252. }).inject(this.inforDiv);
  253. this.shadeTxtSpan = new Element("span.shadeTxtSpan").inject(this.inforDiv);
  254. this.shadeTxtSpan.set("text",txt);
  255. this.shadeDiv.setStyles({
  256. "width":"100%","height":"100%","position":"absolute","opacity":"0.6","background-color":"#cccccc","z-index":"999"
  257. });
  258. this.shadeTxtSpan.setStyles({"color":"#ffffff","font-size":"12px","display":"inline-block","line-height":"16px","padding-left":"5px"});
  259. var x = obj.getSize().x;
  260. var y = obj.getSize().y;
  261. this.shadeDiv.setStyles({
  262. "left":(obj.getLeft()-defaultObj.getLeft())+"px",
  263. "top":(obj.getTop()-defaultObj.getTop())+"px",
  264. "width":x+"px",
  265. "height":y+"px"
  266. });
  267. if(obj.getStyle("position")=="absolute"){
  268. this.shadeDiv.setStyles({
  269. "left":"0px",
  270. "top":"0px"
  271. })
  272. }
  273. this.inforDiv.setStyles({
  274. "left":(x/2)+"px",
  275. "top":(y/2)+"px"
  276. })
  277. },
  278. destroyShade : function(){
  279. if(this.shadeDiv) this.shadeDiv.destroy();
  280. //if(this.shadeDiv) this.shadeDiv.destroy()
  281. },
  282. showErrorMessage:function(xhr,text,error){
  283. var errorText = error;
  284. var errorMessage;
  285. if (xhr) errorMessage = xhr.responseText;
  286. if(errorMessage!=""){
  287. var e = JSON.parse(errorMessage);
  288. if(e.message){
  289. this.notice( e.message,"error");
  290. }else{
  291. this.notice( errorText,"error");
  292. }
  293. }else{
  294. this.notice(errorText,"error");
  295. }
  296. },
  297. aa:function(){
  298. var val = "";if(d.configValue && d.configValue!='') {var v = d.configValue.split(',');for (var i = 0; i < v.length; i++) {if ( val == '') {val = v[i].split('@')[0];} else {val = val + ',' + v[i].split('@')[0];}}} return val
  299. }
  300. });