measuretarget.jsp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
  2. <%@include file="/pages/includes/taglibs.jsp" %>
  3. <head>
  4. <script type="text/javascript" src="<%=request.getContextPath() %>/resource/js/jquery-1.8.3.js"></script>
  5. <script type="text/ecmascript" src="<%=request.getContextPath() %>/resource/plugin/jqgrid/js/jquery.jqGrid.min.js"></script>
  6. <script type="text/ecmascript" src="<%=request.getContextPath() %>/resource/plugin/jqgrid/js/i18n/grid.locale-cn.js"></script>
  7. <script type="text/ecmascript" src="<%=request.getContextPath()%>/resource/js/system/jqdatagridpage.js"></script><script src="<%=request.getContextPath()%>/resource/js/datePicker/WdatePicker.js" type="text/javascript"></script>
  8. <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/resource/plugin/jqueryui/css/custom-theme/jquery-ui-1.9.2.custom.css" />
  9. <link rel="stylesheet" type="text/css" media="screen" href="<%=request.getContextPath() %>/resource/plugin/jqgrid/css/ui.jqgrid.css" />
  10. <script type="text/javascript">
  11. function queryData(){
  12. // 编码
  13. var targetCode = $("#targetCode").val();
  14. // 名称
  15. var targetName = $("#targetName").val();
  16. // 指标体系ID
  17. var tid = $("#tid").val();
  18. jQuery("#gridTable").jqGrid('setGridParam',{url:encodeURI(encodeURI("/singleMachineAnalysis/measureAnalysisTargetMainList.action?targetName="+targetName+"&targetCode="+targetCode+"&tid="+tid))}).trigger("reloadGrid");
  19. }
  20. function queryClear(){
  21. $("#targetCode").val("");
  22. $("#targetName").val("");
  23. }
  24. // 返回主页
  25. function returnAction(){
  26. var targetCodeQS = $("#targetCodeQS").val();
  27. var targetNameQS = $("#targetNameQS").val();
  28. $("#f1").attr("action",encodeURI(encodeURI("/singleMachineAnalysis/singleMachineAnalysisMain.action?targetCodeQS=" + targetCodeQS + "&targetNameQS=" + targetNameQS)));
  29. $("#f1").submit();
  30. }
  31. $(function(){
  32. showJqGrid();
  33. $("#addBtn").click(function() {
  34. jQuery("#gridTable").jqGrid('editGridRow', "new", {
  35. height : 400,
  36. reloadAfterSubmit : false
  37. });
  38. });
  39. });
  40. // 加载jqgrid表格
  41. function showJqGrid(){
  42. // 指标体系ID
  43. var tid = $("#tid").val();
  44. jQuery("#gridTable").jqGrid({
  45. url:encodeURI('/singleMachineAnalysis/measureAnalysisTargetMainList.action?tid='+tid),
  46. datastr: 'data.json',
  47. datatype: "json",
  48. colNames:['编号', '编码','名称', '别名','分类','权重','公式','公式描述','来源表','来源字段','sql条件','操作'],
  49. colModel:[
  50. { name: 'id', index: 'id', width: 200, align: 'center', hidden: true},
  51. { name: 'targetCode', index: 'targetCode', width: 200, align: 'center',editable : true,editoptions : {size : 25}},
  52. { name: 'name', index: 'name', width: 200, align: 'center',editable : true,editoptions : {size : 25}},
  53. { name: 'aname', index: 'aname', width: 200, align: 'center',editable : true,editoptions : {size : 25}},
  54. { name: 'cid', index: 'cid', width: 200, align: 'center',editable : true,edittype : "select",editoptions : {value : "${analysisClassSelect}"}},
  55. { name: 'wid', index: 'wid', width: 200, align: 'center',editable : true,edittype : "select",editoptions : {value : "${analysisWeightSelect}"}},
  56. { name: 'formula', index: 'formula', width: 200, align: 'center',editable : true,editoptions : {size : 25}},
  57. { name: 'formuladesc', index: 'formuladesc', width: 200, align: 'center',editable : true,editoptions : {size : 25}},
  58. { name: 'datasourcestable', index: 'datasourcestable', width: 200, align: 'center',editable : true,editoptions : {size : 25}},
  59. { name: 'datasourcesfield', index: 'datasourcesfield', width: 200, align: 'center',editable : true,editoptions : {size : 25}},
  60. { name: 'datasourcewhere', index: 'datasourcewhere', width: 200, align: 'center',editable : true,editoptions : {size : 25}},
  61. { name: 'operate', index: 'operate', width: 300, align: 'center'}
  62. ],
  63. rowNum:10,
  64. height:'670',
  65. width:'1610',
  66. rowList:[10,20,30],
  67. multiselect : true,
  68. pager: '#gridPager',
  69. sortname: 'id',
  70. viewrecords: true,
  71. autoScroll: true,
  72. autowidth: true,
  73. sortorder: "desc",
  74. editurl : '/singleMachineAnalysis/measureAnalysisTargetMainList.action?tid='+tid,
  75. caption: "定量指标列表",
  76. jsonReader: {
  77. repeatitems: false,
  78. root: function (obj) { return obj.rows; },
  79. page: function (obj) { return obj.pageindex; },
  80. total: function (obj) { return obj.pagecount; },
  81. records: function (obj) { return obj.total; }
  82. },
  83. prmNames: {
  84. page: 'page',
  85. rows: 'pageSize'
  86. },
  87. afterInsertRow:function(rowid,rowdata,rowelem){
  88. var operateLink = "<input type='button' value='修改' onclick=\"jQuery('#gridTable').editRow('" + rowdata.id + "');\" />" +
  89. "<input type='button' value='确定' onclick=\"jQuery('#gridTable').saveRow('" + rowdata.id + "');\" />" +
  90. "<input type='button' value='取消' onclick=\"jQuery('#gridTable').restoreRow('" + rowdata.id + "');\" />";
  91. jQuery("#gridTable").jqGrid('setRowData',rowdata.id,{operate:operateLink});
  92. }
  93. });
  94. }
  95. // 删除选中行
  96. function delData(){
  97. var selectedRowIds = jQuery("#gridTable").jqGrid('getGridParam', 'selarrrow');
  98. var len = selectedRowIds.length;
  99. if(len!=0){
  100. confirm_ = confirm('确认删除选中的记录吗?');
  101. if(confirm_){
  102. $.ajax({
  103. type:"POST",
  104. url:encodeURI(encodeURI("/singleMachineAnalysis/delMeasureTarget.action?ids="+selectedRowIds)),
  105. success:function(data){
  106. var d = eval("("+data+")");
  107. if(d.action=='success'){
  108. for(var i=selectedRowIds.length-1;i>=0;i--) {
  109. $("#gridTable").jqGrid("delRowData", selectedRowIds[i]);
  110. }
  111. alert("记录删除成功!");
  112. }else{
  113. alert("删除失败!");
  114. }
  115. }
  116. });
  117. }
  118. }else{
  119. alert("请选择要删除的记录!");
  120. }
  121. return false;
  122. }
  123. // 判断输入内容是否合法,不能包括逗号(,)和斜杠(/). 结果true校验通过
  124. function judgeFormat(objStr){
  125. var result = false;
  126. var countone = objStr.indexOf('●');
  127. var counttwo = objStr.indexOf('★');
  128. var countEdit = objStr.indexOf('role="textbox" class="editable">');
  129. if(countone==-1 && counttwo==-1 && countEdit==-1){
  130. result = true;
  131. }
  132. return result;
  133. }
  134. function saveAddData(){
  135. // 指标体系ID
  136. var tid = $("#tid").val();
  137. var selectedRowIds = jQuery("#gridTable").jqGrid('getGridParam', 'selarrrow');
  138. var len = selectedRowIds.length;
  139. if(len!=0){
  140. confirm_ = confirm('确认要保存选中的记录吗?');
  141. if(confirm_){
  142. var judge = false;//输入得编码和名称中不能包含逗号和斜杠, true校验通过
  143. var codejudge = false;//编码校验,必须以字母开头,后跟字母、数字或下划线构成。true通过
  144. var params = '';
  145. for(var i=selectedRowIds.length-1;i>=0;i--) {
  146. var rowData = $("#gridTable").jqGrid('getRowData',selectedRowIds[i]);
  147. var id = rowData.id;
  148. var targetCode = rowData.targetCode;
  149. var name = rowData.name;
  150. var aname = rowData.aname;
  151. var cid = rowData.cid;
  152. var wid = rowData.wid;
  153. var formula = rowData.formula;
  154. var formuladesc = rowData.formuladesc;
  155. var datasourcestable = rowData.datasourcestable;
  156. var datasourcesfield = rowData.datasourcesfield;
  157. var datasourcewhere = rowData.datasourcewhere;
  158. // 校验指标编码输入是否合法
  159. var regx=/^[a-zA-Z]{1}[a-zA-Z0-9]*$/;
  160. codejudge =regx.test(targetCode);
  161. if(!codejudge){
  162. judge = false;
  163. break;
  164. }
  165. judge = judgeFormat(targetCode+name+aname+formula+formuladesc+datasourcestable+datasourcesfield+datasourcewhere);
  166. if(!judge){
  167. break;
  168. }
  169. if(params==''){
  170. params = id+'●'+targetCode;
  171. } else {
  172. params = params + '★' + id+'●'+targetCode;
  173. }
  174. /*if(params==''){
  175. params = id+'●'+targetCode+'●'+name+'●'+aname+'●'+cid+'●'+wid+'●'+formula+'●'+formuladesc+'●'+datasourcestable+'●'+datasourcesfield+'●'+datasourcewhere;
  176. } else {
  177. params = params + '★' + id+'●'+targetCode+'●'+name+'●'+aname+'●'+cid+'●'+wid+'●'+formula+'●'+formuladesc+'●'+datasourcestable+'●'+datasourcesfield+'●'+datasourcewhere;
  178. }*/
  179. }
  180. if(judge){
  181. // 编码重复校验
  182. $.ajax({
  183. type:"POST",
  184. url:encodeURI(encodeURI("/singleMachineAnalysis/repeatChectCode.action?records="+params)),
  185. success:function(data){
  186. var d = eval("("+data+")");
  187. if(d.action=='success'){
  188. sendSave(selectedRowIds, tid);
  189. alert("保存成功!");
  190. }else if(d.action=='fail'){
  191. alert("编码重复,不能重复添加相同编码的记录!");
  192. }
  193. }
  194. });
  195. }else{
  196. if(!codejudge){
  197. alert('编码格式错误,必须以字母开头,由字母、数字或下划线构成! 或 修改后未【确定】/【取消】!');
  198. }else{
  199. alert('输入格式错误,不能包含特殊符号(●、★)!');
  200. }
  201. }
  202. }
  203. } else {
  204. alert("请选择要保存的记录!");
  205. }
  206. return false;
  207. }
  208. function sendSave(selectedRowIds, tid){
  209. for(var i=selectedRowIds.length-1;i>=0;i--) {
  210. var rowData = $("#gridTable").jqGrid('getRowData',selectedRowIds[i]);
  211. var id = rowData.id;
  212. var targetCode = rowData.targetCode;
  213. var name = rowData.name;
  214. var aname = rowData.aname;
  215. var cid = rowData.cid;
  216. var wid = rowData.wid;
  217. var formula = rowData.formula;
  218. formula = formula.replace(/\s+/g,"");
  219. var formuladesc = rowData.formuladesc;
  220. formuladesc = formuladesc.replace(/\s+/g,"");
  221. var datasourcestable = rowData.datasourcestable;
  222. var datasourcesfield = rowData.datasourcesfield;
  223. var datasourcewhere = rowData.datasourcewhere;
  224. $.ajax({
  225. type:"POST",
  226. url:"/singleMachineAnalysis/saveMeasureTarget.action?measureTarget.id="+id+"&measureTarget.targetCode="+targetCode+"&measureTarget.name="+encodeURI(encodeURI(name))+"&measureTarget.aname="+encodeURI(encodeURI(aname))+"&measureTarget.cid="+encodeURI(encodeURI(cid))+"&measureTarget.wid="+wid+"&measureTarget.formula="+formula+"&measureTarget.formuladesc="+encodeURI(encodeURI(formuladesc))+"&measureTarget.datasourcestable="+datasourcestable+"&measureTarget.datasourcesfield="+datasourcesfield+"&measureTarget.datasourcewhere="+datasourcewhere+"&tid="+tid,
  227. success:function(data){
  228. queryData();
  229. }
  230. });
  231. }
  232. }
  233. </script>
  234. <style type="text/css">
  235. fieldset legend {
  236. color:#302A2A;
  237. font: bold 16px/2 Verdana, Geneva, sans-serif;
  238. font-weight: bold;
  239. text-align: left;
  240. text-shadow: 2px 2px 2px rgb(88, 126, 156);
  241. }
  242. </style>
  243. </head>
  244. <body>
  245. <fieldset id="fst">
  246. <legend class="item_Name">查询条件</legend>
  247. <table width="100%" cellpadding="0" cellspacing="0" class="dataform">
  248. <tr>
  249. <td style="width: 50px" align="right">
  250. 编码:
  251. </td>
  252. <td width="100px">
  253. <input type="text" id="targetCode" value="" />
  254. </td>
  255. <td style="width: 100px" align="right">
  256. 名称:
  257. </td>
  258. <td style="width: 50px;">
  259. <input type="text" id="targetName" value="" />
  260. </td>
  261. <td style="padding-left: 50px;">
  262. <input type="button" class="button" onclick="javascript:queryData();" value="查询"/>
  263. <input type="button" class="button" onclick="javascript:queryClear();" value="清空"/>
  264. </td>
  265. </tr>
  266. </table>
  267. </fieldset>
  268. <br/>
  269. <table id='gridTable'></table>
  270. <div id='gridPager'></div>
  271. <table width="100%">
  272. <tr>
  273. <td style="width: 50%;">
  274. <input type="button" class="button" id="addBtn" value="增加"/>
  275. <input type="button" class="button" onclick="delData();" value="删除"/>
  276. <input type="button" class="button" onclick="saveAddData();" value="保存"/>
  277. </td>
  278. <td align="right" style="width: 50%;">
  279. <a href="#" onclick="returnAction();">&lt;&lt;返回</a>
  280. </td>
  281. </tr>
  282. </table>
  283. <input type="text" id="targetCodeQS" value="${targetCodeQS}" style="display: none;"/>
  284. <input type="text" id="targetNameQS" value="${targetNameQS}" style="display: none;"/>
  285. <input type="text" id="tid" value="${tid}" style="display: none;"/>
  286. <form action="" method="post" id="f1">
  287. </body>