|
|
@@ -1,49 +1,237 @@
|
|
|
-
|
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
|
|
+ // 用户的dept_id
|
|
|
+ var user_dept_id = 1 ;
|
|
|
+
|
|
|
+ // 稽查小组type
|
|
|
+ var team_type = 2 ;
|
|
|
+
|
|
|
+ // 日期游标
|
|
|
+ var date_cursor = 0 ;
|
|
|
+
|
|
|
+ // var user = $.zui.store.get("user") ; // 缓存用户信息,取出dept_id
|
|
|
+
|
|
|
$('#calendar').calendar();
|
|
|
var calendar = $('#calendar').data('zui.calendar');
|
|
|
- var newEvents =
|
|
|
- [
|
|
|
- {title: '考核二班-晚班', start: '2017-5-1 ', end: '2017-5-1 '},
|
|
|
- {title: '考核三班-晚班', start: '2017-5-1 ', end: '2017-5-1 '},
|
|
|
- {title: '考核四班-晚班', start: '2017-5-1 ', end: '2017-5-1 '},
|
|
|
- {title: '考核一班-休息', start: '2017-5-1 ', end: '2017-5-1 '},
|
|
|
- {title: '考核二班-晚班', start: '2017-5-12 ', end: '2017-5-12 '},
|
|
|
- {title: '考核三班-晚班', start: '2017-5-12 ', end: '2017-5-12 '},
|
|
|
- {title: '考核四班-晚班', start: '2017-5-12 ', end: '2017-5-12 '},
|
|
|
- {title: '考核一班-休息', start: '2017-5-12 ', end: '2017-5-12 '},
|
|
|
- {title: '未排班', start: '2017-5-11 ', end: '2017-5-11 '},
|
|
|
- {title: '未排班', start: '2017-5-11 ', end: '2017-5-11'},
|
|
|
- {title: '未排班', start: '2017-5-11 ', end: '2017-5-11 '},
|
|
|
- {title: '未排班', start: '2017-5-11 ', end: '2017-5-11 '},
|
|
|
- {title: '未排班', start: '2017-5-13 ', end: '2017-5-13 '},
|
|
|
- {title: '未排班', start: '2017-5-13 ', end: '2017-5-13'},
|
|
|
- {title: '未排班', start: '2017-5-13 ', end: '2017-5-13 '},
|
|
|
-
|
|
|
- ];
|
|
|
- calendar.addEvents(newEvents);
|
|
|
+
|
|
|
+ calendarInit();
|
|
|
|
|
|
// 请求稽查人员排班数据
|
|
|
-
|
|
|
- var data = {
|
|
|
- "dept_id":1 ,
|
|
|
- "start_time":new Date(),
|
|
|
- "end_time":new Date()
|
|
|
+ function calendarInit(data_param){
|
|
|
+ var data = {
|
|
|
+ "dept_id": user_dept_id ,
|
|
|
+ "start_time":getCurrentMonthFirst(),
|
|
|
+ "end_time":getCurrentMonthLast()
|
|
|
+ }
|
|
|
+ if(data_param != undefined){
|
|
|
+ data = data_param ;
|
|
|
+ }
|
|
|
+ getTeamClass(data,function(data){
|
|
|
+ var newEvents = [];
|
|
|
+ // console.log(data);
|
|
|
+ for(var i=0;i<data.length;i++){
|
|
|
+ var obj = {id:data[i].id ,title: data[i].team_name+"-"+getTeamName(data[i].class_type), start: timeStamp2String(data[i].start_time,"yyyy-MM-dd"), end: timeStamp2String(data[i].end_time,"yyyy-MM-dd")};
|
|
|
+ newEvents.push(obj);
|
|
|
+ }
|
|
|
+ calendar.addEvents(newEvents);
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取排班信息
|
|
|
+ function getTeamClass(data,_function){
|
|
|
+ post_common_service( "teamClass/getClassList",data,function(data){
|
|
|
+ _function(data);
|
|
|
+ },function(error){
|
|
|
+ return "" ;
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新日历数据
|
|
|
+ function updateCalendar(data){
|
|
|
+ calendar.events = [];
|
|
|
+ calendar.display();
|
|
|
+ calendarInit(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 当月第一天
|
|
|
+ function getCurrentMonthFirst(){
|
|
|
+ var date=new Date();
|
|
|
+ date.setDate(1);
|
|
|
+ return date.toLocaleDateString()+" 00:00:00";
|
|
|
+ }
|
|
|
+
|
|
|
+ // 当月最后一天
|
|
|
+ function getCurrentMonthLast(){
|
|
|
+ var date=new Date();
|
|
|
+ var currentMonth=date.getMonth();
|
|
|
+ var nextMonth=++currentMonth;
|
|
|
+ var nextMonthFirstDay=new Date(date.getFullYear(),nextMonth,1);
|
|
|
+ var oneDay=1000*60*60*24;
|
|
|
+ return new Date(nextMonthFirstDay-oneDay).toLocaleDateString()+" 00:00:00";
|
|
|
+ }
|
|
|
+
|
|
|
+ // 上一个月或者下个月的第一天或者最后一天
|
|
|
+ function getMonthByCondition(pre_or_after,first_or_last){
|
|
|
+ if(first_or_last == 'first'){
|
|
|
+ var date=new Date();
|
|
|
+ date.setDate(1);
|
|
|
+ date.setMonth(date.getMonth()+pre_or_after);
|
|
|
+ return date;
|
|
|
+ }else if(first_or_last == 'last'){
|
|
|
+ var date = new Date();
|
|
|
+ var currentMonth=date.getMonth();
|
|
|
+ var nextMonth=++currentMonth;
|
|
|
+ var nextMonthFirstDay=new Date(date.getFullYear(),nextMonth,1);
|
|
|
+ var oneDay=1000*60*60*24;
|
|
|
+ date = new Date(nextMonthFirstDay-oneDay);
|
|
|
+ date.setMonth(date.getMonth()+pre_or_after);
|
|
|
+ return date ;
|
|
|
+ }
|
|
|
}
|
|
|
- post_common_service( "teamClass/getClassList",data,function(data){
|
|
|
- console.log(data );
|
|
|
- },function(error){})
|
|
|
|
|
|
$('#calendar').calendar().on("clickEvent.zui.calendar", function(event) {
|
|
|
- console.log(event.event);
|
|
|
- // alert(event.event.title);
|
|
|
- // console.log("你点击了一个事件");
|
|
|
- // 处理 clickEvent 事件
|
|
|
- // ...
|
|
|
- // 对话框弹出
|
|
|
- $('#myModal').modal();
|
|
|
+ // console.log(event);
|
|
|
+ click_function(event.event.start);
|
|
|
+ });
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 点击日历触发函数
|
|
|
+ */
|
|
|
+ function click_function(date){
|
|
|
+ setAddTermTitle(date.format("yyyy-MM-dd"));
|
|
|
+ // 保存当前日期
|
|
|
+ $("#save_term_class").data("date",date.format("yyyy-MM-dd"));
|
|
|
+
|
|
|
+ var data = {
|
|
|
+ "dept_id": user_dept_id ,
|
|
|
+ "start_time":date.format("yyyy-MM-dd 00:00:00"),
|
|
|
+ "end_time": date.format("yyyy-MM-dd 00:00:00")
|
|
|
+ }
|
|
|
+
|
|
|
+ getTeamClass(data,function(data){
|
|
|
+ for(var i=0;i<$("select[id*='_term']").length;i++){
|
|
|
+ $("select[id*='_term']").eq(i).val("");
|
|
|
+ }
|
|
|
+ if(data.length > 0){
|
|
|
+ $("#save_term_class").data("modify_flag",1);
|
|
|
+ for(var i=0;i<data.length;i++){
|
|
|
+ $(".class_team_"+data[i].class_type).val(data[i].team_id);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $("#save_term_class").data("modify_flag",0);
|
|
|
+ }
|
|
|
+ $('#myModal').modal();
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ $('#calendar').calendar().on("clickCell.zui.calendar", function(event) {
|
|
|
+ // console.log(event);
|
|
|
+ click_function(event.date);
|
|
|
});
|
|
|
|
|
|
- })
|
|
|
+ // 下一个日期
|
|
|
+ $('#calendar').calendar().on("clickNextBtn.zui.calendar", function(event) {
|
|
|
+ // console.log(event);
|
|
|
+ date_cursor++ ;
|
|
|
+
|
|
|
+ var data = {
|
|
|
+ "dept_id": user_dept_id ,
|
|
|
+ "start_time":getMonthByCondition(date_cursor,'first').format("yyyy-MM-dd 00:00:00"),
|
|
|
+ "end_time": getMonthByCondition(date_cursor,'last').format("yyyy-MM-dd 00:00:00")
|
|
|
+ }
|
|
|
+ updateCalendar(data);
|
|
|
+ });
|
|
|
+
|
|
|
+ // 上一个日期
|
|
|
+ $('#calendar').calendar().on("clickPrevBtn.zui.calendar", function(event) {
|
|
|
+ date_cursor-- ;
|
|
|
+ var data = {
|
|
|
+ "dept_id": user_dept_id ,
|
|
|
+ "start_time":getMonthByCondition(date_cursor,'first').format("yyyy-MM-dd 00:00:00"),
|
|
|
+ "end_time": getMonthByCondition(date_cursor,'last').format("yyyy-MM-dd 00:00:00")
|
|
|
+ }
|
|
|
+ updateCalendar(data);
|
|
|
+ });
|
|
|
+
|
|
|
+ // 今天
|
|
|
+ $('#calendar').calendar().on("clickTodayBtn.zui.calendar", function(event) {
|
|
|
+ // console.log(event);
|
|
|
+ date_cursor = 0 ;
|
|
|
+ calendarInit();
|
|
|
+ });
|
|
|
+
|
|
|
+ $("#save_term_class").click(function(){
|
|
|
+ var data = [];
|
|
|
+ for(var i=0;i<$("select[id*='_term']").length;i++){
|
|
|
+ if($("select[id*='_term']").eq(i).val()!=""){
|
|
|
+ var obj = {
|
|
|
+ "class_type":i+1,
|
|
|
+ "team_id":$("select[id*='_term']").eq(i).val(),
|
|
|
+ "work_date": $("#save_term_class").data("date")+" 00:00:00",
|
|
|
+ "start_time": $("#save_term_class").data("date")+" 00:00:00",
|
|
|
+ "end_time": $("#save_term_class").data("date")+" 00:00:00",
|
|
|
+ "dept_id":user_dept_id
|
|
|
+ };
|
|
|
+ data.push(obj);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(data.length == 0 ){
|
|
|
+ tip("请增加排班!");
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ if( $("#save_term_class").data("modify_flag") != 1){
|
|
|
+ post_common_service("teamClass/add/list",data,function(data){
|
|
|
+ updateCalendar();
|
|
|
+ $('#myModal').modal('hide');
|
|
|
+ },function(error){
|
|
|
+ $('#myModal').modal('hide');
|
|
|
+ })
|
|
|
+ }else{
|
|
|
+ post_common_service("teamClass/update/list",data,function(data){
|
|
|
+ updateCalendar();
|
|
|
+ $('#myModal').modal('hide');
|
|
|
+ },function(error){
|
|
|
+ $('#myModal').modal('hide');
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ $("#close_btn").click(function(){
|
|
|
+ $('#myModal').modal('hide');
|
|
|
+ })
|
|
|
+
|
|
|
+ // 获取部门为1的班组信息
|
|
|
+ getTermClass(user_dept_id);
|
|
|
+
|
|
|
+ // 获取班组信息
|
|
|
+ function getTermClass(dept_id){
|
|
|
+ var data = {
|
|
|
+ 'dept_id':dept_id ,
|
|
|
+ 'type':team_type
|
|
|
+ }
|
|
|
+ post_common_service( "team/getTeamByDeptId/1/50",data,function(data){
|
|
|
+ for(var i=0;i<data.list.length;i++){
|
|
|
+ $("#mooring_term,#middle_term,#night_term,#all_term").append("<option value='"+data.list[i].id+"'>"+data.list[i].name +"</option>")
|
|
|
+ }
|
|
|
+ },function(error){})
|
|
|
+ }
|
|
|
+
|
|
|
+ })
|
|
|
+
|
|
|
+ // 根据class_type 获取班次名称
|
|
|
+ function getTeamName(class_type){
|
|
|
+ if(class_type == 1){
|
|
|
+ return "早班";
|
|
|
+ }else if(class_type == 2){
|
|
|
+ return "中班";
|
|
|
+ }else if(class_type == 3){
|
|
|
+ return "晚班";
|
|
|
+ }else if(class_type == 4){
|
|
|
+ return "全班";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function setAddTermTitle(title){
|
|
|
+ $(".modal-title").html("添加班组-"+title);
|
|
|
+ }
|