common.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. var g = {};
  2. /**
  3. * 打开新窗口
  4. * @param {[type]} url [description]
  5. * @param {[type]} title [description]
  6. * @param {[type]} width [description]
  7. * @param {[type]} height [description]
  8. * @return {[type]} [description]
  9. */
  10. function openWin(url, title, width, height) {
  11. if (width == undefined) {
  12. width = $(window).width() * 0.6 + 'px';
  13. }
  14. if (height == undefined) {
  15. height = $(window).height() * 0.75 + 'px';
  16. }
  17. if (title == undefined) {
  18. title = '系统管理';
  19. }
  20. g.currentWin = layer.open({
  21. type: 2,
  22. title: title,
  23. shadeClose: true,
  24. shade: [0.1, '#fff'],
  25. maxmin: true, //开启最大化最小化按钮
  26. area: [width, height],
  27. content: url
  28. });
  29. }
  30. function openHtml(obj, title, width, height) {
  31. if (width == undefined) {
  32. width = $(window).width() * 0.6 + 'px';
  33. }
  34. if (height == undefined) {
  35. height = $(window).height() * 0.75 + 'px';
  36. }
  37. if (title == undefined) {
  38. title = '系统管理';
  39. }
  40. g.currentHtmlWin = layer.open({
  41. type: 1,
  42. shadeClose: true,
  43. shade: [0.1, '#fff'],
  44. title: title,
  45. maxmin: true, //开启最大化最小化按钮
  46. // skin: 'layui-layer-rim', //加上边框
  47. area: [width, height],
  48. content: $(obj).html()
  49. });
  50. }
  51. /**
  52. * 添加到标答
  53. * @param {*}
  54. * @param {*}
  55. */
  56. function joinTab($title, $url) {
  57. parent.addTab(null, $title, $url);
  58. }
  59. function closeWin() {
  60. layer.close(g.currentWin);
  61. }
  62. //无刷新重载表格
  63. function reloadDataTable() {
  64. try {
  65. g.currentDataTableReload['reload'].call();
  66. } catch (ex) {}
  67. }
  68. /**
  69. * 删除数据
  70. * @param {[type]} url [description]
  71. * @return {[type]} [description]
  72. */
  73. function delWin(url, ids) {
  74. ids = (ids == undefined || ids == '') ? g.currentDataTableIds : ids;
  75. if (ids == '' || ids == undefined) {
  76. layer.msg('请先选择数据');
  77. return;
  78. }
  79. layer.confirm('是否确认删除?', {
  80. btn: ['确认', '取消'] //按钮
  81. }, function() {
  82. $.getJSON(url + ids, function(data, textStatus) {
  83. if (data.status == '1') {
  84. reloadDataTable();
  85. layer.msg('删除成功');
  86. } else {
  87. layer.msg(data.msg);
  88. }
  89. });
  90. }, function() {
  91. });
  92. }
  93. $(document).ready(function() {
  94. $('*[eventType=eventForm]').submit(function() {
  95. $(this).attr('method', 'get');
  96. return true;
  97. });
  98. $('*[eventType=eventAjaxForm]').submit(function() {
  99. var msgIndex = parent.layer.msg('数据提交中...', {
  100. icon: 16,
  101. shade: 0.71
  102. });
  103. $.post($(this).attr('action'), $(this).serialize(), function(data, status) {
  104. parent.layer.close(msgIndex);
  105. if (data.status == '1') {
  106. try {
  107. cbFormSuccess(data);
  108. } catch (ex) {
  109. window.history.back();
  110. // parent.window.location.reload();
  111. }
  112. } else {
  113. try {
  114. cbFormFail(data);
  115. } catch (ex) {
  116. parent.layer.msg(data.msg);
  117. }
  118. }
  119. });
  120. return false;
  121. });
  122. $(document).on('click', '[eventType=event-view]', function() {
  123. var url = $(this).attr('uri');
  124. var pid = $(this).attr('pid');
  125. var width = $(this).attr('win-width');
  126. var height = $(this).attr('win-height');
  127. var id = $(this).parent().find('span').attr('data-' + pid);
  128. openWin(url + id, '查看详细信息', width, height);
  129. });
  130. $(document).on('click', '[eventType=event-edit]', function() {
  131. var url = $(this).attr('uri');
  132. var pid = $(this).attr('pid');
  133. var width = $(this).attr('win-width');
  134. var height = $(this).attr('win-height');
  135. var id = $(this).parent().find('span').attr('data-' + pid);
  136. openWin(url + id, '修改信息', width, height);
  137. });
  138. $('form').keyup(function(event) {
  139. if (event.keyCode == 13) {
  140. try {
  141. $(".lay-btn-diy").trigger("click");
  142. } catch (ex) {}
  143. try {
  144. $('*[eventType=event-query-submit]').click();
  145. } catch (ex) {}
  146. }
  147. });
  148. });
  149. try {
  150. $('*[eventType=event-query-submit]').click(function() {
  151. $('*[eventType=eventForm]').submit();
  152. });
  153. } catch (ex) {}
  154. // try {
  155. // $(".lay-btn-diy").click(function () {
  156. // $('*[eventType=eventForm]').submit();
  157. // });
  158. // } catch (ex) { }
  159. function selfTab(name, value) {
  160. $('*[name=' + name + "]").val(value);
  161. // $('*[eventType=event-query-submit]').click();
  162. }
  163. layui.use(['table', 'form', 'tree', 'laydate'], function() {
  164. laydate = layui.laydate //日期;
  165. lay('*[eventType=event-datetime]').each(function() {
  166. laydate.render({
  167. elem: this,
  168. type: 'datetime',
  169. trigger: 'click'
  170. });
  171. });
  172. $('select[eventType=event_query]', function(data) {
  173. // try {
  174. // $(".lay-btn-diy").trigger("click");
  175. // } catch (ex) { }
  176. // try {
  177. // $('*[eventType=event-query-submit]').click();
  178. // } catch (ex) { }
  179. });
  180. });
  181. /**
  182. * 删除数据
  183. * @param {[type]} url [description]
  184. * @return {[type]} [description]
  185. */
  186. function editLine(url, title) {
  187. layer.confirm('是否确认修改?', {
  188. btn: ['确认', '取消'] //按钮
  189. }, function() {
  190. $.getJSON(url, function(data, textStatus) {
  191. if (data.status == '1') {
  192. layer.msg('修改成功');
  193. reloadDataTable();
  194. } else {
  195. layer.msg(data.msg);
  196. }
  197. });
  198. }, function() {});
  199. }