var map, circle, marker, isEdit = true, isInitEnd = true; $(function () { initTaskMap(); getTaskTypeList(); getTaskCatalogList(); getTaskLevelList(); }) // 初始化任务地图,供选择任务地点 // 调用在线地图功能,内网该功能无法使用 function initTaskMap() { var defaultLongitude = $('#taskLongitude').val(); var defaultLatitude = $('#taskLatitude').val(); var mapdata; var loadIndex = parent.layer.load(0, {shade: [0.3, '#808080']}); $.ajax({ type: 'POST', url: restHost + "config/getConfigByKeyAndName.json", dataType: "json", traditional: true, data: { "name": "地图中心", "key": "mapCenter" }, async: false, success: function (json) { parent.layer.close(loadIndex); if (json.successful == true || json.successful == "true") { mapdata = json.data; } else { } }, error: function (XMLHttpRequest, textStatus, errorThrown) { parent.layer.close(loadIndex); console.log(errorThrown); } }); if (defaultLongitude == "") { defaultLongitude = mapdata.value.split(",")[0]; // defaultLongitude = 108.939474; } if (defaultLatitude == "") { defaultLatitude = mapdata.value.split(",")[1]; // defaultLatitude = 34.343204; } map = new AMap.Map('taskMap_addressOption', { resizeEnable: true, zoom: 12, center: [defaultLongitude, defaultLatitude] }); /*circle = new AMap.Circle({ center: new AMap.LngLat(defaultLongitude, defaultLatitude),// 圆心位置 // radius: 1000, //半径 strokeColor: "#1791fc", //线颜色 strokeOpacity: 1, //线透明度 strokeWeight: 1, //线粗细度 fillColor: "#1791fc", //填充颜色 fillOpacity: 0.1//填充透明度 }); circle.setMap(map); var taskScope = $('#taskScope').val(); circle.setRadius(Number(taskScope));*/ AMap.plugin('AMap.Geocoder', function () { var geocoder = new AMap.Geocoder({ city: "010" //城市,默认:“全国” }); marker = new AMap.Marker({ map: map, bubble: true }); var input = document.getElementById('taskAddress'); var taskArea = document.getElementById('taskArea'); // var message = document.getElementById('addressMessage'); if (isEdit) { map.on('click', function (e) { marker.setPosition(e.lnglat); // 任务经纬度隐藏字段赋值 $('#taskLongitude').val(e.lnglat.lng); $('#taskLatitude').val(e.lnglat.lat); // circle.setCenter(new AMap.LngLat(e.lnglat.lng, e.lnglat.lat)); // 设置1.5秒后范围消失 // setTimeout(circle.hide(), 15000); geocoder.getAddress(e.lnglat, function (status, result) { if (status == 'complete') { input.value = result.regeocode.formattedAddress; taskArea.value = result.regeocode.addressComponent.district; // message.innerHTML = '' } else { // message.innerHTML = '无法获取地址' parent.layer.alert('无法获取地址'); } }); }); /*input.onchange = function(e){ var address = input.value; geocoder.getLocation(address,function(status,result){ if(status=='complete'&&result.geocodes.length){ marker.setPosition(result.geocodes[0].location); map.setCenter(marker.getPosition()) message.innerHTML = '' }else{ message.innerHTML = '无法获取位置' } }); }*/ } }); // 加载高德在线地图输入提示 AMap.plugin('AMap.Autocomplete', function () {//回调函数 //实例化Autocomplete var autoOptions = { city: "", //城市,默认全国 input: "taskAddress" //使用联想输入的input的id }; autocomplete = new AMap.Autocomplete(autoOptions); AMap.event.addListener(autocomplete, "choose", function (e) { if (isEdit) { if (e.poi && e.poi.location) { // 任务经纬度隐藏字段赋值 $('#taskLongitude').val(e.poi.location.lng); $('#taskLatitude').val(e.poi.location.lat); var centerPoint = new AMap.LngLat(e.poi.location.lng, e.poi.location.lat); map.setCenter(centerPoint); //获取区域 var geocoder = new AMap.Geocoder({ city: "010" //城市,默认:“全国” }); geocoder.getAddress(e.poi.location, function (status, result) { var taskArea = document.getElementById('taskArea'); if (status == 'complete') { taskArea.value = result.regeocode.addressComponent.district; // message.innerHTML = '' } else { // message.innerHTML = '无法获取地址' parent.layer.alert('无法获取地址'); } }); // circle.setCenter(centerPoint); marker.setPosition(centerPoint); } } }); AMap.event.addListener(autocomplete, "select", function (e) { if (isEdit) { if (e.poi) { // 任务经纬度隐藏字段赋值 $('#taskLongitude').val(e.poi.location.lng); $('#taskLatitude').val(e.poi.location.lat); var centerPoint = new AMap.LngLat(e.poi.location.lng, e.poi.location.lat); map.setCenter(centerPoint); //获取地址区域 var geocoder = new AMap.Geocoder({ city: "010" //城市,默认:“全国” }); geocoder.getAddress(e.poi.location, function (status, result) { var taskArea = document.getElementById('taskArea'); if (status == 'complete') { taskArea.value = result.regeocode.addressComponent.district; // message.innerHTML = '' } else { // message.innerHTML = '无法获取地址' parent.layer.alert('无法获取地址'); } }); // circle.setCenter(centerPoint); marker.setPosition(centerPoint); } } }); }); } //选择人员 function choicePerson() { parent.layer.open({ type: 2, title: "选择人员", shadeClose: false, shade: [0.8, '#393D49'], closeBtn: 1, move: false, skin: "edit-class editTaskMax", maxmin: false, //开启最大化最小化按钮 area: ['60%', '85%'], btn: ["取消", "确定"], content: ctx + '/iframe/choicePerson.jsp', success: function (layero, index) { var iframeWin = parent.window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象,执行iframe页的方法:iframeWin.method(); var personList = [[], []]; var ul1 = $(".t-principal li"); var ul2 = $(".t-staff li"); if (ul1 != "" || ul1 != 0) { for (var i = 0; i < ul1.length; i++) { personList[0].push($(ul1[i]).attr("id")); } } if (ul2 != "" || ul2 != 0) { for (var i = 0; i < ul2.length; i++) { personList[1].push($(ul2[i]).attr("id")); } } iframeWin.setPersonList(personList); }, btn2: function (indexIframe, layero) { var iframeWin = parent.window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象,执行iframe页的方法:iframeWin.method(); $(".tps-war ul").html(""); var people = iframeWin.surePeople(); if (people[0] == "" || people[1] == "") { return false; } else { //TODO var flag = checkUserPolicyForChoisePerson(people); if (flag) { generatePeople(people); createScheduleTable(); parent.layer.close(indexIframe); } } return false; } }); } //选择人员生成到页面 function generatePeople(people) { var html = [], num = 0; for (var i = 0; i < 2; i++) { html[i] = ""; if (people[i] != "") { num += parseInt(people[i].length); for (var j = 0; j < people[i].length; j++) { if (j == (people[i].length - 1)) { html[i] += "
  • " + people[i][j] + "
  • "; } else { html[i] += "
  • " + people[i][j] + "、
  • "; } } } } if (html[0] != "") { $(".t-principal").css("display", "block"); $(".t-principal").html("负责人" + html[0]); } else { $(".t-principal").css("display", "none"); } if (html[1] != "") { $(".t-staff").html(html[1]); } $(".tps-war label").html(num + "人"); $(".tps-war").css("display", "block"); textLength(); } //生成人员到页面限制字符长度 function textLength() { $(".tps-war").each(function () { var width = parseFloat($(".tps-war").siblings("input").css("width")); var maxwidth = parseInt((width - 180) / 12); var html = ""; var li = $(".tps-war").find("li"); for (var i = 0; i < li.length; i++) { html += $(li).eq(i).html(); if (html.length > maxwidth) { $(li).eq(i).nextAll("li").addClass("hidden"); $(li).eq(i).html($(li).eq(i).html() + "...等"); break; } } }); } //获取任务分类 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) { if (platform == "1") {//公安账号创建的时候排除一些其他的任务类型 if (obj.platform == platform) { var h = ''; h = h + '
  • '; h = h + ''; h = h + ''; h = h + '' + obj.type + '任务'; h = h + '
  • '; $("#taskTypeArea").append(h); } } else { var h = ''; h = h + '
  • '; h = h + ''; h = h + ''; h = h + '' + obj.type + '任务'; h = h + '
  • '; $("#taskTypeArea").append(h); } }); } else { ajaxError(json); } }, error: function (XMLHttpRequest, textStatus, errorThrown) { console.log(errorThrown); } }); } //获取任务类型 function getTaskCatalogList() { $.ajax({ type: 'POST', url: restHost + "getTaskCatalog.json", dataType: "json", data: { "sid": sid }, async: false, success: function (json) { if (json.successful == true || json.successful == "true") { $.each(json.data, function (index, obj) { var h = ''; h = h + '
  • '; h = h + ''; h = h + ''; h = h + '' + obj.catalog + ''; h = h + '
  • '; $("#taskCatalogArea").append(h); if (obj.children != null && obj.children.length > 0) { var subHtml = ''; subHtml = subHtml + '
    '; subHtml = subHtml + ''; subHtml = subHtml + ''; subHtml = subHtml + '
    '; $("#subCatalogArea").append(subHtml); } }); } else { ajaxError(json); } }, error: function (XMLHttpRequest, textStatus, errorThrown) { console.log(errorThrown); } }); } //选择任务类型 function choiseCatalog(parentId) { $(".rad-sub").hide(); $("#" + parentId).show(); } //获取任务等级 function getTaskLevelList() { $.ajax({ type: 'POST', url: restHost + "getTaskLevel.json", dataType: "json", data: { "sid": sid }, async: false, success: function (json) { if (json.successful == true || json.successful == "true") { $.each(json.data, function (index, obj) { $("#taskLevel").append(''); }); } else { ajaxError(json); } }, error: function (XMLHttpRequest, textStatus, errorThrown) { console.log(errorThrown); } }); } //班次列表弹窗 function scheduleList() { parent.layer.open({ type: 2, // title: "班次维护", title: false, shadeClose: false, shade: [0.8, '#393D49'], closeBtn: 0, move: false, skin: "edit-class editTaskMax", maxmin: false, //开启最大化最小化按钮 area: ['80%', '60%'], content: ctx + '/iframe/scheduleList.jsp', cancel: function (index) { choiseSchedule(); return false; } }); } //选择班次弹窗 function choiseSchedule() { parent.layer.open({ type: 2, title: "选择班次", shadeClose: false, shade: [0.8, '#393D49'], closeBtn: 1, move: false, skin: "confirm-class btnDefault-class", maxmin: false, //开启最大化最小化按钮 area: ['520px', '360px'], btn: ["编辑班次", "确定"], content: ctx + '/iframe/choiseSchedule.jsp', success: function (layero, index) { var iframeWin = parent.window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象,执行iframe页的方法:iframeWin.method(); var scheduleIds = []; $.each($(".all-shift li"), function (index, obj) { scheduleIds.push($(obj).attr("id")); }); iframeWin.setScheduleList(scheduleIds); }, btn1: function (indexIframe, layero) { scheduleList(); parent.layer.close(indexIframe); }, btn2: function (indexIframe, layero) { var iframeWin = parent.window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象,执行iframe页的方法:iframeWin.method(); var scheduleHtml = iframeWin.getChoiseSchedule(); if (scheduleHtml == "") { return false; } else { $(".all-shift").html(scheduleHtml); createScheduleTable(); parent.layer.close(indexIframe); } } }); } //modify by zjh time 2018-06-01 17:42:51 content:任务详情字数不能超过500个字 function checkWord() { if ($("#detail").val().length > 500) { toastrError("任务详情不能大于500字,现在字数:"+$("#detail").val().length); } } function save() { $("#saveBtn").removeAttr("onclick"); var loadIndex = parent.layer.load(0, {shade: [0.3, '#808080']}); //在此运行代码 var taskName = $("#name").val(); var address = $("#taskAddress").val(); var peopleIds = []; var scheduleIds = []; var taskType = $('input:radio[name="taskType.id"]:checked').val(); var taskCatalog = $('input:radio[name="taskCatalog.id"]:checked').val(); var isRepeat = $('input:radio[name="isRepeat"]:checked').val(); var detailLength= $("#detail").val().length; var taskLevel = $("#taskLevel").val(); var detail = $("#detail").val(); var scope = $("#taskScope").val(); var longitude = $("#taskLongitude").val(); var latitude = $("#taskLatitude").val(); var area = $("#taskArea").val(); // var autoHoliday = $("#autoHoliday").val(); var taskId = $("#taskId").val(); var startDate = $("#appDateTime1").val(); var endDate = $("#appDateTime2").val(); var ul1 = $(".t-principal li"); var ul2 = $(".t-staff li"); var chargers = []; //modify by zjh time 2018-06-01 17:42:51 content:任务详情字数不能超过500个字 if (detailLength > 500) { parent.layer.close(loadIndex); $("#saveBtn").attr("onclick", "save()"); toastrError("任务详情不能大于500字,现在字数:"+detailLength); return; } if (ul1 != "" || ul1 != 0) { for (var i = 0; i < ul1.length; i++) { peopleIds.push($(ul1[i]).attr("id")); chargers.push(true); } } if (ul2 != "" || ul2 != 0) { for (var i = 0; i < ul2.length; i++) { peopleIds.push($(ul2[i]).attr("id")); chargers.push(false); } } $.each($(".all-shift li"), function (index, obj) { scheduleIds.push($(obj).attr("id")); }); //任务详情 if(isEmpty($("#detail").val())){ parent.layer.close(loadIndex); $("#saveBtn").attr("onclick", "save()"); toastrError("请填写任务详情!"); return; } if (taskName == '') { parent.layer.close(loadIndex); $("#saveBtn").attr("onclick", "save()"); toastrError("请填写任务名称!"); return; } else if (address == '') { parent.layer.close(loadIndex); $("#saveBtn").attr("onclick", "save()"); toastrError("请填写任务地点!"); return; } else if (taskType == '' || taskType == null) { parent.layer.close(loadIndex); $("#saveBtn").attr("onclick", "save()"); toastrError("请选择任务分类!"); return; } else if (taskCatalog == '' || taskCatalog == null) { parent.layer.close(loadIndex); $("#saveBtn").attr("onclick", "save()"); toastrError("请选择任务类型!"); return; } else if (taskLevel == '' || taskLevel == null) { parent.layer.close(loadIndex); $("#saveBtn").attr("onclick", "save()"); toastrError("请选择任务等级!"); return; } else if (peopleIds.length < 1) { parent.layer.close(loadIndex); $("#saveBtn").attr("onclick", "save()"); toastrError("请选择参与人员!"); return; } else if (scheduleIds.length < 1) { parent.layer.close(loadIndex); $("#saveBtn").attr("onclick", "save()"); toastrError("请选择班次!"); return; } else if (taskType == "1") { if (isRepeat == '' || isRepeat == null) { toastrError("请选择考勤类型!"); $("#saveBtn").attr("onclick", "save()"); return; } } else if (taskType == "2") { if (startDate == "" || endDate == "") { parent.layer.close(loadIndex); $("#saveBtn").attr("onclick", "save()"); toastrError("请选择有效期!"); return; } } var dateList = []; var dateInputs = $(".workday-table .table thead .bg-fg input"); $.each(dateInputs, function (index, obj) { dateList.push($("#saveBtn").val()); }); var flag = true; var message = ""; var personList = '{"personList":['; $.each(peopleIds, function (indexPerson, peopleId) { if (!flag) { return; } personList += '{"id":' + peopleId + ',"inCharge":' + chargers[indexPerson] + ',"scheduleList":['; var scheduleListStr = ""; $.each(dateList, function (indexDate, date) { // if(taskType =="1" && isRepeat == "1"){ // scheduleListStr += '{"taskDate":"'+date+'","scheduleDetail":['+scheduleIds.join(",")+']},'; // }else{ var choiseScheduleIds = []; var choiseSchedules = $(".workday-table .table tbody .peopleId" + peopleId + " td:nth-child(" + (indexDate + 2) + ") ul .active"); $.each(choiseSchedules, function (indexSchedule, choiseSchedule) { choiseScheduleIds.push($(choiseSchedule).attr("data_id")); }); if (choiseScheduleIds.length > 0) { scheduleListStr += '{"taskDate":"' + date + '","scheduleDetail":[' + choiseScheduleIds.join(",") + ']},'; } // } }); if (scheduleListStr == "") { message = "存在人员未排班!"; flag = false; return; } personList += scheduleListStr; personList = personList.substring(0, personList.length - 1); personList += ']},'; }); personList = personList.substring(0, personList.length - 1); personList += ']}'; if (!flag) { parent.layer.close(loadIndex); $("#saveBtn").attr("onclick", "save()"); toastrError(message); return; } // checkUserPolicy(peopleIds,$("#saveBtn")); submitForm($("#saveBtn")); parent.layer.close(loadIndex); $("#saveBtn").attr("onclick", "save()"); } function getTaskInfo(taskId) { var loadIndex = parent.layer.load(0, {shade: [0.3, '#808080']}); $.ajax({ type: 'POST', url: restHost + "task/findById/" + taskId + ".json", dataType: "json", data: { "sid": sid }, // async : false, success: function (json) { if (json.successful == true || json.successful == "true") { var task = json.data; isInitEnd = false; $("#taskId").val(task.id); $("#taskLongitude").val(task.longitude); $("#taskLatitude").val(task.latitude); $("#taskArea").val(task.area); $("#name").val(task.name); $("#taskAddress").val(task.address); $("#taskLevel").val(task.taskLevel.id); $("#detail").val(task.detail); $("#scope").val(task.scope); var personList = task.personList; $(".t-principal").html("负责人"); $.each(task.personList, function (indexPerson, person) { if (person.inCharge) { $(".t-principal").append("
  • " + person.person.realName + "
  • "); } else { $(".t-staff").append("
  • " + person.person.realName + "
  • "); } }); $(".tps-war label").html(task.personList.length + "人"); $(".tps-war").css("display", "block"); $(".t-principal").css("display", "block"); textLength(); $.each(task.scheduleList, function (indexPerson, schedule) { $(".all-shift").append("
  • " + schedule.name + ' ' + schedule.startTime + '~' + schedule.endTime + "
  • "); }); $("input[name='taskCatalog.id'][value=" + task.taskCatalog.id + "]").prop("checked", true); $("input[name='taskCatalog.id'][value=" + task.taskCatalog.id + "]").parents(".rad-sub").show(); var isRepeat = "1"; if (task.repeat || task.repeat == "true") { isRepeat = "1"; } else { isRepeat = "0"; } if (isRepeat == "0") { if (task.personList.length > 0 && task.personList[0].scheduleList.length > 0) { var taskDate = task.personList[0].scheduleList[0].taskDate; if (taskDate != null) { $("#appDate").val(taskDate.split("-")[0] + "-" + taskDate.split("-")[1]); } } } if (task.taskType.id == "2") { $("#appDateTime1").val(task.startDate); $("#appDateTime2").val(task.endDate); } // /*if(task.autoHoliday){ $("#autoHoliday").prop("checked",true); }*/ //任务分类不能修改 $("input[name='taskType.id'][value=" + task.taskType.id + "]").click(); $("input[name='isRepeat'][value=" + isRepeat + "]").click(); if (task.taskStatus.id == "2") { $("input[name='taskType.id'][value!=" + task.taskType.id + "]").parent().remove(); if (task.repeat == true) { $("#isRepeat_li2").remove(); } else if (task.repeat == false) { $("#isRepeat_li1").remove(); } } // $("input[name='taskType.id']").attr("disabled",true); var dateList = []; var dateInputs = $(".workday-table .table thead .bg-fg input"); $.each(dateInputs, function (index, obj) { dateList.push($(obj).val()); }); $.each(task.personList, function (indexPerson, person) { $.each(person.scheduleList, function (indexSchedule, schedule) { var indexDate = 0; $.each(dateInputs, function (index, obj) { dateList.push($(obj).val()); if ($(obj).val() == schedule.taskDate) { indexDate += index; return; } }); var scheduleLis = $(".workday-table .table tbody .peopleId" + person.person.id + " td:nth-child(" + (indexDate + 2) + ") ul li"); $.each(scheduleLis, function (indexLi, scheduleLi) { $.each(schedule.scheduleDetail, function (indexLi, scheduleDetail) { if ($(scheduleLi).attr("data_id") == scheduleDetail.id) { $(scheduleLi).click(); $(scheduleLi).parent().addClass("hidden"); } }); }); }); }); //已完成的临时任务只查看不能操作 if (task.taskType.id == "2" && task.taskStatus.id != "1") { isEdit = false; $('a').removeAttr('href');//去掉a标签中的href属性 $('a,label,div,.workday-table .departing td').removeAttr('onclick');//去掉onclick属性 $('.workday-table .departing td ul').remove(); $('.btn-ligr').addClass('btn-gray'); $('.btn-ligr').removeClass('btn-ligr'); $('.control').remove();//去掉 $('input').attr("readonly", "readonly"); $('input,select').attr("disabled", "disabled"); } initTaskMap(); isInitEnd = true; //设置不可编辑内容 if (task.taskStatus == "2") { $("#isRepeat1").attr('disabled', true); $("#isRepeat2").attr('disabled', true); $("#Schedule").removeAttr('onclick');//去掉onclick属性 $("#appDate").attr("disabled", "disabled"); $("#person").removeAttr('href'); } } else { ajaxError(json); } parent.layer.close(loadIndex); }, error: function (XMLHttpRequest, textStatus, errorThrown) { parent.layer.close(loadIndex); console.log(errorThrown); } }); } function checkUserPolicyForChoisePerson(people) { if(policyRemind == "0"){ return true; } var peopleIds = []; for (var i = 0; i < 2; i++) { if (people[i] != "") { for (var j = 0; j < people[i].length; j++) { peopleIds.push(people[i + 2][j]); } } } var flag = false; $.ajax({ type: 'POST', url: restHost + "person/checkUserPolicy.json", dataType: "json", traditional: true, data: { "sid": sid, "userIds": peopleIds }, async: false, success: function (json) { if (json.successful == true || json.successful == "true") { flag = true; } else { personids = []; persons = json.data; var msg = ''; $.each(persons, function (i, item) { if (msg == "") { msg = msg + item.name; } else { msg = msg + "、" + item.name; } personids[i] = item.id; }); var title = '成员' + msg + '等没有保险保障,不允许派发任务!'; parent.policy_remind(title, personids,"0"); } }, error: function (XMLHttpRequest, textStatus, errorThrown) { console.log(errorThrown); } }); return flag; } function checkUserPolicy(peopleIds, obj) { var flag = false; $.ajax({ type: 'POST', url: restHost + "person/checkUserPolicy.json", dataType: "json", traditional: true, data: { "sid": sid, "userIds": peopleIds }, async: false, success: function (json) { // parent.layer.close(loadIndex); if (json.successful == true || json.successful == "true") { submitForm(obj); flag = true; } else { persons = json.data; var msg = ''; $.each(persons, function (i, item) { if (msg == "") { msg = msg + item; } else { msg = msg + "、" + item; } }); continueTask(msg, obj); } }, error: function (XMLHttpRequest, textStatus, errorThrown) { // parent.layer.close(loadIndex); $(obj).attr("onclick", "save()"); console.log(errorThrown); } }); return falg; } function continueTask(msg, obj) { var name1 = "张三"; var name2 = "李四"; parent.layer.confirm('

    任务人员中:' + msg + '。未购买保险保障,是否继续派遣任务?

    ', { title: "温馨提示", skin: "confirm-class", btn: ['确定', '取消'] //按钮 }, function (index) { // 按钮1的回调 parent.layer.close(index); submitForm(obj); }) } function submitForm(obj) { $(obj).removeAttr("onclick"); var loadIndex = parent.layer.load(0, {shade: [0.3, '#808080']}); //在此运行代码 var taskName = $("#name").val(); var address = $("#taskAddress").val(); var peopleIds = []; var scheduleIds = []; var taskType = $('input:radio[name="taskType.id"]:checked').val(); var taskCatalog = $('input:radio[name="taskCatalog.id"]:checked').val(); var isRepeat = $('input:radio[name="isRepeat"]:checked').val(); var taskLevel = $("#taskLevel").val(); var detail = $("#detail").val(); var scope = $("#taskScope").val(); var longitude = $("#taskLongitude").val(); var latitude = $("#taskLatitude").val(); var area = $("#taskArea").val(); //var autoHoliday = $("#autoHoliday").val(); var taskId = $("#taskId").val(); var startDate = $("#appDateTime1").val(); var endDate = $("#appDateTime2").val(); var ul1 = $(".t-principal li"); var ul2 = $(".t-staff li"); var chargers = []; if (ul1 != "" || ul1 != 0) { for (var i = 0; i < ul1.length; i++) { peopleIds.push($(ul1[i]).attr("id")); chargers.push(true); } } if (ul2 != "" || ul2 != 0) { for (var i = 0; i < ul2.length; i++) { peopleIds.push($(ul2[i]).attr("id")); chargers.push(false); } } $.each($(".all-shift li"), function (index, obj) { scheduleIds.push($(obj).attr("id")); }); var dateList = []; var dateInputs = $(".workday-table .table thead .bg-fg input"); $.each(dateInputs, function (index, obj) { dateList.push($(obj).val()); }); var flag = true; var message = ""; var personList = '{"personList":['; $.each(peopleIds, function (indexPerson, peopleId) { if (!flag) { return; } personList += '{"id":' + peopleId + ',"inCharge":' + chargers[indexPerson] + ',"scheduleList":['; var scheduleListStr = ""; $.each(dateList, function (indexDate, date) { var choiseScheduleIds = []; var choiseSchedules = $(".workday-table .table tbody .peopleId" + peopleId + " td:nth-child(" + (indexDate + 2) + ") ul .active"); $.each(choiseSchedules, function (indexSchedule, choiseSchedule) { choiseScheduleIds.push($(choiseSchedule).attr("data_id")); }); if (choiseScheduleIds.length > 0) { scheduleListStr += '{"taskDate":"' + date + '","scheduleDetail":[' + choiseScheduleIds.join(",") + ']},'; } }); personList += scheduleListStr; personList = personList.substring(0, personList.length - 1); personList += ']},'; }); personList = personList.substring(0, personList.length - 1); personList += ']}'; $.ajax({ type: 'POST', url: restHost + "task/update.json", dataType: "json", traditional: true, data: { "sid": sid, "id": taskId, "name": taskName, "address": address, "area": area, "taskType.id": taskType, "taskCatalog.id": taskCatalog, "repeat": isRepeat, "taskLevel.id": taskLevel, "detail": detail, "scope": scope, "longitude": longitude, "latitude": latitude, //"autoHoliday" : autoHoliday, "schedules": scheduleIds, "startDate": startDate, "endDate": endDate, "persons": personList }, // async : false, success: function (json) { parent.layer.close(loadIndex); if (json.successful == true || json.successful == "true") { toastrSuccess("操作成功!"); setTimeout("parent.taskList();", 3000); } else { ajaxError(json); } }, error: function (XMLHttpRequest, textStatus, errorThrown) { parent.layer.close(loadIndex); $(obj).attr("onclick", "save()"); console.log(errorThrown); } }); }