123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428 |
- // 部门id
- var dpids = top.com.sinosoft.lz.system.user.LoginInfo.getDeptids();
- //取得用户真实姓名
- var realname = top.com.sinosoft.lz.system.user.LoginInfo.getReal_name();
- //部门名称
- var deptName = top.com.sinosoft.lz.system.user.LoginInfo.getDeptnames();
- //父部门id
- var parentId = top.com.sinosoft.lz.system.user.LoginInfo.getParent_ids();
- //部门id
- var deptId = top.com.sinosoft.lz.system.user.LoginInfo.getDeptids();
- var userId = top.com.sinosoft.lz.system.user.LoginInfo.getUser_id();
- var role_id = top.com.sinosoft.lz.system.user.LoginInfo.getRoleids();
- var flag = false;
- var isNew = false; //是否是新增记录
- var editingRow; // 双击的当前编辑行
- var isValida = true; //是否需要验证
- var test3= /^\d+[\u4e00-\u9fa5]+$/;
- var test1 = /^\d+\w+/;
- var test2 = /^\d+/;
- var pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?-]");
- var g;
- var deptData = {"list" : []};
-
-
- var xtyx={"value" : "R002105430210","key" : "系统运行部"};
- var aqjg={"value" : "R002105430213","key" : "安全监管部"};
- var sbgl={"value" : "R002105430211","key" : "生产设备部"};
- var scyx={"value" : "R002105430212","key" : "市场营销部"};
- var isCount = {"list":[
- {"value":"0","key":"该字段既统计又要输入数字"},
- {"value":"1","key":"该字段不统计但要输入数字"},
- {"value":"2","key":"该字段既不统计又不要输入数字"},
- {"value":"3","key":"该字段需要日期统计"}]};
-
- function initComplete() {
- initGrid();
- var row = g.getRow(0);
- g.deleteRow(row);
-
- var tableType = {"list":[
- {"value":"0","key":"统计型报表"},
- {"value":"1","key":"明细型报表"}
- ]};
-
-
- $("#TABLE_TYPE").data("data",tableType);
- $("#TABLE_TYPE").render();
- var role =getUserRoleIdArr(role_id);
- if($.inArray("R002105430205",role)!=-1||$.inArray("R002105430210",role)!=-1){
- deptData.list.push(xtyx,aqjg,sbgl,scyx);
- }
-
- $("#DEPT_NAME").data('data',deptData);
- $("#DEPT_NAME").render();
-
-
- $("#tableName").on("blur",function(){
-
- var _this = $(this);
- var roleVal = $("#DEPT_NAME");
- checkTableName(_this,roleVal);
- });
-
-
- $("#tableName").on("click",function(){
- var _this = $(this);
-
- if(_this.hasClass("error")){
- $("#errMsg").hide();
- _this.removeClass("error");
- }
- });
-
-
- $("#DEPT_NAME").on("change",function(){
- var tableObj = $("#tableName");
- var tableName = tableObj.val().trim();
- var _this = $(this);
- if(tableObj.hasClass("error")){
- tableObj.removeClass("error");
- $("#errMsg").hide();
- }
- if(tableName!=""){
- checkTableName(tableObj,_this);
- }
-
-
- });
- }
-
- function initGrid() {
- //获得值班人员
- g = $("#maingrid").quiGrid({
- columns : [
- {display : '一级表头', name : 'TABLE_HEAD',align : 'center',width : "20%", editor : {type : 'text',maxlength:'20'}},
- {display : '字段名', name : 'COLUMN_NAME',align : 'center',width : "20%", editor : {type : 'text',maxlength:'20'}},
- {display : '统计类型', name : 'IS_COUNT',align : 'center',width : "20%",editor : {type : 'select',data : isCount,selWidth : 225},
- render : function(item) {
- for (var i = 0; i < isCount["list"].length; i++) {
- if (isCount["list"][i]['value'] == item.IS_COUNT)
- return isCount["list"][i]['key'];
- }
- return item.IS_COUNT;
- }
-
- },
- {display : '长度', name : 'LENGTH',align : 'center',width : "20%", editor : {type : 'text',maxlength : '11',inputMode : 'numberOnly',tip : '只能输入数字'}},
- {display : '操作',isSort : false,width : "20%", render : function(rowdata, rowindex, value) {
- var h = "";
- if (!rowdata._editing) {
- flag = false;
- h += "<a onclick='onDelete(" + rowindex + ")'><span class='icon_delete'>删除</span></a> ";
- } else {
- flag = true;
- h += "<a onclick='endEdit(" + rowindex + ")'><span class='icon_ok'>确认</span></a> ";
- h += "<a onclick='onDelete(" +rowindex+","+rowdata._editing+")'><span class='icon_delete'>取消</span></a> ";
- }
- return h;
- }
- } ],
-
- data:{"rows":[{
-
- }]},
- rownumbers : true,
- usePager : false,
- percentWidthMode : true,
- height : '600',
- width : '100%',
- enabledEdit : true,
- clickToEdit : false,
- onDblClickRow : function(rowdata, rowindex) {
- if (flag) {
- top.Dialog.alert("请先完成当前记录的编辑!");
- return;
- }
- g.beginEdit(rowindex);
- },
- onBeforeSubmitEdit : onBeforeSubmitEdit,
- onAfterSubmitEdit : onAfterSubmitEdit,
- toolbar : {
- items : [ { text : '新增',click : addUser,iconClass : 'icon_add'},
- { line : true }]
- }
- });
- }
- //删除
- function onDelete(rowidx,edit) {
- var newAddData = g.getAdded();
-
- //没确认和按删除
- if((rowidx==0&&newAddData[0]["_editing"]&&newAddData[0]["COLUMN_NAME"]==undefined)||edit==undefined){
- top.Dialog.confirm("确定要删除该记录吗?", function() {
- isValida = false;
- flag = false;
- g.endEdit(rowidx);
- //删除记录
-
- var row = g.getRow(rowidx);
-
- g.deleteRow(row);
-
- });
-
- }else{
-
- cancelEdit(rowidx);
-
- }
-
- }
- //编辑
- function beginEdit(rowid) {
- g.beginEdit(rowid);
- }
- //取消编辑
- function cancelEdit(rowid) {
- g.cancelEdit(rowid);
- }
- //结束编辑
- function endEdit(rowid) {
- editingRow = '';
- var getNewData = g.getAdded();
- var rowData = g.getRow(rowid);
-
- var tableHead = $("#maingrid .textinput").eq(0).val();
- var columnName = $("#maingrid .textinput").eq(1).val();
- var checkColumn = $.checkColumnName(getNewData,"TABLE_HEAD",tableHead,"COLUMN_NAME",columnName);
- if(checkColumn || rowData["TABLE_HEAD"]==tableHead&&rowData["COLUMN_NAME"]==columnName){
- g.endEdit(rowid);
- }else{
- top.Dialog.alert("此表头下的字段名已存在,请另起字段名");
- }
- }
- function addUser(){
- if(flag){
- top.Dialog.alert("请先完成当前记录的编辑!");
- return;
- }
- editingRow=0;
- isNew=true;
- var row = g.getRow(0);
- var rowData={
- duty_way:0
- };
-
- g.addEditRow(rowData, row, true);
-
- }
-
- //全部确认修改
- function endAllEdit() {
- g.endEdit();
- }
- //全部取消修改
- function cancelAllEdit() {
- g.cancelEdit();
- }
- //编辑提交前事件
- function onBeforeSubmitEdit(e) {
- if(isValida){
-
- if(pattern.test(e.newdata.TABLE_HEAD)){
-
- top.Dialog.alert("表头不能含有特殊字符");
- return false;
- }
-
- if(test1.test(e.newdata.COLUMN_NAME)||test2.test(e.newdata.COLUMN_NAME)||test3.test(e.newdata.COLUMN_NAME)){
- top.Dialog.alert("字段名不能全是数字或以数字开头");
- return false;
- }
-
- if (e.newdata.COLUMN_NAME == "" || validateInput(e.newdata.COLUMN_NAME, "^[\" \"]+$")) {
- top.Dialog.alert("字段名不能为空!");
- return false;
- }
- if(pattern.test(e.newdata.COLUMN_NAME)){
- top.Dialog.alert("字段名不能含有特殊字符!");
- return false;
- }
- if (e.newdata.IS_COUNT == "") {
- top.Dialog.alert("统计类型不能为空!");
- return false;
- }
- if (e.newdata.LENGTH == "" || validateInput(e.newdata.LENGTH, "^[\" \"]+$")) {
- top.Dialog.alert("长度不能为空!");
- return false;
- }
-
- if(pattern.test(e.newdata.LENGTH)){
- top.Dialog.alert("长度不能含有特殊字符");
- return false;
- }
- var len = parseInt(e.newdata.LENGTH);
- if(len<1||len>6000){
- top.Dialog.alert("长度要在0到6000之间");
- return false;
- }
- }
- isValida = true;
- }
- //编辑后事件
- function onAfterSubmitEdit(e) {
- isNew = false;
- }
-
- //保存方法bg
- function saveTable() {
- var tableName = $("#tableName");
-
-
- if(flag){
- top.Dialog.alert("请先完成当前记录的编辑!");
- return;
- }
- var newTableName = tableName.val().trim();
- var deptObj = $("#DEPT_NAME");
- var dept = deptObj.attr("relvalue");
- var tableType = $("#TABLE_TYPE").attr("relvalue");
- if(pattern.test(newTableName)){
- top.Dialog.alert("新增表名不能含有特殊字符");
- return;
- }
-
- if(dept==""||dept==undefined||dept=="undefined"){
- top.Dialog.alert("请选择填报部门");
- return;
- }
- if(tableType==""||tableType==undefined||tableType=="undefined"){
- top.Dialog.alert("报表类型不能为空");
- return;
- }
- if(newTableName==""){
- top.Dialog.alert("新增表名不能为空");
- return ;
- }
- var newData =g.getAdded();
- if(newData.length==0&&newTableName!=""){
- top.Dialog.alert("请添加表格的内容后再保存");
- return;
- }
-
- checkTableName(tableName,deptObj);
-
- if(!$("#errMsg").is(":hidden")){
- top.Dialog.alert( deptObj.attr("relText")+"下的此表名已存在,请另起表名或另选部门");
- return;
- }
-
-
-
- var by1=new BeiYong("","COLUMN_1","2","500");
- var by2=new BeiYong("","COLUMN_2","2","500");
- var by3=new BeiYong("","COLUMN_3","2","500");
- var by4=new BeiYong("","COLUMN_4","2","500");
- var by5=new BeiYong("","COLUMN_5","2","500");
- var by6=new BeiYong("","COLUMN_6","2","500");
- var objArr= g.getData();
- objArr.push(by1,by2,by3,by4,by5,by6);
- var data = JSON.stringify(objArr);
- /* return;*/
- $("body").eq(0).showLoading();
- $.ajax({
- url : $.pathname()+ "/ws/newTable/NewTableService/CreateTable",
- type : 'post',
- data : {
- json:data,
- table:newTableName,
- role:dept,
- deptName:$("#DEPT_NAME").attr("reltext"),
- tableType:tableType
- },
- dataType : 'json',
- timeout : 60000,
- success : function(data){
- $("body").eq(0).hideLoading();
- if(data.Msg.sucsess==true){
- top.Dialog.alert("新增成功");
- goback();
- }else{
- top.Dialog.alert("新增失败");
- }
-
- },
- error : function(){
- top.Dialog.alert('操作失败');
- }
- });
- }
- function clear_msg() {
- top.Dialog.confirm("确定要重置?将会清空填写的数据,请慎重选择|重置",function(){
- if(flag){
- top.Dialog.alert("当前存在在编辑的记录,不能重置");
- return;
- }
-
- $("#tableName").val("");
- $("#tableName").removeClass("error");
- $("#errMsg").hide();
- $("#DEPT_NAME").render();
- $("#TABLE_TYPE").render();
- var len = g.getAdded().length;
- if(len!=0){
- for(var i=0;i<len;i++){
- var row = g.getRow(0);
- g.deleteRow(row);
- }
-
- }
-
-
- });
- }
-
- function goback(){
- var iframe = parent.document.getElementsByName("frmright")[0];
- iframe.src = "/nwyj/page/business/em/report/report_model.jsp";
- }
-
-
-
- window.onload = function(){
- $(".selectbox").attr("readonly","readonly");
- };
-
- var BeiYong = function(TABLE_HEAD,COLUMN_NAME,IS_COUNT,LENGTH){
- this.TABLE_HEAD = TABLE_HEAD;
- this.COLUMN_NAME = COLUMN_NAME;
- this.IS_COUNT = IS_COUNT;
- this.LENGTH = LENGTH;
- };
-
-
- function checkTableName(tabObj,roleObj){
- var _this = tabObj;
- var tableName = _this.val().trim();
- var roleVal = roleObj.val();
- if(tableName!=""&& deptName!=""){
- var count = getThing($.pathname()+ "/ws/newTable/NewTableService/checkTableName",{"type":"yj","tableName":tableName,"roleId":roleVal},"text");
- if(count!=0){
-
- $("#errMsg").text(roleObj.attr("relText")+"下的此表名已存在").show();
- _this.addClass("error");
- }
-
- }
- }
|