define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { var Controller = { index: function () { // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'send/message/subscriptionlist/index?not_in_ids='+Config.not_in_ids, table: 'admin_config', } }); var table = $("#table"); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'admin_id', sortName: 'admin_id', columns: [ [ { checkbox: true, formatter: function(i , row){ if(window.gzhArr.indexOf(row.admin_id) != -1){ return {checked : true}; } } }, {field: 'sub_nickname', title: __('公众号名称')}, {field: 'admin_id', title: __('账号ID'),operate:false}, {field: 'username', title: __('用户名称')}, {field: 'nickname', title: __('用户昵称')}, ] ], onCheckAll:function(rows){ $(rows).each(function(index, row){ if(window.gzhArr.indexOf(row.admin_id) == -1){ window.gzhArr.push(row.admin_id); window.htmlArr.push({ admin_id:row.admin_id, sub_nickname:row.sub_nickname, username:row.username, nickname:row.nickname }); } ; }); }, onUncheckAll:function(rows){ $(rows).each(function(index, row){ var tdIndex = window.gzhArr.indexOf(row.admin_id); if( tdIndex != -1){ window.gzhArr.splice(tdIndex , 1); window.htmlArr.splice( tdIndex , 1); } ; }); }, onCheck:function(row){ var idIndex = window.gzhArr.indexOf(row.admin_id); if(idIndex == -1){ window.gzhArr.push(row.admin_id); window.htmlArr.push({ admin_id:row.admin_id, sub_nickname:row.sub_nickname, username:row.username, nickname:row.nickname }); }; }, onUncheck:function(row){ var idIndex = window.gzhArr.indexOf(row.admin_id); if(idIndex != -1){ window.gzhArr.splice( idIndex , 1); window.htmlArr.splice( idIndex , 1); }; }, }); // 给父层的id数组 $(function(){ window.gzhArr = []; window.htmlArr = []; if(!window.parent.gzhIdArr){ window.parent.gzhIdArr = []; } window.PIdArr = window.parent.gzhIdArr; if(!window.parent.gzhHtmlArr){ window.parent.gzhHtmlArr = []; } window.PhtmlArr = window.parent.gzhHtmlArr; }); // 添加时将数组转字符串, 设置给hidden input的value $('.btn-add-subscription-list').click(function(){ //id整理 if(PIdArr.length > 0 ){ $(window.gzhArr).each(function(index, item){ if(PIdArr.indexOf(item) == -1){ PIdArr.push(item); }; }); }else{ PIdArr = window.gzhArr; }; $(window.parent.document).find('#subscription_ids').val(PIdArr.join(',')); window.parent.gzhIdArr = PIdArr; // 所有数据整理 if(PhtmlArr.length == 0){ PhtmlArr = window.htmlArr; }else{ $(window.htmlArr).each(function (index , item) { var flag = true; $(PhtmlArr).each(function (idx , itemInner) { if(itemInner.admin_id == item.admin_id){ flag = false; } }); if(flag){ PhtmlArr.push(item); } }); }; window.parent.gzhHtmlArr = PhtmlArr; var gzhParentHtml = ""; $(window.parent.gzhHtmlArr).each(function (index, item) { var tempHtml = '' + ' ' + '' + item.sub_nickname + ' ' + '' + item.admin_id + ' ' + '' + item.username + ' ' + '' + item.nickname + ' ' + '' + '删除' + ' ' + ''; gzhParentHtml += tempHtml; }); $(window.parent.document).find('#gzh_table tbody').html(gzhParentHtml); Fast.api.close(''); }); // 为表格绑定事件 Table.api.bindevent(table); }, subscriptions_list: function () { // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'send/message/subscriptionlist/subscriptions_list?in_ids='+Config.in_ids, table: 'admin_config', } }); var table = $("#table"); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'admin_id', sortName: 'admin_id', columns: [ [ {field: 'sub_nickname', title: __('公众号名称')}, {field: 'admin_id', title: __('账号ID'),operate:false}, {field: 'username', title: __('用户名称')}, {field: 'nickname', title: __('用户昵称')}, ] ], }); // 为表格绑定事件 Table.api.bindevent(table); }, test_user: function () { // 初始化表格参数配置 Table.api.init({ extend: { test_user_url: 'send/message/subscriptionlist/test_user?not_in_ids='+Config.not_in_ids, table: 'admin_config', } }); var table = $("#table"); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.test_user_url, pk: 'admin_id', sortName: 'admin_id', columns: [ [ { checkbox: true }, {field: 'sub_nickname', title: __('公众号名称')}, {field: 'admin_id', title: __('账号ID'),operate:false}, {field: 'username', title: __('用户名称')}, {field: 'nickname', title: __('用户昵称')}, ] ], onCheckAll:function(rows){ $(rows).each(function(index, row){ if(window.gzhArr.indexOf(row.admin_id) == -1){ window.gzhArr.push(row.admin_id); window.htmlArr.push({ admin_id:row.admin_id, sub_nickname:row.sub_nickname, username:row.username, nickname:row.nickname }); } ; }); }, onUncheckAll:function(rows){ $(rows).each(function(index, row){ var tdIndex = window.gzhArr.indexOf(row.admin_id); if( tdIndex != -1){ window.gzhArr.splice(tdIndex , 1); window.htmlArr.splice( tdIndex , 1); } ; }); }, onCheck:function(row){ window.admin_id = row.admin_id; window.htmlArr = { admin_id:row.admin_id, sub_nickname:row.sub_nickname, username:row.username, nickname:row.nickname }; }, onUncheck:function(row){ }, }); // 给父层的id数组 $(function(){ window.admin_id = ""; window.htmlArr = {}; window.parent.testGzhId = window.parent.testGzhId ? window.parent.testGzhId : ""; window.parent.testGzhObj = window.parent.testGzhObj ? window.parent.testGzhObj : {}; }); // 添加时将数组转字符串, 设置给hidden input的value $('.btn-add-test-subscription-list').click(function(){ //id整理 window.parent.testGzhId = admin_id; window.parent.testGzhObj = htmlArr; var gzhParentHtml = ""+ ' ' + '' + htmlArr.sub_nickname + ' ' + '' + htmlArr.admin_id + ' ' + '' + htmlArr.username + ' ' + '' + htmlArr.nickname + ' ' + '' + '删除' + ' ' + ''; $(window.parent.document).find('#gzh_table1 tbody').html(gzhParentHtml); $(window.parent.document).find('#test_channel_id').val(admin_id); Fast.api.close(''); }); // 为表格绑定事件 Table.api.bindevent(table); }, add: function () { Controller.api.bindevent(); }, edit: function () { Controller.api.bindevent(); }, api: { bindevent: function () { Form.api.bindevent($("form[role=form]")); } } }; return Controller; });