special.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form','upload'], function ($, undefined, Backend, Table, Form,Upload) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'auth/special/index',
  8. add_url: 'auth/special/add',
  9. edit_url: 'auth/special/edit',
  10. del_url: 'auth/special/del',
  11. multi_url: 'auth/special/multi',
  12. do_choose: 'auth/special/operate',
  13. select_url: 'referral/vipreferral/selectchannel',
  14. import_url: 'auth/special/import',
  15. },
  16. showToggle: false,
  17. showColumns: false,
  18. visible: false,
  19. commonSearch: false,
  20. showExport: false
  21. });
  22. var table = $("#table");
  23. table.bootstrapTable({
  24. url: $.fn.bootstrapTable.defaults.extend.index_url,
  25. columns: [
  26. [
  27. {field: 'id', title: '菜单ID'},
  28. {field: 'title', title: __('菜单名称')},
  29. {
  30. field: 'id',
  31. operate:false,
  32. title: __('关联账号'),
  33. formatter: Controller.api.formatter.fm_associate_channels
  34. },
  35. {
  36. field: 'id',
  37. operate:false,
  38. title: __('一键清除'),
  39. formatter: function (index, row, value) {
  40. return "<a href='javascript:;' class='qd-associate-all' data-rule_id='" + index + "' data-channel_id='"+ row.channel_id+"'>清除所有账号</a>";
  41. }
  42. }
  43. ]
  44. ]
  45. });
  46. //一键清除
  47. $(document).on('click', '.qd-associate-all', function () {
  48. var rule_id = $(this).data("rule_id");
  49. Layer.confirm(
  50. '确定要清理所有账号吗',
  51. {icon: 3, title: __('Warning'), offset: 0, shadeClose: true},
  52. function (index) {
  53. $.post('/admin/auth/special/operate',
  54. {
  55. 'auth_rule_id': rule_id,
  56. 'channel_ids': "*",
  57. 'method': 'remove'
  58. },
  59. function (result) {
  60. Toastr.success('操作成功');
  61. //刷新页面
  62. table.bootstrapTable('refresh');
  63. });
  64. Layer.close(index);
  65. }
  66. );
  67. });
  68. // 列表关联
  69. $(document).on('click', '.qd-associate', function () {
  70. var rule_id = $(this).data("rule_id");
  71. var group_id = $(this).data("group-id");
  72. var channel_ids = $(this).data("channel_id");
  73. if (channel_ids == 'undefined') {
  74. channel_ids = '';
  75. }
  76. Fast.api.open('/admin/auth/admin/select?operate=add&channel_ids=' + channel_ids +'&group_ids='+group_id, "关联账号", {callback: function (data) {
  77. $.post('/admin/auth/special/operate',
  78. {
  79. 'auth_rule_id': rule_id,
  80. 'channel_ids': data,
  81. 'method': 'add'
  82. },
  83. function (result) {
  84. Toastr.success('操作成功');
  85. //刷新页面
  86. table.bootstrapTable('refresh');
  87. });
  88. }
  89. });
  90. });
  91. // 列表 查看
  92. $(document).on('click', '.qd-view', function () {
  93. var rule_id = $(this).data("rule_id");
  94. var channel_ids = $(this).data("channel_id");
  95. if (channel_ids == 'undefined') {
  96. channel_ids = '';
  97. }
  98. Fast.api.open('/admin/auth/admin/select?operate=remove&channel_ids=' + channel_ids, "查看关联", {callback: function (data) {
  99. $.post('/admin/auth/special/operate',
  100. {
  101. 'auth_rule_id': rule_id,
  102. 'channel_ids': data,
  103. 'method': 'remove'
  104. },
  105. function (result) {
  106. Toastr.success('操作成功');
  107. //刷新页面
  108. table.bootstrapTable('refresh');
  109. });
  110. }
  111. });
  112. });
  113. //上传
  114. $(document).on('click', '.qd-upload', function () {
  115. var rule_id = $(this).data("rule_id");
  116. var channel_ids = $(this).data("channel_id");
  117. if (channel_ids == 'undefined') {
  118. channel_ids = '';
  119. }
  120. Fast.api.open('/admin/auth/special/import?ids='+channel_ids+'&rule_id='+rule_id, "上传文件", $(this).data() || {});
  121. });
  122. $(document).on("click", ".qd-edit", function () {
  123. var rule_id = $(this).data("rule_id");
  124. var channel_ids = $(this).data("channel_id");
  125. if (channel_ids == 'undefined') {
  126. channel_ids = '';
  127. }
  128. layer.open({
  129. type: 1,
  130. title: '批量关联',
  131. maxmin: true,
  132. area: ['60%', '80%'],
  133. btn: ['确定', '取消'],
  134. shadeClose: true, //点击遮罩关闭层
  135. content: $("#qd_multi_edit"),
  136. yes: function (data) {
  137. var channel_ids = $("#c-channel_id").val();
  138. $("#c-channel_id").val("");
  139. $.post('/admin/auth/special/operate',
  140. {
  141. 'auth_rule_id': rule_id,
  142. 'channel_ids': channel_ids,
  143. 'method': 'add'
  144. },
  145. function (result) {
  146. Toastr.success('操作成功');
  147. //刷新页面
  148. table.bootstrapTable('refresh');
  149. });
  150. layer.closeAll();
  151. }
  152. });
  153. });
  154. // 为表格绑定事件
  155. Table.api.bindevent(table);
  156. },
  157. add: function () {
  158. Form.api.bindevent($("form[role=form]"));
  159. },
  160. edit: function () {
  161. Form.api.bindevent($("form[role=form]"));
  162. },
  163. import: function () {
  164. Form.api.bindevent($("form[role=form]"));
  165. },
  166. api: {
  167. formatter: {
  168. fm_associate_channels:function (value, row, index) {
  169. html = '';
  170. if(row.channel_id == '*'){
  171. html += "已关联所有账号";
  172. }else{
  173. html += "<a href='javascript:;' class='qd-associate' data-rule_id='" + value + "' data-channel_id='"+ row.channel_id+"' data-group-id='"+row.group_id+"'>关联账号</a>&nbsp;&nbsp;";
  174. html += "<a href='javascript:;' class='qd-view' data-rule_id='" + value + "' data-channel_id='"+ row.channel_id+"' data-group-id='"+row.group_id+"'>查看</a>&nbsp;&nbsp;";
  175. /*html += "<a href='javascript:;' class='qd-upload' data-rule_id='" + value + "' data-channel_id='"+ row.channel_id+"'><i class=\"fa fa-upload\"></i>上传文件关联</a>";*/
  176. html += "<a href='javascript:;' class='qd-edit' data-rule_id='" + value + "' data-channel_id='"+ row.channel_id+"'>批量关联</a>";
  177. }
  178. return html;
  179. }
  180. },
  181. }
  182. };
  183. return Controller;
  184. });