supporterManage.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. app.controller('supporterManageCtrl', ['$scope', "$state", '$stateParams', '$http', '$timeout', 'uiGridConstants', 'i18nService', 'toaster', 'md5', function ($scope, $state, $stateParams, $http, $timeout, uiGridConstants, i18nService, toaster, MD5) {
  2. i18nService.setCurrentLang("zh-cn");
  3. $scope.gridOptions = {
  4. data: 'myData',
  5. showGridFooter: true, //是否显示grid footer
  6. // rowHeight: 80,
  7. //-------- 分页属性 ----------------
  8. paginationPageSizes: [50, 200, 500, 1000, 2000], //每页显示个数可选项
  9. paginationCurrentPage: 1, //当前页码
  10. paginationPageSize: 50, //每页显示个数
  11. totalItems: 0,// 总数量
  12. useExternalPagination: true,//是否使用分页按钮
  13. //过滤
  14. // enableFiltering: true,
  15. columnDefs: [],
  16. //---------------api---------------------
  17. onRegisterApi: function (gridApi) {
  18. $scope.gridApi = gridApi;
  19. gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
  20. if ($scope.setPagingData) {
  21. $scope.getPagedDataAsync(newPage, pageSize);
  22. }
  23. });
  24. }
  25. };
  26. //枚举常量
  27. $scope.enum = {};
  28. //查询条件
  29. var condition = $scope.condition = {
  30. searchKey: "",
  31. };
  32. //事件
  33. $scope.event = {
  34. statusChange: function (key, item) {
  35. condition[key].value = item.value;
  36. condition[key].label = item.label;
  37. this.search()
  38. },
  39. search: function () {
  40. $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize);
  41. }
  42. };
  43. function setColumnDefs() {
  44. $scope.gridOptions.columnDefs = [
  45. {
  46. field: 'nickname', displayName: '昵称',
  47. },
  48. {field: 'username', displayName: '用户名'},
  49. {
  50. field: 'createdTime',
  51. displayName: '注册时间',
  52. },
  53. {
  54. field: 'status',
  55. displayName: '状态',
  56. cellTemplate: '<div class="temp-row" >{{row.entity.status}}</div>'
  57. },
  58. ];
  59. var operCol = {
  60. field: 'operation',
  61. displayName: '操作',
  62. enableFiltering: false,
  63. enableSorting: false,
  64. enableHiding: false,//禁止在列选择器中隐藏
  65. enableColumnMenu: false,// 是否显示列头部菜单按钮
  66. minWidth: 300,
  67. cellTemplate: '<div class="grid-button">' +
  68. '<button class="btn btn-sm btn-rounded btn-danger" ng-if="row.entity.status==\'normal\'" ng-click="grid.appScope.ban(row.entity,false)"><i class="fa fa-ban"></i> 封号</button>' +
  69. '<button class="btn btn-sm btn-rounded btn-success" ng-if="row.entity.status!==\'normal\'" ng-click="grid.appScope.ban(row.entity,true)"><i class="fa fa-unlock"></i> 解封</button>' +
  70. // '<button class="btn btn-sm btn-rounded btn-info"ng-click="grid.appScope.unfreeze(row.entity)"><i class="fa fa-smile-o"></i> 解除限制</button>' +
  71. '</div>'
  72. };
  73. $scope.gridOptions.columnDefs.push(operCol)
  74. var fields = $scope.gridOptions.columnDefs;
  75. for (var index in fields) {
  76. var item = fields[index];
  77. if (item && item['minWidth'] == null) {
  78. item['minWidth'] = 120;
  79. }
  80. }
  81. }
  82. $scope.setPagingData = function (data, curPage, pageSize) {
  83. var firstRow = (curPage - 1) * pageSize;
  84. var pagedData = data.data.dataList;
  85. $scope.myData = pagedData;
  86. $scope.gridOptions.totalItems = data.data.total;
  87. };
  88. $scope.getPagedDataAsync = function (curPage, pageSize, searchText) {
  89. if ($scope.gridOptionsLoading) {
  90. return;
  91. }
  92. var params = {
  93. pageSize: pageSize,
  94. pageIndex: curPage
  95. };
  96. if (condition.searchKey != "") {
  97. params.searchKey = condition.searchKey
  98. }
  99. $scope.gridOptionsLoading = true;
  100. $http.get('/superadmin/querySupporters', {
  101. params: params
  102. }).then(function (data) {
  103. data = data.data
  104. $scope.gridOptionsLoading = false;
  105. $scope.setPagingData(data, curPage, pageSize);
  106. }).catch(function (data) {
  107. toaster.pop("error", "提示", "获取数据列表失败");
  108. });
  109. };
  110. function initDataGrid() {
  111. //首次加载表格
  112. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  113. }
  114. setColumnDefs();
  115. initDataGrid();
  116. //广告开关
  117. $scope.selectedIds = []
  118. function getSelectRows() {
  119. var rows = $scope.gridApi.selection.getSelectedRows();
  120. if (rows.length === 0) {
  121. toaster.pop("info", "提示", "请选择数据!");
  122. return false;
  123. }
  124. var ids = [];
  125. for (var i = 0; i < rows.length; i++) {
  126. ids.push(rows[i].id);
  127. }
  128. $scope.selectedIds = ids;
  129. return ids
  130. }
  131. //封号|解封
  132. $scope.ban = function (entity, targetStatus) {
  133. var url = "/superadmin/toggleSupporterStatus";
  134. $.confirm({
  135. content: '确定这样操作?',
  136. buttons: {
  137. ok: {
  138. btnClass: 'btn-red',
  139. action: function () {
  140. $http({
  141. method: 'POST',
  142. url: url,
  143. data: {
  144. id: entity.id,
  145. normal: targetStatus
  146. }
  147. }).then(function (response) {
  148. entity.normal = targetStatus;
  149. console.log(response);
  150. if (response.data.result) {
  151. toaster.pop("success", "提示", "修改状态成功!");
  152. } else {
  153. toaster.pop("error", "提示", "修改状态失败!");
  154. }
  155. }, function (response) {
  156. toaster.pop("error", "提示", "修改状态失败!");
  157. });
  158. }
  159. },
  160. }
  161. });
  162. };
  163. function getOneRow() {
  164. var rows = $scope.gridApi.selection.getSelectedRows();
  165. if (rows.length === 0) {
  166. toaster.pop("info", "提示", "请选择数据!");
  167. return false;
  168. }
  169. if (rows.length > 1) {
  170. toaster.pop("info", "提示", "只能选中编辑一条数据");
  171. return false;
  172. }
  173. return rows[0]
  174. }
  175. // 解除5次错误限制
  176. $scope.unfreeze = function (entity) {
  177. var entity = getOneRow();
  178. if (!entity) {
  179. return
  180. }
  181. var url = "/superadmin/unfreeze";
  182. $http({
  183. method: 'POST',
  184. url: url,
  185. data: {
  186. role: "supporter",
  187. id: entity.id,
  188. }
  189. }).then(function (response) {
  190. if (response.data.result) {
  191. toaster.pop("success", "提示", "解除限制成功!");
  192. } else {
  193. toaster.pop("error", "提示", "解除限制失败!");
  194. }
  195. }, function (response) {
  196. toaster.pop("error", "提示", "解除限制失败!");
  197. });
  198. };
  199. // 必须先声明,否则ui-select无法双绑
  200. $scope.dialogData = {};
  201. // 编辑
  202. $scope.edit = function (entity) {
  203. var rows = $scope.gridApi.selection.getSelectedRows();
  204. if (rows.length === 0) {
  205. toaster.pop("info", "提示", "请选择数据!");
  206. return;
  207. }
  208. if (rows.length > 1) {
  209. toaster.pop("info", "提示", "只能选中编辑一条数据");
  210. return;
  211. }
  212. $scope.dialogData = rows[0];
  213. $("#editSupporterForm").modal();
  214. }
  215. $scope.save = function () {
  216. if ($scope.editSupporterForm.$invalid) {
  217. toaster.pop("warning", "提示", "请填写正确的数据");
  218. return
  219. }
  220. $http({
  221. method: 'POST',
  222. url: '/superadmin/editSupporter',
  223. data: {
  224. id: $scope.dialogData.id,
  225. nickname: $scope.dialogData.nickname,
  226. username: $scope.dialogData.username,
  227. }
  228. }).then(function (response) {
  229. initDataGrid();
  230. $('#editSupporterForm').modal('hide');
  231. }, function (response) {
  232. toaster.pop("error", "提示", "保存失败!");
  233. });
  234. }
  235. }]);