123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352 |
- app.controller('advertiserCtrl', ['$scope', '$http', '$timeout', 'uiGridConstants', 'i18nService', 'toaster', 'md5', function ($scope, $http, $timeout, uiGridConstants, i18nService, toaster, MD5) {
- i18nService.setCurrentLang("zh-cn");
- $scope.gridOptions = {
- data: 'myData',
- showGridFooter: true, //是否显示grid footer
- // rowHeight: 80,
- //-------- 分页属性 ----------------
- paginationPageSizes: [10, 20, 50, 100], //每页显示个数可选项
- paginationCurrentPage: 1, //当前页码
- paginationPageSize: 10, //每页显示个数
- 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);
- }
- });
- }
- };
- //查询条件
- var condition = $scope.condition = {
- searchKey: "",
- //状态 true false 默认激活
- activited: {value: true, label: "激活"},
- };
- //枚举常量
- $scope.enum = {
- activited: [
- {value: null, label: "-全部状态-"},
- {value: true, label: "激活"},
- {value: false, label: "禁用"}
- ],
- };
- //事件
- $scope.event = {
- conditionChange: function (key, item) {
- condition[key].value = item.value;
- condition[key].label = item.label;
- $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize);
- },
- search: function () {
- $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize);
- }
- };
- function setColumnDefs() {
- $scope.gridOptions.columnDefs = [
- {field: 'nickname', displayName: '姓名'},
- {field: 'username', displayName: '联系方式'},
- {field: 'quota', displayName: '额度'},
- {
- field: 'dateTimeAdded',
- displayName: '注册时间',
- cellTemplate: '<div class="temp-row" ng-bind="row.entity.dateTimeAdded"></div>'
- },
- // {
- // field: 'status', displayName: '状态',
- // cellTemplate: '<div class="temp-row" ng-class="{' +
- // '\'text-dark\':row.entity.status==false,' +
- // '\'text-success\':row.entity.status==true' +
- // '}" >{{row.entity.status==false?"停用":"激活"}}</div>'
- // },
- {
- field: 'oper', displayName: '操作',
- enableFiltering: false,
- enableSorting: false,
- enableHiding: false,//禁止在列选择器中隐藏
- enableColumnMenu: false,// 是否显示列头部菜单按钮
- width: 200,
- cellTemplate: '<div class="grid-button">' +
- '<button class="btn btn-sm btn-rounded btn-success" ng-if="row.entity.activited==false" ng-click="grid.appScope.openOrClose(row.entity,true)"><i class="fa fa-play"></i> 激活</button>' +
- '<button class="btn btn-sm btn-rounded btn-default" ng-if="row.entity.activited==true" ng-click="grid.appScope.openOrClose(row.entity,false)"><i class="fa fa-close"></i> 停用</button>' +
- '</div>'
- }
- ];
- var fields = $scope.gridOptions.columnDefs;
- for (var index in fields) {
- var item = fields[index];
- if (item && item['minWidth'] == null) {
- item['minWidth'] = 100;
- }
- }
- }
- //打开或关闭
- $scope.openOrClose = function (entity, activited) {
- $http({
- method: 'POST',
- url: '/manager/toggleAdvertiserActivation',
- data: {id: entity.id, activited: activited}
- }).then(function (response) {
- initDataGrid();
- }, function (response) {
- toaster.pop("error", "提示", "操作失败!");
- });
- };
- $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) {
- var params = {
- pageSize: pageSize,
- pageIndex: curPage
- };
- if (condition.searchKey != "") {
- params.searchKey = condition.searchKey
- }
- if (condition.activited.value != null) {
- params.activited = condition.activited.value
- }
- $http.get('/manager/getAdvertiserList', {
- params: params
- }).then(function (data) {
- $scope.setPagingData(data.data, curPage, pageSize);
- }).catch(function (data) {
- toaster.pop("error", "提示", "获取数据列表失败");
- });
- };
- function initDataGrid() {
- //首次加载表格
- $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
- }
- setColumnDefs();
- initDataGrid();
- //添加
- $scope.add = function () {
- //重置表单状态
- $scope.modelForm.$setPristine();
- $scope.modelForm.$setUntouched();
- $scope.dialogName = "开户";
- $scope.dialogData = {activited: true, isNew: true};
- $("#modelPanel").modal();
- };
- //编辑密码 默认123456
- $scope.editPassword = function () {
- //重置表单状态
- $scope.passwordForm.$setPristine();
- $scope.passwordForm.$setUntouched();
- var rows = $scope.gridApi.selection.getSelectedRows();
- if (rows.length == 0) {
- toaster.pop("info", "提示", "请选择数据!");
- return;
- }
- if (rows.length > 1) {
- toaster.pop("info", "提示", "只能选中编辑一条数据");
- return;
- }
- var item = rows[0];
- $scope.passwordData = $.extend({password: 123456}, item);
- $("#passwordPanel").modal();
- };
- $scope.setAdvertiserQuota = function () {
- //重置表单状态
- $scope.quotaForm.$setPristine();
- $scope.quotaForm.$setUntouched();
- var rows = $scope.gridApi.selection.getSelectedRows();
- if (rows.length == 0) {
- toaster.pop("info", "提示", "请选择数据!");
- return;
- }
- if (rows.length > 1) {
- toaster.pop("info", "提示", "只能选中编辑一条数据");
- return;
- }
- var item = rows[0];
- $scope.quotaData = $.extend({}, item);
- $("#quotaPanel").modal();
- };
- //提交表单保存
- $scope.saveData = function () {
- //表单未校验通过不能提交
- if ($scope.modelForm.$invalid) {
- return;
- }
- var url = "";
- if ($scope.dialogData.id == null) {
- url = "/manager/addAdvertiser";
- } else {
- url = "/manager/editAdvertiser";
- }
- //深度克隆 避免操作原对象
- var data = $.extend(true, {}, $scope.dialogData);
- if ($scope.dialogData.isNew) {
- var password = MD5.createHash($scope.dialogData.password + '');
- data.password = password;
- }
- // 删除多余的字段
- delete data.isNew
- $http({
- method: 'POST',
- url: url,
- data: data
- }).then(function (response) {
- $('#modelPanel').modal('hide');//弹窗消失
- $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
- toaster.pop("success", "提示", "开户成功!");
- }, function (response) {
- toaster.pop("error", "提示", "开户失败!");
- });
- };
- //编辑
- $scope.edit = function () {
- //重置表单状态
- $scope.editForm.$setPristine();
- $scope.editForm.$setUntouched();
- var rows = $scope.gridApi.selection.getSelectedRows();
- if (rows.length == 0) {
- toaster.pop("info", "提示", "请选择数据!");
- return;
- }
- if (rows.length > 1) {
- toaster.pop("info", "提示", "只能选中编辑一条数据");
- return;
- }
- var item = rows[0];
- $scope.dialogData = $.extend(true, {}, item);
- var devConditionSrc = $.extend(true, [], item.devCondition);
- // 数据适配
- $scope.dialogData.devCondition = $scope.conditionFun.getRenderingCondition(devConditionSrc);
- //标记这是编辑框在加载
- $scope.conditionFun.noClearSelect = true;
- $("#editForm").modal();
- };
- //提交表单保存
- $scope.saveEditData = function () {
- //表单未校验通过不能提交
- if ($scope.editForm.$invalid) {
- return;
- }
- var url = "/manager/editAdvertiser";
- //深度克隆 避免操作原对象
- var dialogData = $.extend(true, {}, $scope.dialogData);
- //精简保存的数据
- dialogData.devCondition = $scope.conditionFun.getCondition(dialogData);
- $http({
- method: 'POST',
- url: url,
- data: {
- id: dialogData.id,
- devCondition: dialogData.devCondition,
- }
- }).then(function (response) {
- $('#editForm').modal('hide');//弹窗消失
- $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
- toaster.pop("success", "提示", "操作成功!");
- }, function (response) {
- toaster.pop("error", "提示", "操作失败!");
- });
- };
- //修改密码提交
- $scope.savePassword = function () {
- //表单未校验通过不能提交
- if ($scope.passwordForm.$invalid) {
- return;
- }
- var url = "/manager/editAdvertiserPassword";
- var password = MD5.createHash($scope.passwordData.password + '');
- $http({
- method: 'POST',
- url: url,
- data: {
- id: $scope.passwordData.id,
- password: password
- }
- }).then(function (response) {
- $('#passwordPanel').modal('hide');//弹窗消失
- $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
- }, function (response) {
- toaster.pop("error", "提示", "修改密码失败!");
- });
- };
- $scope.saveQuota = function () {
- //表单未校验通过不能提交
- if ($scope.quotaForm.$invalid) {
- return;
- }
- var url = "/manager/setAdvertiserQuota ";
- $http({
- method: 'POST',
- url: url,
- data: {
- id: $scope.quotaData.id,
- quota: $scope.quotaData.quota
- }
- }).then(function (response) {
- $('#quotaPanel').modal('hide');//弹窗消失
- $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
- }, function (response) {
- toaster.pop("error", "提示", "修改失败!");
- });
- };
- }]);
|