ImportExplorer.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. MWF.xDesktop.requireApp("Attendance", "Explorer", null, false);
  2. MWF.xDesktop.requireApp("Template", "Explorer", null, false);
  3. MWF.xDesktop.requireApp("Template", "MDomItem", null, false);
  4. MWF.xDesktop.requireApp("Organization", "Selector.package", null, false);
  5. MWF.xApplication.Attendance.ImportExplorer = new Class({
  6. Extends: MWF.xApplication.Attendance.Explorer,
  7. Implements: [Options, Events],
  8. initialize: function(node, app, actions, options){
  9. this.setOptions(options);
  10. this.app = app;
  11. this.path = "/x_component_Attendance/$ImportExplorer/";
  12. this.cssPath = "/x_component_Attendance/$ImportExplorer/"+this.options.style+"/css.wcss";
  13. this._loadCss();
  14. this.actions = actions;
  15. this.node = $(node);
  16. this.initData();
  17. if (!this.personActions) this.personActions = new MWF.xAction.org.express.RestActions();
  18. },
  19. loadView : function(){
  20. this.view = new MWF.xApplication.Attendance.ImportExplorer.View(this.elementContentNode, this.app,this, this.viewData, this.options.searchKey );
  21. this.view.load();
  22. this.setContentSize();
  23. },
  24. createDocument: function(){
  25. if(this.view)this.view._createDocument();
  26. },
  27. importExcel : function(){
  28. this.importer = new MWF.xApplication.Attendance.ImportExplorer.Importer( this );
  29. this.importer.upload();
  30. },
  31. checkData : function(){
  32. var selector = new MWF.xApplication.Attendance.ImportExplorer.YearMonthSelctor(this);
  33. selector.edit();
  34. },
  35. analyseData : function(){
  36. this.actions.analyseDetail("0","0",function(){
  37. this.app.notice("分析考勤数据成功","success")
  38. }.bind(this))
  39. },
  40. staticData : function(){
  41. this.actions.staticAllDetail(function(){
  42. this.app.notice("统计考勤数据成功","success")
  43. }.bind(this))
  44. },
  45. downloadTemplate : function(){
  46. window.open( this.path + encodeURIComponent( "dataTemplate.xls" ), "_blank" )
  47. },
  48. showDescription: function( el ){
  49. if( this.descriptionNode ){
  50. this.descriptionNode.setStyle("display","block");
  51. this.descriptionNode.position({
  52. relativeTo: el,
  53. position: 'bottomLeft',
  54. edge: 'upperCenter',
  55. offset:{
  56. x : -60,
  57. y : 0
  58. }
  59. });
  60. }else{
  61. this.descriptionNode = new Element("div", {"styles": this.css.descriptionNode}).inject(this.node);
  62. this.descriptionNode.position({
  63. relativeTo: el,
  64. position: 'bottomLeft',
  65. edge: 'upperCenter',
  66. offset:{
  67. x : -60,
  68. y : 0
  69. }
  70. });
  71. this.descriptionNode.addEvent("mousedown", function(e){e.stopPropagation();});
  72. document.body.addEvent("mousedown", function(){ this.descriptionNode.setStyle("display","none")}.bind(this));
  73. var table = new Element("table", {
  74. "width" : "100%", "border" : "0", "cellpadding" : "5", "cellspacing" : "0", "styles" : this.css.filterTable, "class" : "filterTable"
  75. }).inject( this.descriptionNode );
  76. var tr = new Element("tr").inject(table);
  77. new Element("td",{ "text" : "数据导入步骤" , "styles" : this.css.descriptionTdHead }).inject(tr);
  78. var tr = new Element("tr").inject(table);
  79. new Element("td",{ "text" :"1、下载Excel模板,根据模板格式填写考勤数据;" , "styles" : this.css.descriptionTdValue }).inject(tr);
  80. var tr = new Element("tr").inject(table);
  81. new Element("td",{ "text" : "2、点击导入考勤数据按钮,选择考勤数据并确定,系统将校验考勤数据是否正确并导入数据;" , "styles" : this.css.descriptionTdValue }).inject(tr);
  82. var tr = new Element("tr").inject(table);
  83. new Element("td",{ "text" : "3、点击核对考勤数据按钮,选择需要核对的年度和月份,系统将核对需要考勤的人员的数据;" , "styles" : this.css.descriptionTdValue }).inject(tr);
  84. var tr = new Element("tr").inject(table);
  85. new Element("td",{ "text" : "4、点击分析考勤数据按钮,系统将生成出勤明细数据;" , "styles" : this.css.descriptionTdValue }).inject(tr);
  86. var tr = new Element("tr").inject(table);
  87. new Element("td",{ "text" : "5、点击统计考勤数据按钮,系统将生成个人、部门、公司的出勤率统计。" , "styles" : this.css.descriptionTdValue }).inject(tr);
  88. }
  89. }
  90. });
  91. MWF.xApplication.Attendance.ImportExplorer.View = new Class({
  92. Extends: MWF.xApplication.Attendance.Explorer.View,
  93. _createItem: function(data){
  94. return new MWF.xApplication.Attendance.ImportExplorer.Document(this.table, data, this.explorer, this);
  95. },
  96. _getCurrentPageData: function(callback, count){
  97. this.actions.listAttachmentInfo(function(json){
  98. if (callback) callback(json);
  99. });
  100. },
  101. _removeDocument: function(document, all){
  102. this.actions.deleteAttachment(document.id, function(json){
  103. this.explorer.view.reload();
  104. this.app.notice(this.app.lp.deleteDocumentOK, "success");
  105. }.bind(this));
  106. },
  107. _createDocument: function(){
  108. //var permission = new MWF.xApplication.Attendance.ImportExplorer.Importer(this.explorer);
  109. //permission.create();
  110. },
  111. _openDocument: function( documentData ){
  112. this.actions.getAttachmentStream( documentData.id )
  113. }
  114. })
  115. MWF.xApplication.Attendance.ImportExplorer.Document = new Class({
  116. Extends: MWF.xApplication.Attendance.Explorer.Document
  117. ,
  118. openVaild : function( e ){
  119. //this.importer = new MWF.xApplication.Attendance.ImportExplorer.Importer( this );
  120. }
  121. })
  122. MWF.xApplication.Attendance.ImportExplorer.YearMonthSelctor = new Class({
  123. Extends: MWF.xApplication.Attendance.Explorer.PopupForm,
  124. _createTableContent: function(){
  125. var html = "<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>"+
  126. "<tr><td colspan='2' styles='formTableHead'>选择核对月份</td></tr>" +
  127. "<tr><td styles='formTabelTitle' lable='cycleYear'></td>"+
  128. " <td styles='formTableValue' item='cycleYear'></td></tr>" +
  129. "<tr><td styles='formTabelTitle' lable='cycleMonth'></td>"+
  130. " <td styles='formTableValue' item='cycleMonth'></td></tr>" +
  131. "</table>"
  132. this.formTableArea.set("html",html);
  133. MWF.xDesktop.requireApp("Template", "MForm", function(){
  134. this.form = new MForm( this.formTableArea, {}, {
  135. isEdited : this.isEdited || this.isNew,
  136. itemTemplate : {
  137. cycleYear : {
  138. text:"年度",
  139. type : "select",
  140. selectValue : function(){
  141. var years = []; d = new Date();
  142. for(var i=0 ; i<5; i++){
  143. years.push(d.getFullYear());
  144. d.setFullYear(d.getFullYear()-1)
  145. }
  146. return years;
  147. }
  148. },
  149. cycleMonth : {
  150. text:"月份",
  151. type : "select",
  152. defaultValue : function(){ return new Date().getMonth(); },
  153. selectValue : ["1","2","3","4","5","6","7","8","9","10","11","12"]
  154. }
  155. }
  156. }, this.app);
  157. this.form.load();
  158. }.bind(this), true);
  159. },
  160. _ok: function( data, callback ){
  161. this.app.restActions.checkDetail( data.cycleYear, data.cycleMonth, function(json){
  162. this.app.notice("考勤数据核对成功");
  163. this.close();
  164. }.bind(this));
  165. }
  166. })
  167. MWF.xApplication.Attendance.ImportExplorer.Importer = new Class({
  168. Extends: MWF.widget.Common,
  169. initialize: function( explorer, data ){
  170. this.explorer = explorer;
  171. this.app = explorer.app;
  172. this.data = data || {};
  173. this.css = this.explorer.css;
  174. this.actions = this.explorer.actions;
  175. this.load();
  176. },
  177. load: function(){
  178. },
  179. _openCheckPage : function( ){
  180. this.checkMarkNode = new Element("div", {
  181. "styles": this.css.checkMarkNode,
  182. "events": {
  183. "mouseover": function(e){e.stopPropagation();},
  184. "mouseout": function(e){e.stopPropagation();}
  185. }
  186. }).inject(this.app.content, "after");
  187. this.checkAreaNode = new Element("div", {
  188. "styles": this.css.checkAreaNode
  189. });
  190. this.createNode();
  191. this.checkAreaNode.inject(this.checkMarkNode, "after");
  192. this.checkAreaNode.fade("in");
  193. this.setCheckNodeSize();
  194. this.setCheckNodeSizeFun = this.setCheckNodeSize.bind(this);
  195. this.addEvent("resize", this.setCheckNodeSizeFun);
  196. },
  197. createNode: function(){
  198. var _self = this;
  199. this.checkNode = new Element("div", {
  200. "styles": this.css.checkNode
  201. }).inject(this.checkAreaNode);
  202. this.closeCheckNode = new Element("div", {
  203. "styles": this.css.closeCheckNode
  204. }).inject(this.checkNode);
  205. this.closeCheckNode.addEvent("click", function(){
  206. this.closeLayout();
  207. }.bind(this))
  208. this.checkFormNode = new Element("div", {
  209. "styles": this.css.checkFormNode
  210. }).inject(this.checkNode);
  211. var lp = this.app.lp.importer;
  212. this.checkFormTitleNode = new Element("div", {
  213. "styles": this.css.checkFormTitleNode,
  214. "text" : "考勤数据导入校验结果"
  215. }).inject(this.checkFormNode);
  216. this.checkFormDescriptionNode = new Element("div", {
  217. "styles": this.css.checkFormDescriptionNode,
  218. "text" : "您上传的文件:“" + this.uploadFileName + "”未通过校验,请修改后重新导入。"
  219. }).inject(this.checkFormNode);
  220. this.checkTableContainer = new Element("div", {
  221. "styles": this.css.checkTableContainer
  222. }).inject(this.checkFormNode);
  223. this.checkTableArea = new Element("div", {
  224. "styles": this.css.checkTableArea
  225. }).inject(this.checkTableContainer);
  226. if( this.checkData.checkStatus != "error" ){
  227. }else{
  228. //"rowCount": 46,
  229. // "errorCount": 46,
  230. var table = new Element("table", {
  231. "width" : "100%", "border" : "", "cellpadding" : "5", "cellspacing" : "0", "styles" : this.css.editTable, "class" : "editTable"
  232. }).inject( this.checkTableArea );
  233. var tr = new Element("tr").inject(table);
  234. var td = new Element("td", { "styles" : this.css.editTableTitle, "text" : "员工号" }).inject(tr);
  235. var td = new Element("td", { "styles" : this.css.editTableTitle, "text" : "员工名字" }).inject(tr);
  236. var td = new Element("td", { "styles" : this.css.editTableTitle, "text" : "日期" }).inject(tr);
  237. var td = new Element("td", { "styles" : this.css.editTableTitle, "text" : "上班时间" }).inject(tr);
  238. var td = new Element("td", { "styles" : this.css.editTableTitle, "text" : "下班时间" }).inject(tr);
  239. var td = new Element("td", { "styles" : this.css.editTableTitle, "text" : "检查结果" }).inject(tr);
  240. var td = new Element("td", { "styles" : this.css.editTableTitle, "text" : "描述" }).inject(tr);
  241. td.setStyle( "width" , "300px" );
  242. this.checkData.detailList.each(function( d ){
  243. var tr = new Element("tr").inject(table);
  244. var td = new Element("td", { "styles" : this.css.editTableValue , "text": d.employeeNo }).inject(tr);
  245. var td = new Element("td", { "styles" : this.css.editTableValue , "text": d.employeeName }).inject(tr);
  246. var td = new Element("td", { "styles" : this.css.editTableValue , "text": d.recordDateString }).inject(tr);
  247. var td = new Element("td", { "styles" : this.css.editTableValue , "text": d.onDutyTime }).inject(tr);
  248. var td = new Element("td", { "styles" : this.css.editTableValue , "text": d.offDutyTime }).inject(tr);
  249. var td = new Element("td", { "styles" : this.css.editTableValue , "text": d.checkStatus == "error" ? "错误" : "正确" }).inject(tr);
  250. var td = new Element("td", { "styles" : this.css.editTableValue , "text": d.description }).inject(tr);
  251. }.bind(this))
  252. }
  253. //this.checkFormNode.set("html", html);
  254. this.setScrollBar(this.checkTableContainer)
  255. //
  256. //this.cancelActionNode = new Element("div", {
  257. // "styles": this.css.checkCancelActionNode,
  258. // "text": this.app.lp.cancel
  259. //}).inject(this.checkFormNode);
  260. //this.checkOkActionNode = new Element("div", {
  261. // "styles": this.css.checkOkActionNode,
  262. // "text": this.app.lp.ok
  263. //}).inject(this.checkFormNode);
  264. //
  265. //this.cancelActionNode.addEvent("click", function(e){
  266. // this.cancelCreate(e);
  267. //}.bind(this));
  268. //this.checkOkActionNode.addEvent("click", function(e){
  269. // this.okCreate(e);
  270. //}.bind(this));
  271. },
  272. setCheckNodeSize: function(){
  273. var size = this.app.node.getSize();
  274. var allSize = this.app.content.getSize();
  275. this.checkAreaNode.setStyles({
  276. "width": ""+size.x+"px",
  277. "height": ""+size.y+"px"
  278. });
  279. var hY = size.y*0.9;
  280. var mY = size.y*0.2/2;
  281. this.checkNode.setStyles({
  282. "height": ""+hY+"px",
  283. "margin-top": ""+mY+"px"
  284. });
  285. var formHeight = hY*0.95;
  286. if (formHeight< 250) formHeight = 250;
  287. this.checkFormNode.setStyles({
  288. "height": ""+formHeight+"px"
  289. });
  290. var titlesize = this.checkFormTitleNode.getSize();
  291. var descriptionsize = this.checkFormDescriptionNode.getSize();
  292. var tableHeight = formHeight - titlesize.y - descriptionsize.y - 50;
  293. this.checkTableContainer.setStyles({
  294. "height": ""+tableHeight+"px"
  295. });
  296. },
  297. closeLayout: function(e){
  298. this.checkMarkNode.destroy();
  299. this.checkAreaNode.destroy();
  300. delete this;
  301. },
  302. upload : function(){
  303. if (!this.uploadFileAreaNode){
  304. this.uploadFileAreaNode = new Element("div");
  305. var html = "<input name=\"file\" type=\"file\"/>";
  306. this.uploadFileAreaNode.set("html", html);
  307. this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  308. this.fileUploadNode.addEvent("change", function(){
  309. var files = fileNode.files;
  310. if (files.length){
  311. for (var i = 0; i < files.length; i++) {
  312. var file = files.item(i);
  313. var tmp = file.name.split(".");
  314. this.uploadFileName = file.name;
  315. if( tmp[tmp.length-1].toLowerCase() != "xls" && tmp[tmp.length-1].toLowerCase() != "xlsx" ){
  316. this.app.notice("请导入excel文件!","error");
  317. return;
  318. }
  319. var formData = new FormData();
  320. formData.append('file', file);
  321. this.actions.uploadAttachment( function( json ){
  322. var id = json.id;
  323. this.actions.checkAttachment(id, function(data){
  324. this.checkData = data.data;
  325. if( this.checkData.checkStatus == "error" ){
  326. this._openCheckPage()
  327. }else{
  328. this.app.notice("文件已经成功上传并通过校验,系统正在导入,请不要关闭页面!","success");
  329. this.import( id );
  330. }
  331. }.bind(this))
  332. }.bind(this), function(xhr, text, error){
  333. var errorText = error;
  334. if (xhr) errorText = xhr.responseText;
  335. this.app.notice( errorText,"error");
  336. }.bind(this), formData, file);
  337. }
  338. }
  339. }.bind(this));
  340. }
  341. var fileNode = this.uploadFileAreaNode.getFirst();
  342. fileNode.click();
  343. },
  344. import: function( id ){
  345. this.actions.importAttachment( id, function(json){
  346. if( json.type == "ERROR" ){
  347. this.app.notice( json.message , "error");
  348. }else{
  349. this.app.notice("数据导入成功!","success");
  350. //this.app.notice("数据导入成功,系统正在分析打卡记录!","success");
  351. //var recordList = json.data.dateRecordList;
  352. //var listCount = recordList.length;
  353. //var prcessedCount = 0;
  354. //
  355. //this.actions.analyseDetail( "(0)" , "(0)" ,function(){
  356. //
  357. // this.app.notice("分析打卡数据成功,系统正在统计考勤记录!","success");
  358. //
  359. // recordList.each( function( r ){
  360. // this.actions.staticDetail( r.year , r.month ,function(){
  361. // prcessedCount ++;
  362. // if( prcessedCount == listCount ){
  363. // this.app.notice("统计考勤记录成功,已完成所有导入步骤!","success");
  364. // }
  365. // }.bind(this))
  366. // }.bind(this))
  367. //
  368. //}.bind(this))
  369. }
  370. }.bind(this))
  371. }
  372. })