check_team_schedule.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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. // 选择下拉框
  12. var role_selectinput ;
  13. var team_stuffs = [] ;
  14. selectInitInput(team_stuffs);
  15. function selectInitInput(objs){
  16. $("#relash").empty();
  17. $("#relash").append('<input type="text" class="form-control class_team_41" id="team_detail" >');
  18. role_selectinput = $('#relash #team_detail').comboTree({
  19. source: objs,
  20. isMultiple: true
  21. });
  22. }
  23. function getSelectInputValue(){
  24. return role_selectinput.getSelectedItemsId();
  25. }
  26. $('#calendar').calendar();
  27. var calendar = $('#calendar').data('zui.calendar');
  28. calendarInit();
  29. // 请求稽查人员排班数据
  30. function calendarInit(data_param){
  31. var data = {
  32. "dept_id": user_dept_id ,
  33. "start_time":getCurrentMonthFirst(),
  34. "end_time":getCurrentMonthLast(),
  35. 'type':team_type
  36. }
  37. if(data_param != undefined){
  38. data = data_param ;
  39. }
  40. getTeamClass(data,function(data){
  41. var newEvents = [];
  42. // console.log(data);
  43. for(var i=0;i<data.length;i++){
  44. 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};
  45. newEvents.push(obj);
  46. }
  47. // console.log(newEvents)
  48. calendar.addEvents(newEvents);
  49. })
  50. }
  51. // 获取排班信息
  52. function getTeamClass(data,_function){
  53. post_common_service( "teamClass/getClassList",data,function(data){
  54. _function(data);
  55. },function(error){
  56. return "" ;
  57. })
  58. }
  59. // 更新日历数据
  60. function updateCalendar(data){
  61. calendar.events = [];
  62. calendar.display();
  63. calendarInit(data);
  64. }
  65. // 当月第一天
  66. function getCurrentMonthFirst(){
  67. var date=new Date();
  68. date.setDate(1);
  69. date.setHours(0);
  70. date.setMinutes(0);
  71. date.setSeconds(0);
  72. return date.Format("yyyy-MM-dd HH:mm:ss");
  73. }
  74. // 当月最后一天
  75. function getCurrentMonthLast(){
  76. var date=new Date();
  77. var currentMonth=date.getMonth();
  78. var nextMonth=++currentMonth;
  79. var nextMonthFirstDay=new Date(date.getFullYear(),nextMonth,1);
  80. var oneDay=1000*60*60*24;
  81. var date1 = new Date(nextMonthFirstDay-oneDay);
  82. date1.setHours(0);
  83. date1.setMinutes(0);
  84. date1.setSeconds(0);
  85. return date1.Format("yyyy-MM-dd HH:mm:ss");
  86. }
  87. // 上一个月或者下个月的第一天或者最后一天
  88. function getMonthByCondition(pre_or_after,first_or_last){
  89. if(first_or_last == 'first'){
  90. var date=new Date();
  91. date.setDate(1);
  92. date.setMonth(date.getMonth()+pre_or_after);
  93. return date;
  94. }else if(first_or_last == 'last'){
  95. var date = new Date();
  96. var currentMonth=date.getMonth();
  97. var nextMonth=++currentMonth;
  98. var nextMonthFirstDay=new Date(date.getFullYear(),nextMonth,1);
  99. var oneDay=1000*60*60*24;
  100. date = new Date(nextMonthFirstDay-oneDay);
  101. date.setMonth(date.getMonth()+pre_or_after);
  102. return date ;
  103. }
  104. }
  105. $('#calendar').calendar().on("clickEvent.zui.calendar", function(event) {
  106. // console.log(event);
  107. click_function(event.event.start);
  108. });
  109. /**
  110. * 点击日历触发函数
  111. */
  112. function click_function(date){
  113. setAddTermTitle(date.format("yyyy-MM-dd"));
  114. // 保存当前日期
  115. $("#save_term_class").data("date",date.format("yyyy-MM-dd"));
  116. $("#team_detail").val("");
  117. var data = {
  118. "dept_id": user_dept_id ,
  119. "start_time":date.format("yyyy-MM-dd 00:00:00"),
  120. "end_time": date.format("yyyy-MM-dd 00:00:00"),
  121. 'type':team_type
  122. }
  123. getTeamClass(data,function(data){
  124. for(var i=0;i<$("select[id*='_term']").length;i++){
  125. $("select[id*='_term']").eq(i).val("");
  126. }
  127. if(data.length > 0){
  128. $("#save_term_class").data("modify_flag",1);
  129. for(var i=0;i<data.length;i++){
  130. $(".class_team_"+data[i].class_type).val(data[i].team_id);
  131. }
  132. var user_ids_name = data[0].user_ids_name ;
  133. var user_ids = data[0].user_ids;
  134. // 请求班组下人员信息
  135. var dataObj ={ "id": data[0].team_id };
  136. post_common_service( "team/getDetailById",dataObj,function(data){
  137. get_input_data(data) ;
  138. // $("#team_detail").val(user_ids_name.substring(0,user_ids_name.length-1));
  139. var user_id = user_ids.split(",");
  140. var user_name = user_ids_name.substring(0,data.user_ids_name.length-1).split(',');
  141. var team_temp_stuffs = [];
  142. for(var i=0; i< user_id.length ;i++ ){
  143. $('span[data-id="'+ user_id[i] +'"] input').attr("checked",true);
  144. var zdataItem = {};
  145. zdataItem["id"] =user_id[i] ;
  146. zdataItem["title"] = user_name[i];
  147. team_temp_stuffs.push(zdataItem);
  148. }
  149. role_selectinput._selectedItems = team_temp_stuffs ;
  150. role_selectinput.refreshInputVal();
  151. },function(error){})
  152. }else{
  153. $("#save_term_class").data("modify_flag",0);
  154. }
  155. $('#myModal').modal();
  156. })
  157. }
  158. $('#calendar').calendar().on("clickCell.zui.calendar", function(event) {
  159. // console.log(event);
  160. click_function(event.date);
  161. });
  162. // 下一个日期
  163. $('#calendar').calendar().on("clickNextBtn.zui.calendar", function(event) {
  164. // console.log(event);
  165. date_cursor++ ;
  166. var data = {
  167. "dept_id": user_dept_id ,
  168. "start_time":getMonthByCondition(date_cursor,'first').format("yyyy-MM-dd 00:00:00"),
  169. "end_time": getMonthByCondition(date_cursor,'last').format("yyyy-MM-dd 00:00:00"),
  170. 'type':team_type
  171. }
  172. updateCalendar(data);
  173. });
  174. // 上一个日期
  175. $('#calendar').calendar().on("clickPrevBtn.zui.calendar", function(event) {
  176. date_cursor-- ;
  177. var data = {
  178. "dept_id": user_dept_id ,
  179. "start_time":getMonthByCondition(date_cursor,'first').format("yyyy-MM-dd 00:00:00"),
  180. "end_time": getMonthByCondition(date_cursor,'last').format("yyyy-MM-dd 00:00:00"),
  181. 'type':team_type
  182. }
  183. updateCalendar(data);
  184. });
  185. // 今天
  186. $('#calendar').calendar().on("clickTodayBtn.zui.calendar", function(event) {
  187. // console.log(event);
  188. date_cursor = 0 ;
  189. calendarInit();
  190. });
  191. $("#save_term_class").click(function(){
  192. var data = [];
  193. var user_ids = getSelectInputValue();
  194. var str_user_ids = '';
  195. if(user_ids!=false){
  196. for(var i=0;i<user_ids.length;i++){
  197. str_user_ids = str_user_ids + ((i!=0)?(','+user_ids[i]):user_ids[i]);
  198. }
  199. }
  200. if(str_user_ids == ''){
  201. tip("请选择值班人员");
  202. return ;
  203. }
  204. for(var i=0;i<$("select[id*='_term']").length;i++){
  205. if($("select[id*='_term']").eq(i).val()!=""){
  206. var obj = {
  207. "class_type":4,
  208. "team_id":$("select[id*='_term']").eq(i).val(),
  209. "work_date": $("#save_term_class").data("date")+" 00:00:00",
  210. "start_time": $("#save_term_class").data("date")+" 00:00:00",
  211. "end_time": $("#save_term_class").data("date")+" 00:00:00",
  212. "dept_id": user_dept_id,
  213. "user_ids": str_user_ids
  214. };
  215. data.push(obj);
  216. }
  217. }
  218. if(data.length == 0 ){
  219. tip("请填写排班信息!");
  220. return ;
  221. }
  222. if( $("#save_term_class").data("modify_flag") != 1){
  223. post_common_service("teamClass/add/list",data,function(data){
  224. updateCalendar();
  225. tip("今日排班成功!");
  226. $('#myModal').modal('hide');
  227. },function(error){
  228. $('#myModal').modal('hide');
  229. })
  230. }else{
  231. post_common_service("teamClass/update/list",data,function(data){
  232. updateCalendar();
  233. tip("今日排班成功!");
  234. $('#myModal').modal('hide');
  235. },function(error){
  236. $('#myModal').modal('hide');
  237. })
  238. }
  239. })
  240. $("#close_btn").click(function(){
  241. $('#myModal').modal('hide');
  242. })
  243. // 获取部门为1的班组信息
  244. getTermClass(user_dept_id);
  245. // 获取班组信息
  246. function getTermClass(dept_id){
  247. var data = {
  248. 'dept_id':dept_id ,
  249. 'type':team_type
  250. }
  251. post_common_service( "team/getTeamByDeptId/1/50",data,function(data){
  252. for(var i=0;i<data.list.length;i++){
  253. $("#mooring_term,#middle_term,#night_term,#all_term").append("<option value='"+data.list[i].id+"'>"+data.list[i].name +"</option>")
  254. }
  255. },function(error){})
  256. }
  257. $("#all_term").change(function(){
  258. if($(this).val() !="" ){
  259. // 请求班组下人员信息
  260. var data ={ "id": $(this).val() };
  261. post_common_service( "team/getDetailById",data,function(data){
  262. get_input_data(data)
  263. },function(error){})
  264. }else{
  265. $("#team_detail").val();
  266. }
  267. })
  268. function get_input_data(data){
  269. if(data.user_ids.length > 0){
  270. var user_name = data.user_ids_name.substring(0,data.user_ids_name.length-1).split(',');
  271. var user_id = data.user_ids.split(",");
  272. team_stuffs = [] ;
  273. for(var i =0;i< user_name.length;i++){
  274. var zdataItem = {};
  275. zdataItem["id"] =user_id[i] ;
  276. zdataItem["title"] = user_name[i];
  277. team_stuffs.push(zdataItem);
  278. }
  279. selectInitInput(team_stuffs);
  280. }
  281. }
  282. // 根据class_type 获取班次名称
  283. function getTeamName(class_type){
  284. if(class_type == 1){
  285. return "早班";
  286. }else if(class_type == 2){
  287. return "中班";
  288. }else if(class_type == 3){
  289. return "夜班";
  290. }else if(class_type == 4){
  291. return "全班";
  292. }
  293. }
  294. function setAddTermTitle(title){
  295. $(".modal-title").html("添加班组-"+title);
  296. }
  297. })