123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- 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: '<div class="temp-row" >{{row.entity.status}}</div>'
- },
- ];
- var operCol = {
- field: 'operation',
- displayName: '操作',
- enableFiltering: false,
- enableSorting: false,
- enableHiding: false,//禁止在列选择器中隐藏
- enableColumnMenu: false,// 是否显示列头部菜单按钮
- minWidth: 300,
- cellTemplate: '<div class="grid-button">' +
- '<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>' +
- '<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>' +
- // '<button class="btn btn-sm btn-rounded btn-info"ng-click="grid.appScope.unfreeze(row.entity)"><i class="fa fa-smile-o"></i> 解除限制</button>' +
- '</div>'
- };
- $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", "提示", "保存失败!");
- });
- }
- }]);
|