usergroup.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'send/message/usergroup/index?not_in_ids='+Config.not_in_ids,
  8. table: 'send_user_group',
  9. }
  10. });
  11. var table = $("#table");
  12. // 初始化表格
  13. table.bootstrapTable({
  14. url: $.fn.bootstrapTable.defaults.extend.index_url,
  15. pk: 'id',
  16. sortName: 'id',
  17. columns: [
  18. [
  19. {
  20. checkbox: true,
  21. formatter: function(i , row){
  22. if(window.ugArr.indexOf(row.id) != -1){
  23. return {checked : true};
  24. }
  25. }
  26. },
  27. {field: 'id', title: __('ID')},
  28. {field: 'group_name', title: __('集合名称'),operate:'LIKE'},
  29. {
  30. field: 'group_type',
  31. title: __('选取规则'),
  32. searchList: {"0":__('全部用户'),"1":__('自定义'),"2":__('条件筛选')},
  33. formatter: function(val,row,index){
  34. if(val == 0){
  35. return '全部用户';
  36. }else if(val == 1){
  37. return '自定义';
  38. }else if(val == 2) {
  39. return '条件筛选';
  40. }
  41. }
  42. },
  43. ]
  44. ],
  45. checkboxHeader:false,
  46. onCheck:function (row) {
  47. window.ugArr.push(row.id);
  48. var flag = true;
  49. $(window.tmpUserGroup).each(function(index, item){
  50. if(item.id == row.id){
  51. flag = false;
  52. }
  53. });
  54. if(flag){
  55. window.tmpUserGroup.push(row);
  56. }
  57. if(window.ugArr.length > 1){
  58. layer.alert("只允许选择一项");
  59. }
  60. },
  61. onUncheck:function(row){
  62. window.ugArr.splice(window.ugArr.indexOf(row.id) , 1);
  63. $(window.tmpUserGroup).each(function(index , item){
  64. if(item.id == row.id){
  65. window.tmpUserGroup.splice(index, 1);
  66. }
  67. });
  68. },
  69. });
  70. // 为表格绑定事件
  71. Table.api.bindevent(table);
  72. $(document).ready(function(){
  73. window.tmpUserGroup = [];
  74. window.ugArr = [];
  75. });
  76. // 点击添加
  77. $('.btn-add-user-group').on('click',function () {
  78. if(!window.parent.PUserGroup){
  79. window.parent.PUserGroup ={};
  80. };
  81. if(window.ugArr.length == 1 && window.tmpUserGroup.length == 1){
  82. window.parent.PUserGroup = window.tmpUserGroup[0];
  83. window.parent.PUserGroupId = window.ugArr[0];
  84. $(window.parent.document).find('#selected_user_group_ids').val(window.parent.PUserGroupId);
  85. $(window.parent.document).find("#user_group_ids").val(window.parent.PUserGroupId);
  86. var type = "";
  87. switch (window.parent.PUserGroup.group_type) {
  88. case 0:
  89. type = "全部用户";
  90. break;
  91. case 1:
  92. type = "自定义";
  93. break;
  94. case 2:
  95. type = "条件筛选";
  96. break;
  97. }
  98. var ugHtml = '' +
  99. '<tr data-index="0"> ' +
  100. '<td style="text-align: center; vertical-align: middle; ">' +
  101. window.parent.PUserGroup.id +
  102. '</td> ' +
  103. '<td style="text-align: center; vertical-align: middle; ">' +
  104. window.parent.PUserGroup.group_name +
  105. '</td> ' +
  106. '<td style="text-align: center; vertical-align: middle; ">' +
  107. type +
  108. '</td> ' +
  109. '<td style="text-align: center; vertical-align: middle; ">' +
  110. '<a class="user_group_del_btn" href="javascript:;">删除</a>' +
  111. '</td> ' +
  112. '</tr>';
  113. $(window.parent.document).find('#yhz_table tbody').html(ugHtml);
  114. Fast.api.close('');
  115. }else {
  116. layer.alert("只允许选择一项");
  117. };
  118. });
  119. },
  120. add: function () {
  121. Controller.api.bindevent();
  122. },
  123. edit: function () {
  124. Controller.api.bindevent();
  125. },
  126. api: {
  127. bindevent: function () {
  128. Form.api.bindevent($("form[role=form]"));
  129. }
  130. }
  131. };
  132. return Controller;
  133. });