admin.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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: 'department/admin/index',
  8. add_url: 'department/admin/add',
  9. edit_url: 'department/admin/edit',
  10. del_url: 'department/admin/del',
  11. multi_url: 'department/admin/multi',
  12. }
  13. });
  14. var table = $("#table");
  15. //在表格内容渲染完成后回调的事件
  16. table.on('post-body.bs.table', function (e, json) {
  17. });
  18. var columnss=[
  19. {field: 'state', checkbox: true, },
  20. {field: 'id', title: '编号', sortable: true,},
  21. {field: 'username', title: __('Username'), operate: "LIKE",},
  22. {field: 'nickname', title: __('Nickname'), operate: "LIKE",},
  23. {field: 'status', title: __("Status"), searchList: {"normal":__('Normal'),"hidden":__('Hidden')}, formatter: Table.api.formatter.status},
  24. // {field: 'dadmin', title: __('Principal') , operate:false,
  25. // formatter: function (value, row, index) {
  26. // var str=__('No');
  27. // if (value.length == 0)
  28. // return str ;
  29. // $.each(value,function(i,v){ //arrTmp数组数据
  30. // if (v.is_principal==1){
  31. // str='<span class="text-success">'+__('Yes')+'</span>' ;
  32. // }
  33. // });
  34. // return str ;
  35. // }
  36. // },
  37. // {field: 'data_scope', title: __('数据范围') , operate:false,
  38. // formatter: function (value, row, index) {
  39. // var str=__('默认');
  40. // if (value==1){
  41. // str='<span class="text-red">'+__('全部')+'</span>' ;
  42. // }else if ( row.dadmin.length > 0){
  43. // $.each( row.dadmin,function(i,v){ //arrTmp数组数据
  44. // if (v.is_principal==1){
  45. // str='<span class="text-success">'+__('部门')+'</span>' ;
  46. // }
  47. // });
  48. // }
  49. // return str ;
  50. // }
  51. // },
  52. {
  53. field: 'department_id',
  54. title: __('Department'),
  55. visible: false,
  56. addclass: 'selectpage',
  57. extend: 'data-source="department/index/index" data-field="name"',
  58. operate: 'in',
  59. formatter: Table.api.formatter.search
  60. },
  61. {
  62. field: 'dadmin',
  63. title: __('Department'),
  64. formatter: function (value, row, index) {
  65. if (value.length == 0)
  66. return '-' ;
  67. var department="";
  68. $.each(value,function(i,v){ //arrTmp数组数据
  69. if (v.department){
  70. department+=department?','+v.department.name:v.department.name;
  71. }
  72. });
  73. return Table.api.formatter.flag.call(this, department, row, index);
  74. }, operate:false
  75. },
  76. // {
  77. // field: 'groups',
  78. // title: __('Group'),
  79. // formatter: function (value, row, index) {
  80. // if (value.length == 0)
  81. // return '-' ;
  82. // var groups_text="";
  83. // $.each(value,function(i,v){ //arrTmp数组数据
  84. // if (v.get_group){
  85. // groups_text+=groups_text?','+v.get_group.name:v.get_group.name;
  86. // }
  87. // });
  88. // return Table.api.formatter.flag.call(this, groups_text, row, index);
  89. // }
  90. // , operate:false
  91. // },
  92. // {field: 'email', title: __('Email'), operate: "LIKE",},
  93. ];
  94. // if (Config.exits_mobile) {
  95. // //如果是选择
  96. // columnss.push({
  97. // field: 'mobile', title: __('Mobile'), operate: "LIKE",
  98. // });
  99. // }
  100. columnss.push(
  101. {field: 'createtime', title: __('Create time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
  102. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
  103. // buttons: [
  104. // {
  105. // name: 'principal',
  106. // text: __('Principal'),
  107. // title: __('Principal set'),
  108. // icon: 'fa fa-street-view',
  109. // classname: 'btn btn-xs btn-danger btn-dialog',
  110. // url: 'department/admin/principal',
  111. // },
  112. // ],
  113. formatter: function (value, row, index) {
  114. return Table.api.formatter.operate.call(this, value, row, index);
  115. }});
  116. // 初始化表格
  117. table.bootstrapTable({
  118. url: $.fn.bootstrapTable.defaults.extend.index_url,
  119. columns: [columnss],
  120. //启用固定列
  121. fixedColumns: true,
  122. //固定右侧列数
  123. fixedRightNumber: 1,
  124. });
  125. // 为表格绑定事件
  126. Table.api.bindevent(table);
  127. require(['jstree'], function () {
  128. //全选和展开
  129. $(document).on("click", "#checkall", function () {
  130. $("#departmenttree").jstree($(this).prop("checked") ? "check_all" : "uncheck_all");
  131. });
  132. $(document).on("click", "#expandall", function () {
  133. $("#departmenttree").jstree($(this).prop("checked") ? "open_all" : "close_all");
  134. });
  135. $('#departmenttree').on("changed.jstree", function (e, data) {
  136. console.log(data.selected.join(","));
  137. $(".commonsearch-table input[name=department_id]").val(data.selected.join(","));
  138. console.log($(".commonsearch-table input[name=department_id]").val()+"@@@@");
  139. console.log('222222');
  140. table.bootstrapTable('refresh', {});
  141. return false;
  142. });
  143. $('#departmenttree').jstree({
  144. "themes": {
  145. "stripes": true
  146. },
  147. "checkbox": {
  148. "keep_selected_style": false,
  149. },
  150. "types": {
  151. "channel": {
  152. "icon": false,
  153. },
  154. "list": {
  155. "icon": false,
  156. },
  157. "link": {
  158. "icon": false,
  159. },
  160. "disabled": {
  161. "check_node": false,
  162. "uncheck_node": false
  163. }
  164. },
  165. 'plugins': ["types", "checkbox"],
  166. "core": {
  167. "multiple": true,
  168. 'check_callback': true,
  169. "data": Config.departmentList
  170. }
  171. });
  172. });
  173. },
  174. add: function () {
  175. Controller.api.bindevent();
  176. },
  177. principal:function(){
  178. Controller.api.bindevent();
  179. },
  180. edit: function () {
  181. Controller.api.bindevent();
  182. },
  183. api: {
  184. bindevent: function () {
  185. Form.api.bindevent($("form[role=form]"));
  186. // $(document).on("change", "#department_ids", function(){
  187. // //变更后的回调事件
  188. // var dname=$(this).find("option:selected").first().text()
  189. // var nickname=$("#nickname").val();
  190. // var a = nickname.indexOf("-");
  191. //
  192. // if (a!=-1){
  193. // nickname=nickname.substring(0, a);
  194. // }
  195. // dname = dname.replace(/\s*/g,"");
  196. // nickname+="-"+dname.replace(/&nbsp;|│|└|├\s*/ig, "");
  197. // $("#nickname").val(nickname);
  198. // });
  199. },
  200. }
  201. };
  202. return Controller;
  203. });