actInfoList.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. layui.define(['layer', 'form'], function (exports) {
  2. var $ = layui.jquery,layer = layui.layer,form = layui.form;
  3. var table = $('#dateTable').DataTable({
  4. ajax: {
  5. url: base+"/actInfo/query",
  6. data : function(data) {
  7. data.actName = $.trim($("#actName").val());
  8. }
  9. },
  10. "columns": [ // 自定义数据列
  11. {data:function(obj){
  12. return '<input type="checkbox" lay-skin="primary" lay-filter="oneChoose" data-id="'+obj.id+'" />';
  13. }},
  14. {data: 'act_name'},
  15. {data: function(obj){
  16. return web.getDictVal('act_type',obj.act_type);
  17. }},
  18. {data: 'start_date'},
  19. {data: 'end_date'},
  20. {data: function(obj){
  21. return obj.limit_num+web.getDictVal('limit_type',obj.limit_type);
  22. }},
  23. {data: 'expect_users'},
  24. {data: 'act_url'},
  25. {data:function(obj){
  26. return '<a class="layui-btn layui-btn-mini btn-analyze">统计分析</a>';
  27. },sClass:'text-c'},
  28. {data:function(obj){
  29. return '<a title="编辑" class="ml-5 btn-edit"><i class="layui-icon">&#xe642;</i></a>'+
  30. '<a title="删除" class="ml-5 btn-delete"><i class="layui-icon">&#xe640;</i></a>';
  31. },sClass:'text-c'}
  32. ],
  33. "stateSaveParams": function () { // 初始化完成调用事件
  34. // 重新渲染form checkbox
  35. form.render('checkbox');
  36. web.hideTableBtns("#dateTable");
  37. }
  38. }).on('click', '.btn-delete', function (e) {
  39. e.stopPropagation();
  40. var row = table.row($(this).parents('tr')).data();
  41. layer.confirm('确认要删除吗?', function (index) {
  42. del(row.id);
  43. });
  44. }).on('click', '.btn-edit', function (e) {
  45. e.stopPropagation();
  46. var row = table.row($(this).parents('tr')).data();
  47. add("编辑", row.id);
  48. }).on('click', '.btn-analyze', function (e) {
  49. e.stopPropagation();
  50. var row = table.row($(this).parents('tr')).data();
  51. analyze(row.id);
  52. }).on("dblclick","tr",function () {
  53. //获取值的对象数据
  54. var row = table.row(this).data();
  55. add("编辑用户",row.id);
  56. });
  57. form.on('checkbox(allChoose)', function(data){
  58. var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
  59. child.each(function(index, item){
  60. item.checked = data.elem.checked;
  61. });
  62. form.render('checkbox');
  63. });
  64. //查询
  65. $("#btn-query").on('click',function(){
  66. table.ajax.reload();
  67. });
  68. //新增
  69. $('#btn-add').on('click',function(){
  70. add("新增","");
  71. });
  72. //删除
  73. $('#btn-delete').on('click', function(){
  74. var ids = web.getIds($('#dateTable'),'data-id');
  75. if (ids.length == 0) {
  76. layer.msg("请至少选中一条数据");
  77. } else {
  78. layer.confirm('确认要删除吗?', function (index) {
  79. del(ids.join(","));
  80. });
  81. }
  82. });
  83. //启用
  84. $('#btn-enable').on('click', function(){
  85. var ids = web.getIds($('#dateTable'),'data-id');
  86. if (ids.length == 0) {
  87. layer.msg("请至少选中一条数据");
  88. } else {
  89. layer.confirm('确认要启用吗?', function (index) {
  90. updateStatus(ids.join(','),'1');
  91. });
  92. }
  93. });
  94. //停用
  95. $('#btn-disable').on('click', function(){
  96. var ids = web.getIds($('#dateTable'),'data-id');
  97. if (ids.length == 0) {
  98. layer.msg("请至少选中一条数据");
  99. } else {
  100. layer.confirm('确认要停用吗?', function (index) {
  101. updateStatus(ids.join(','),'0');
  102. });
  103. }
  104. });
  105. //删除
  106. function del(id){
  107. web.ajaxPost(base + "/actInfo/delete", {id: id}, function (data) {
  108. if (data.success) {
  109. table.ajax.reload();
  110. layer.msg('删除成功');
  111. } else {
  112. layer.msg('删除失败');
  113. }
  114. });
  115. }
  116. //修改状态
  117. function updateStatus(id,status){
  118. web.ajaxPost(base + "/actInfo/updateStatus", {id: id,status:status}, function (data) {
  119. if (data.success) {
  120. table.ajax.reload();
  121. layer.msg('操作成功');
  122. } else {
  123. layer.msg('操作失败');
  124. }
  125. });
  126. }
  127. //弹出
  128. function add(title,id){
  129. var url="actInfoForm.jsp";
  130. if(id){
  131. url +="?id="+id;
  132. }
  133. layer_show(title,url,"100%","100%");
  134. }
  135. //分析
  136. function analyze(id){
  137. var url="actInfoDetail.jsp?id="+id;
  138. layer_show("统计分析",url,"100%","100%");
  139. }
  140. exports('actInfoList', {});
  141. });