charge_team_schedule.js 33 KB

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