define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { var Controller = { index: function () { // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'general/optchannels/index', edit_url: 'general/optchannels/edit', bw_list_url: 'general/optchannels/bw_list', } }); var table = $("#table"); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'id', sortName: 'id', search: false, commonSearch:true, searchFormVisible: true, columns: [ [ {checkbox: true}, {field: 'id', title: 'ID'}, {field: 'username', title: '用户名', operate:'LIKE'}, {field: 'nickname', title: '昵称', operate:'LIKE'}, {field: 'benefit', title: '抽成比例'}, {field: 'normal_num', title: '普通订单值'}, {field: 'vip_num', title: 'VIP订单值'}, {field: 'is_blacklist', title: '属性',searchList: {"0": __('白名单'),"1": __('黑名单')}, formatter: function(val,row,index){return val=="0"?"白名单":'黑名单';}}, {field: 'clear', title: '黑名单用户处理', formatter: function(val,row,index){ var msg = '-'; if(!row.is_blacklist){ switch (row.clear) { case 0: msg = '未清除清除'; break; case 1: msg = '待清除'; break; case 2: msg = '已清除'; break; } } return msg; }}, {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} ] ] }); // 为表格绑定事件 Table.api.bindevent(table); $(document).delegate('.clearblackuser', 'click', function () { var id = $(this).data('id'); layer.confirm('确定要清除吗?', { btn: ['确定','取消'] //按钮 }, function(){ $.post('/admin/general/optchannels/clearblackuser', {id: id}, function () { layer.msg('操作成功'); table.bootstrapTable('refresh'); }); }, function(){ layer.close(); }); }); $('.btn-white-list').on('click',function () { var ids = Table.api.selectedids(table); $.ajax({ url:'general/optchannels/bw_list', type:"post", data: { ids:ids, is_blacklist:0 }, success:function(){ window.location.reload(); } }); }); $('.btn-black-list').on('click',function () { var ids = Table.api.selectedids(table); $.ajax({ url:'general/optchannels/bw_list', type:"post", data: { ids:ids, is_blacklist:1 }, success:function(){ table.bootstrapTable('refresh'); } }); }); }, edit: function () { /** * form表单验证 */ $("form[role=form]").data("validator-options", { ignore: ':hidden', beforeSubmit: function (form) { if ($('#c-is_blacklist').val() == 1 && $('#c-show_black').val() == 1) { Layer.alert('黑名单渠道无法显示黑名单用户') return false; } } }); Controller.api.bindevent(); }, api: { bindevent: function () { Form.api.bindevent($("form[role=form]")); } } }; return Controller; });