learun-form.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. $.SaveForm = function (options) {
  2. var defaults = {
  3. url: "",
  4. param: [],
  5. type: "post",
  6. dataType: "json",
  7. loading: "正在处理数据...",
  8. success: null,
  9. close: true
  10. };
  11. var options = $.extend(defaults, options);
  12. Loading(true, options.loading);
  13. if ($('[name=__RequestVerificationToken]').length > 0) {
  14. options.param["__RequestVerificationToken"] = $('[name=__RequestVerificationToken]').val();
  15. }
  16. window.setTimeout(function () {
  17. $.ajax({
  18. url: options.url,
  19. data: options.param,
  20. type: options.type,
  21. dataType: options.dataType,
  22. success: function (data) {
  23. if (data.type == "3") {
  24. dialogAlert(data.message, -1);
  25. } else {
  26. Loading(false);
  27. dialogMsg(data.message, 1);
  28. options.success(data);
  29. if (options.close == true) {
  30. dialogClose();
  31. }
  32. }
  33. },
  34. error: function (XMLHttpRequest, textStatus, errorThrown) {
  35. Loading(false);
  36. dialogMsg(errorThrown, -1);
  37. },
  38. beforeSend: function () {
  39. Loading(true, options.loading);
  40. },
  41. complete: function () {
  42. Loading(false);
  43. }
  44. });
  45. }, 500);
  46. }
  47. $.SetForm = function (options) {
  48. var defaults = {
  49. url: "",
  50. param: [],
  51. type: "get",
  52. dataType: "json",
  53. success: null,
  54. async:false
  55. };
  56. var options = $.extend(defaults, options);
  57. $.ajax({
  58. url: options.url,
  59. data: options.param,
  60. type: options.type,
  61. dataType: options.dataType,
  62. async: options.async,
  63. success: function (data) {
  64. if (data != null && data.type == "3") {
  65. dialogAlert(data.message, -1);
  66. } else {
  67. options.success(data);
  68. }
  69. },
  70. error: function (XMLHttpRequest, textStatus, errorThrown) {
  71. dialogMsg(errorThrown, -1);
  72. }, beforeSend: function () {
  73. Loading(true);
  74. },
  75. complete: function () {
  76. Loading(false);
  77. }
  78. });
  79. }
  80. $.RemoveForm = function (options) {
  81. var defaults = {
  82. msg: "注:您确定要删除吗?该操作将无法恢复",
  83. loading: "正在删除数据...",
  84. url: "",
  85. param: [],
  86. type: "post",
  87. dataType: "json",
  88. success: null
  89. };
  90. var options = $.extend(defaults, options);
  91. dialogConfirm(options.msg, function (r) {
  92. if (r) {
  93. Loading(true, options.loading);
  94. window.setTimeout(function () {
  95. var postdata = options.param;
  96. if ($('[name=__RequestVerificationToken]').length > 0) {
  97. postdata["__RequestVerificationToken"] = $('[name=__RequestVerificationToken]').val();
  98. }
  99. $.ajax({
  100. url: options.url,
  101. data: postdata,
  102. type: options.type,
  103. dataType: options.dataType,
  104. success: function (data) {
  105. if (data.type == "3") {
  106. dialogAlert(data.message, -1);
  107. } else {
  108. dialogMsg(data.message, 1);
  109. options.success(data);
  110. }
  111. },
  112. error: function (XMLHttpRequest, textStatus, errorThrown) {
  113. Loading(false);
  114. dialogMsg(errorThrown, -1);
  115. },
  116. beforeSend: function () {
  117. Loading(true, options.loading);
  118. },
  119. complete: function () {
  120. Loading(false);
  121. }
  122. });
  123. }, 500);
  124. }
  125. });
  126. }
  127. $.ConfirmAjax = function (options) {
  128. var defaults = {
  129. msg: "提示信息",
  130. loading: "正在处理数据...",
  131. url: "",
  132. param: [],
  133. type: "post",
  134. dataType: "json",
  135. success: null
  136. };
  137. var options = $.extend(defaults, options);
  138. dialogConfirm(options.msg, function (r) {
  139. if (r) {
  140. Loading(true, options.loading);
  141. window.setTimeout(function () {
  142. var postdata = options.param;
  143. if ($('[name=__RequestVerificationToken]').length > 0) {
  144. postdata["__RequestVerificationToken"] = $('[name=__RequestVerificationToken]').val();
  145. }
  146. $.ajax({
  147. url: options.url,
  148. data: postdata,
  149. type: options.type,
  150. dataType: options.dataType,
  151. success: function (data) {
  152. Loading(false);
  153. if (data.type == "3") {
  154. dialogAlert(data.message, -1);
  155. } else {
  156. dialogMsg(data.message, 1);
  157. options.success(data);
  158. }
  159. },
  160. error: function (XMLHttpRequest, textStatus, errorThrown) {
  161. Loading(false);
  162. dialogMsg(errorThrown, -1);
  163. },
  164. beforeSend: function () {
  165. Loading(true, options.loading);
  166. },
  167. complete: function () {
  168. Loading(false);
  169. }
  170. });
  171. }, 200);
  172. }
  173. });
  174. }
  175. $.ExistField = function (controlId, url, param) {
  176. var $control = $("#" + controlId);
  177. if (!$control.val()) {
  178. return false;
  179. }
  180. var data = {
  181. keyValue: request('keyValue')
  182. };
  183. data[controlId] = $control.val();
  184. var options = $.extend(data, param);
  185. $.ajax({
  186. url: url,
  187. data: options,
  188. type: "get",
  189. dataType: "text",
  190. async: false,
  191. success: function (data) {
  192. if (data.toLocaleLowerCase() == 'false') {
  193. ValidationMessage($control, '已存在,请重新输入');
  194. $control.attr('fieldexist', 'yes');
  195. } else {
  196. $control.attr('fieldexist', 'no');
  197. }
  198. },
  199. error: function (XMLHttpRequest, textStatus, errorThrown) {
  200. dialogMsg(errorThrown, -1);
  201. }
  202. });
  203. }