app.controller('supporterManageCtrl', ['$scope', "$state", '$stateParams', '$http', '$timeout', 'uiGridConstants', 'i18nService', 'toaster', 'md5', function ($scope, $state, $stateParams, $http, $timeout, uiGridConstants, i18nService, toaster, MD5) { i18nService.setCurrentLang("zh-cn"); $scope.gridOptions = { data: 'myData', showGridFooter: true, //是否显示grid footer // rowHeight: 80, //-------- 分页属性 ---------------- paginationPageSizes: [50, 200, 500, 1000, 2000], //每页显示个数可选项 paginationCurrentPage: 1, //当前页码 paginationPageSize: 50, //每页显示个数 totalItems: 0,// 总数量 useExternalPagination: true,//是否使用分页按钮 //过滤 // enableFiltering: true, columnDefs: [], //---------------api--------------------- onRegisterApi: function (gridApi) { $scope.gridApi = gridApi; gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) { if ($scope.setPagingData) { $scope.getPagedDataAsync(newPage, pageSize); } }); } }; //枚举常量 $scope.enum = {}; //查询条件 var condition = $scope.condition = { searchKey: "", }; //事件 $scope.event = { statusChange: function (key, item) { condition[key].value = item.value; condition[key].label = item.label; this.search() }, search: function () { $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize); } }; function setColumnDefs() { $scope.gridOptions.columnDefs = [ { field: 'nickname', displayName: '昵称', }, {field: 'username', displayName: '用户名'}, { field: 'createdTime', displayName: '注册时间', }, { field: 'status', displayName: '状态', cellTemplate: '
{{row.entity.status}}
' }, ]; var operCol = { field: 'operation', displayName: '操作', enableFiltering: false, enableSorting: false, enableHiding: false,//禁止在列选择器中隐藏 enableColumnMenu: false,// 是否显示列头部菜单按钮 minWidth: 300, cellTemplate: '
' + '' + '' + // '' + '
' }; $scope.gridOptions.columnDefs.push(operCol) var fields = $scope.gridOptions.columnDefs; for (var index in fields) { var item = fields[index]; if (item && item['minWidth'] == null) { item['minWidth'] = 120; } } } $scope.setPagingData = function (data, curPage, pageSize) { var firstRow = (curPage - 1) * pageSize; var pagedData = data.data.dataList; $scope.myData = pagedData; $scope.gridOptions.totalItems = data.data.total; }; $scope.getPagedDataAsync = function (curPage, pageSize, searchText) { if ($scope.gridOptionsLoading) { return; } var params = { pageSize: pageSize, pageIndex: curPage }; if (condition.searchKey != "") { params.searchKey = condition.searchKey } $scope.gridOptionsLoading = true; $http.get('/superadmin/querySupporters', { params: params }).then(function (data) { data = data.data $scope.gridOptionsLoading = false; $scope.setPagingData(data, curPage, pageSize); }).catch(function (data) { toaster.pop("error", "提示", "获取数据列表失败"); }); }; function initDataGrid() { //首次加载表格 $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize); } setColumnDefs(); initDataGrid(); //广告开关 $scope.selectedIds = [] function getSelectRows() { var rows = $scope.gridApi.selection.getSelectedRows(); if (rows.length === 0) { toaster.pop("info", "提示", "请选择数据!"); return false; } var ids = []; for (var i = 0; i < rows.length; i++) { ids.push(rows[i].id); } $scope.selectedIds = ids; return ids } //封号|解封 $scope.ban = function (entity, targetStatus) { var url = "/superadmin/toggleSupporterStatus"; $.confirm({ content: '确定这样操作?', buttons: { ok: { btnClass: 'btn-red', action: function () { $http({ method: 'POST', url: url, data: { id: entity.id, normal: targetStatus } }).then(function (response) { entity.normal = targetStatus; console.log(response); if (response.data.result) { toaster.pop("success", "提示", "修改状态成功!"); } else { toaster.pop("error", "提示", "修改状态失败!"); } }, function (response) { toaster.pop("error", "提示", "修改状态失败!"); }); } }, } }); }; function getOneRow() { var rows = $scope.gridApi.selection.getSelectedRows(); if (rows.length === 0) { toaster.pop("info", "提示", "请选择数据!"); return false; } if (rows.length > 1) { toaster.pop("info", "提示", "只能选中编辑一条数据"); return false; } return rows[0] } // 解除5次错误限制 $scope.unfreeze = function (entity) { var entity = getOneRow(); if (!entity) { return } var url = "/superadmin/unfreeze"; $http({ method: 'POST', url: url, data: { role: "supporter", id: entity.id, } }).then(function (response) { if (response.data.result) { toaster.pop("success", "提示", "解除限制成功!"); } else { toaster.pop("error", "提示", "解除限制失败!"); } }, function (response) { toaster.pop("error", "提示", "解除限制失败!"); }); }; // 必须先声明,否则ui-select无法双绑 $scope.dialogData = {}; // 编辑 $scope.edit = function (entity) { var rows = $scope.gridApi.selection.getSelectedRows(); if (rows.length === 0) { toaster.pop("info", "提示", "请选择数据!"); return; } if (rows.length > 1) { toaster.pop("info", "提示", "只能选中编辑一条数据"); return; } $scope.dialogData = rows[0]; $("#editSupporterForm").modal(); } $scope.save = function () { if ($scope.editSupporterForm.$invalid) { toaster.pop("warning", "提示", "请填写正确的数据"); return } $http({ method: 'POST', url: '/superadmin/editSupporter', data: { id: $scope.dialogData.id, nickname: $scope.dialogData.nickname, username: $scope.dialogData.username, } }).then(function (response) { initDataGrid(); $('#editSupporterForm').modal('hide'); }, function (response) { toaster.pop("error", "提示", "保存失败!"); }); } }]);