admin.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'selectpage'], function ($, undefined, Backend, Table, Form, SelectPage) {
  2. let 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. });
  14. let table = $("#table");
  15. //在表格内容渲染完成后回调的事件
  16. table.on('post-body.bs.table', function (e, json) {
  17. $("tbody tr[data-index]", this).each(function () {
  18. if (parseInt($("td:eq(1)", this).text()) == Config.admin.id) {
  19. $("input[type=checkbox]", this).prop("disabled", true);
  20. }
  21. });
  22. });
  23. // 初始化表格
  24. table.bootstrapTable({
  25. url: $.fn.bootstrapTable.defaults.extend.index_url,
  26. showToggle: false,
  27. showColumns: false,
  28. queryParams: function (params) {
  29. //如果希望追加搜索条件,可使用
  30. let filter = params.filter ? JSON.parse(params.filter) : {};
  31. let op = params.op ? JSON.parse(params.op) : {};
  32. if(filter.institution_id){
  33. params.institution_id = filter.institution_id;
  34. delete filter.institution_id;
  35. }
  36. if(op.institution_id){
  37. delete op.institution_id;
  38. }
  39. params.filter = JSON.stringify(filter);
  40. params.op = JSON.stringify(op);
  41. return params;
  42. },
  43. columns: [
  44. [
  45. // {field: 'state', checkbox: true, },
  46. // {field: 'id', title: 'ID'},
  47. {field: 'username', title: __('Username')},
  48. {field: 'nickname', title: __('Nickname')},
  49. {field: 'phone', title: __('Phone')},
  50. {field: 'institution_id', title: __('医院'),visible: false},
  51. {
  52. field: 'groups_text',
  53. title: __('Group'),
  54. operate:false,
  55. width: '20%',
  56. formatter: Table.api.formatter.label
  57. },
  58. // {
  59. // field: 'institution_text',
  60. // title: __('Institution_count'),
  61. // width: '10%',
  62. // searchable: true,
  63. // formatter: function (val) {
  64. // if(val){
  65. // return '<strong>'+ val.split(',').length +'</strong>';
  66. // } else {
  67. // return 0;
  68. // }
  69. // }
  70. // },
  71. {field: 'email', title: __('Email')},
  72. {
  73. field: 'status',
  74. title: __("Status"),
  75. formatter: Table.api.formatter.status,
  76. searchList: {1: '正常', 2: '禁用'},
  77. custom: {1: 'success', 2: 'danger'},
  78. },
  79. {field: 'logintime', title: __('Login time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
  80. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function (value, row, index) {
  81. if(row.id == Config.admin.id){
  82. return '';
  83. }
  84. return Table.api.formatter.operate.call(this, value, row, index);
  85. }}
  86. ]
  87. ]
  88. });
  89. // 为表格绑定事件
  90. Table.api.bindevent(table);
  91. initInstitutionSearchList('institution_text');
  92. $.ajax({
  93. url: 'institution/institution/institutionSelectList',
  94. type: 'post',
  95. dataType: 'json',
  96. success: function success(res) {
  97. let data = res.rows;
  98. $('#institution_id').selectPage({
  99. data : data,
  100. orderBy: 'index'
  101. });
  102. }
  103. });
  104. },
  105. add: function () {
  106. initInstitutionSearchList('c-institution');
  107. Form.api.bindevent($("form[role=form]"));
  108. },
  109. edit: function () {
  110. initInstitutionSearchList('c-institution');
  111. Form.api.bindevent($("form[role=form]"));
  112. }
  113. };
  114. let initInstitutionSearchList = function (id) {
  115. $.ajax({
  116. url: 'institution/institution/institutionSelectList',
  117. type: 'post',
  118. dataType: 'json',
  119. success: function success(res) {
  120. let data = res.rows;
  121. $('#'+id).selectPage({
  122. data : data,
  123. orderBy: 'index',
  124. multiple: true
  125. });
  126. }
  127. });
  128. };
  129. return Controller;
  130. });