0f16990d96141b56c5516d30aaebfb4fcc264c3e.svn-base 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. // 部门id
  2. var dpids = top.com.sinosoft.lz.system.user.LoginInfo.getDeptids();
  3. //取得用户真实姓名
  4. var realname = top.com.sinosoft.lz.system.user.LoginInfo.getReal_name();
  5. //部门名称
  6. var deptName = top.com.sinosoft.lz.system.user.LoginInfo.getDeptnames();
  7. //父部门id
  8. var parentId = top.com.sinosoft.lz.system.user.LoginInfo.getParent_ids();
  9. //部门id
  10. var deptId = top.com.sinosoft.lz.system.user.LoginInfo.getDeptids();
  11. var userId = top.com.sinosoft.lz.system.user.LoginInfo.getUser_id();
  12. var role_id = top.com.sinosoft.lz.system.user.LoginInfo.getRoleids();
  13. var flag = false;
  14. var isNew = false; //是否是新增记录
  15. var editingRow; // 双击的当前编辑行
  16. var isValida = true; //是否需要验证
  17. var test3= /^\d+[\u4e00-\u9fa5]+$/;
  18. var test1 = /^\d+\w+/;
  19. var test2 = /^\d+/;
  20. var pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?-]");
  21. var g;
  22. var deptData = {"list" : []};
  23. var xtyx={"value" : "R002105430210","key" : "系统运行部"};
  24. var aqjg={"value" : "R002105430213","key" : "安全监管部"};
  25. var sbgl={"value" : "R002105430211","key" : "生产设备部"};
  26. var scyx={"value" : "R002105430212","key" : "市场营销部"};
  27. var isCount = {"list":[
  28. {"value":"0","key":"该字段既统计又要输入数字"},
  29. {"value":"1","key":"该字段不统计但要输入数字"},
  30. {"value":"2","key":"该字段既不统计又不要输入数字"},
  31. {"value":"3","key":"该字段需要日期统计"}]};
  32. function initComplete() {
  33. initGrid();
  34. var row = g.getRow(0);
  35. g.deleteRow(row);
  36. var tableType = {"list":[
  37. {"value":"0","key":"统计型报表"},
  38. {"value":"1","key":"明细型报表"}
  39. ]};
  40. $("#TABLE_TYPE").data("data",tableType);
  41. $("#TABLE_TYPE").render();
  42. var role =getUserRoleIdArr(role_id);
  43. if($.inArray("R002105430205",role)!=-1||$.inArray("R002105430210",role)!=-1){
  44. deptData.list.push(xtyx,aqjg,sbgl,scyx);
  45. }
  46. $("#DEPT_NAME").data('data',deptData);
  47. $("#DEPT_NAME").render();
  48. $("#tableName").on("blur",function(){
  49. var _this = $(this);
  50. var roleVal = $("#DEPT_NAME");
  51. checkTableName(_this,roleVal);
  52. });
  53. $("#tableName").on("click",function(){
  54. var _this = $(this);
  55. if(_this.hasClass("error")){
  56. $("#errMsg").hide();
  57. _this.removeClass("error");
  58. }
  59. });
  60. $("#DEPT_NAME").on("change",function(){
  61. var tableObj = $("#tableName");
  62. var tableName = tableObj.val().trim();
  63. var _this = $(this);
  64. if(tableObj.hasClass("error")){
  65. tableObj.removeClass("error");
  66. $("#errMsg").hide();
  67. }
  68. if(tableName!=""){
  69. checkTableName(tableObj,_this);
  70. }
  71. });
  72. }
  73. function initGrid() {
  74. //获得值班人员
  75. g = $("#maingrid").quiGrid({
  76. columns : [
  77. {display : '一级表头', name : 'TABLE_HEAD',align : 'center',width : "20%", editor : {type : 'text',maxlength:'20'}},
  78. {display : '字段名', name : 'COLUMN_NAME',align : 'center',width : "20%", editor : {type : 'text',maxlength:'20'}},
  79. {display : '统计类型', name : 'IS_COUNT',align : 'center',width : "20%",editor : {type : 'select',data : isCount,selWidth : 225},
  80. render : function(item) {
  81. for (var i = 0; i < isCount["list"].length; i++) {
  82. if (isCount["list"][i]['value'] == item.IS_COUNT)
  83. return isCount["list"][i]['key'];
  84. }
  85. return item.IS_COUNT;
  86. }
  87. },
  88. {display : '长度', name : 'LENGTH',align : 'center',width : "20%", editor : {type : 'text',maxlength : '11',inputMode : 'numberOnly',tip : '只能输入数字'}},
  89. {display : '操作',isSort : false,width : "20%", render : function(rowdata, rowindex, value) {
  90. var h = "";
  91. if (!rowdata._editing) {
  92. flag = false;
  93. h += "<a onclick='onDelete(" + rowindex + ")'><span class='icon_delete'>删除</span></a> ";
  94. } else {
  95. flag = true;
  96. h += "<a onclick='endEdit(" + rowindex + ")'><span class='icon_ok'>确认</span></a> ";
  97. h += "<a onclick='onDelete(" +rowindex+","+rowdata._editing+")'><span class='icon_delete'>取消</span></a> ";
  98. }
  99. return h;
  100. }
  101. } ],
  102. data:{"rows":[{
  103. }]},
  104. rownumbers : true,
  105. usePager : false,
  106. percentWidthMode : true,
  107. height : '600',
  108. width : '100%',
  109. enabledEdit : true,
  110. clickToEdit : false,
  111. onDblClickRow : function(rowdata, rowindex) {
  112. if (flag) {
  113. top.Dialog.alert("请先完成当前记录的编辑!");
  114. return;
  115. }
  116. g.beginEdit(rowindex);
  117. },
  118. onBeforeSubmitEdit : onBeforeSubmitEdit,
  119. onAfterSubmitEdit : onAfterSubmitEdit,
  120. toolbar : {
  121. items : [ { text : '新增',click : addUser,iconClass : 'icon_add'},
  122. { line : true }]
  123. }
  124. });
  125. }
  126. //删除
  127. function onDelete(rowidx,edit) {
  128. var newAddData = g.getAdded();
  129. //没确认和按删除
  130. if((rowidx==0&&newAddData[0]["_editing"]&&newAddData[0]["COLUMN_NAME"]==undefined)||edit==undefined){
  131. top.Dialog.confirm("确定要删除该记录吗?", function() {
  132. isValida = false;
  133. flag = false;
  134. g.endEdit(rowidx);
  135. //删除记录
  136. var row = g.getRow(rowidx);
  137. g.deleteRow(row);
  138. });
  139. }else{
  140. cancelEdit(rowidx);
  141. }
  142. }
  143. //编辑
  144. function beginEdit(rowid) {
  145. g.beginEdit(rowid);
  146. }
  147. //取消编辑
  148. function cancelEdit(rowid) {
  149. g.cancelEdit(rowid);
  150. }
  151. //结束编辑
  152. function endEdit(rowid) {
  153. editingRow = '';
  154. var getNewData = g.getAdded();
  155. var rowData = g.getRow(rowid);
  156. var tableHead = $("#maingrid .textinput").eq(0).val();
  157. var columnName = $("#maingrid .textinput").eq(1).val();
  158. var checkColumn = $.checkColumnName(getNewData,"TABLE_HEAD",tableHead,"COLUMN_NAME",columnName);
  159. if(checkColumn || rowData["TABLE_HEAD"]==tableHead&&rowData["COLUMN_NAME"]==columnName){
  160. g.endEdit(rowid);
  161. }else{
  162. top.Dialog.alert("此表头下的字段名已存在,请另起字段名");
  163. }
  164. }
  165. function addUser(){
  166. if(flag){
  167. top.Dialog.alert("请先完成当前记录的编辑!");
  168. return;
  169. }
  170. editingRow=0;
  171. isNew=true;
  172. var row = g.getRow(0);
  173. var rowData={
  174. duty_way:0
  175. };
  176. g.addEditRow(rowData, row, true);
  177. }
  178. //全部确认修改
  179. function endAllEdit() {
  180. g.endEdit();
  181. }
  182. //全部取消修改
  183. function cancelAllEdit() {
  184. g.cancelEdit();
  185. }
  186. //编辑提交前事件
  187. function onBeforeSubmitEdit(e) {
  188. if(isValida){
  189. if(pattern.test(e.newdata.TABLE_HEAD)){
  190. top.Dialog.alert("表头不能含有特殊字符");
  191. return false;
  192. }
  193. if(test1.test(e.newdata.COLUMN_NAME)||test2.test(e.newdata.COLUMN_NAME)||test3.test(e.newdata.COLUMN_NAME)){
  194. top.Dialog.alert("字段名不能全是数字或以数字开头");
  195. return false;
  196. }
  197. if (e.newdata.COLUMN_NAME == "" || validateInput(e.newdata.COLUMN_NAME, "^[\" \"]+$")) {
  198. top.Dialog.alert("字段名不能为空!");
  199. return false;
  200. }
  201. if(pattern.test(e.newdata.COLUMN_NAME)){
  202. top.Dialog.alert("字段名不能含有特殊字符!");
  203. return false;
  204. }
  205. if (e.newdata.IS_COUNT == "") {
  206. top.Dialog.alert("统计类型不能为空!");
  207. return false;
  208. }
  209. if (e.newdata.LENGTH == "" || validateInput(e.newdata.LENGTH, "^[\" \"]+$")) {
  210. top.Dialog.alert("长度不能为空!");
  211. return false;
  212. }
  213. if(pattern.test(e.newdata.LENGTH)){
  214. top.Dialog.alert("长度不能含有特殊字符");
  215. return false;
  216. }
  217. var len = parseInt(e.newdata.LENGTH);
  218. if(len<1||len>6000){
  219. top.Dialog.alert("长度要在0到6000之间");
  220. return false;
  221. }
  222. }
  223. isValida = true;
  224. }
  225. //编辑后事件
  226. function onAfterSubmitEdit(e) {
  227. isNew = false;
  228. }
  229. //保存方法bg
  230. function saveTable() {
  231. var tableName = $("#tableName");
  232. if(flag){
  233. top.Dialog.alert("请先完成当前记录的编辑!");
  234. return;
  235. }
  236. var newTableName = tableName.val().trim();
  237. var deptObj = $("#DEPT_NAME");
  238. var dept = deptObj.attr("relvalue");
  239. var tableType = $("#TABLE_TYPE").attr("relvalue");
  240. if(pattern.test(newTableName)){
  241. top.Dialog.alert("新增表名不能含有特殊字符");
  242. return;
  243. }
  244. if(dept==""||dept==undefined||dept=="undefined"){
  245. top.Dialog.alert("请选择填报部门");
  246. return;
  247. }
  248. if(tableType==""||tableType==undefined||tableType=="undefined"){
  249. top.Dialog.alert("报表类型不能为空");
  250. return;
  251. }
  252. if(newTableName==""){
  253. top.Dialog.alert("新增表名不能为空");
  254. return ;
  255. }
  256. var newData =g.getAdded();
  257. if(newData.length==0&&newTableName!=""){
  258. top.Dialog.alert("请添加表格的内容后再保存");
  259. return;
  260. }
  261. checkTableName(tableName,deptObj);
  262. if(!$("#errMsg").is(":hidden")){
  263. top.Dialog.alert( deptObj.attr("relText")+"下的此表名已存在,请另起表名或另选部门");
  264. return;
  265. }
  266. var by1=new BeiYong("","COLUMN_1","2","500");
  267. var by2=new BeiYong("","COLUMN_2","2","500");
  268. var by3=new BeiYong("","COLUMN_3","2","500");
  269. var by4=new BeiYong("","COLUMN_4","2","500");
  270. var by5=new BeiYong("","COLUMN_5","2","500");
  271. var by6=new BeiYong("","COLUMN_6","2","500");
  272. var objArr= g.getData();
  273. objArr.push(by1,by2,by3,by4,by5,by6);
  274. var data = JSON.stringify(objArr);
  275. /* return;*/
  276. $("body").eq(0).showLoading();
  277. $.ajax({
  278. url : $.pathname()+ "/ws/newTable/NewTableService/CreateTable",
  279. type : 'post',
  280. data : {
  281. json:data,
  282. table:newTableName,
  283. role:dept,
  284. deptName:$("#DEPT_NAME").attr("reltext"),
  285. tableType:tableType
  286. },
  287. dataType : 'json',
  288. timeout : 60000,
  289. success : function(data){
  290. $("body").eq(0).hideLoading();
  291. if(data.Msg.sucsess==true){
  292. top.Dialog.alert("新增成功");
  293. goback();
  294. }else{
  295. top.Dialog.alert("新增失败");
  296. }
  297. },
  298. error : function(){
  299. top.Dialog.alert('操作失败');
  300. }
  301. });
  302. }
  303. function clear_msg() {
  304. top.Dialog.confirm("确定要重置?将会清空填写的数据,请慎重选择|重置",function(){
  305. if(flag){
  306. top.Dialog.alert("当前存在在编辑的记录,不能重置");
  307. return;
  308. }
  309. $("#tableName").val("");
  310. $("#tableName").removeClass("error");
  311. $("#errMsg").hide();
  312. $("#DEPT_NAME").render();
  313. $("#TABLE_TYPE").render();
  314. var len = g.getAdded().length;
  315. if(len!=0){
  316. for(var i=0;i<len;i++){
  317. var row = g.getRow(0);
  318. g.deleteRow(row);
  319. }
  320. }
  321. });
  322. }
  323. function goback(){
  324. var iframe = parent.document.getElementsByName("frmright")[0];
  325. iframe.src = "/nwyj/page/business/em/report/report_model.jsp";
  326. }
  327. window.onload = function(){
  328. $(".selectbox").attr("readonly","readonly");
  329. };
  330. var BeiYong = function(TABLE_HEAD,COLUMN_NAME,IS_COUNT,LENGTH){
  331. this.TABLE_HEAD = TABLE_HEAD;
  332. this.COLUMN_NAME = COLUMN_NAME;
  333. this.IS_COUNT = IS_COUNT;
  334. this.LENGTH = LENGTH;
  335. };
  336. function checkTableName(tabObj,roleObj){
  337. var _this = tabObj;
  338. var tableName = _this.val().trim();
  339. var roleVal = roleObj.val();
  340. if(tableName!=""&& deptName!=""){
  341. var count = getThing($.pathname()+ "/ws/newTable/NewTableService/checkTableName",{"type":"yj","tableName":tableName,"roleId":roleVal},"text");
  342. if(count!=0){
  343. $("#errMsg").text(roleObj.attr("relText")+"下的此表名已存在").show();
  344. _this.addClass("error");
  345. }
  346. }
  347. }