123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- var Controller = {
- index: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'postbackchannel/index?rule_id=' + Config.rule_id + '&action=' + Config.action,
- table: 'admin',
- },
- search: false,
- });
- var table = $("#table");
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- sortName: 'id',
- columns:[
- Controller.api.showFilterColumns(table)
- ]
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- $(document).delegate('.batch_relation', 'click', function () {
- var ids = [];
- var action = $(this).data('action');
- if ($(this).data('channel_id')) {
- ids.push($(this).data('channel_id'));
- } else {
- ids = Table.api.selectedids(table);
- }
- Controller.api.batchrelation(ids, action, table)
- });
- },
- api: {
- showFilterColumns:function(table){
- cols = [
- {checkbox: true},
- {field: 'id', title: __('Id')},
- {field: 'username', title: __('Username'), operate:'LIKE'},
- {field: 'nickname', title: __('Nickname'), operate:'LIKE'},
- {field: 'operate', title: __('Operate'), operate:false,formatter: function (value, row, table) {
- if (Config.action == 'relation') {
- return "<a href='javascript:;' class='batch_relation' data-action='add' data-channel_id='"+row.id+"'>关联</a>";
- } else {
- return "<a href='javascript:;' class='batch_relation' data-action='delete' data-channel_id='"+row.id+"'>删除</a>";
- }
- }}
- ];
- if (Config.channels == '*') {
- cols.pop();
- }
- return cols;
- },
- bindevent: function () {
- Form.api.bindevent($("form[role=form]"));
- },
- batchrelation: function (ids, action, table) {
- if (ids.length) {
- var msg = '';
- if (ids[0] == '-1') {
- if (!$(table).find('.no-records-found').length) {
- if (action == 'add') {
- msg = '关联全部渠道?';
- } else {
- msg = '删除全部渠道及推广链接?';
- }
- } else {
- Layer.alert('渠道为空,操作取消');
- return;
- }
- } else {
- msg = __('已选中渠道个数:%s', ids.length);
- }
- Layer.confirm(
- msg,
- {icon: 3, title: __('Warning'), offset: 0, shadeClose: true},
- function (index) {
- var url = 'postbackchannel/batch_relation';
- var options = {url: url, data: { channel_ids: ids.join(","), rule_id: Config.rule_id, action: action}};
- Fast.api.ajax(options, function (data, ret) {
- Layer.msg('处理成功!');
- table.bootstrapTable('refresh');
- }, function (data, ret) {
- });
- Layer.close(index);
- }
- );
- }
- }
- }
- };
- return Controller;
- });
|