common.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. console.log(g.currentDataTableIds);
  76. if (ids == '' || ids == undefined) {
  77. layer.msg('请先选择数据');
  78. return;
  79. }
  80. layer.confirm('是否确认删除?', {
  81. btn: ['确认', '取消'] //按钮
  82. }, function() {
  83. $.getJSON(url + ids, function(data, textStatus) {
  84. if (data.status == '1') {
  85. reloadDataTable();
  86. layer.msg('删除成功');
  87. } else {
  88. layer.msg(data.msg);
  89. }
  90. });
  91. }, function() {
  92. });
  93. }
  94. $(document).ready(function() {
  95. $('*[eventType=eventForm]').submit(function() {
  96. $(this).attr('method', 'get');
  97. return true;
  98. });
  99. $('*[eventType=eventAjaxForm]').submit(function() {
  100. var uid = $(this).serialize() + $(this).attr('action');
  101. if (g.parentUid == uid) {
  102. return false;
  103. }
  104. g.parentUid = uid;
  105. var msgIndex = parent.layer.msg('数据提交中...', {
  106. icon: 16,
  107. shade: 0.71
  108. });
  109. $.post($(this).attr('action'), $(this).serialize(), function(data, status) {
  110. parent.layer.close(msgIndex);
  111. if (data.status == '1') {
  112. try {
  113. cbFormSuccess(data);
  114. } catch (ex) {
  115. window.history.back();
  116. // parent.window.location.reload();
  117. }
  118. } else {
  119. try {
  120. cbFormFail(data);
  121. } catch (ex) {
  122. parent.layer.msg(data.msg);
  123. }
  124. }
  125. });
  126. return false;
  127. });
  128. $(document).on('click', '[eventType=event-view]', function() {
  129. var url = $(this).attr('uri');
  130. var pid = $(this).attr('pid');
  131. var width = $(this).attr('win-width');
  132. var height = $(this).attr('win-height');
  133. var id = $(this).parent().find('span').attr('data-' + pid);
  134. openWin(url + id, '查看详细信息', width, height);
  135. });
  136. $(document).on('click', '[eventType=event-edit]', function() {
  137. var url = $(this).attr('uri');
  138. var pid = $(this).attr('pid');
  139. var width = $(this).attr('win-width');
  140. var height = $(this).attr('win-height');
  141. var id = $(this).parent().find('span').attr('data-' + pid);
  142. openWin(url + id, '修改信息', width, height);
  143. });
  144. $('form').keyup(function(event) {
  145. if (event.keyCode == 13) {
  146. try {
  147. $(".lay-btn-diy").trigger("click");
  148. } catch (ex) {}
  149. try {
  150. $('*[eventType=event-query-submit]').click();
  151. } catch (ex) {}
  152. }
  153. });
  154. });
  155. try {
  156. $('*[eventType=event-query-submit]').click(function() {
  157. $('*[eventType=eventForm]').submit();
  158. });
  159. } catch (ex) {}
  160. // try {
  161. // $(".lay-btn-diy").click(function () {
  162. // $('*[eventType=eventForm]').submit();
  163. // });
  164. // } catch (ex) { }
  165. function selfTab(name, value) {
  166. $('*[name=' + name + "]").val(value);
  167. // $('*[eventType=event-query-submit]').click();
  168. }
  169. layui.use(['table', 'form', 'tree', 'laydate'], function() {
  170. laydate = layui.laydate //日期;
  171. lay('*[eventType=event-datetime]').each(function() {
  172. laydate.render({
  173. elem: this,
  174. type: 'datetime',
  175. trigger: 'click'
  176. });
  177. });
  178. $('select[eventType=event_query]', function(data) {
  179. // try {
  180. // $(".lay-btn-diy").trigger("click");
  181. // } catch (ex) { }
  182. // try {
  183. // $('*[eventType=event-query-submit]').click();
  184. // } catch (ex) { }
  185. });
  186. });
  187. /**
  188. * 删除数据
  189. * @param {[type]} url [description]
  190. * @return {[type]} [description]
  191. */
  192. function editLine(url, title) {
  193. layer.confirm('是否确认修改?', {
  194. btn: ['确认', '取消'] //按钮
  195. }, function() {
  196. $.getJSON(url, function(data, textStatus) {
  197. if (data.status == '1') {
  198. layer.msg('修改成功');
  199. reloadDataTable();
  200. } else {
  201. layer.msg(data.msg);
  202. }
  203. });
  204. }, function() {});
  205. }