editDataDictionary.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. var childDataDictionaryTable;
  2. function searchChildList() {
  3. var jsonObject = {"parentId":parentId};
  4. if(childDataDictionaryTable == undefined){
  5. childDataDictionaryTable = $("#childDataDictionaryTable").ligerGrid({
  6. columns : [
  7. {
  8. display : '标准项',
  9. name : 'dname',
  10. align : 'center',
  11. width : 220,
  12. editor: dnameEditor
  13. },{
  14. display : '设定值',
  15. name : 'dvalue',
  16. width : 180,
  17. align : 'center',
  18. editor: dvalueEditor
  19. },{
  20. display : '排序号',
  21. name : 'dorder',
  22. width : 100,
  23. align : 'center',
  24. type: 'int',
  25. editor: dorderEditor
  26. },{
  27. display : '是否默认',
  28. name : 'is_default',
  29. width : 80,
  30. align : 'center',
  31. type:'int',
  32. editor: isDefaultEditor,
  33. render: function (item){
  34. if (parseInt(item.is_default) == 0) return '否';
  35. return '是';
  36. }
  37. },{
  38. display : '是否有效',
  39. name : 'is_valid',
  40. width : 80,
  41. align : 'center',
  42. type:'int',
  43. editor: isValidEditor,
  44. render : function(rowdata, rowindex, value) {
  45. var h = "";
  46. if(value == 1){
  47. h += "是";
  48. }else{
  49. h += "<font style='color:#ff0000'>否</font> ";
  50. }
  51. return h;
  52. }
  53. },{
  54. display : '操作',
  55. width : 120,
  56. align : 'center',
  57. isSort: false,
  58. render : function(rowdata, rowindex, value) {
  59. var h = "";
  60. if (!rowdata._editing){
  61. h += "<a href='javascript:beginEdit(\"" + rowindex + "\")'>修改</a> ";
  62. h += "<a href='javascript:deleteRow(\"" + rowindex + "\",\""+ rowdata.universalid +"\")'>删除</a> ";
  63. }
  64. else{
  65. var isDelete = rowdata.universalid ? "false" : "true";
  66. h += "<a href='javascript:submitEdit(\"" + rowindex + "\",\""+ rowdata.universalid + "\")'>提交</a> ";
  67. h += "<a href='javascript:cancelEdit(" + rowindex + ", "+isDelete+")'>取消</a> ";
  68. }
  69. return h;
  70. }
  71. }],
  72. url : 'contractDataDictionaryAction.do?task=getDataDictionaryList&time=' + new Date().getTime(),
  73. width : "99.8%",
  74. height : "99%",
  75. parms :jsonObject,
  76. enabledEdit: true,
  77. clickToEdit: false,
  78. pageParmName : 'curPage',
  79. usePager:false,
  80. pagesizeParmName : 'pageSize',
  81. onError:function(err){
  82. alert("获取数据失败,请刷新页面后重试!");
  83. }
  84. });
  85. }else{
  86. childDataDictionaryTable._setParms(jsonObject);
  87. childDataDictionaryTable.loadData();
  88. }
  89. }
  90. function beginEdit(rowid) {
  91. childDataDictionaryTable.beginEdit(rowid);
  92. }
  93. function cancelEdit(rowid, isDelete) {
  94. childDataDictionaryTable.cancelEdit(rowid);
  95. if(isDelete){
  96. childDataDictionaryTable.deleteRow(rowid);
  97. }
  98. }
  99. function submitEdit(rowid,universalid){
  100. childDataDictionaryTable.endEdit(rowid);
  101. var rows = childDataDictionaryTable.getCheckedRows();
  102. var dnameValue = encodeURI(rows[0].dname);
  103. var dvalueValue = encodeURI(rows[0].dvalue);
  104. var dorderValue = rows[0].dorder;
  105. var isDefaultValue = rows[0].is_default;
  106. var isValidValue = rows[0].is_valid;
  107. var jsonObject = {"id":universalid,"parentId":parentId,"dname":dnameValue,"dvalue":dvalueValue,"dorder":dorderValue,"isDefault":isDefaultValue,"isValid":isValidValue};
  108. var url = "";
  109. if(universalid && universalid != "undefined"){
  110. url = "contractDataDictionaryAction.do?task=updateChildDataDictionary";
  111. }else{
  112. url = "contractDataDictionaryAction.do?task=addChildDataDictionary";
  113. }
  114. $.ajax({
  115. type:"POST",
  116. url:url,
  117. data : jsonObject,
  118. timeout:10000,
  119. cache:false,
  120. dataType:"json",
  121. beforeSend:function(){
  122. showWaittingDialog("正在提交中,请稍后……");
  123. },
  124. success:function(data){
  125. if(data.success){
  126. $.ligerDialog.success("保存成功");
  127. childDataDictionaryTable.loadData();
  128. }else{
  129. showAjaxError(null, data.error);
  130. childDataDictionaryTable.beginEdit(rowid);
  131. }
  132. },
  133. error:function(err){
  134. childDataDictionaryTable.beginEdit(rowid);
  135. showAjaxError(err);
  136. },
  137. complete:function(){
  138. closeWaittingDialog();
  139. }
  140. });
  141. }
  142. function deleteRow(rowid,universalid){
  143. if(universalid == 'undefined' || universalid == "" || universalid == undefined){
  144. childDataDictionaryTable.deleteRow(rowid);
  145. }else{
  146. var delRow = childDataDictionaryTable.getSelected();
  147. if(delRow.is_valid == 1){
  148. alert("当前要被删除的标准项还是'有效'状态!\n为避免误删导致不可估计的后果,请先将该项设置为'无效'状态后再删除!");
  149. return;
  150. }
  151. if (confirm('您确定要删除该标准项吗?')){
  152. $.ajax({
  153. type:"POST",
  154. url:"contractDataDictionaryAction.do?task=delDataDictionary&universalid=" + universalid,
  155. data : "",
  156. timeout:10000,
  157. dataType:"json",
  158. beforeSend:function(){
  159. showWaittingDialog("正在提交中,请稍后……");
  160. },
  161. success:function(msg){
  162. childDataDictionaryTable.deleteRow(rowid);
  163. },
  164. error:function(err){
  165. showAjaxError(err);
  166. },
  167. complete:function(){
  168. closeWaittingDialog();
  169. }
  170. });
  171. }
  172. }
  173. }
  174. function addNewRow(){
  175. for (var rowid in childDataDictionaryTable.records){
  176. var row = childDataDictionaryTable.getRow(rowid);
  177. if(!row.universalid){
  178. return;
  179. }
  180. }
  181. childDataDictionaryTable.addEditRow();
  182. }
  183. function getSelected(){
  184. var row = childDataDictionaryTable.getSelectedRow();
  185. if (!row) { alert('请选择行'); return; }
  186. alert(JSON.stringify(row));
  187. }
  188. function getData(){
  189. var data = childDataDictionaryTable.getData();
  190. alert(JSON.stringify(data));
  191. }
  192. function save1() {
  193. var rs = $.validate({
  194. name : "dvalue",
  195. model : [ {
  196. type : "require",
  197. msg : "请填写设定值"
  198. }]
  199. });
  200. if (rs) {
  201. var jsonObject = {"id":$("#universalid").val(), "dvalue":$("#dvalue").val()};
  202. $.ajax({
  203. type:"POST",
  204. url:"contractDataDictionaryAction.do?task=updateDataDictionary",
  205. data : jsonObject,
  206. timeout:10000,
  207. cache:false,
  208. dataType:"json",
  209. beforeSend:function(){
  210. showWaittingDialog("正在提交中,请稍后……");
  211. },
  212. success:function(data){
  213. if(data.success){
  214. $.ligerDialog.success("保存成功");
  215. }else{
  216. showAjaxError(null, data.error);
  217. }
  218. },
  219. error:showAjaxError,
  220. complete:closeWaittingDialog
  221. });
  222. }
  223. }