/** * 功能: * * * @author HXB * @date 2015/09/18 */ // 获取用户部门 var dept_id = top.com.sinosoft.lz.system.user.LoginInfo.getCorp_ids(); // 获取公司 var corp_name=top.com.sinosoft.lz.system.user.LoginInfo.getCorp_names(); // 获取用户Id var user_id = top.com.sinosoft.lz.system.user.LoginInfo.getUser_id(); //获取用户角色 var role_id = top.com.sinosoft.lz.system.user.LoginInfo.getRoleids(); //取得用户真实名字 var realName = top.com.sinosoft.lz.system.user.LoginInfo.getReal_name(); /** 定义变量* */ var _this = this; _this.listGrid = null;// 数据列表 _this.searchPanel = null; // 查询面板 $queryForm = null;// 查询区域表单 $searchButt = null;// 查询按钮 $more = null; // 更多 _this.loadParams = null;// 列表加载参数 var is_import = false;//是导入还是查看,导入时的修改提交只要结束编辑该行就行,若是查看,则修改提交需要访问后台 deptJson = {"list":[]}; var is_edit = false;//false表示没有正在编辑的行,true表示有一行正在编辑 var is_add = false;//是否新增 /** 私有方法* */ //导入方法 function submitInfo() { var val= $("#import_report").val(); var end = val.substring(val.indexOf(".")+1); if(end=="xls"||end=="xlsx"){ addfn(); }else{ top.Dialog.alert("请导入正确的excel文件"); return; } }; //保存 function fileToSave($form){ //showProgressBar("正在提交中..."); //表单异步提交处理 $form.ajaxSubmit({ url:$.pathname() + "/ws/importGpsUser/BaoGongDianTaskService/importBaoGongDiantask?report_type=2&taskId="+fd_id, type : 'post', success: function(responseText, statusText, xhr, $form){ //alert(responseText); responseText = eval('('+responseText+')'); _this.gridData = responseText; var data = JSON.stringify(_this.gridData); //alert(encodeURI(encodeURI(_this.gridData))); _this.listGrid.setOptions({ "data" :JSON.parse(decodeURI(data)) }); /*if(_this.gridData.rows.length <= 8){ _this.listGrid.options.height ="500px"; loadGridData(); }*/ is_import = true; is_edit = false; is_add = false; //loadGridData(); setThisHeight(); //_this.listGrid.cancelEdit(rowid); }, error : function(e) { top.Dialog.alert('导入失败!'); } }); } //导入excle function addfn() { var $form = $("#editForm"); fileToSave($form); }; //导入后保存 // 新增报表 function save() { _this.listGrid.endEdit(); var urls = $.pathname() + "/ws/importGpsUser/BaoGongDianTaskService/saveGridData"; var row = _this.listGrid.getData(); if(row==""){ top.Dialog.alert("表格中无任何数据,请重新导入!"); return; } if($(".errorData").text()!=""){ top.Dialog.alert("请修改表格中红色的错误数据后,再尝试保存!"); return; } var json=JSON.stringify(row); $.ajax({ url : urls, type : 'post', timeout : 15000, async : false, data : { json:json, user_id:user_id, comp_id : dept_id, report_type:'2', real_name:realName, task_id:fd_id, corp_name:corp_name }, dataType : 'json', success : function(data) { if(data.Msg.sucsess==true){ top.Dialog.alert("保存成功"); is_import = false; }else{ top.Dialog.alert("保存失败"); is_import = false; } loadThisGrid(); }, error : function(e) { $.messager.alert('保存失败!', '访问服务失败!', 'error'); } }); } function loadThisGrid(){ var url = $.pathname() + '/ws/crud/CRUDService/queryQui'; $.ajax({ url : url, type : 'post', async : false, data :_this.loadParams, dataType : 'json', success : function(data) { _this.listGrid.setOptions({data:data}); setThisHeight(); }, error : function(e) { $.messager.alert('保存失败!', '访问服务失败!', 'error'); } }); } function initgrid(){ $queryForm = $("#queryForm"); // 列表加载参数 _this.loadParams = { listId : '620', condition : "is_del=0 ", "TASK_ID_620":fd_id }; /** grid载入数据* */ _this.listGrid = $("#dataGrid").quiGrid({ columns : [ /*{ display : '编号', name : 'ID', hide : true }, */{ display : '保供电任务编号', name : 'GPS_TASK_NUMBER_620', align : 'center', width : 150, showTitle:true }, { display : '保供电资源投入', columns :[{ display : '应急发电车(UPS电源)', columns :[{ display : '单日最大用量/台', name : 'GPS_TASK_FDC_DAY_620', showTitle : true, width : 150, editor: { type: 'text',maxlength:6,inputMode:"numberOnly" }, render : function(rowdata, rowindex, value, column){ if(!checkName(value,"sl")){ value = value==undefined?"":value; value = "
"+value+"
"; } return value; } }, { display : '投入总量/台次', name : 'GPS_TASK__FDC_TOTAL_620', showTitle : true, width : 150, editor: { type: 'text',maxlength:6,inputMode:"numberOnly" }, render : function(rowdata, rowindex, value, column){ if(!checkName(value,"sl")){ value = value==undefined?"":value; value = "
"+value+"
"; } return value; } }] }, { display : '应急发电机(UPS电源)', columns :[{ display : '单日最大用量/台', name : 'GPS_TASK_FDJ_DAY_620', showTitle : true, width : 150, editor: { type: 'text',maxlength:6,inputMode:"numberOnly" }, render : function(rowdata, rowindex, value, column){ if(!checkName(value,"sl")){ value = value==undefined?"":value; value = "
"+value+"
"; } return value; } }, { display : '投入总量/台次', name : 'GPS_TASK_FDJ_TOTAL_620', showTitle : true, width : 150, editor: { type: 'text',maxlength:6,inputMode:"numberOnly"}, render : function(rowdata, rowindex, value, column){ if(!checkName(value,"sl")){ value = value==undefined?"":value; value = "
"+value+"
"; } return value; } }] }, { display : '车辆/辆次', name : 'GPS_TASK_CAR_620', showTitle : true, width : 150, editor: { type: 'text',maxlength:6,inputMode:"numberOnly" }, render : function(rowdata, rowindex, value, column){ if(!checkName(value,"sl")){ value = value==undefined?"":value; value = "
"+value+"
"; } return value; } }] }, { display : '保供电人员投入', columns :[{ display : '值班指挥管理人员/人日', name : 'GPS_TASK_ZBZHGLRY_620', showTitle : true, width : 150, editor: { type: 'text',maxlength:6,inputMode:"numberOnly" }, render : function(rowdata, rowindex, value, column){ if(!checkName(value,"sl")){ value = value==undefined?"":value; value = "
"+value+"
"; } return value; } }, { display : '本单位班组人员/人日', name : 'GPS_TASK_BDWBZRY_620', showTitle : true, width : 150, editor: { type: 'text',maxlength:6,inputMode:"numberOnly" }, render : function(rowdata, rowindex, value, column){ if(!checkName(value,"sl")){ value = value==undefined?"":value; value = "
"+value+"
"; } return value; } }, { display : '安保人员/人日', name : 'GPS_TASK_ABRY_620', showTitle : true, width : 150, editor: { type: 'text',maxlength:6,inputMode:"numberOnly" }, render : function(rowdata, rowindex, value, column){ if(!checkName(value,"sl")){ value = value==undefined?"":value; value = "
"+value+"
"; } return value; } }, { display : '外委生产人员/人日', name : 'GPS_TASK_WWSCRY_620', showTitle : true, width : 150, editor: { type: 'text',maxlength:6,inputMode:"numberOnly" }, render : function(rowdata, rowindex, value, column){ if(!checkName(value,"sl")){ value = value==undefined?"":value; value = "
"+value+"
"; } return value; } }] },/*{ display : '保供电任务时间', columns : [{ display : '开始日期', name : 'START_TIME_620', align : 'center', width : 220, showTitle:true },{ display : '结束日期', name : 'END_TIME_620', align : 'center', width : 180, showTitle:true },{ display : '持续时间/天', name : 'GPS_CONTINATION_TIME_620', align : 'center', width : 180, showTitle:true }] }, */{ display : '操作', align : 'center', width : 150, isSort : false, render: function (rowdata, rowindex, value) { var h = ""; if (!rowdata._editing) { h += "修改 "; h += "删除 "; } else { h += "提交 "; // h += "删除 "; h += "取消 "; } return h; } }], //url : $.pathname() + '/ws/crud/CRUDService/queryQui', //params :_this.loadParams, data:"", sortOrder : 'desc', // 排序方式 rownumbers : true, //checkbox : true, //width : '100%', height:'550px', pageSize : 10, usePager : true, percentWidthMode : true, sortName : 'UPDATEDATE_620', enabledEdit: true, clickToEdit: false, // onDblClickRow:function(rowdata, rowindex){ // beginEdit(rowindex); // }, onBeforeEdit: onBeforeEdit, onBeforeSubmitEdit: onBeforeSubmitEdit, onAfterSubmitEdit: onAfterSubmitEdit, toolbar : { items : [ { text : '新增',click : addJournaling,iconClass : 'icon_add'}] } }); //setThisHeight(); } //批量删除 function onDelete(rowidx) { if(is_edit){ top.Dialog.alert("请先完成当前记录的编辑!"); return; } _this.listGrid.select(rowidx); var rows = _this.listGrid.getSelectedRows(rowidx); var rowsLength = rows.length; if (rowsLength == 0) {//请选中要删除的记录! top.Dialog.alert("请选中要删除的记录!"); return; } var ids = ""; for ( var i = 0; i < rowsLength; i++) { ids += rows[i].FD_OBJECTID620+ ","; } if(ids=="undefined,"){ _this.listGrid.deleteSelectedRow(); loadGridData(); }else{ var url = $.pathname() +"/ws/crud/CRUDService/delete/"; var params = { objectIDs : ids, classid : 620 }; top.Dialog.confirm("确定要删除吗?|删除", function() { $.request.del(url,params,function(result){ if (result.Msg.sucsess == true) { top.Dialog.alert("删除成功!"); is_edit = false; // 刷新表格数据 loadGridData(); } else { top.Dialog.alert("删除失败!"); } }); }); } } function addJournaling(){ if(is_edit){ top.Dialog.alert("请先完成当前记录的编辑!"); return; } editingRow=0; isNew=true; var row = _this.listGrid.getRow(0); var rowData={ taskid:fd_id, real_name:realName, compId:dept_id }; var rowdata = _this.listGrid.getData(); if(rowdata.length<=8){ /*_this.listGrid.options.height = "500px"; loadGridData();*/ _this.listGrid.setOptions({"height":"500px"}); _this.listGrid.resetHeight(); setThisHeight(); } _this.listGrid .addEditRow(rowData, row, true); is_edit = true; is_add = true; } //删除 /*function onDelete(rowidx){ top.Dialog.confirm("确定要删除吗?|删除", function() { isValida = false; flag = false; endEdit(rowidx); //删除记录 var row = _this.listGrid.getRow(rowidx); //删除操作 var url = $.pathname() + "/ws/crud/CRUDService/delete/"; var params = { objectIDs : row.FD_OBJECTID_620, classid : 620, }; $.request.del(url, params, function(result) { if (result.Msg.sucsess == true) { top.Dialog.alert("删除成功!"); // 刷新表格数据 _this.listGrid.rend(); } else { top.Dialog.alert("删除失败!"); } }); _this.listGrid.deleteRow(row); }); // top.Dialog.confirm("确定要删除该记录吗?",function(){ // isValida = false; // flag = false; // endEdit(rowidx); // //删除记录 // var row = _this.listGrid.getRow(rowidx); // $.post("/qui/userdbAction.do?method=deleteUser", // {"ids":row.userId}, // function(result){ // handleResult(result); // },"json"); // //刷新表格 // loadGridData(); // }); }*/ //编辑 function beginEdit(rowid) { if(!is_edit){ var rowdata = _this.listGrid.getData(); if(rowdata.length<=8){ _this.listGrid.setOptions({ "height" :"500px" });//.options.height = "500px"; loadGridData(); setThisHeight(); } _this.listGrid.beginEdit(rowid); is_edit = true; }else{ top.Dialog.alert("请先完成当前记录的编辑!"); return; } } //取消编辑 function cancelEdit(rowid) { if(is_add){//如果是新增的那一行,则直接调删除的方法 _this.listGrid.select(rowid); _this.listGrid.deleteSelectedRow(); loadGridData(); }else{ _this.listGrid.cancelEdit(rowid); } is_edit = false; is_add = false; } //结束编辑 function endEdit(rowid) { _this.listGrid.endEdit(rowid); is_edit = false; is_add = false; } //将row JSON对象转化为bo对象 function rowToBO(row) { var params = row.FD_OBJECTID_620+'&'+row.BGD_DW_620+'&' +row.MAN_COUNT_620+'&'+row.CAR_COUNT_620+'&'+ +row.BGD_FDC_620+'&'+row.BGD_FDJ_620+'&'+ realName+'&'+dept_id+'&'+ row.XINGHAO_620+'&'+row.RONGLIANG_620+'&'+ row.CHANJIA_620+'&'+row.QTZHUNGBEI_620; return params; } //删除后的提示 function handleResult(result){ if(result == 1){ top.Dialog.alert("删除成功!",null,null,null,1); loadGridData(); }else{ top.Dialog.alert("删除失败!"); } } //全部确认修改 function endAllEdit(){ _this.listGrid.endEdit(); is_edit = false; } //全部取消修改 function cancelAllEdit() { _this.listGrid.cancelEdit(); is_edit = false; } //编辑前事件 function onBeforeEdit(e) { var str="编辑前事件,可阻止某些行或列进行编辑。列名:"+e.column.name+";行号:"+e.rowindex+";编辑前的值:"+e.value+"\n"; //if(e.record.id=="121"){ //top.Dialog.alert("此行不可编辑",null,null,null,2); // return false; //} } //编辑提交前事件 function onBeforeSubmitEdit(e){ var ee = e.newdata; if(!is_edit){ return false; } } function checkDept(value,rowindex){ var flag = false; for (var i = 0; i < deptJson["list"].length; i++) { if (deptJson["list"][i]['value'] == value){ flag = true; break; } } /*if(!flag){ if(rowindex){ top.Dialog.alert("第"+(rowindex+1)+"行数据‘单位’没在该任务保供电责任单位中!"); } }*/ return flag; } //编辑后事件 function onAfterSubmitEdit(e) { if(is_import){//如果是导入还未保存 return ; } // 在这里一律作修改处理 var rowData = e.newdata; rowData.classid = "620"; rowData.FD_OBJECTID620 = e.record.FD_OBJECTID620; rowData.INPUT_UNIT_620 = dept_id; rowData.INPUT_USER_620 = realName; rowData.TASK_ID_620 = fd_id; //ajax方式提交数据到数据库 //var _url = $.pathname() + '/ws/importGpsUser/BaoGongDianTaskService/saveZiYuanBaoBiao'; var _url = $.pathname() + '/ws/crud/CRUDService/create/'; if(e.record.FD_OBJECTID620){ _url = $.pathname() + '/ws/crud/CRUDService/update/'; } $.ajax({ url : _url, type : 'post', async : false, data : rowData, dataType : 'json', success : function(data) { top.Dialog.alert(data.Msg.info); loadGridData(); }, error : function(e) { top.Dialog.alert('保存失败!', '访问服务失败!', 'error'); } }); //var row =certInfoGrid.getRow(e.rowindex); //$.post("/material/certInfo/saveCertInfo.do?",rowToBO(row),function(){},"json"); } $(function() { //getDeptMsgByTaskId(); $("#import_gpsUser").live("click",submitInfo); $("#save").live("click",save); initgrid(); loadGridData(); $("#export_btn").bind("click",exportData); }); function loadGridData(){ var _url = $.pathname() + '/ws/crud/CRUDService/queryQui'; _this.loadParams = { listId : '620', condition : "is_del=0 and TASK_ID='"+fd_id+"'", "TASK_ID_620":fd_id }; $.ajax({ url : _url, type : 'post', data : _this.loadParams, dataType : 'json', success : function(data) { if(data.rows.length==0){ data.rows = [{aa:""}]; } _this.listGrid.setOptions({data:data}); _this.listGrid.loadData(); }, error : function(e) { //$.messager.alert('保存失败!', '访问服务失败!', 'error'); top.Dialog.alert('访问服务失败!'); } }); } //导出 function exportData(){ excelExport( 620, {condition:"is_del=0 and TASK_ID='"+fd_id+"'"}, "保供电任务报表", "FD_OBJECTID,INPUT_UNIT_ID,INPUT_UNIT_NAME,INPUT_NAME,INPUT_NAME_ID,START_TIME,END_TIME,UPDATEDATE,INPUT_TIME,IS_DEL,ISSUE_TIME,ISSUE_DEPT,GPS_CONTINATION_TIME,TASK_ID", "保供电任务报表", "gps" ); }; /*** * 通过任务id查询出保供电责任单位的单位及id */ function getDeptMsgByTaskId(){ var _url = $.pathname() + '/ws/importGpsUser/BaoGongDianTaskService/getDeptMsgByTaskId'; $.ajax({ url : _url, type : 'post', async : false, data : {TaskId:fd_id}, dataType : 'text', success : function(data) { data = eval('('+data+')'); var deptArr = data[0].GPS_AREA_NAME; deptArr = deptArr.split(","); for (var i = 0; i < deptArr.length; i++) { deptJson.list.push({"key":deptArr[i],"value":deptArr[i]}); } }, error : function(e) { $.messager.alert('保存失败!', '访问服务失败!', 'error'); } }); } //检查数据格式是否正确 function checkName(data,type){ var flag = true; var c = ""; if(type=="rm"){//人名 checkRex = /^[\u4e00-\u9fa5]{1,5}$/; }else if(type=="dh"){//电话 //checkRex = /^1{1}[0,9]{10}$/; checkRex = /^(\+\d{2,3}\-)?\d{11}$/; }else if(type=="sj"){//时间 checkRex = /^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))\\s{1}[0-5]{1}[0-9]{1}\\:[0-5]{1}[0-9]{1}$/; }else if(type=="sl"){//数量 checkRex = /^[0-9]{1,5}$/; } if(type=="zbfs"){//值班方式 if(data=='在岗值班' || data=='电话值班' || data=='应急指挥中心值班'){ flag = true; }else{ flag = false; } }else if(type=="zf"){//字符 checkRex = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()|{}【】‘;:”“'。,、?]"); if(checkRex.test(data)){ flag=false; } }else if(!checkRex.test(data)){ flag = false; } return flag; } function setThisHeight(){ $("#formContent").height($(".box_middleright").height()); $(parent.document.body).find("iframe").height($(window.document.body).height()+30); $(top.document.body).find("iframe").height($(parent.document.body).height()); }