123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- var Controller = {
- index: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'auth/admin/index',
- add_url: 'auth/admin/add',
- edit_url: 'auth/admin/edit',
- del_url: 'auth/admin/del',
- multi_url: 'auth/admin/multi',
- },
- showToggle: false,
- showColumns: false,
- visible: false,
- searchFormVisible: true,
- commonSearch: true,
- showExport: false,
- search: false
- });
- var table = $("#table");
- // 初始化表格
- if(Config.admin.id==1){
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- columns: [
- [
- {field: 'state', checkbox: true, },
- {field: 'id', title: 'ID'},
- {field: 'username', title: __('Username'),operate: 'LIKE %...%'},
- {field: 'nickname', title: __('Nickname'),operate: 'LIKE %...%'},
- {field: 'groups_text', title: __('Group'), operate:false, formatter: Table.api.formatter.label},
- {field: 'email', title: __('Email'), operate:false},
- {field: 'mobile', title: __('Mobile'), operate:false},
- {field: 'status', title: __("Status"), operate:false, formatter: Table.api.formatter.status},
- {field: 'logintime', title: __('Login time'), operate:false, formatter: Table.api.formatter.datetime},
- {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function (value, row, index) {
- if(row.id == Config.admin.id){
- return '';
- }
- return Table.api.formatter.operate.call(this, value, row, index);
- }}
- ]
- ]
- });
- }else{
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- columns: [
- [
- {field: 'state', checkbox: true, },
- {field: 'id', title: 'ID'},
- {field: 'username', title: __('Username')},
- {field: 'nickname', title: __('Nickname')},
- {field: 'groups_text', title: __('Group'), operate:false, formatter: Table.api.formatter.label},
- {field: 'email', title: __('Email')},
- {field: 'mobile', title: __('Mobile')},
- {field: 'status', title: __("Status"), formatter: Table.api.formatter.status},
- {field: 'logintime', title: __('Login time'), formatter: Table.api.formatter.datetime}
- ]
- ]
- });
- }
- // 为表格绑定事件
- Table.api.bindevent(table);
- },
- select: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'auth/admin/select'
- },
- searchFormVisible: true,
- search:false,
- });
- var table = $("#table");
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url + '?&operate=' +Config.operate+ '&channel_ids='+ Config.channel_ids+'&group_ids='+Config.group_ids,
- pk: 'id',
- sortName: 'id desc',
- sortOrder: '',
- columns: [Controller.api.showColumns()],
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- // 单个关联操作
- $(document).on('click', '.qd-doassociate', function () {
- var kl_id = $(this).data("kl_id");
- var channel_id = $(this).data("channel_id");
- var qd_this= $(this);
- Fast.api.close(channel_id);
- });
- // 勾选,关联渠道
- $('.js_assosite').on('click', function (e, data) {
- var ids = Table.api.selectedids(table);
- Layer.confirm(
- __('已选中条数:%s', ids.length),
- {icon: 3, title: __('Warning'), offset: 0, shadeClose: true},
- function (index) {
- var strids = ($.isArray(ids) ? ids.join(",") : ids);
- Fast.api.close(strids);
- }
- );
- });
- $('.js_assosite_all').on('click', function (e, data) {
- var kl_id = $(this).data('kl_id');
- Layer.confirm(
- '确定要关联所有渠道吗',
- {icon: 3, title: __('Warning'), offset: 0, shadeClose: true},
- function (index) {
- Fast.api.close('*');
- }
- );
- });
- // 勾选,查看 删除渠道
- $('.js_assosite_del').on('click', function (e, data) {
- var ids = Table.api.selectedids(table);
- Layer.confirm(
- __('已选中条数:%s', ids.length),
- {icon: 3, title: __('Warning'), offset: 0, shadeClose: true},
- function (index) {
- var strids = ($.isArray(ids) ? ids.join(",") : ids);
- Fast.api.close(strids);
- Layer.close(index);
- }
- );
- });
- // 单个关联操作
- $(document).on('click', '.qd-doassociate-del', function () {
- var kl_id = $(this).data("kl_id");
- var channel_id = $(this).data("channel_id");
- var qd_this= $(this);
- Fast.api.close(channel_id);
- });
- },
- add: function () {
- Form.api.bindevent($("form[role=form]"));
- $('.btn-success').on('click', function () {
- if($("select[name='group[]']").val().indexOf("7") != -1 || $("select[name='group[]']").val().indexOf("8") != -1){
- var city = $('#c-city_code').val().split(',');
- if(city.length > 50){
- Toastr.error('城市白名单不能多余50个');
- return false;
- }
- var ip = $('#c-ip').val().split(',');
- if(ip.length > 20){
- Toastr.error('IP白名单不能多余20个');
- return false;
- }
- }
- });
- },
- edit: function () {
- Form.api.bindevent($("form[role=form]"));
- $('.btn-success').on('click', function () {
- if($("input[name='group[]']").val() == "7" || $("input[name='group[]']").val() == "8"){
- var city = $('#c-city_code').val().split(',');
- if(city.length > 50){
- Toastr.error('城市白名单不能多余50个');
- return false;
- }
- var ip = $('#c-ip').val().split(',');
- if(ip.length > 20){
- Toastr.error('IP白名单不能多余20个');
- return false;
- }
- }
- });
- },
- api: {
- showColumns:function(){
- var cols = new Array();
- cols.push({checkbox: true});
- cols.push({field: 'id', title: 'ID'});
- cols.push({field: 'username', title: __('Username'), operate: 'LIKE %...%'});
- cols.push({field: 'nickname', title: __('Nickname'), operate: 'LIKE %...%'});
- cols.push({field: 'groups_text', title: __('Group'), operate:false, formatter: Table.api.formatter.label});
- if(Config.operate == 'add'){
- cols.push({
- field: 'operate',
- title: __('Operate'),
- table: table,
- events: Table.api.events.operate,
- formatter: function (value, row, index) {
- html = "";
- html += "<a href='javascript:;' class='qd-doassociate' data-channel_id='"+row.id+"' data-kl_id='"+Config.kl_id+"'>关联</a>";
- return html;
- }
- });
- } else {
- cols.push({
- field: 'operate',
- title: __('Operate'),
- table: table,
- events: Table.api.events.operate,
- formatter: function (value, row, index) {
- return "<a href='javascript:;' class='qd-doassociate-del' data-channel_id='"+row.id+"' data-kl_id='"+Config.kl_id+"'>删除</a>";
- }
- });
- }
- return cols;
- },
- },
- };
- return Controller;
- });
|