overtimeStats.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. var myChart = echarts.init(document.getElementById('attendanceStatsChar'),'walden');
  2. var myChart2 = echarts.init(document.getElementById('attendanceStatsChar2'),'walden');
  3. option = {
  4. tooltip: {
  5. trigger: 'axis'
  6. },
  7. grid:{
  8. left: '3%',
  9. right: '4%',
  10. bottom: '1%',
  11. containLabel: true
  12. },
  13. legend: {
  14. data:['加班工时(H)','加班费用(元)'],
  15. width:'90%',
  16. left:'left'
  17. },
  18. xAxis:
  19. {
  20. type: 'category',
  21. data: [],
  22. axisLabel: {
  23. interval: 0,
  24. formatter:function(value)
  25. {
  26. var ret = "";//拼接加\n返回的类目项
  27. var maxLength = 1;//每项显示文字个数
  28. var valLength = value.length;//X轴类目项的文字个数
  29. var rowN = Math.ceil(valLength / maxLength); //类目项需要换行的行数
  30. if (rowN > 1)//如果类目项的文字大于3,
  31. {
  32. for (var i = 0; i < rowN; i++) {
  33. var temp = "";//每次截取的字符串
  34. var start = i * maxLength;//开始截取的位置
  35. var end = start + maxLength;//结束截取的位置
  36. //这里也可以加一个是否是最后一行的判断,但是不加也没有影响,那就不加吧
  37. temp = value.substring(start, end) + "\n";
  38. ret += temp; //凭借最终的字符串
  39. }
  40. return ret;
  41. }
  42. else {
  43. return value;
  44. }
  45. }
  46. }
  47. },
  48. yAxis: [
  49. {
  50. type: 'value',
  51. name:'加班工时(H)',
  52. axisLabel: {
  53. formatter: '{value} H'
  54. }
  55. },
  56. {
  57. type: 'value',
  58. name:'加班费用(元)',
  59. axisLabel: {
  60. formatter: '{value}元'
  61. }
  62. }
  63. ],
  64. dataZoom: [
  65. {
  66. type: 'inside',
  67. start: 0,
  68. end: 100
  69. }
  70. ],
  71. series: [
  72. {
  73. name:'',
  74. type:'bar',
  75. data:[]
  76. }
  77. ]
  78. };
  79. option2 = {
  80. tooltip: {
  81. trigger: 'axis'
  82. },
  83. grid:{
  84. left: '3%',
  85. right: '4%',
  86. bottom: '1%',
  87. containLabel: true
  88. },
  89. legend: {
  90. data:['加班工时(H)','加班费用(元)'],
  91. width:'90%',
  92. left:'left'
  93. },
  94. xAxis:
  95. {
  96. type: 'category',
  97. data: [],
  98. axisLabel: {
  99. interval: 0,
  100. formatter:function(value)
  101. {
  102. var ret = "";//拼接加\n返回的类目项
  103. var maxLength = 1;//每项显示文字个数
  104. var valLength = value.length;//X轴类目项的文字个数
  105. var rowN = Math.ceil(valLength / maxLength); //类目项需要换行的行数
  106. if (rowN > 1)//如果类目项的文字大于3,
  107. {
  108. for (var i = 0; i < rowN; i++) {
  109. var temp = "";//每次截取的字符串
  110. var start = i * maxLength;//开始截取的位置
  111. var end = start + maxLength;//结束截取的位置
  112. //这里也可以加一个是否是最后一行的判断,但是不加也没有影响,那就不加吧
  113. temp = value.substring(start, end) + "\n";
  114. ret += temp; //凭借最终的字符串
  115. }
  116. return ret;
  117. }
  118. else {
  119. return value;
  120. }
  121. }
  122. }
  123. },
  124. yAxis: [
  125. {
  126. type: 'value',
  127. name:'加班工时(H)',
  128. axisLabel: {
  129. formatter: '{value} H'
  130. }
  131. },
  132. {
  133. type: 'value',
  134. name:'加班费用(元)',
  135. axisLabel: {
  136. formatter: '{value}元'
  137. }
  138. }
  139. ],
  140. dataZoom: [
  141. {
  142. type: 'inside',
  143. start: 0,
  144. end: 100
  145. }
  146. ],
  147. series: [
  148. {
  149. name:'',
  150. type:'bar',
  151. data:[]
  152. }
  153. ]
  154. };
  155. $(function() {
  156. $(document).ready(function() {
  157. attendanceStatssearch();
  158. });
  159. });
  160. function attendanceStatssearch(){
  161. handleAjaxSimple("overtimeStatsController.do?overtimeStatsData", $("#attendanceStatsForm").serialize(), handleSuccess);
  162. }
  163. function handleSuccess(data){
  164. if(data.cdata.noData){
  165. $(".content").hide();
  166. $("#uptb").hide();
  167. $("#upbg").hide();
  168. $("#upexport").hide();
  169. $(".err-info").show();
  170. }else{
  171. $(".content").show();
  172. $(".err-info").hide();
  173. //$("#upBtn").show();
  174. $("#uptb").show();
  175. $("#upbg").show();
  176. var srcstr = $("#uptb").attr("src");
  177. if(srcstr.indexOf("tb1.png") < 0){
  178. $("#upexport").show();
  179. }
  180. var rolefalg = $("#roleFlag").val();
  181. var prostr;
  182. if(rolefalg == 1){
  183. prostr = '项目';
  184. }else{
  185. prostr = '部门';
  186. }
  187. var charheadStr;
  188. var attType = $("#attType").val();
  189. if(attType == 0 ){
  190. charheadStr =$("#curYear").val()+"年"+$("#attMonth").val()+"月各"+prostr+"加班时长及费用";
  191. }else if(attType == 1){
  192. var attQuarters = $("#attQuarters").val();
  193. if(attQuarters == 1){
  194. charheadStr = $("#curYear").val()+"年一季度(01月-03月)各"+prostr+"加班时长及费用";
  195. }else if(attQuarters == 2){
  196. charheadStr = $("#curYear").val()+"年二季度(04月-06月)各"+prostr+"加班时长及费用";
  197. }else if(attQuarters == 3){
  198. charheadStr = $("#curYear").val()+"年三季度(07月-09月)各"+prostr+"加班时长及费用";
  199. }else {
  200. charheadStr = $("#curYear").val()+"年四季度(10月-12月)各"+prostr+"加班时长及费用";
  201. }
  202. }else if(attType == 2){
  203. charheadStr = $("#curYear").val()+"年度各"+prostr+"加班时长及费用";
  204. }
  205. $("#upcharheaddiv").html(charheadStr);
  206. initCharDate(data.cdata);
  207. initNdateList(data.tdata);
  208. }
  209. }
  210. function initNdateList(data){
  211. var rolefalg = $("#roleFlag").val();
  212. var pjNamestr;
  213. var pidNamestr;
  214. if(rolefalg == 1){
  215. pjNamestr = '项目名称';
  216. pidNamestr='项目经理';
  217. }else{
  218. pjNamestr = '项目名称';
  219. pidNamestr='部门名称';
  220. }
  221. var attType = $("#attType").val();
  222. var peopleNumStr;
  223. if(attType == 0 ){
  224. peopleNumStr = "当月加班总人数";
  225. }else{
  226. peopleNumStr = "每月加班平均人数";
  227. }
  228. var colums = [[
  229. {field:'pName',title:pjNamestr,width:150},
  230. {field:'pidName',title:pidNamestr,width:150},
  231. {field:'unitPeopleTotal',title:peopleNumStr,width:150 ,align:'right',halign:'center' },
  232. {field:'overtimeDurationStr',title:'加班工时',width:150},
  233. {field:'overtimeFee',title:'加班费用(元)',width:150 ,align:'right',halign:'center' }
  234. ]]
  235. $('#attendanceStatsTable').datagrid({
  236. singleSelect : true,
  237. loadMsg:'数据加载中,请稍后……',
  238. columns:colums,
  239. rownumbers:true,
  240. fitColumns:true
  241. }).datagrid('loadData',data);
  242. }
  243. function initCharDate(data){
  244. myChart.clear();
  245. option.xAxis.data = data.xAxisData;
  246. option.series = data.series;
  247. myChart.setOption(option);
  248. myChart.resize();
  249. }
  250. function showTabel(){
  251. $("#attendanceStatsChar").hide();
  252. $("#tablediv").show();
  253. $("#upexport").show();
  254. $("#uptb").attr("src","images/tb.png");
  255. $("#upbg").attr("src","images/bg1.png");
  256. //$("#attendanceStatsTable").datagrid("resize");
  257. var h=$(".content").height();
  258. $('#attendanceStatsTable').datagrid('resize', {
  259. height :h-50
  260. });
  261. }
  262. function showChar(){
  263. $("#tablediv").hide();
  264. $("#attendanceStatsChar").show();
  265. $("#upexport").hide();
  266. $("#uptb").attr("src","images/tb1.png");
  267. $("#upbg").attr("src","images/bg.png");
  268. myChart.resize();
  269. }
  270. myChart.on('click', function (params) {
  271. console.log(params);
  272. var rolefalg = $("#roleFlag").val();
  273. var attType = $("#attType").val();
  274. if(rolefalg == 1){
  275. $("#downcharheaddiv").html(params.name + "-"+$("#curYear").val()+"年01月~"+$("#curYear").val()+"年12月加班时长及费用趋势变化");
  276. $("#upcharheaddiv2").html($("#curYear").val()+"年度项目加班时长及费用");
  277. if(attType == 2){
  278. var data ={
  279. "attYear" : $("#curYear").val(),
  280. "pid":params.data.id
  281. };
  282. handleAjaxSimple("overtimeStatsController.do?overtimeYearInto", data, showDownChar);
  283. }
  284. }else{
  285. $("#downcharheaddiv").html($("#pid").find("option:selected").text()+"-"+$("#curYear").val()+"年"+$("#attMonth").val()+"月"+params.name+"人员加班时长及费用");
  286. $("#upcharheaddiv2").html($("#curYear").val()+"年"+ $("#attMonth").val()+"月员工加班时长及费用对比图");
  287. if(attType == 0){
  288. var data = {
  289. "attYear" : $("#curYear").val(),
  290. "attMonth" : $("#attMonth").val(),
  291. "pid":$("#pid").val(),
  292. "did":params.data.id
  293. }
  294. handleAjaxSimple("overtimeStatsController.do?overtimeMonthInto", data, showDownChar);
  295. }
  296. }
  297. })
  298. function goBefore(){
  299. $("#attendanceStatsChar2").css("display","none");
  300. $("#tablediv2").hide();
  301. $("#searchColums").show();
  302. $("#downcharhead").hide();
  303. $("#attendanceStatsChar").show();
  304. $("#upcharhead").show();
  305. $("#upcharhead2").hide();
  306. $("#upBtn").show();
  307. $("#downBtn").hide();
  308. $("#downexport").hide();
  309. $("#downtb").attr("src","images/tb1.png");
  310. $("#downbg").attr("src","images/bg.png");
  311. myChart.resize();
  312. }
  313. //显示下钻图表
  314. function showDownChar(data){
  315. $("#attendanceStatsChar").css("display","none");
  316. $("#attendanceStatsChar2").show();
  317. $("#upBtn").hide();
  318. $("#downBtn").show();
  319. $("#searchColums").hide();
  320. $("#downcharhead").show();
  321. $("#upcharhead").hide();
  322. $("#upcharhead2").show();
  323. $("#yearspan2").html($("#curYear").val());
  324. initDownCharDate(data.cdata);
  325. initDownTabDate(data.tdata);
  326. }
  327. function initDownCharDate(data){
  328. myChart2.clear();
  329. option2.xAxis.data = data.xAxisData;
  330. option2.series = data.series;
  331. myChart2.setOption(option2);
  332. myChart2.resize();
  333. }
  334. function initDownTabDate(data){
  335. var rolefalg = $("#roleFlag").val();
  336. var pjNamestr;
  337. var pidNamestr;
  338. var userNameField;
  339. var colums ;
  340. if(rolefalg == 1){
  341. colums = [[
  342. {field:'yearMonth',title:'日期范围',width:150},
  343. {field:'pName',title:'项目名称',width:150},
  344. {field:'pidName',title:'项目经理',width:150},
  345. {field:'unitPeopleTotal',title:'加班总人数(人)',width:150 ,align:'right',halign:'center' },
  346. {field:'overtimeDurationStr',title:'加班工时',width:150},
  347. {field:'overtimeFee',title:'加班费用(元)',width:150 ,align:'right',halign:'center'}
  348. ]]
  349. }else{
  350. colums = [[
  351. {field:'pName',title:'项目名称',width:150},
  352. {field:'pidName',title:'部门名称',width:150},
  353. {field:'userName',title:'员工姓名',width:150},
  354. {field:'datumWorkDuration',title:'基准工作时长',width:150},
  355. {field:'overtimeDurationStr',title:'加班工时',width:150},
  356. {field:'overtimeFee',title:'加班费用(元)',width:150 ,align:'right',halign:'center'}
  357. ]]
  358. }
  359. $('#attendanceStatsTable2').datagrid({
  360. singleSelect : true,
  361. loadMsg:'数据加载中,请稍后……',
  362. columns:colums,
  363. rownumbers:true,
  364. fitColumns:true
  365. }).datagrid('loadData',data);
  366. }
  367. function showDownTabelBtn(){
  368. $("#attendanceStatsChar2").hide();
  369. $("#tablediv2").show();
  370. $("#downexport").show();
  371. $("#downtb").attr("src","images/tb.png");
  372. $("#downbg").attr("src","images/bg1.png");
  373. //$("#attendanceStatsTable2").datagrid("resize");
  374. var h=$(".content").height();
  375. $('#attendanceStatsTable2').datagrid('resize', {
  376. height :h-50
  377. });
  378. }
  379. function showDownCharBtn(){
  380. $("#tablediv2").hide();
  381. $("#downexport").hide();
  382. $("#downtb").attr("src","images/tb1.png");
  383. $("#downbg").attr("src","images/bg.png");
  384. $("#attendanceStatsChar2").show();
  385. myChart2.resize();
  386. }
  387. function exportExcel(flag){
  388. var opts;
  389. if(flag == 1){
  390. opts = $('#attendanceStatsTable').datagrid('getColumnFields'); //这是获取到所有的FIELD
  391. }else{
  392. opts = $('#attendanceStatsTable2').datagrid('getColumnFields'); //这是获取到所有的FIELD
  393. }
  394. var exceltitles=[];
  395. for(i=0;i<opts.length;i++)
  396. {
  397. //var col = $('div[class$="'+opts[i]+'"] :not(.datagrid-sort-icon)').html();
  398. var col = $('td[field="'+opts[i]+'"] div :not(.datagrid-sort-icon)').html();
  399. exceltitles.push(col);//把TITLEPUSH到数组里去
  400. }
  401. var formdom = '<form method="post" id="formdom" action="overtimeStatsController.do?exportExcel"><input name="flag" value="'+flag+'" /><input name="exceltitles" value="'+exceltitles+'" /><input name="exceltitleIds" value="'+opts+'" /></form>';
  402. $("#export").html(formdom);
  403. $("#formdom").submit();
  404. }