admin.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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: 'auth/admin/index',
  8. add_url: 'auth/admin/add',
  9. edit_url: 'auth/admin/edit',
  10. del_url: 'auth/admin/del',
  11. multi_url: 'auth/admin/multi',
  12. },
  13. showToggle: false,
  14. showColumns: false,
  15. visible: false,
  16. searchFormVisible: true,
  17. commonSearch: true,
  18. showExport: false,
  19. search: false
  20. });
  21. var table = $("#table");
  22. // 初始化表格
  23. if(Config.admin.id==1){
  24. table.bootstrapTable({
  25. url: $.fn.bootstrapTable.defaults.extend.index_url,
  26. columns: [
  27. [
  28. {field: 'state', checkbox: true, },
  29. {field: 'id', title: 'ID'},
  30. {field: 'username', title: __('Username'),operate: 'LIKE %...%'},
  31. {field: 'nickname', title: __('Nickname'),operate: 'LIKE %...%'},
  32. {field: 'groups_text', title: __('Group'), operate:false, formatter: Table.api.formatter.label},
  33. {field: 'email', title: __('Email'), operate:false},
  34. {field: 'mobile', title: __('Mobile'), operate:false},
  35. {field: 'status', title: __("Status"), operate:false, formatter: Table.api.formatter.status},
  36. {field: 'logintime', title: __('Login time'), operate:false, formatter: Table.api.formatter.datetime},
  37. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function (value, row, index) {
  38. if(row.id == Config.admin.id){
  39. return '';
  40. }
  41. return Table.api.formatter.operate.call(this, value, row, index);
  42. }}
  43. ]
  44. ]
  45. });
  46. }else{
  47. table.bootstrapTable({
  48. url: $.fn.bootstrapTable.defaults.extend.index_url,
  49. columns: [
  50. [
  51. {field: 'state', checkbox: true, },
  52. {field: 'id', title: 'ID'},
  53. {field: 'username', title: __('Username')},
  54. {field: 'nickname', title: __('Nickname')},
  55. {field: 'groups_text', title: __('Group'), operate:false, formatter: Table.api.formatter.label},
  56. {field: 'email', title: __('Email')},
  57. {field: 'mobile', title: __('Mobile')},
  58. {field: 'status', title: __("Status"), formatter: Table.api.formatter.status},
  59. {field: 'logintime', title: __('Login time'), formatter: Table.api.formatter.datetime}
  60. ]
  61. ]
  62. });
  63. }
  64. // 为表格绑定事件
  65. Table.api.bindevent(table);
  66. },
  67. select: function () {
  68. // 初始化表格参数配置
  69. Table.api.init({
  70. extend: {
  71. index_url: 'auth/admin/select'
  72. },
  73. searchFormVisible: true,
  74. search:false,
  75. });
  76. var table = $("#table");
  77. // 初始化表格
  78. table.bootstrapTable({
  79. url: $.fn.bootstrapTable.defaults.extend.index_url + '?&operate=' +Config.operate+ '&channel_ids='+ Config.channel_ids+'&group_ids='+Config.group_ids,
  80. pk: 'id',
  81. sortName: 'id desc',
  82. sortOrder: '',
  83. columns: [Controller.api.showColumns()],
  84. });
  85. // 为表格绑定事件
  86. Table.api.bindevent(table);
  87. // 单个关联操作
  88. $(document).on('click', '.qd-doassociate', function () {
  89. var kl_id = $(this).data("kl_id");
  90. var channel_id = $(this).data("channel_id");
  91. var qd_this= $(this);
  92. Fast.api.close(channel_id);
  93. });
  94. // 勾选,关联渠道
  95. $('.js_assosite').on('click', function (e, data) {
  96. var ids = Table.api.selectedids(table);
  97. Layer.confirm(
  98. __('已选中条数:%s', ids.length),
  99. {icon: 3, title: __('Warning'), offset: 0, shadeClose: true},
  100. function (index) {
  101. var strids = ($.isArray(ids) ? ids.join(",") : ids);
  102. Fast.api.close(strids);
  103. }
  104. );
  105. });
  106. $('.js_assosite_all').on('click', function (e, data) {
  107. var kl_id = $(this).data('kl_id');
  108. Layer.confirm(
  109. '确定要关联所有渠道吗',
  110. {icon: 3, title: __('Warning'), offset: 0, shadeClose: true},
  111. function (index) {
  112. Fast.api.close('*');
  113. }
  114. );
  115. });
  116. // 勾选,查看 删除渠道
  117. $('.js_assosite_del').on('click', function (e, data) {
  118. var ids = Table.api.selectedids(table);
  119. Layer.confirm(
  120. __('已选中条数:%s', ids.length),
  121. {icon: 3, title: __('Warning'), offset: 0, shadeClose: true},
  122. function (index) {
  123. var strids = ($.isArray(ids) ? ids.join(",") : ids);
  124. Fast.api.close(strids);
  125. Layer.close(index);
  126. }
  127. );
  128. });
  129. // 单个关联操作
  130. $(document).on('click', '.qd-doassociate-del', function () {
  131. var kl_id = $(this).data("kl_id");
  132. var channel_id = $(this).data("channel_id");
  133. var qd_this= $(this);
  134. Fast.api.close(channel_id);
  135. });
  136. },
  137. add: function () {
  138. Form.api.bindevent($("form[role=form]"));
  139. $('.btn-success').on('click', function () {
  140. if($("select[name='group[]']").val().indexOf("7") != -1 || $("select[name='group[]']").val().indexOf("8") != -1){
  141. var city = $('#c-city_code').val().split(',');
  142. if(city.length > 50){
  143. Toastr.error('城市白名单不能多余50个');
  144. return false;
  145. }
  146. var ip = $('#c-ip').val().split(',');
  147. if(ip.length > 20){
  148. Toastr.error('IP白名单不能多余20个');
  149. return false;
  150. }
  151. }
  152. });
  153. },
  154. edit: function () {
  155. Form.api.bindevent($("form[role=form]"));
  156. $('.btn-success').on('click', function () {
  157. if($("input[name='group[]']").val() == "7" || $("input[name='group[]']").val() == "8"){
  158. var city = $('#c-city_code').val().split(',');
  159. if(city.length > 50){
  160. Toastr.error('城市白名单不能多余50个');
  161. return false;
  162. }
  163. var ip = $('#c-ip').val().split(',');
  164. if(ip.length > 20){
  165. Toastr.error('IP白名单不能多余20个');
  166. return false;
  167. }
  168. }
  169. });
  170. },
  171. api: {
  172. showColumns:function(){
  173. var cols = new Array();
  174. cols.push({checkbox: true});
  175. cols.push({field: 'id', title: 'ID'});
  176. cols.push({field: 'username', title: __('Username'), operate: 'LIKE %...%'});
  177. cols.push({field: 'nickname', title: __('Nickname'), operate: 'LIKE %...%'});
  178. cols.push({field: 'groups_text', title: __('Group'), operate:false, formatter: Table.api.formatter.label});
  179. if(Config.operate == 'add'){
  180. cols.push({
  181. field: 'operate',
  182. title: __('Operate'),
  183. table: table,
  184. events: Table.api.events.operate,
  185. formatter: function (value, row, index) {
  186. html = "";
  187. html += "<a href='javascript:;' class='qd-doassociate' data-channel_id='"+row.id+"' data-kl_id='"+Config.kl_id+"'>关联</a>";
  188. return html;
  189. }
  190. });
  191. } else {
  192. cols.push({
  193. field: 'operate',
  194. title: __('Operate'),
  195. table: table,
  196. events: Table.api.events.operate,
  197. formatter: function (value, row, index) {
  198. return "<a href='javascript:;' class='qd-doassociate-del' data-channel_id='"+row.id+"' data-kl_id='"+Config.kl_id+"'>删除</a>";
  199. }
  200. });
  201. }
  202. return cols;
  203. },
  204. },
  205. };
  206. return Controller;
  207. });