check_team_schedule.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. $(document).ready(function() {
  2. $("#main_content_title").html("稽查人员排班")
  3. var user = $.zui.store.get("user") ; // 缓存用户信息,取出dept_id
  4. // console.log(user );
  5. // 用户的dept_id
  6. var user_dept_id = user.organid ;
  7. // 稽查小组type
  8. var team_type = 2 ;
  9. // 日期游标
  10. var date_cursor = 0 ;
  11. $('#calendar').calendar();
  12. var calendar = $('#calendar').data('zui.calendar');
  13. calendarInit();
  14. // 请求稽查人员排班数据
  15. function calendarInit(data_param){
  16. var data = {
  17. "dept_id": user_dept_id ,
  18. "start_time":getCurrentMonthFirst(),
  19. "end_time":getCurrentMonthLast(),
  20. 'type':team_type
  21. }
  22. if(data_param != undefined){
  23. data = data_param ;
  24. }
  25. getTeamClass(data,function(data){
  26. var newEvents = [];
  27. // console.log(data);
  28. for(var i=0;i<data.length;i++){
  29. var obj = {id:data[i].id ,desc:data[i].team_name ,title: data[i].team_name+"-"+getTeamName(data[i].class_type), start: data[i].start_time, end: data[i].end_time};
  30. newEvents.push(obj);
  31. }
  32. // console.log(newEvents)
  33. calendar.addEvents(newEvents);
  34. })
  35. }
  36. // 获取排班信息
  37. function getTeamClass(data,_function){
  38. post_common_service( "teamClass/getClassList",data,function(data){
  39. _function(data);
  40. },function(error){
  41. return "" ;
  42. })
  43. }
  44. // 更新日历数据
  45. function updateCalendar(data){
  46. calendar.events = [];
  47. calendar.display();
  48. calendarInit(data);
  49. }
  50. // 当月第一天
  51. function getCurrentMonthFirst(){
  52. var date=new Date();
  53. date.setDate(1);
  54. date.setHours(0);
  55. date.setMinutes(0);
  56. date.setSeconds(0);
  57. return date.Format("yyyy-MM-dd HH:mm:ss");
  58. }
  59. // 当月最后一天
  60. function getCurrentMonthLast(){
  61. var date=new Date();
  62. var currentMonth=date.getMonth();
  63. var nextMonth=++currentMonth;
  64. var nextMonthFirstDay=new Date(date.getFullYear(),nextMonth,1);
  65. var oneDay=1000*60*60*24;
  66. var date1 = new Date(nextMonthFirstDay-oneDay);
  67. date1.setHours(0);
  68. date1.setMinutes(0);
  69. date1.setSeconds(0);
  70. return date1.Format("yyyy-MM-dd HH:mm:ss");
  71. }
  72. // 上一个月或者下个月的第一天或者最后一天
  73. function getMonthByCondition(pre_or_after,first_or_last){
  74. if(first_or_last == 'first'){
  75. var date=new Date();
  76. date.setDate(1);
  77. date.setMonth(date.getMonth()+pre_or_after);
  78. return date;
  79. }else if(first_or_last == 'last'){
  80. var date = new Date();
  81. var currentMonth=date.getMonth();
  82. var nextMonth=++currentMonth;
  83. var nextMonthFirstDay=new Date(date.getFullYear(),nextMonth,1);
  84. var oneDay=1000*60*60*24;
  85. date = new Date(nextMonthFirstDay-oneDay);
  86. date.setMonth(date.getMonth()+pre_or_after);
  87. return date ;
  88. }
  89. }
  90. $('#calendar').calendar().on("clickEvent.zui.calendar", function(event) {
  91. // console.log(event);
  92. click_function(event.event.start);
  93. });
  94. /**
  95. * 点击日历触发函数
  96. */
  97. function click_function(date){
  98. setAddTermTitle(date.format("yyyy-MM-dd"));
  99. // 保存当前日期
  100. $("#save_term_class").data("date",date.format("yyyy-MM-dd"));
  101. $("#team_detail").html("");
  102. var data = {
  103. "dept_id": user_dept_id ,
  104. "start_time":date.format("yyyy-MM-dd 00:00:00"),
  105. "end_time": date.format("yyyy-MM-dd 00:00:00"),
  106. 'type':team_type
  107. }
  108. getTeamClass(data,function(data){
  109. for(var i=0;i<$("select[id*='_term']").length;i++){
  110. $("select[id*='_term']").eq(i).val("");
  111. }
  112. if(data.length > 0){
  113. $("#save_term_class").data("modify_flag",1);
  114. for(var i=0;i<data.length;i++){
  115. $(".class_team_"+data[i].class_type).val(data[i].team_id);
  116. }
  117. $("#team_detail").html(data[0].user_ids_name);
  118. }else{
  119. $("#save_term_class").data("modify_flag",0);
  120. }
  121. $('#myModal').modal();
  122. })
  123. }
  124. $('#calendar').calendar().on("clickCell.zui.calendar", function(event) {
  125. // console.log(event);
  126. click_function(event.date);
  127. });
  128. // 下一个日期
  129. $('#calendar').calendar().on("clickNextBtn.zui.calendar", function(event) {
  130. // console.log(event);
  131. date_cursor++ ;
  132. var data = {
  133. "dept_id": user_dept_id ,
  134. "start_time":getMonthByCondition(date_cursor,'first').format("yyyy-MM-dd 00:00:00"),
  135. "end_time": getMonthByCondition(date_cursor,'last').format("yyyy-MM-dd 00:00:00"),
  136. 'type':team_type
  137. }
  138. updateCalendar(data);
  139. });
  140. // 上一个日期
  141. $('#calendar').calendar().on("clickPrevBtn.zui.calendar", function(event) {
  142. date_cursor-- ;
  143. var data = {
  144. "dept_id": user_dept_id ,
  145. "start_time":getMonthByCondition(date_cursor,'first').format("yyyy-MM-dd 00:00:00"),
  146. "end_time": getMonthByCondition(date_cursor,'last').format("yyyy-MM-dd 00:00:00"),
  147. 'type':team_type
  148. }
  149. updateCalendar(data);
  150. });
  151. // 今天
  152. $('#calendar').calendar().on("clickTodayBtn.zui.calendar", function(event) {
  153. // console.log(event);
  154. date_cursor = 0 ;
  155. calendarInit();
  156. });
  157. $("#save_term_class").click(function(){
  158. var data = [];
  159. for(var i=0;i<$("select[id*='_term']").length;i++){
  160. if($("select[id*='_term']").eq(i).val()!=""){
  161. var obj = {
  162. "class_type":4,
  163. "team_id":$("select[id*='_term']").eq(i).val(),
  164. "work_date": $("#save_term_class").data("date")+" 00:00:00",
  165. "start_time": $("#save_term_class").data("date")+" 00:00:00",
  166. "end_time": $("#save_term_class").data("date")+" 00:00:00",
  167. "dept_id": user_dept_id,
  168. "user_ids": $("#team_detail").data("user_ids")
  169. };
  170. data.push(obj);
  171. }
  172. }
  173. if(data.length == 0 ){
  174. tip("请增加排班!");
  175. return ;
  176. }
  177. if( $("#save_term_class").data("modify_flag") != 1){
  178. post_common_service("teamClass/add/list",data,function(data){
  179. updateCalendar();
  180. $('#myModal').modal('hide');
  181. },function(error){
  182. $('#myModal').modal('hide');
  183. })
  184. }else{
  185. post_common_service("teamClass/update/list",data,function(data){
  186. updateCalendar();
  187. $('#myModal').modal('hide');
  188. },function(error){
  189. $('#myModal').modal('hide');
  190. })
  191. }
  192. })
  193. $("#close_btn").click(function(){
  194. $('#myModal').modal('hide');
  195. })
  196. // 获取部门为1的班组信息
  197. getTermClass(user_dept_id);
  198. // 获取班组信息
  199. function getTermClass(dept_id){
  200. var data = {
  201. 'dept_id':dept_id ,
  202. 'type':team_type
  203. }
  204. post_common_service( "team/getTeamByDeptId/1/50",data,function(data){
  205. for(var i=0;i<data.list.length;i++){
  206. $("#mooring_term,#middle_term,#night_term,#all_term").append("<option value='"+data.list[i].id+"'>"+data.list[i].name +"</option>")
  207. }
  208. },function(error){})
  209. }
  210. })
  211. $("#all_term").change(function(){
  212. if($(this).val() !="" ){
  213. // 请求班组下人员信息
  214. var data ={ "id": $(this).val() };
  215. post_common_service( "team/getDetailById",data,function(data){
  216. $("#team_detail").html(data.user_ids_name);
  217. $("#team_detail").data("user_ids",data.user_ids);
  218. },function(error){})
  219. }else{
  220. $("#team_detail").html("");
  221. }
  222. })
  223. // 根据class_type 获取班次名称
  224. function getTeamName(class_type){
  225. if(class_type == 1){
  226. return "早班";
  227. }else if(class_type == 2){
  228. return "中班";
  229. }else if(class_type == 3){
  230. return "晚班";
  231. }else if(class_type == 4){
  232. return "全班";
  233. }
  234. }
  235. function setAddTermTitle(title){
  236. $(".modal-title").html("添加班组-"+title);
  237. }