/** * Created by bcxin on 2017/1/14. */ $(document).ready(function(){ //限制字符个数 $(".text_overflow").each(function(){ var maxwidth=22; if($(this).text().length>maxwidth){ $(this).text($(this).text().substring(0,maxwidth)); $(this).html($(this).html()+'...'); } }); //点击删除 var ind=""; $("tbody").on("click","i",function(){ ind=$(this).parent().parent().parent().index(); ind++; }); $(".modal-footer").on("click",".sure",function(){ $("tbody tr:nth-child("+ind+")").remove(); }) $("tbody").on("mouseenter","td.col-xs-1 b",function(){ var height=parseFloat($(this).parent().parent().css("height"))-parseFloat($(this).css("height")); var top=parseFloat($(this).css("top")); if(top!=(height/2)) { $(this).css("top", height / 2 + "px"); $(this).parent().siblings("a").find("i").css("top", height / 2 + "px"); } }) $("tbody td.col-xs-1 b").trigger("mouseenter"); }); getTaskTypeList(); search(); function search(){ $('#pageNum').val("0"); getPersonListForPage("taskForm","taskArea"); } function choiseTaskType(){ var taskType = $("#type").val(); if(taskType == "2"){ $("#isRepeat").val(""); $("#isRepeat").attr("disabled",true); }else{ $("#isRepeat").attr("disabled",false); } } function initPage(){ var totalCount = Number($('#totalCount').val()) || 0; var showCount = $('#showCount').val() || 5; var limit = Number($('#numPerPage').val()) || 8; $('#callBackPager').extendPagination({ totalCount: totalCount, showCount: showCount, showPage:5, limit: limit, callback: function (curr, limit, totalCount) { $('#pageNum').val(Number($('#pageNum').val())-1); getPersonListForPage("taskForm","taskArea"); } }); } function getPersonListForPage(formId,contentId){ var index = parent.layer.load(0, {shade: [0.3,'#808080']}); var data=$("#"+formId).serialize(); $.ajax({ type : 'POST', url : restHost + "task/searchForManage.json", data : $("#"+formId).serialize(), dataType : "json", success : function(json) { if (json.successful == true || json.successful == "true") { $('#totalCount').val(json.data.totalCount); $("#"+contentId).empty(); var taskList = json.data.data; if(taskList.length>0){ $.each(taskList,function(index, obj) { var taskHtml = ""; var isrepeat = ""; if(obj.taskType.id != "2"){ isrepeat = obj.repeat ? "固定班次":"排班制"; } taskHtml = taskHtml + ''; taskHtml = taskHtml + ''+(index+1)+''; taskHtml = taskHtml + '' + obj.name + ''; taskHtml = taskHtml + '' + obj.taskType.type + ''; taskHtml = taskHtml + ''+isrepeat +''; var TaskTime = ''; $.each(obj.scheduleList,function(index, schedule) { TaskTime = TaskTime +schedule.name+':'+schedule.startTime+'~'+schedule.endTime ; }); taskHtml = taskHtml + ''; taskHtml = taskHtml + "

" + TaskTime + "

" taskHtml = taskHtml + ''; taskHtml = taskHtml + '

' + obj.address + '

'; taskHtml = taskHtml + '' + obj.personList.length + ''; taskHtml = taskHtml + '' + obj.taskStatus.status + ''; taskHtml = taskHtml + ''; if(obj.taskType.id == "1" ||(obj.taskType.id == "2" && obj.taskStatus.id == "1")){ //编辑权限 if(editflag) { taskHtml = taskHtml + ' '; } //删除权限 if(delflag) { taskHtml = taskHtml + ' '; } }else{ //新增权限 if(addflag) { taskHtml = taskHtml + ' '; } } taskHtml = taskHtml + ''; taskHtml = taskHtml + ''; $("#"+contentId).append(taskHtml); }); if($('#pageNum').val() == "0"){ initPage(); } }else{ $("#"+contentId).append('暂无相关数据!'); } } parent.layer.close(index); }, error: function(XMLHttpRequest, textStatus, errorThrown){ parent.layer.close(index); console.log(errorThrown); } }); } function getTaskTypeList(){ $.ajax({ type : 'POST', url : restHost + "getTaskType.json", dataType : "json", data : { "sid" : sid }, async : false, success : function(json) { if (json.successful == true || json.successful == "true") { $.each(json.data, function(index, obj) { $("#type").append(''); }); } else { ajaxError(json); } }, error: function(XMLHttpRequest, textStatus, errorThrown) { console.log(errorThrown); } }); } function deleteTask(taskId){ parent.layer.confirm('确认要删除该任务吗?', { title : "温馨提示", skin:"confirm-class", btn : [ '确认', '取消' ] //按钮 }, function(index) { var personId = $("#personId").val(); if (personId == "") { toastrError("保安人员信息异常,请关闭重试。"); } else { $.ajax({ type : 'POST', url : restHost + "/task/delete/"+taskId+".json", dataType : "json", data : { "sid" : sid }, async : false, success : function(json) { if (json.successful == true || json.successful == "true") { toastrSuccess("操作成功!"); search(); // $("#task"+taskId).remove(); } else { ajaxError(json); } }, error : function(XMLHttpRequest, textStatus, errorThrown) { console.log(errorThrown); } }); parent.layer.close(index); } }); }