AtsAttenceCalculate.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. /*******************************************************************************
  2. *
  3. * 考勤管理-考勤计算js
  4. *
  5. * <pre>
  6. *
  7. * 作者:hugh zhuang
  8. * 邮箱:zhuangxh@jee-soft.cn
  9. * 日期:2015-06-01-上午11:10:52
  10. * 版权:广州宏天软件有限公司版权所有
  11. * </pre>
  12. *
  13. ******************************************************************************/
  14. var AtsAttenceCalculatePlugin = null;
  15. ;(function($, window, document, undefined) {
  16. var pluginName = "AtsAttenceCalculate",
  17. defaults = {
  18. },
  19. me,
  20. _attencePolicyId = null,
  21. _startTime = null,
  22. _endTime = null,
  23. _sidValue = [];
  24. function Plugin(element, options) {
  25. this.settings = $.extend({}, defaults, options);
  26. this._defaults = defaults;
  27. this._name = pluginName;
  28. this.init();
  29. }
  30. Plugin.prototype = {
  31. init:function(){
  32. me = this;
  33. AtsAttenceCalculatePlugin = this;
  34. this.initAttenceCycle();
  35. //选择tab
  36. $('.nav-tabs > li').click(function(){
  37. var $this = $(this);
  38. if($this.hasClass('active'))
  39. return ;
  40. $this.siblings('li').removeClass('active');
  41. $this.addClass("active");
  42. me. searchGrid();
  43. });
  44. //加载数据
  45. this.loadGrid();
  46. //查询
  47. $('a.fa-search').click(function(){
  48. me.searchGrid();
  49. });
  50. $('a.allCalculate').click(function(){
  51. me.startUpdateCalculatingStatus();
  52. me.calculate();
  53. });
  54. $('a.calculateSelect').click(function(){
  55. var selectedIds = $("#reportGrid").jqGrid('getGridParam','selarrrow');
  56. if (selectedIds == null || selectedIds.length < 1) {
  57. $.ligerDialog.alert("请选择要计算的人员!","提示信息");
  58. return;
  59. }
  60. var fileIds = [];
  61. for (var i = 0; i < selectedIds.length; i++) {
  62. var rowData = $("#reportGrid").jqGrid("getRowData", selectedIds[i]);
  63. if(!rowData.fileId) continue
  64. fileIds.push(rowData.fileId);
  65. }
  66. me.startUpdateCalculatingStatus();
  67. me.calculate(fileIds.join(","));
  68. });
  69. $('a.summary').click(function(){
  70. var url=__ctx + "/platform/ats/atsAttenceCalculateSet/edit.ht?type=1";
  71. url=url.getNewUrl();
  72. DialogUtil.open({
  73. height:400,
  74. width: 500,
  75. title : '汇总显示',
  76. url: url,
  77. isResize: true,
  78. sucCall:function(rtn){
  79. // me.loadGrid();
  80. }
  81. });
  82. });
  83. $('a.detail').click(function(){
  84. var url=__ctx + "/platform/ats/atsAttenceCalculateSet/edit.ht?type=2";
  85. url=url.getNewUrl();
  86. DialogUtil.open({
  87. height:400,
  88. width: 500,
  89. title : '明细显示',
  90. url: url,
  91. isResize: true,
  92. sucCall:function(rtn){
  93. // me.loadGrid();
  94. }
  95. });
  96. });
  97. $('a.export').click(function(){
  98. var action = $('.nav-tabs > li.active').attr("action");
  99. $('#action').val(action);
  100. $('#orgPath1').val($('#orgId').val())
  101. $('#fullname1').val($('#fullname').val())
  102. $('#attencePolicy1').val($('#attencePolicy').val());
  103. // var attenceCycleOption = $("#attenceCycle").find("option:selected");
  104. $('#startTime1').val($('#startTime').val());
  105. $('#endTime1').val($('#endTime').val());
  106. var type = $('#attenceType').val();
  107. if(!$.isEmpty(type))
  108. type =type.join(",");
  109. else
  110. type ="";
  111. $('#attenceType1').val(type);
  112. $.ligerDialog.waitting("请稍后……");
  113. $("#exportForm").submit();
  114. var isDownload = window.setInterval(function() {
  115. $.ajax({
  116. type : "POST",
  117. dataType:"json",
  118. url :__ctx+"/platform/ats/atsAttenceCalculate/isDownload.ht",
  119. success : function(data) {
  120. if(data.success){
  121. $.ligerDialog.closeWaitting();
  122. clearInterval(isDownload);
  123. }
  124. }
  125. });
  126. }, 1000);
  127. });
  128. this.handleSearchKeyPress();
  129. $("#attenceType").multiselect({
  130. noneSelectedText: "=请选择=",
  131. checkAllText: "全选",
  132. uncheckAllText: '全不选',
  133. selectedText: '# 已选择'
  134. });
  135. },
  136. //开启检测后台计算session的状态的定时器,更新数据
  137. startUpdateCalculatingStatus:function(){
  138. var updateCalculatingStatus=window.setInterval(function() {
  139. $.post(__ctx+"/platform/ats/atsAttenceCalculate/getCalculatingState.ht",{},
  140. function (data, textStatus){
  141. if(data.status){
  142. $.ligerDialog.closeWaitting();
  143. $.ligerDialog.waitting(data.msg);
  144. }else{
  145. clearInterval(updateCalculatingStatus);
  146. }
  147. },
  148. "json");
  149. }, 3000);
  150. },
  151. /**
  152. * 处理回车查询
  153. */
  154. handleSearchKeyPress:function (){
  155. $(".search-form :input").keypress(function(e) {
  156. if( e.keyCode == 13){//回车
  157. $("a.fa-search").click();
  158. }else if(e.keyCode == 27){//ESC
  159. }
  160. })
  161. },
  162. initAttenceCycle:function(){
  163. var date = new Date();
  164. var ydate = date.Format("yyyy-MM");
  165. $('#attenceCycle').val(ydate);
  166. },
  167. searchGrid:function(){
  168. var flag= me.getInitVal();
  169. if(flag){
  170. return;
  171. }
  172. $.ligerDialog.waitting("请稍后……");
  173. var action = $('.nav-tabs > li.active').attr("action");
  174. $('#attenceTypeLi').hide();
  175. $('#abnormityLi').hide();
  176. if(action == "1"){//已计算人员
  177. me.loadGrid();
  178. } else if(action == "2"){//未计算人员
  179. me.loadNoUserGrid();
  180. } else if(action == "3"){//结果明细
  181. $('#abnormityLi').show();
  182. $('#attenceTypeLi').show();
  183. me.loadResultDetailGrid();
  184. }
  185. },
  186. /**
  187. * 计算数据
  188. */
  189. calculate:function(fileIds){
  190. var action = $('.nav-tabs > li.active').attr("action");
  191. if(action == "3"){
  192. $.ligerDialog.alert("该视图不进行计算!","提示信息");
  193. return;
  194. }
  195. var flag = me.getInitVal();
  196. if(flag){
  197. return;
  198. }
  199. $.ligerDialog.waitting("请稍后……");
  200. me.remoteCall(
  201. {method : "calculate",
  202. param : {
  203. "startTime" : _startTime,
  204. "endTime" : _endTime,
  205. "attencePolicyId" : _attencePolicyId,
  206. "fileIds":fileIds?fileIds:''
  207. },
  208. success : function(data) {
  209. $.ligerDialog.closeWaitting();
  210. if(data.success)
  211. me.searchGrid();
  212. }
  213. });
  214. },
  215. getInitVal: function(){
  216. _attencePolicyId = $('#attencePolicy').val();
  217. // var attenceCycleOption = $("#attenceCycle").find("option:selected");attenceCycleOption.
  218. _startTime = $('#startTime').val();
  219. _endTime = $('#endTime').val();
  220. if($.isEmpty(_attencePolicyId) ){
  221. $.ligerDialog.alert("请选择考勤制度");
  222. return true;
  223. }
  224. if($.isEmpty(_startTime) ){
  225. $.ligerDialog.alert("请输入开始时间");
  226. return true;
  227. }
  228. if($.isEmpty(_endTime) ){
  229. $.ligerDialog.alert("请输入结束时间");
  230. return true;
  231. }
  232. return false;
  233. },
  234. remoteCall:function(conf){
  235. var url = conf.url;
  236. if(conf.method)
  237. url = __ctx+"/platform/ats/atsAttenceCalculate/"+conf.method+".ht";
  238. $.ajax({
  239. type : "POST",
  240. url :url,
  241. data : conf.param?conf.param:{},
  242. success : function(data) {
  243. conf.success.call(this,data);
  244. }
  245. });
  246. },
  247. loadGrid:function(){
  248. $('#dataGrid').empty();
  249. $('#dataGrid')
  250. .append(
  251. '<div id="gridPager1"></div> <table id="reportGrid" style="height:1px;"></table>');
  252. this.renderDataGrid("getGridColModel");
  253. },
  254. renderDataGrid:function(method){
  255. me.getInitVal();
  256. me.remoteCall({
  257. method : method,
  258. param : {
  259. "startTime" : _startTime,
  260. "endTime" : _endTime,
  261. "attencePolicyId" : _attencePolicyId
  262. },
  263. success : function(data) {
  264. me.doRenderDataGrid(data);
  265. }
  266. });
  267. },
  268. doRenderDataGrid : function(data) {
  269. var table = $("#reportGrid");
  270. var url = __ctx+"/platform/ats/atsAttenceCalculate/reportGrid.ht";
  271. var colNames = data.colNames;
  272. var colModel = data.colModel;
  273. var options = {
  274. url : url,
  275. postData:{
  276. "orgPath":$('#orgId').val(),
  277. "Q_fullname_SL":$('#fullname').val(),
  278. "Q_beginattenceTime_DL":_startTime,
  279. "Q_endattenceTime_DE":_endTime,
  280. "Q_attencePolicy_L":_attencePolicyId,
  281. "Q_account_S":$('#account').val()
  282. },
  283. datatype : "json",
  284. multiselect : true,
  285. rownumbers : false,
  286. colNames : colNames,
  287. colModel : colModel,
  288. rowNum : 30,
  289. // pager : '#gridPager1',
  290. autoheight : true,
  291. height : 'auto',
  292. width:document.body.clientWidth-30,
  293. gridview : true,
  294. pginput : true,
  295. shrinkToFit :colModel.length > 10 ? false
  296. : true,
  297. autoScroll: true,
  298. viewrecords : true,
  299. rowNum : 10,// 每页显示记录数
  300. rowList : [ 10, 20, 50, 100],// 用于改变显示行数的下拉列表框的元素数组。
  301. jsonReader : {
  302. root : "results",// json中代表实际模型数据的入口
  303. total : "total", // json中代表总页数的数据
  304. page : "page", // json中代表当前页码的数据
  305. records : "records",// json中代表数据行总数的数据
  306. repeatitems :false
  307. // 如果设为false,则jqGrid在解析json时,会根据name来搜索对应的数据元素(即可以json中元素可以不按顺序);而所使用的name是来自于colModel中的name设定。
  308. },
  309. prmNames : {
  310. page : "page", // 表示请求页码的参数名称
  311. rows : "pageSize" // 表示请求行数的参数名称
  312. },
  313. pager : $('#gridPager1'),
  314. grouping : true,
  315. groupingView : {
  316. groupField : [ 'orgName' ],
  317. groupColumnShow : [ false ],
  318. groupText : [ '<b>{0}</b>' ],
  319. groupCollapse : false,
  320. groupOrder : [ 'asc' ],
  321. groupSummary : [ true ],
  322. groupDataSorted : true,
  323. showSummaryOnHide : true
  324. },
  325. onCellSelect : function(rowid, index, contents,event) {
  326. if (index == 0)
  327. return;
  328. var data = $("#reportGrid").jqGrid("getRowData", rowid),
  329. fileId = data['fileId'],colName = colModel[index - 1].name,
  330. userName = data['userName'];
  331. //
  332. if ( colName == 'account' ||colName == 'userName') {
  333. me.showCalendarDetailAction(fileId,userName,_startTime,_endTime);
  334. }else if (colName.substring(0, 1) == "S") {
  335. if (contents == 0) {
  336. $.ligerDialog.alert("该汇总项没有明细!","提示信息");
  337. return;
  338. }
  339. me.showSummaryDetailAction(fileId,userName,colName,colModel[index - 1].label,_startTime,_endTime);
  340. }else {
  341. me.showBillDetailAction(fileId,userName,colModel[index - 1].index);
  342. }
  343. },
  344. onSelectRow : function(id) {
  345. jQuery('#reportGrid').jqGrid('editRow', id,
  346. false, function() {
  347. });
  348. //_sidValue
  349. // sidValue.push(id);
  350. // lastsel2 = id;
  351. // $("#reportGrid")
  352. // .attr("sid", sidValue.join(","));
  353. },
  354. gridComplete : function() {
  355. $.ligerDialog.closeWaitting();
  356. }
  357. };
  358. $("#reportGrid").html();
  359. $("#reportGrid").jqGrid(options);
  360. // $("#reportGrid").jqGrid('setFrozenColumns');
  361. var h= (document.body.clientHeight)+'px';
  362. $('#reportGrid .ui-jqgrid-bdiv').css('height', h).css(
  363. 'width', '100%').css('overflow-y', 'scroll',
  364. 'overflow-x', 'scroll');
  365. $('#reportGrid .ui-jqgrid .ui-jqgrid-htable th div').css('height','35px');
  366. },
  367. /**
  368. * 展示日历
  369. */
  370. showCalendarDetailAction:function(fileId,userName,startTime,endTime){
  371. var url=__ctx + "/platform/ats/atsAttenceCalculate/calendar.ht?fileId="
  372. +fileId+"&startTime="+startTime+"&endTime="+endTime;
  373. url=url.getNewUrl();
  374. DialogUtil.open({
  375. height:600,
  376. width: 800,
  377. title : userName+"("+startTime+"--"+endTime+")",
  378. url: url,
  379. isResize: true
  380. });
  381. },
  382. /**
  383. * 汇总明细
  384. */
  385. showSummaryDetailAction:function(fileId,userName,colName,collabel,startTime,endTime){
  386. var url=__ctx + "/platform/ats/atsAttenceCalculate/summary.ht?fileId="
  387. +fileId+"&startTime="+startTime+"&endTime="+endTime+"&colName="+colName;
  388. url=url.getNewUrl();
  389. DialogUtil.open({
  390. height:600,
  391. width: 800,
  392. title : userName+"["+collabel+"]("+startTime+"--"+endTime+")",
  393. url: url,
  394. isResize: true
  395. });
  396. },
  397. /**
  398. * 详细明细
  399. */
  400. showBillDetailAction:function(fileId,userName,colName){
  401. var url=__ctx + "/platform/ats/atsAttenceCalculate/bill.ht?fileId="
  402. +fileId+"&colName="+colName;
  403. url=url.getNewUrl();
  404. DialogUtil.open({
  405. height:600,
  406. width: 800,
  407. title : userName+"["+colName+"]---考勤记录",
  408. url: url,
  409. isResize: true
  410. });
  411. },
  412. /**
  413. * 没有计算的人员数据
  414. */
  415. loadNoUserGrid:function(){
  416. var conf = {
  417. url:__ctx+"/platform/ats/atsAttenceCalculate/getNoneCalList.ht",
  418. colNames : [ 'fileId', '考勤编号', '工号', '姓名', '组织', '岗位' ],
  419. colModel : [ {
  420. name : 'fileId',
  421. hidden : true
  422. }, {
  423. name : 'cardNumber'
  424. }, {
  425. name : 'account',
  426. width : 80
  427. }, {
  428. name : 'userName'
  429. }, {
  430. name : 'orgName'
  431. }, {
  432. name : 'posName'
  433. } ],
  434. multikey:"fileId",
  435. };
  436. me.renderReportGrid(conf);
  437. },
  438. /**
  439. * 结果汇总明细
  440. */
  441. loadResultDetailGrid:function(){
  442. var conf = {
  443. url:__ctx+"/platform/ats/atsAttenceCalculate/detailList.ht",
  444. colNames : [ 'id', '姓名', '工号', '组织', '考勤日期',"星期","班次名称","是否异常","类型","第一段上班","第一段下班","第二段上班","第二段下班", "第三段上班","第三段下班"],
  445. colModel : [ {
  446. name : 'id',
  447. hidden : true
  448. }, {
  449. name : 'userName',
  450. width : 80
  451. }, {
  452. name : 'account',
  453. width : 80
  454. }, {
  455. name : 'orgName',
  456. width : 80
  457. }, {
  458. name : 'attenceTime',
  459. width : 80
  460. }, {
  461. name : 'week',
  462. width : 80
  463. },{
  464. name : 'shiftName',
  465. width : 80
  466. },{
  467. name: 'abnormity',
  468. width : 80
  469. },{
  470. name : 'attenceType',
  471. width : 80
  472. },{
  473. name : 'shiftTime11',
  474. width : 80
  475. },{
  476. name : 'shiftTime12',
  477. width : 80
  478. }, {
  479. name : 'shiftTime21',
  480. width : 80
  481. },{
  482. name : 'shiftTime22',
  483. width : 80
  484. },{
  485. name : 'shiftTime31',
  486. width : 80
  487. },{
  488. name : 'shiftTime32',
  489. width : 80
  490. } ],
  491. multikey:"id",
  492. };
  493. me.renderReportGrid(conf);
  494. },
  495. renderReportGrid:function(conf){
  496. $('#dataGrid').empty();
  497. $('#dataGrid').append('<div id="gridPager1"></div> <table id="reportGrid" style="height:1px;"></table>');
  498. var type = $('#attenceType').val();
  499. if(!$.isEmpty(type))
  500. type =type.join(",");
  501. else
  502. type ="";
  503. var options = {
  504. url:conf.url,
  505. postData:{
  506. "orgPath":$('#orgId').val(),
  507. "Q_fullname_SL":$('#fullname').val(),
  508. "Q_account_S":$('#account').val(),
  509. "Q_beginattenceTime_DL":_startTime,
  510. "Q_endattenceTime_DE":_endTime,
  511. "Q_attencePolicy_L":_attencePolicyId,
  512. "type":type,
  513. "Q_abnormity_S":$("#abnormity").val()
  514. },
  515. datatype : "json", // 数据来源,本地数据
  516. mtype : "POST",// 提交方式
  517. height : document.body.clientHeight - 265,// 高度,表格高度。可为数值、百分比或'auto'
  518. width : document.body.clientWidth - 30,
  519. colNames :conf.colNames,
  520. colModel : conf.colModel,
  521. multikey : conf.multikey?conf.multikey:"id",
  522. multiselect : true,
  523. rownumbers : true,// 添加左侧行号
  524. viewrecords : true,// 是否在浏览导航栏显示记录总数
  525. rowNum : 10,// 每页显示记录数
  526. rowList : [ 10, 20, 50, 100],// 用于改变显示行数的下拉列表框的元素数组。
  527. jsonReader : {
  528. root : "results",// json中代表实际模型数据的入口
  529. total : "total", // json中代表总页数的数据
  530. page : "page", // json中代表当前页码的数据
  531. records : "records",// json中代表数据行总数的数据
  532. repeatitems :false
  533. // 如果设为false,则jqGrid在解析json时,会根据name来搜索对应的数据元素(即可以json中元素可以不按顺序);而所使用的name是来自于colModel中的name设定。
  534. },
  535. prmNames : {
  536. page : "page", // 表示请求页码的参数名称
  537. rows : "pageSize" // 表示请求行数的参数名称
  538. },
  539. shrinkToFit : conf.colModel.length > 10 ? false:true,
  540. pager : $('#gridPager1'),
  541. gridComplete : function() {
  542. $.ligerDialog.closeWaitting();
  543. }
  544. };
  545. $("#reportGrid").html();
  546. $("#reportGrid").jqGrid(options);
  547. }
  548. }
  549. $.fn[pluginName] = function(options) {
  550. return this
  551. .each(function() {
  552. if (!$.data(this, "plugin_" + pluginName)) {
  553. $.data(this, "plugin_" + pluginName, new Plugin(this,
  554. options));
  555. }
  556. });
  557. };
  558. })(jQuery, window, document);
  559. $(document).ready(function() {
  560. $('body').AtsAttenceCalculate();
  561. });
  562. function selectAttencePolicy(){
  563. AtsAttencePolicyDialog({
  564. isSingle:true,
  565. callback:function(data){
  566. $('#attencePolicy').val(data.id);
  567. $('#attencePolicyName').val(data.name);
  568. }
  569. })
  570. }
  571. function selectOrg(){
  572. OrgDialog({isSingle:true,callback:function(orgId,orgName){
  573. $('#orgId').val(orgId);
  574. $('#orgName').val(orgName);
  575. }});
  576. }
  577. function selectUser(){
  578. UserDialog({isSingle:true,callback:function(userId,userName){
  579. $('#userId').val(userId);
  580. $('#userName').val(userName);
  581. }});
  582. }