charge_team_schedule.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. // $(document).ready(function() {
  2. // initChargeTeamSchedule()
  3. // })
  4. function initChargeTeamSchedule(){
  5. // $("#main_content_title").html("收费人员排班")
  6. var user = $.zui.store.get("user") ; // 缓存用户信息,取出dept_id
  7. // 用户的dept_id
  8. var user_dept_id = user.organid ;
  9. // 收费小组type
  10. var team_type = 1 ;
  11. // 日期游标
  12. var date_cursor = 0 ;
  13. $('#calendar').calendar();
  14. var calendar = $('#calendar').data('zui.calendar');
  15. calendarInit();
  16. // 请求收费人员排班数据
  17. function calendarInit(data_param){
  18. var datap = {
  19. "dept_id": user_dept_id ,
  20. "start_time":getMonthByCondition(date_cursor,'first').Format("yyyy-MM-dd HH:mm:ss"),//getCurrentMonthFirst(),
  21. "end_time":getMonthByCondition(date_cursor,'last').Format("yyyy-MM-dd HH:mm:ss"),//getCurrentMonthLast(),
  22. 'type':team_type
  23. }
  24. if(data_param != undefined){
  25. datap = data_param ;
  26. }
  27. getTeamClass(datap,function(data){
  28. var newEvents = [];
  29. // console.log(data);
  30. for(var i=0;i<data.length;i++){
  31. var obj = {id:data[i].id ,desc:data[i].team_name ,title: data[i].team_name+"-"+getTeamName(data[i].class_type), start: data[i].end_time, end: data[i].end_time};//都以开始时间的日期为准
  32. newEvents.push(obj);
  33. }
  34. // 这里轮训给每天都增加一个事件
  35. var date = getMonthByCondition(date_cursor,'first');//new Date();
  36. var end_date = getMonthByCondition(date_cursor,'last');//new Date(getCurrentMonthLast2()) ;
  37. if(data_param != undefined){
  38. date = new Date(data_param.start_time);
  39. end_date = new Date(data_param.end_time) ;
  40. }
  41. for(var i =0;i<31;i++){
  42. if( date.setDate(i+1) < end_date ){
  43. var obj = {id:-1 ,desc:'详细排班' ,title: '+详细排班', start:date.Format('yyyy-MM-dd'), end: date.Format('yyyy-MM-dd'),color:'#bd7b46'};
  44. newEvents.push(obj);
  45. }
  46. }
  47. calendar.addEvents(newEvents);
  48. })
  49. }
  50. // 获取排班信息
  51. function getTeamClass(data,_function){
  52. post_common_service( "teamClass/getClassList",data,function(data){
  53. _function(data);
  54. },function(error){
  55. return "" ;
  56. })
  57. }
  58. getStation();
  59. var lans = 0;
  60. var entrance_number = 0;
  61. var exit_number = 0;
  62. // 获取收费站信息
  63. function getStation(){
  64. get_common_service( "dept/getFsByDept","",function(data){
  65. if(data != null){
  66. $(".thread_charge").append("<th>"+data.name+"</th>");
  67. $(".thread_charge").append("<th>值班室</th>");
  68. // console.log(data);
  69. lans = data.lanes_number;
  70. entrance_number = data.entrance_numer ;
  71. exit_number = data.exit_numer ;
  72. // for(var i=0;i<data.lanes_number;i++){
  73. // $(".thread_charge").append("<th>进口车道"+(i+1)+"</th>");
  74. // }
  75. for(var i=0;i<entrance_number;i++){
  76. $(".thread_charge").append("<th>入口"+(i+1)+"</th>");
  77. }
  78. for(var i=0;i<exit_number;i++){
  79. $(".thread_charge").append("<th>出口"+(i+1)+"</th>");
  80. }
  81. }
  82. },function(error){
  83. return "" ;
  84. })
  85. }
  86. getClassCode();
  87. var classCode = {};
  88. /**
  89. * 获取班组信息
  90. */
  91. function getClassCode(){
  92. var data = {} ;
  93. post_common_service( "teamClass/getClassCode",data,function(data){
  94. for(var i=0;i<data.length;i++){
  95. classCode[data[i].code] = data[i];
  96. }
  97. // console.log(classCode);
  98. $(".class_type_1").html(classCode[1].class_name);
  99. $(".class_type_2").html(classCode[2].class_name);
  100. $(".class_type_3").html(classCode[3].class_name);
  101. },function(error){
  102. return "" ;
  103. })
  104. }
  105. // 更新日历数据
  106. function updateCalendar(data){
  107. calendar.events = [];
  108. calendar.display();
  109. calendarInit(data);
  110. }
  111. // 当月第一天
  112. function getCurrentMonthFirst(){
  113. var date=new Date();
  114. date.setDate(1);
  115. date.setHours(0);
  116. date.setMinutes(0);
  117. date.setSeconds(0);
  118. return date.Format("yyyy-MM-dd HH:mm:ss");
  119. }
  120. // 当月最后一天
  121. function getCurrentMonthLast(){
  122. var date=new Date();
  123. var currentMonth=date.getMonth();
  124. var nextMonth=++currentMonth;
  125. var nextMonthFirstDay=new Date(date.getFullYear(),nextMonth,1);
  126. var oneDay=1000*60*60*24;
  127. var date1 = new Date(nextMonthFirstDay-oneDay);
  128. date1.setHours(23);
  129. date1.setMinutes(59);
  130. date1.setSeconds(59);
  131. return date1.Format("yyyy-MM-dd HH:mm:ss");
  132. }
  133. // 当月最后一天
  134. function getCurrentMonthLast2(){
  135. var date=new Date();
  136. var currentMonth=date.getMonth();
  137. var nextMonth=++currentMonth;
  138. var nextMonthFirstDay=new Date(date.getFullYear(),nextMonth,1);
  139. var oneDay=0;//1000*60*60*24;
  140. var date1 = new Date(nextMonthFirstDay-oneDay);
  141. date1.setHours(0);
  142. date1.setMinutes(0);
  143. date1.setSeconds(0);
  144. return date1.Format("yyyy-MM-dd HH:mm:ss");
  145. }
  146. // 上一个月或者下个月的第一天或者最后一天
  147. function getMonthByCondition(pre_or_after,first_or_last){
  148. if(first_or_last == 'first'){
  149. var date=new Date();
  150. date.setDate(1);
  151. date.setHours(0);
  152. date.setMinutes(0);
  153. date.setSeconds(0);
  154. date.setMonth(date.getMonth()+pre_or_after);
  155. return date;
  156. }else if(first_or_last == 'last'){
  157. var date = new Date();
  158. date.setMonth(date.getMonth()+pre_or_after);//此处月份加减,不能放到最后加减,会引起月份天数不对
  159. var currentMonth=date.getMonth();
  160. var nextMonth=++currentMonth;
  161. var nextMonthFirstDay=new Date(date.getFullYear(),nextMonth,1);
  162. var date1 = nextMonthFirstDay;
  163. date1.setDate(date1.getDate()-1);
  164. date1.setHours(23);
  165. date1.setMinutes(59);
  166. date1.setSeconds(59);
  167. return date1 ;
  168. }
  169. }
  170. /**
  171. * 顶班日期
  172. */
  173. function date_time(){
  174. $.jeDate("#start_time",{
  175. format:"hh:mm:00",
  176. isinitVal:true,
  177. zIndex:99999999
  178. });
  179. $.jeDate("#end_time",{
  180. format:"hh:mm:00",
  181. isinitVal:true,
  182. zIndex:99999999
  183. });
  184. }
  185. date_time();
  186. $("#save_user_class").click(function(){
  187. var now_date = new Date();
  188. if(now_date.Format('yyyy-MM-dd') > $("#save_user_class").data("work_date") ){
  189. tip("不能生成过期的排班");
  190. return ;
  191. }
  192. var dutyList = [];
  193. var work_date = $("#save_user_class").data("work_date")+"00:00:00";
  194. for(var j=1;j<4;j++){
  195. var cache = $(".tr-"+j).data("cache");
  196. if(cache) {
  197. for(var i=0;i<lans+1;i++){
  198. if($(".tr-"+j+" td select").eq(i).val()!='' && $(".tr-"+j+" td select").eq(i).val()!=null ){
  199. var start_time = $("#save_user_class").data("work_date")+ classCode[j].start_time+":00" ;
  200. if(j==3) {
  201. var date = new Date($("#save_user_class").data("work_date").replace(/-/,"/"));
  202. date.setDate(date.getDate()-1);
  203. start_time = date.Format("yyyy-MM-dd")+" "+classCode[j].start_time+":00";
  204. }
  205. var end_time = $("#save_user_class").data("work_date")+classCode[j].end_time+":00";
  206. // 这边需要
  207. // console.log($(".tr-"+j+" td select").eq(i).data("data"));
  208. var list = $(".tr-"+j+" td select").eq(i).data("data");
  209. var obj = {"list":list , "work_date":work_date,"dept_id":cache.dept_id,"user_id": $(".tr-"+j+" td select").eq(i).val() , "class_type":j,"team_id":cache.team_id,"start_time":start_time, "end_time":end_time,"lane":$(".tr-"+j+" td select").eq(i).parent().attr('tag') };
  210. dutyList.push(obj);
  211. }
  212. }
  213. }
  214. }
  215. console.log(dutyList);
  216. $("#save_user_class").attr("disabled","disabled");
  217. if($("#save_user_class").data("modify_flag")){
  218. $("#save_user_class").data("modify_flag",false);
  219. post_common_service( "userClass/updateList",dutyList,function(data){
  220. tip("修改成功");
  221. $('#add_fee_station').modal('hide');
  222. $("#save_user_class").attr("disabled",false );
  223. },function(error){
  224. return "" ;
  225. })
  226. return ;
  227. }
  228. post_common_service( "userClass/addList",dutyList,function(data){
  229. tip("添加成功");
  230. $('#add_fee_station').modal('hide');
  231. $("#save_user_class").attr("disabled",false );
  232. },function(error){
  233. return "" ;
  234. })
  235. })
  236. var cols = [{width: 60,text: '序号',type: 'number',flex: false,colClass: 'text-center'},
  237. { width: 130,text: '开始时间',type: 'string',flex: false,colClass: 'text-center'},
  238. { width: 130, text: '结束时间',type: 'string',flex: false,sort: 'down',colClass: 'text-center'},
  239. {width: 130,text: '人员姓名',type: 'string',flex: false,colClass: 'text-center'},
  240. {width: 230, text: '操作',type: 'string',flex: false,colClass: 'text-center'}
  241. ];
  242. $('.datatable').datatable({
  243. checkable: false,
  244. sortable: false,
  245. data: {
  246. cols: cols,
  247. rows: []
  248. }
  249. });
  250. var temp_data ;
  251. // 更新表格数据
  252. function updateTableData(obj){
  253. var rowdata =[];
  254. if (obj != null && obj.length > 0) {
  255. for(var i=0;i<obj.length;i++){
  256. var userdata = {};
  257. userdata["checked"] = false;
  258. userdata["data"] = [i + 1, obj[i].start_time, obj[i].end_time, obj[i].user_name, ' <button class="btn btn-primary btn_remove" value=' + i + ' ><i class="icon icon-remove-circle"></i>删除</button>'];
  259. rowdata.push(userdata);
  260. }
  261. }
  262. $('.datatable').datatable('load', {
  263. cols: cols,
  264. rows: rowdata
  265. });
  266. }
  267. $(".datatable").delegate(".btn_remove","click",function(){
  268. var bind_data = temp_data;
  269. // alert($(this).val())
  270. if($(this).val()!=null && $(this).val()!=''){
  271. bind_data.splice( $(this).val() ,1)
  272. // $(".add-btn").data("data",bind_data);
  273. temp_data = bind_data;
  274. updateTableData(temp_data);
  275. }
  276. })
  277. var time_interval_obj = "";
  278. $(".table").delegate(".i-self","click",function(){
  279. $("#team_info_ti").html($(this).prev().html());
  280. $(".save_class_info").data("data",$(this).prev());
  281. // 将时间区间值的span 对象缓存起来
  282. time_interval_obj = $(this).parent().parent().children().eq(0).children();
  283. //console.log(time_interval_obj);
  284. temp_data = $(this).prev().data("data") ;
  285. $("#lists").show();
  286. $("#add_update").hide();
  287. updateTableData(temp_data);
  288. showPopup4CommonBtns("添加顶班详情","720px","#add_detail_info","",function(){
  289. },function(){})
  290. })
  291. // 增加按钮
  292. $(".add-btn").click(function(){
  293. $("#team_info_ti").val("");
  294. $("#lists").hide();
  295. $("#add_update").show();
  296. $("#start_time").val(time_interval_obj.eq(1).html()+':00');
  297. $("#end_time").val(time_interval_obj.eq(2).html()+':00');
  298. })
  299. // 保存班组信息
  300. $(".save_class_info").click(function(){
  301. $(".save_class_info").data("data").data("data", temp_data);
  302. layer.closeAll();
  303. })
  304. $(".return-btn").click(function(){
  305. $("#lists").show();
  306. $("#add_update").hide();
  307. })
  308. // 保存
  309. $("#save_btn").click(function(){
  310. var bind_data = temp_data;
  311. if(bind_data == null){
  312. bind_data = [] ;
  313. }
  314. // 判断时间区间
  315. // $(".modal-title span").html()
  316. var start_time_interval = $(".modal-title span").html() +' ' + time_interval_obj.eq(1).html()+":00";
  317. var end_time_interval = $(".modal-title span").html() +' ' + time_interval_obj.eq(2).html()+":00";
  318. var id = $("#team_info_ti").val();
  319. var start_time = $(".modal-title span").html() +' ' + $("#start_time").val();
  320. var end_time = $(".modal-title span").html() +' ' + $("#end_time").val() ;
  321. var name = $("#team_info_ti").find("option:selected").text();
  322. if(start_time_interval > end_time_interval){
  323. var prev_date = new Date((start_time_interval).replace(/-/,"/"));
  324. prev_date.setDate(prev_date.getDate()-1) ;
  325. start_time_interval = prev_date.Format("yyyy-MM-dd HH:mm:00") ;
  326. if( $("#start_time").val() >= '23:00:00'){
  327. prev_date = new Date((start_time).replace(/-/,"/"));
  328. prev_date.setDate(prev_date.getDate()-1) ;
  329. start_time = prev_date.Format("yyyy-MM-dd HH:mm:00") ;
  330. }
  331. if( $("#end_time").val() > '23:00:00'){
  332. prev_date = new Date((end_time).replace(/-/,"/"));
  333. prev_date.setDate(prev_date.getDate()-1) ;
  334. end_time = prev_date.Format("yyyy-MM-dd HH:mm:00") ;
  335. }
  336. }
  337. // alert( 'start_time:'+start_time + 'end_time:'+end_time + 'start_time_i:'+start_time_interval +'end_time_i:'+end_time_interval );
  338. if(start_time >=end_time){
  339. tip("时间设置不合理,开始时间不能大于结束时间");
  340. return ;
  341. }
  342. if(!(start_time >= start_time_interval && end_time <= end_time_interval)){
  343. tip("不是当前值班时间段");
  344. return ;
  345. }
  346. // 这边需要判断一下,时间不能重叠
  347. for(var i=0;i<bind_data.length;i++){
  348. if(!(start_time >= bind_data[i].end_time || end_time <= bind_data[i].start_time)){
  349. tip("设置的时间不能重叠");
  350. return ;
  351. }
  352. }
  353. if( id !="" && start_time !='' && end_time !=''){
  354. bind_data.push({"user_name":name , "start_time":start_time , "end_time": end_time,"id":id});
  355. temp_data = bind_data;
  356. $("#lists").show();
  357. $("#add_update").hide();
  358. updateTableData(temp_data);
  359. }else{
  360. tip("信息需填写完整");
  361. }
  362. })
  363. $('#calendar').calendar().on("clickEvent.zui.calendar", function(event) {
  364. // console.log(event。event.id);
  365. if(event.event.id == -1){
  366. // 这边负责添加整个页面的数据 按车道排班
  367. $('#add_fee_station').modal({'backdrop': 'static'});
  368. $(".modal-title").html("收费站排班表-<span>"+event.event.start.Format("yyyy-MM-dd")+"</span>");
  369. $("#save_user_class").data("work_date",event.event.start.Format("yyyy-MM-dd "));
  370. var data = {
  371. "dept_id": user_dept_id ,
  372. "start_time":event.event.start.Format("yyyy-MM-dd 00:00:00"),
  373. "end_time": event.event.start.Format("yyyy-MM-dd 00:00:00"),
  374. 'type':team_type
  375. }
  376. post_common_service( "teamClass/getClassListAndUsers",data,function(data){
  377. $("#save_user_class").html("生成今日值班");
  378. $(".tr-1,.tr-2,.tr-3").empty();
  379. for(var i=0;i<data.length;i++){
  380. var ct = data[i].class_type ;
  381. $(".tr-"+ct ).data("cache",data[i]);
  382. $(".tr-"+ct).append("<td><span>"+ classCode[ct].class_name +"</span> <span>"+classCode[ct].start_time+"</span> - <span>"+classCode[ct].end_time +"</span></td>");
  383. var selectv = "<select class='form-control select-self'>"
  384. selectv += ("<option value=''>请选择</option>");
  385. for(var j=0;j<data[i].users.length;j++){
  386. var obj = data[i].users[j];
  387. selectv += ("<option value='"+data[i].users[j].id+"'>"+ data[i].users[j].truename +"</option>");
  388. }
  389. selectv += "</select> <i title='顶班详情' alt='顶班详情' class='icon icon-tags i-self'></i>";
  390. $(".tr-"+ct).append("<td class='c-"+ct+"-0' tag='0'>"+ selectv +"</td>")
  391. for(var z=0;z<entrance_number;z++){
  392. $(".tr-"+ct).append("<td class='c-"+ct+"-"+(z+1)+"' tag='"+(z+1)+"'>"+ selectv +"</td>")
  393. }
  394. for(var z=0;z<exit_number;z++){
  395. $(".tr-"+ct).append("<td class='c-"+ct+"--"+(z+1)+"' tag='-"+(z+1)+"'>"+ selectv +"</td>")
  396. }
  397. }
  398. if(data.length ==0){
  399. $(".tr-1").append("<td>"+ classCode["1"].class_name +" "+classCode["1"].start_time+" - "+classCode["1"].end_time +"</td>");
  400. $(".tr-2").append("<td>"+ classCode[2].class_name +" "+classCode[2].start_time+" - "+classCode[2].end_time +"</td>");
  401. $(".tr-3").append("<td>"+ classCode[3].class_name +" "+classCode[3].start_time+" - "+classCode[3].end_time +"</td>");
  402. for(var i=0;i<lans+1;i++){
  403. $(".tr-1,.tr-2,.tr-3").append("<td></td>");
  404. }
  405. }else{
  406. var cache = $(".tr-1").data("cache");
  407. var work_date = $("#save_user_class").data("work_date")+"00:00:00";
  408. var param = {
  409. 'dept_id':user_dept_id,
  410. 'work_date':work_date
  411. }
  412. post_common_service( "userClass/getList",param,function(data){
  413. // 这边将值班数据检索出来,初始化收费站车道排班中
  414. // console.log(data);
  415. if(data.length > 0){
  416. $("#save_user_class").data("modify_flag",true);
  417. $("#save_user_class").html("修改今日值班");
  418. }else{
  419. $("#save_user_class").html("生成今日值班");
  420. $("#save_user_class").data("modify_flag",false);
  421. }
  422. for(var i=0;i<data.length;i++){
  423. // console.log(data[i].list)
  424. // 这边需要把id转换成user_id
  425. if(data[i].list != null)
  426. $(".c-"+data[i].class_type+"-"+data[i].lane+" select").data("data",data[i].list);
  427. for(var j=0;j<data[i].list.length;j++){
  428. data[i].list[j].id = data[i].list[j].user_id ;
  429. }
  430. var aim_selector = $(".c-"+data[i].class_type+"-"+data[i].lane+" select") ;
  431. aim_selector.val(data[i].user_id);
  432. if(aim_selector.find("option:selected").text() == ''){
  433. aim_selector.append("<option value='"+ data[i].user_id +"' selected='selected'>"+ data[i].user_name +"</option>")
  434. }
  435. // $(".table .tr-"+data[i].class_type+" select").eq(i%(lans+1)).val(data[i].user_id);
  436. }
  437. },function(error){
  438. return "" ;
  439. })
  440. }
  441. },function(error){
  442. return "" ;
  443. })
  444. }else{
  445. click_function(event.event.start);
  446. }
  447. });
  448. /**
  449. * 点击日历触发函数
  450. */
  451. function click_function(date){
  452. setAddTermTitle(date.Format("yyyy-MM-dd"));
  453. // 保存当前日期
  454. $("#save_term_class").data("date",date.Format("yyyy-MM-dd"));
  455. var data = {
  456. "dept_id": user_dept_id ,
  457. "start_time":date.Format("yyyy-MM-dd 00:00:00"),
  458. "end_time": date.Format("yyyy-MM-dd 00:00:00"),
  459. 'type':team_type
  460. }
  461. getTeamClass(data,function(data){
  462. for(var i=0;i<$("select[id*='_term']").length;i++){
  463. $("select[id*='_term']").eq(i).val("");
  464. }
  465. if(data.length > 0){
  466. $("#save_term_class").data("modify_flag",1);
  467. for(var i=0;i<data.length;i++){
  468. $(".class_team_"+data[i].class_type).val(data[i].team_id);
  469. }
  470. }else{
  471. $("#save_term_class").data("modify_flag",0);
  472. }
  473. $('#myModal').modal();
  474. })
  475. }
  476. $('#calendar').calendar().on("clickCell.zui.calendar", function(event) {
  477. // console.log(event);
  478. click_function(event.date);
  479. });
  480. // 下一个日期
  481. $('#calendar').calendar().on("clickNextBtn.zui.calendar", function(event) {
  482. // console.log(event);
  483. date_cursor++ ;
  484. var data = {
  485. "dept_id": user_dept_id ,
  486. "start_time":getMonthByCondition(date_cursor,'first').Format("yyyy-MM-dd HH:mm:ss"),
  487. "end_time": getMonthByCondition(date_cursor,'last').Format("yyyy-MM-dd HH:mm:ss"),
  488. 'type':team_type
  489. }
  490. updateCalendar(data);
  491. });
  492. // 上一个日期
  493. $('#calendar').calendar().on("clickPrevBtn.zui.calendar", function(event) {
  494. date_cursor-- ;
  495. var data = {
  496. "dept_id": user_dept_id ,
  497. "start_time":getMonthByCondition(date_cursor,'first').Format("yyyy-MM-dd HH:mm:ss"),
  498. "end_time": getMonthByCondition(date_cursor,'last').Format("yyyy-MM-dd HH:mm:ss"),
  499. 'type':team_type
  500. }
  501. updateCalendar(data);
  502. });
  503. // 今天
  504. $('#calendar').calendar().on("clickTodayBtn.zui.calendar", function(event) {
  505. // console.log(event);
  506. date_cursor = 0 ;
  507. calendarInit();
  508. });
  509. $("#save_term_class").click(function(){
  510. // 判断当前时间和待添加班组时间判断
  511. var now_date = new Date();
  512. if(now_date.Format('yyyy-MM-dd') > $("#save_term_class").data("date") ){
  513. tip("不能生成过期的排班");
  514. return ;
  515. }
  516. var data = [];
  517. for(var i=0;i<$("select[id*='_term']").length;i++){
  518. if($("select[id*='_term']").eq(i).val()!=""){
  519. var start_time = $("#save_term_class").data("date")+" "+classCode[i+1].start_time+":00";
  520. if(i+1==3){
  521. var date = new Date($("#save_term_class").data("date").replace(/-/,"/"));
  522. date.setDate(date.getDate()-1);
  523. start_time = date.Format("yyyy-MM-dd")+" "+classCode[i+1].start_time+":00";
  524. }
  525. // 这边需要转换一下,关于值
  526. var team_type_value = 1;
  527. if(i+1 == 1){
  528. team_type_value = 3 ;
  529. }else if(i+1 == 2){
  530. team_type_value = 1 ;
  531. }else{
  532. team_type_value = 2 ;
  533. }
  534. var obj = {
  535. "class_type":team_type_value,
  536. "team_id":$("select[id*='_term']").eq(i).val(),
  537. "work_date": $("#save_term_class").data("date")+" 00:00:00",
  538. "start_time": start_time,
  539. "end_time": $("#save_term_class").data("date")+" "+classCode[i+1].end_time+":00",
  540. "dept_id":user_dept_id
  541. };
  542. // console.log(obj);
  543. data.push(obj);
  544. }
  545. }
  546. if(data.length == 0 ){
  547. tip("请增加排班!");
  548. return ;
  549. }
  550. if( $("#save_term_class").data("modify_flag") != 1){
  551. post_common_service("teamClass/add/list",data,function(data){
  552. updateCalendar();
  553. $('#myModal').modal('hide');
  554. },function(error){
  555. $('#myModal').modal('hide');
  556. })
  557. }else{
  558. post_common_service("teamClass/update/list",data,function(data){
  559. updateCalendar();
  560. $('#myModal').modal('hide');
  561. },function(error){
  562. $('#myModal').modal('hide');
  563. })
  564. }
  565. })
  566. $(".close_btn").click(function(){
  567. $('#myModal,#add_fee_station').modal('hide');
  568. })
  569. // 获取部门为1的班组信息
  570. getTermClass(user_dept_id);
  571. // 获取班组信息
  572. function getTermClass(dept_id){
  573. var data = {
  574. 'dept_id':dept_id ,
  575. 'type':team_type
  576. }
  577. post_common_service( "team/getTeamByDeptId/1/50",data,function(data){
  578. for(var i=0;i<data.list.length;i++){
  579. $("#mooring_term,#middle_term,#night_term,#all_term").append("<option value='"+data.list[i].id+"'>"+data.list[i].name +"</option>")
  580. }
  581. },function(error){})
  582. }
  583. }
  584. // 根据class_type 获取班次名称
  585. function getTeamName(class_type){
  586. if(class_type == 1){
  587. return "早班";
  588. }else if(class_type == 2){
  589. return "中班";
  590. }else if(class_type == 3){
  591. return "夜班";
  592. }else if(class_type == 4){
  593. return "全班";
  594. }
  595. }
  596. function setAddTermTitle(title){
  597. $(".modal-title").html("添加班组-"+title);
  598. }