123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- var Controller = {
- index: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'send/message/usergroup/index?not_in_ids='+Config.not_in_ids,
- table: 'send_user_group',
- }
- });
- var table = $("#table");
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- sortName: 'id',
- columns: [
- [
- {
- checkbox: true,
- formatter: function(i , row){
- if(window.ugArr.indexOf(row.id) != -1){
- return {checked : true};
- }
- }
- },
- {field: 'id', title: __('ID')},
- {field: 'group_name', title: __('集合名称'),operate:'LIKE'},
- {
- field: 'group_type',
- title: __('选取规则'),
- searchList: {"0":__('全部用户'),"1":__('自定义'),"2":__('条件筛选')},
- formatter: function(val,row,index){
- if(val == 0){
- return '全部用户';
- }else if(val == 1){
- return '自定义';
- }else if(val == 2) {
- return '条件筛选';
- }
- }
- },
- ]
- ],
- checkboxHeader:false,
- onCheck:function (row) {
- window.ugArr.push(row.id);
- var flag = true;
- $(window.tmpUserGroup).each(function(index, item){
- if(item.id == row.id){
- flag = false;
- }
- });
- if(flag){
- window.tmpUserGroup.push(row);
- }
- if(window.ugArr.length > 1){
- layer.alert("只允许选择一项");
- }
- },
- onUncheck:function(row){
- window.ugArr.splice(window.ugArr.indexOf(row.id) , 1);
- $(window.tmpUserGroup).each(function(index , item){
- if(item.id == row.id){
- window.tmpUserGroup.splice(index, 1);
- }
- });
- },
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- $(document).ready(function(){
- window.tmpUserGroup = [];
- window.ugArr = [];
- });
- // 点击添加
- $('.btn-add-user-group').on('click',function () {
- if(!window.parent.PUserGroup){
- window.parent.PUserGroup ={};
- };
- if(window.ugArr.length == 1 && window.tmpUserGroup.length == 1){
- window.parent.PUserGroup = window.tmpUserGroup[0];
- window.parent.PUserGroupId = window.ugArr[0];
- $(window.parent.document).find('#selected_user_group_ids').val(window.parent.PUserGroupId);
- $(window.parent.document).find("#user_group_ids").val(window.parent.PUserGroupId);
-
- var type = "";
- switch (window.parent.PUserGroup.group_type) {
- case 0:
- type = "全部用户";
- break;
- case 1:
- type = "自定义";
- break;
- case 2:
- type = "条件筛选";
- break;
- }
- var ugHtml = '' +
- '<tr data-index="0"> ' +
- '<td style="text-align: center; vertical-align: middle; ">' +
- window.parent.PUserGroup.id +
- '</td> ' +
- '<td style="text-align: center; vertical-align: middle; ">' +
- window.parent.PUserGroup.group_name +
- '</td> ' +
- '<td style="text-align: center; vertical-align: middle; ">' +
- type +
- '</td> ' +
- '<td style="text-align: center; vertical-align: middle; ">' +
- '<a class="user_group_del_btn" href="javascript:;">删除</a>' +
- '</td> ' +
- '</tr>';
- $(window.parent.document).find('#yhz_table tbody').html(ugHtml);
- Fast.api.close('');
- }else {
- layer.alert("只允许选择一项");
- };
- });
- },
- add: function () {
- Controller.api.bindevent();
- },
- edit: function () {
- Controller.api.bindevent();
- },
- api: {
- bindevent: function () {
- Form.api.bindevent($("form[role=form]"));
- }
- }
- };
- return Controller;
- });
|