123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- layui.define(['layer', 'form'], function (exports) {
- var $ = layui.jquery,layer = layui.layer,form = layui.form;
-
- var table = $('#dateTable').DataTable({
- ajax: {
- url: base+"/actInfo/query",
- data : function(data) {
- data.actName = $.trim($("#actName").val());
- }
- },
- "columns": [ // 自定义数据列
- {data:function(obj){
- return '<input type="checkbox" lay-skin="primary" lay-filter="oneChoose" data-id="'+obj.id+'" />';
- }},
- {data: 'act_name'},
- {data: function(obj){
- return web.getDictVal('act_type',obj.act_type);
- }},
- {data: 'start_date'},
- {data: 'end_date'},
- {data: function(obj){
- return obj.limit_num+web.getDictVal('limit_type',obj.limit_type);
- }},
- {data: 'expect_users'},
- {data: 'act_url'},
- {data:function(obj){
- return '<a class="layui-btn layui-btn-mini btn-analyze">统计分析</a>';
- },sClass:'text-c'},
- {data:function(obj){
- return '<a title="编辑" class="ml-5 btn-edit"><i class="layui-icon"></i></a>'+
- '<a title="删除" class="ml-5 btn-delete"><i class="layui-icon"></i></a>';
- },sClass:'text-c'}
- ],
- "stateSaveParams": function () { // 初始化完成调用事件
- // 重新渲染form checkbox
- form.render('checkbox');
- web.hideTableBtns("#dateTable");
- }
- }).on('click', '.btn-delete', function (e) {
- e.stopPropagation();
- var row = table.row($(this).parents('tr')).data();
- layer.confirm('确认要删除吗?', function (index) {
- del(row.id);
- });
- }).on('click', '.btn-edit', function (e) {
- e.stopPropagation();
- var row = table.row($(this).parents('tr')).data();
- add("编辑", row.id);
- }).on('click', '.btn-analyze', function (e) {
- e.stopPropagation();
- var row = table.row($(this).parents('tr')).data();
- analyze(row.id);
- }).on("dblclick","tr",function () {
- //获取值的对象数据
- var row = table.row(this).data();
- add("编辑用户",row.id);
- });
-
- form.on('checkbox(allChoose)', function(data){
- var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
- child.each(function(index, item){
- item.checked = data.elem.checked;
- });
- form.render('checkbox');
- });
-
- //查询
- $("#btn-query").on('click',function(){
- table.ajax.reload();
- });
-
- //新增
- $('#btn-add').on('click',function(){
- add("新增","");
- });
-
- //删除
- $('#btn-delete').on('click', function(){
- var ids = web.getIds($('#dateTable'),'data-id');
- if (ids.length == 0) {
- layer.msg("请至少选中一条数据");
- } else {
- layer.confirm('确认要删除吗?', function (index) {
- del(ids.join(","));
- });
- }
- });
-
- //启用
- $('#btn-enable').on('click', function(){
- var ids = web.getIds($('#dateTable'),'data-id');
- if (ids.length == 0) {
- layer.msg("请至少选中一条数据");
- } else {
- layer.confirm('确认要启用吗?', function (index) {
- updateStatus(ids.join(','),'1');
- });
- }
- });
-
- //停用
- $('#btn-disable').on('click', function(){
- var ids = web.getIds($('#dateTable'),'data-id');
- if (ids.length == 0) {
- layer.msg("请至少选中一条数据");
- } else {
- layer.confirm('确认要停用吗?', function (index) {
- updateStatus(ids.join(','),'0');
- });
- }
- });
- //删除
- function del(id){
- web.ajaxPost(base + "/actInfo/delete", {id: id}, function (data) {
- if (data.success) {
- table.ajax.reload();
- layer.msg('删除成功');
- } else {
- layer.msg('删除失败');
- }
- });
- }
- //修改状态
- function updateStatus(id,status){
- web.ajaxPost(base + "/actInfo/updateStatus", {id: id,status:status}, function (data) {
- if (data.success) {
- table.ajax.reload();
- layer.msg('操作成功');
- } else {
- layer.msg('操作失败');
- }
- });
- }
- //弹出
- function add(title,id){
- var url="actInfoForm.jsp";
- if(id){
- url +="?id="+id;
- }
- layer_show(title,url,"100%","100%");
- }
-
- //分析
- function analyze(id){
- var url="actInfoDetail.jsp?id="+id;
- layer_show("统计分析",url,"100%","100%");
- }
-
- exports('actInfoList', {});
- });
|