NewEMIS.Comm.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. function alertMsg(message) {
  2. window.top.$.messager.alert("系统消息", message, "info");
  3. }
  4. function redirect(url) {
  5. window.location.href = url;
  6. }
  7. function confirmMsg(message, handler) {
  8. window.top.$.messager.confirm("系统提示", message, handler);
  9. }
  10. //删除数据方法
  11. //url:删除方法url
  12. //paramName:删除方法参数名称
  13. //key:主键列
  14. $.fn.deleteRows = function (url, paramName, key) {
  15. this.deleteRows(url, paramName, key, "datagrid");
  16. }
  17. $.fn.deleteRows = function (url, paramName, key, control) {
  18. control = control || "datagrid";
  19. var me = this;
  20. var selrows = me[control]("getChecked")
  21. if (selrows.length > 0) {
  22. confirmMsg("确定删除吗?", function (r) {
  23. var ids = new Array();
  24. $(selrows).each(function (i, row) {
  25. ids.push(row[key]);
  26. })
  27. if (r) {
  28. var param = JSON.parse("{ \"" + paramName + "\":\"\"}");
  29. param[paramName] = JSON.stringify(ids);
  30. $.post(url, param, function (responseJson) {
  31. alertMsg(responseJson.msg);
  32. $('.pagination-load').click(); // [control]('reload');
  33. }, "json");
  34. }
  35. })
  36. } else {
  37. alertMsg('请选择需要删除的数据!');
  38. }
  39. }
  40. //验证datagrid是否只选择一行数据
  41. $.fn.isSingle = function () {
  42. var rows = this.datagrid("getChecked");
  43. if (rows.length != 1) {
  44. alertMsg('请选择一行数据!');
  45. return false;
  46. }
  47. return true;
  48. }
  49. //提交表单
  50. //formID:提交的表单ID
  51. //postUrl:处理方法
  52. //handler:处理完成后执行方法
  53. function submitForm(formID, postUrl, handler, target) {
  54. options = { formID: formID, postUrl: postUrl, handler: handler, target: target, isShowMsg: true, isValidate: false };
  55. submitFormJson(options);
  56. }
  57. function submitFormJson(options) {
  58. options = options || {};
  59. options.target = options.target || $(event ? event.srcElement : options.target);
  60. var button = options.target.closest('[class*=button]');
  61. var enabled = button.attr('isopera') != 'true';
  62. if (($("#" + options.formID).form('validate') && enabled) || options.isValidate) {
  63. button.attr('isopera', true);
  64. button.attr('disabled', true);
  65. try {
  66. $.post(options.postUrl, $("#" + options.formID).getFormData(), function (data) {
  67. if (options.isShowMsg)
  68. alertMsg(data.msg);
  69. //if (data.result) { }
  70. if ($.isFunction(options.handler))
  71. options.handler(data);
  72. if (typeof (jQuery) != "unknown" && typeof (button.attr('isopera')) != "undefined") {
  73. button.attr('isopera', false);
  74. button.attr('disabled', false);
  75. }
  76. });
  77. }
  78. catch (e) {
  79. $.messager.alert("系统提示", e.toString());
  80. }
  81. }
  82. }
  83. //提交表单
  84. //formID:提交的表单ID
  85. //postUrl:处理方法
  86. //handler:处理完成后执行方法
  87. function submitFormNoShow(formID, postUrl, handler, target) {
  88. options = { formID: formID, postUrl: postUrl, handler: handler, target: target, isShowMsg: false };
  89. submitFormJson(options);
  90. }
  91. function isNumber(value) {
  92. return (/^[1-9]\d*$/gi).test(value);
  93. }
  94. function topDialogIframe() {
  95. var id = $('div.easyui-topDialog').attr("id");
  96. if (window[id + "_iframe"]) return window[id + "_iframe"];
  97. else return window;
  98. }
  99. //json转字符串
  100. function json2str(o) {
  101. var arr = [];
  102. var fmt = function (s) {
  103. if (typeof s == 'object' && s != null) return json2str(s);
  104. return /^(string|number)$/.test(typeof s) ? "'" + s + "'" : s;
  105. }
  106. for (var i in o) arr.push("'" + i + "':" + fmt(o[i]));
  107. return '{' + arr.join(',') + '}';
  108. }
  109. //同步-ajax
  110. function Invoke(url, param, dataType) {
  111. dataType = dataType | "json";
  112. var result;
  113. $.ajax({
  114. type: "POST",
  115. url: url,
  116. async: false,
  117. data: param,
  118. dataType: "json",
  119. success: function (msg) {
  120. result = msg;
  121. },
  122. error: function (r, s, e) {
  123. $.messager.alert("系统提示", s);
  124. }
  125. });
  126. return result;
  127. }
  128. //异步-ajax
  129. function beginInvoke(url, param, endInvoike) {
  130. endInvoike = endInvoike || function () { };
  131. $.ajax({
  132. type: "POST",
  133. url: url,
  134. async: true,
  135. data: param,
  136. dataType: "json",
  137. beforeSend: function () {
  138. var top = ($(window).height() - 26) / 2;
  139. var left = ($(window).width() - 26) / 2;
  140. var stop = $(document).scrollTop();
  141. var sleft = $(document).scrollLeft();
  142. $('<img></img>', {
  143. id: 'img-loading',
  144. css: {
  145. width: 26,
  146. height: 26,
  147. position: 'absolute',
  148. background: '#fff',
  149. left: left + sleft,
  150. top: top + stop
  151. },
  152. src: CMS_SystemConfig.VirtualDirectoryPath + '/Content/themes/bootstrap/images/wait.gif'
  153. }).appendTo('body').fadeTo('fast', 0.8);
  154. return true;
  155. },
  156. success: function (datas) {
  157. endInvoike(datas);
  158. },
  159. error: function (r, s, e) {
  160. $.messager.alert("系统提示", s);
  161. },
  162. complete: function () {
  163. $('body').find('#img-loading').remove();
  164. }
  165. });
  166. }
  167. //生成GUID
  168. function Guid() {
  169. var guid = "";
  170. for (var i = 1; i <= 32; i++) {
  171. var n = Math.floor(Math.random() * 16.0).toString(16);
  172. guid += n;
  173. if ((i == 8) || (i == 12) || (i == 16) || (i == 20))
  174. guid += "-";
  175. }
  176. return guid;
  177. }
  178. //把View数据模型没使用到的属性加到form里面
  179. //model:json格式的model
  180. //form:加到的容器
  181. function InitPropertyValue(model, form) {
  182. for (var property in model) {
  183. if (form.find("[name=" + property + "]").length == 0)
  184. form.append("<input type='hidden' id='" + property + "' name='" + property + "' value='" + decodeURIComponent(model[property]).replace("+", " ") + "'/>");
  185. };
  186. }