naturetarget.jsp 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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/natureAnalysisTargetMainList.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 : 300,
  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/natureAnalysisTargetMainList.action?tid='+tid),
  46. datastr: 'data.json',
  47. datatype: "json",
  48. colNames:['编号', '编码','名称', '别名','分类','权重','操作'],
  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: 'operate', index: 'operate', width: 200, align: 'center'}
  57. ],
  58. rowNum:10,
  59. height:'670',
  60. width:'1610',
  61. rowList:[10,20,30],
  62. multiselect : true,
  63. pager: '#gridPager',
  64. sortname: 'id',
  65. viewrecords: true,
  66. autowidth: true,
  67. sortorder: "desc",
  68. editurl : '/singleMachineAnalysis/natureAnalysisTargetMainList.action?tid='+tid,
  69. caption: "定性指标列表",
  70. jsonReader: {
  71. repeatitems: false,
  72. root: function (obj) { return obj.rows; },
  73. page: function (obj) { return obj.pageindex; },
  74. total: function (obj) { return obj.pagecount; },
  75. records: function (obj) { return obj.total; }
  76. },
  77. prmNames: {
  78. page: 'page',
  79. rows: 'pageSize'
  80. },
  81. afterInsertRow:function(rowid,rowdata,rowelem){
  82. var operateLink = "<input type='button' value='修改' onclick=\"jQuery('#gridTable').editRow('" + rowdata.id + "');\" />" +
  83. "<input type='button' value='确定' onclick=\"jQuery('#gridTable').saveRow('" + rowdata.id + "');\" />" +
  84. "<input type='button' value='取消' onclick=\"jQuery('#gridTable').restoreRow('" + rowdata.id + "');\" />";
  85. jQuery("#gridTable").jqGrid('setRowData',rowdata.id,{operate:operateLink});
  86. }
  87. });
  88. }
  89. // 删除选中行
  90. function delData(){
  91. var selectedRowIds = jQuery("#gridTable").jqGrid('getGridParam', 'selarrrow');
  92. var len = selectedRowIds.length;
  93. if(len!=0){
  94. confirm_ = confirm('确认删除选中的记录吗?');
  95. if(confirm_){
  96. $.ajax({
  97. type:"POST",
  98. url:encodeURI(encodeURI("/singleMachineAnalysis/delNatureTarget.action?ids="+selectedRowIds)),
  99. success:function(data){
  100. var d = eval("("+data+")");
  101. if(d.action=='success'){
  102. for(var i=selectedRowIds.length-1;i>=0;i--) {
  103. $("#gridTable").jqGrid("delRowData", selectedRowIds[i]);
  104. }
  105. alert("记录删除成功!");
  106. }else{
  107. alert("删除失败!");
  108. }
  109. }
  110. });
  111. }
  112. }else{
  113. alert("请选择要删除的记录!");
  114. }
  115. return false;
  116. }
  117. // 判断输入内容是否合法,不能包括逗号(,)和斜杠(/). 结果true校验通过
  118. function judgeFormat(objStr){
  119. var result = false;
  120. var countone = objStr.indexOf('●');
  121. var counttwo = objStr.indexOf('★');
  122. var countEdit = objStr.indexOf('role="textbox" class="editable">');
  123. if(countone==-1 && counttwo==-1 && countEdit==-1){
  124. result = true;
  125. }
  126. return result;
  127. }
  128. function saveAddData(){
  129. // 指标体系ID
  130. var tid = $("#tid").val();
  131. var selectedRowIds = jQuery("#gridTable").jqGrid('getGridParam', 'selarrrow');
  132. var len = selectedRowIds.length;
  133. if(len!=0){
  134. confirm_ = confirm('确认要保存选中的记录吗?');
  135. if(confirm_){
  136. var judge = false;//输入得编码和名称中不能包含逗号和斜杠, true校验通过
  137. var codejudge = false;//编码校验,必须以字母开头,后跟字母、数字或下划线构成。true通过
  138. var params = '';
  139. for(var i=selectedRowIds.length-1;i>=0;i--) {
  140. var rowData = $("#gridTable").jqGrid('getRowData',selectedRowIds[i]);
  141. var id = rowData.id;
  142. var targetCode = rowData.targetCode;
  143. var name = rowData.name;
  144. var aname = rowData.aname;
  145. var cid = rowData.cid;
  146. var wid = rowData.wid;
  147. // 校验指标编码输入是否合法
  148. var regx=/^[a-zA-Z]{1}[a-zA-Z0-9]*$/;
  149. codejudge =regx.test(targetCode);
  150. if(!codejudge){
  151. judge = false;
  152. break;
  153. }
  154. judge = judgeFormat(targetCode+name+aname);
  155. if(!judge){
  156. break;
  157. }
  158. if(params==''){
  159. params = id+'●'+targetCode+'●'+name+'●'+aname+'●'+cid+'●'+wid;
  160. } else {
  161. params = params + '★' + id+'●'+targetCode+'●'+name+'●'+aname+'●'+cid+'●'+wid;
  162. }
  163. }
  164. if(judge){
  165. $.ajax({
  166. type:"POST",
  167. url:encodeURI(encodeURI("/singleMachineAnalysis/saveNatureTarget.action?records="+params+"&tid="+tid)),
  168. success:function(data){
  169. var d = eval("("+data+")");
  170. if(d.action=='success'){
  171. queryData();
  172. alert("保存成功!");
  173. }else if(d.action=='fail'){
  174. alert("编码重复,不能重复添加相同编码的记录!");
  175. }else{
  176. alert("保存失败!");
  177. }
  178. }
  179. });
  180. }else{
  181. if(!codejudge){
  182. alert('编码格式错误,必须以字母开头,由字母、数字或下划线构成!或 修改后未【确定】/【取消】!');
  183. }else{
  184. alert('输入的编码、名称或别名格式错误,不能包含特殊符号(●、★)');
  185. }
  186. }
  187. }
  188. } else {
  189. alert("请选择要保存的记录!");
  190. }
  191. return false;
  192. }
  193. </script>
  194. <style type="text/css">
  195. fieldset legend {
  196. color:#302A2A;
  197. font: bold 16px/2 Verdana, Geneva, sans-serif;
  198. font-weight: bold;
  199. text-align: left;
  200. text-shadow: 2px 2px 2px rgb(88, 126, 156);
  201. }
  202. </style>
  203. </head>
  204. <body>
  205. <fieldset id="fst">
  206. <legend class="item_Name">查询条件</legend>
  207. <table width="100%" cellpadding="0" cellspacing="0" class="dataform">
  208. <tr>
  209. <td style="width: 50px" align="right">
  210. 编码:
  211. </td>
  212. <td width="100px">
  213. <input type="text" id="targetCode" value="" />
  214. </td>
  215. <td style="width: 100px" align="right">
  216. 名称:
  217. </td>
  218. <td style="width: 50px;">
  219. <input type="text" id="targetName" value="" />
  220. </td>
  221. <td style="padding-left: 50px;">
  222. <input type="button" class="button" onclick="javascript:queryData();" value="查询"/>
  223. <input type="button" class="button" onclick="javascript:queryClear();" value="清空"/>
  224. </td>
  225. </tr>
  226. </table>
  227. </fieldset>
  228. <br/>
  229. <table id='gridTable'></table>
  230. <div id='gridPager'></div>
  231. <table width="100%">
  232. <tr>
  233. <td style="width: 50%;">
  234. <input type="button" class="button" id="addBtn" value="增加"/>
  235. <input type="button" class="button" onclick="delData();" value="删除"/>
  236. <input type="button" class="button" onclick="saveAddData();" value="保存"/>
  237. </td>
  238. <td align="right" style="width: 50%;">
  239. <a href="#" onclick="returnAction();">&lt;&lt;返回</a>
  240. </td>
  241. </tr>
  242. </table>
  243. <input type="text" id="targetCodeQS" value="${targetCodeQS}" style="display: none;"/>
  244. <input type="text" id="targetNameQS" value="${targetNameQS}" style="display: none;"/>
  245. <input type="text" id="tid" value="${tid}" style="display: none;"/>
  246. <form action="" method="post" id="f1">
  247. </body>