targetsystem.jsp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. $("#targetCodeQ").val(targetCode);
  17. $("#targetNameQ").val(targetName);
  18. jQuery("#gridTable").jqGrid('setGridParam',{url:encodeURI(encodeURI("/singleMachineAnalysis/singleMachineAnalysisMainList.action?targetName="+targetName+"&targetCode="+targetCode))}).trigger("reloadGrid");
  19. }
  20. function queryClear(){
  21. $("#targetCode").val("");
  22. $("#targetName").val("");
  23. $("#targetCodeQ").val("");
  24. $("#targetNameQ").val("");
  25. }
  26. function requestAction(url){
  27. // 判断指标体系数据是否已经保存
  28. var index = url.indexOf('tid=jqg');
  29. if(index>-1){
  30. alert('请先保存指标体系数据!');
  31. return false;
  32. }
  33. // 编码
  34. var targetCodeQ = $("#targetCodeQ").val();
  35. // 名称
  36. var targetNameQ = $("#targetNameQ").val();
  37. $("#f1").attr("action",encodeURI(encodeURI(url+ "&targetCodeQS=" + targetCodeQ + "&targetNameQS=" + targetNameQ)) );
  38. $("#f1").submit();
  39. }
  40. $(function(){
  41. // 编码
  42. var targetCodeQ = $("#targetCodeQ").val();
  43. // 名称
  44. var targetNameQ = $("#targetNameQ").val();
  45. $("#targetCode").val(targetCodeQ);
  46. $("#targetName").val(targetNameQ);
  47. showJqGrid();
  48. $("#addBtn").click(function() {
  49. jQuery("#gridTable").jqGrid('editGridRow', "new", {
  50. height : 300,
  51. reloadAfterSubmit : false
  52. });
  53. });
  54. });
  55. // 删除选中行
  56. function delData(){
  57. var selectedRowIds = jQuery("#gridTable").jqGrid('getGridParam', 'selarrrow');
  58. var len = selectedRowIds.length;
  59. if(len!=0){
  60. confirm_ = confirm('确认删除选中的记录吗?');
  61. if(confirm_){
  62. $.ajax({
  63. type:"POST",
  64. url:encodeURI(encodeURI("/singleMachineAnalysis/delTargetSystem.action?ids="+selectedRowIds)),
  65. success:function(data){
  66. var d = eval("("+data+")");
  67. if(d.action=='success'){
  68. for(var i=selectedRowIds.length-1;i>=0;i--) {
  69. $("#gridTable").jqGrid("delRowData", selectedRowIds[i]);
  70. }
  71. alert("记录删除成功!");
  72. }else if(d.action=='fail'){
  73. alert("所选记录存在定性或定量指标数据,不能直接删除!");
  74. }else{
  75. alert("删除失败!");
  76. }
  77. }
  78. });
  79. }
  80. }else{
  81. alert("请选择要删除的记录!");
  82. }
  83. return false;
  84. }
  85. // 判断输入内容是否合法,不能包括逗号(,)和斜杠(/). 结果true校验通过
  86. function judgeFormat(objStr){
  87. var result = false;
  88. var countone = objStr.indexOf('●');
  89. var counttwo = objStr.indexOf('★');
  90. if(countone==-1 && counttwo==-1){
  91. result = true;
  92. }
  93. return result;
  94. }
  95. function saveAddData(){
  96. var selectedRowIds = jQuery("#gridTable").jqGrid('getGridParam', 'selarrrow');
  97. var len = selectedRowIds.length;
  98. if(len!=0){
  99. confirm_ = confirm('确认要保存选中的记录吗?');
  100. if(confirm_){
  101. var judge = false;//输入得编码和名称中不能包含逗号和斜杠, true校验通过
  102. var codejudge = false;//编码校验,必须以字母开头,后跟字母、数字或下划线构成。true通过
  103. var params = '';
  104. for(var i=selectedRowIds.length-1;i>=0;i--) {
  105. var rowData = $("#gridTable").jqGrid('getRowData',selectedRowIds[i]);
  106. var id = rowData.id;
  107. var targetCode = rowData.targetCode;
  108. var name = rowData.name;
  109. var equipmentId = rowData.equipmentId;
  110. var windPowerstationId = rowData.windPowerstationId;
  111. var projectId = rowData.projectId;
  112. var lineId = rowData.lineId;
  113. // 校验指标编码输入是否合法
  114. var regx=/^[a-zA-Z]{1}[a-zA-Z0-9]*$/;
  115. codejudge =regx.test(targetCode);
  116. if(!codejudge){
  117. judge = false;
  118. break;
  119. }
  120. judge = judgeFormat(targetCode+name);
  121. if(!judge){
  122. break;
  123. }
  124. var index = id.indexOf('jqg');
  125. if(index>-1){
  126. if(params==''){
  127. params = targetCode+'●'+name+'●'+equipmentId+'●'+windPowerstationId+'●'+projectId+'●'+lineId;
  128. } else {
  129. params = params + '★' + targetCode+'●'+name+'●'+equipmentId+'●'+windPowerstationId+'●'+projectId+'●'+lineId;
  130. }
  131. }
  132. }
  133. if(judge){
  134. if(params==''){
  135. alert('选中的数据中没有未被保存的数据!');
  136. } else {
  137. $.ajax({
  138. type:"POST",
  139. url:encodeURI(encodeURI("/singleMachineAnalysis/saveTargetSystem.action?records="+params)),
  140. success:function(data){
  141. var d = eval("("+data+")");
  142. if(d.action=='success'){
  143. queryData();
  144. alert("保存成功!");
  145. }else if(d.action=='fail'){
  146. alert("编码重复,不能重复添加相同编码的记录!");
  147. }else{
  148. alert("保存失败!");
  149. }
  150. }
  151. });
  152. }
  153. }else{
  154. if(!codejudge){
  155. alert('编码格式错误,必须以字母开头,由字母、数字或下划线构成!');
  156. }else{
  157. alert('输入的编码或名称格式错误,不能包含特殊符号(●、★)');
  158. }
  159. }
  160. }
  161. } else {
  162. alert("请选择要保存的记录!");
  163. }
  164. return false;
  165. }
  166. // 加载jqgrid表格
  167. function showJqGrid(){
  168. // 编码
  169. var targetCodeQ = $("#targetCodeQ").val();
  170. // 名称
  171. var targetNameQ = $("#targetNameQ").val();
  172. jQuery("#gridTable").jqGrid({
  173. url:encodeURI(encodeURI('/singleMachineAnalysis/singleMachineAnalysisMainList.action?targetCode='+targetCodeQ+'&targetName='+targetNameQ)),
  174. datastr: 'data.json',
  175. datatype: "json",
  176. colNames:['编号', '编码','名称','设备型号','场站','工程','线路','操作'],
  177. colModel:[
  178. { name: 'id', index: 'id', width: 200, align: 'center', hidden: true},
  179. { name: 'targetCode', index: 'targetCode', width: 200, align: 'center',editable : true,editoptions : {size : 25}},
  180. { name: 'name', index: 'name', width: 200, align: 'center',editable : true,editoptions : {size : 25}},
  181. { name: 'equipmentId', index: 'equipmentId', width: 200, align: 'center',editable : true,edittype : "select",editoptions : {value : "${equipmentSelect}"}},
  182. { name: 'windPowerstationId', index: 'windPowerstationId', width: 200, align: 'center',editable : true,edittype : "select",editoptions : {value : "${windPowerStationSelect}"}},
  183. { name: 'projectId', index: 'projectId', width: 200, align: 'center',editable : true,edittype : "select",editoptions : {value : "${projectSelect}"}},
  184. { name: 'lineId', index: 'lineId', width: 200, align: 'center',editable : true,edittype : "select",editoptions : {value : "${lineSelect}"}},
  185. { name: 'operate', index: 'operate', width: 200, align: 'center'}
  186. ],
  187. rowNum:10,
  188. rowList:[10,20,30],
  189. height:'670',
  190. width:'1610',
  191. multiselect : true,
  192. pager: '#gridPager',
  193. sortname: 'id',
  194. viewrecords: true,
  195. autowidth: true,
  196. sortorder: "desc",
  197. editurl:encodeURI(encodeURI('/singleMachineAnalysis/singleMachineAnalysisMainList.action?targetCode='+targetCodeQ+'&targetName='+targetNameQ)),
  198. caption: "指标体系列表",
  199. jsonReader: {
  200. repeatitems: false,
  201. root: function (obj) { return obj.rows; },
  202. page: function (obj) { return obj.pageindex; },
  203. total: function (obj) { return obj.pagecount; },
  204. records: function (obj) { return obj.total; }
  205. },
  206. prmNames: {
  207. page: 'page',
  208. rows: 'pageSize'
  209. },
  210. afterInsertRow:function(rowid,rowdata,rowelem){
  211. var operateLink = "<a href=\"#\" onclick=\"requestAction('/singleMachineAnalysis/natureAnalysisTargetMain.action?tid=" + rowdata.id + "')\">定性指标</a>&nbsp/&nbsp"+
  212. "<a href=\"#\" onclick=\"requestAction('/singleMachineAnalysis/measureAnalysisTargetMain.action?tid=" + rowdata.id + "')\">定量指标</a>";
  213. jQuery("#gridTable").jqGrid('setRowData',rowdata.id,{operate:operateLink});
  214. }
  215. });
  216. }
  217. </script>
  218. <style type="text/css">
  219. fieldset legend {
  220. color:#302A2A;
  221. font: bold 16px/2 Verdana, Geneva, sans-serif;
  222. font-weight: bold;
  223. text-align: left;
  224. text-shadow: 2px 2px 2px rgb(88, 126, 156);
  225. }
  226. </style>
  227. </head>
  228. <body>
  229. <fieldset id="fst">
  230. <legend class="item_Name">查询条件</legend>
  231. <table width="1000px" cellpadding="0" cellspacing="0" class="dataform">
  232. <tr>
  233. <td style="width: 50px" align="right">
  234. 编码:
  235. </td>
  236. <td width="100px">
  237. <input type="text" id="targetCode" value="" />
  238. <input type="text" id="targetCodeQ" value="${targetCodeQS}" style="display: none;"/>
  239. </td>
  240. <td style="width: 100px" align="right">
  241. 名称:
  242. </td>
  243. <td style="width: 50px;">
  244. <input type="text" id="targetName" value="" />
  245. <input type="text" id="targetNameQ" value="${targetNameQS}" style="display: none;"/>
  246. </td>
  247. <td style="padding-left: 50px;">
  248. <input type="button" class="button" onclick="javascript:queryData();" value="查询"/>
  249. <input type="button" class="button" onclick="javascript:queryClear();" value="清空"/>
  250. </td>
  251. </tr>
  252. </table>
  253. </fieldset>
  254. <br/>
  255. <table id='gridTable'></table>
  256. <div id='gridPager'></div>
  257. <table>
  258. <tr>
  259. <td width="100%">
  260. <input type="button" class="button" id="addBtn" value="增加"/>
  261. <input type="button" class="button" onclick="delData();" value="删除"/>
  262. <input type="button" class="button" onclick="saveAddData();" value="保存"/>
  263. </td>
  264. </tr>
  265. </table>
  266. <form action="" method="post" id="f1">
  267. </body>