123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- app.controller('moniListCtrl', ['$scope', '$http', "$state", '$timeout', 'uiGridConstants', 'i18nService', 'toaster', function ($scope, $http, $state, $timeout, uiGridConstants, i18nService, toaster) {
- i18nService.setCurrentLang("zh-cn");
- moment.locale('zh-cn');
- $scope.gridOptions = {
- data: 'myData',
- showGridFooter: true, //是否显示grid footer
- //-------- 分页属性 ----------------
- 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);
- }
- });
- }
- };
- //枚举常量
- $scope.enum = {
- status: [
- {value: "addingFans", label: "加粉中"},
- {value: "fansFull", label: "粉丝已满"},
- {value: "adminStop", label: "管理员暂停"},
- {value: "dayFullStop", label: "日限额满停"},
- {value: "appOver", label: "公众号不可用", disabled: true},
- ],
- priority: [
- {value: 5, label: "最高"},
- {value: 4, label: "高"},
- {value: 3, label: "一般"},
- {value: 2, label: "低"},
- {value: 1, label: "最低"},
- ],
- };
- //查询条件
- $scope.query = {
- searchKey: "",
- };
- $scope.ngEvent = {
- //查询
- query: function () {
- $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize);
- },
- compressorImg: function (file, callback) {
- if (file) {
- var imageCompressor = new Compressor(file, {
- quality: .7,
- // 图片尺寸
- maxWidth: 1920,
- maxHeight: 1920,
- success: function (result) {
- var formData = new FormData();
- formData.append('file', result, result.name);
- if (callback) {
- callback(formData);
- }
- }
- });
- }
- },
- addPic: function () {
- var imgUpload = $("#addImg");
- var file = imgUpload[0].files[0];
- this.compressorImg(file, function (formData) {
- var url = '/common/upload?type=moniQrCode';
- $http({
- method: 'POST',
- url: url,
- transformRequest: angular.identity,
- headers: {
- 'Content-Type': undefined// 禁止angular对data的处理
- },
- data: formData
- }).then(function (response) {
- var url = response.data.para;
- $scope.dialogData.qrCode = url;
- //重置文件路径,避免选中重复不触发onchange
- var imgUpload = $("#addImg");
- imgUpload[0].value = "";
- }, function (response) {
- toaster.pop("error", "提示", "上传失败!");
- });
- })
- },
- };
- function setColumnDefs() {
- $scope.gridOptions.columnDefs = [
- {field: 'appName', displayName: '公众号',},
- {field: 'appId', displayName: 'appId',},
- {field: 'rawAppId', displayName: '原始appId',},
- {field: 'secret', displayName: 'secret',},
- {
- field: 'priority', displayName: '优先级',
- cellTemplate: '<div class="ui-grid-cell-contents" >{{grid.appScope.formatterPriority(row.entity)}}</div>'
- },
- {
- field: 'status', displayName: '状态',
- cellTemplate: '<div class="ui-grid-cell-contents" >{{grid.appScope.formatterStatus(row.entity)}}</div>'
- },
- {field: 'title', displayName: '广告词', minWidth: 300,},
- {field: 'desc', displayName: '说明',},
- {field: 'maxDayAddingCount', displayName: '每日加粉限额',},
- {
- field: 'operation',
- displayName: '操作',
- enableFiltering: false,
- enableSorting: false,
- enableHiding: false,//禁止在列选择器中隐藏
- enableColumnMenu: false,// 是否显示列头部菜单按钮
- minWidth: 150,
- cellTemplate: '<div class="grid-button">' +
- '<button class="btn btn-sm btn-rounded btn-default" ng-click="grid.appScope.goAgents(row.entity)"><i class="fa fa-users"></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.formatterStatus = function (entity) {
- var status = entity.status;
- var statusList = $scope.enum.status;
- var label = "";
- for (var index = 0; index < statusList.length; index++) {
- var item = statusList[index];
- if (item.value == status) {
- label = item.label
- }
- }
- return label;
- };
- $scope.formatterPriority = function (entity) {
- var targetValue = entity.priority;
- var enumList = $scope.enum.priority;
- var label = "";
- for (var index = 0; index < enumList.length; index++) {
- var item = enumList[index];
- if (item.value == targetValue) {
- label = item.label
- }
- }
- return label;
- };
- $scope.setPagingData = function (data) {
- var pagedData = data.data.dataList;
- $scope.myData = pagedData;
- $scope.gridOptions.totalItems = data.data.total;
- };
- $scope.getPagedDataAsync = function (curPage, pageSize) {
- var params = {
- pageSize: pageSize,
- pageIndex: curPage
- };
- var query = $scope.query;
- params.searchKey = query.searchKey
- $http.get('/superadmin/getMoniApps', {
- params: params
- }).then(function (data) {
- data = data.data
- $scope.setPagingData(data, curPage, pageSize);
- }).catch(function (data) {
- toaster.pop("error", "提示", "获取数据列表失败");
- });
- };
- function initDataGrid() {
- //首次加载表格
- $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
- }
- setColumnDefs();
- initDataGrid();
- $scope.goAgents = function (entity) {
- $state.go('app.user.agents', {
- moniAppId: entity.appId,
- managerId: "",
- }, {
- reload: true
- });
- }
- 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]
- }
- $scope.dialogData = {};
- $scope.add = function () {
- $scope.dialogData = {};
- $("#moniEdit").modal()
- }
- $scope.edit = function () {
- var row = getOneRow();
- if (!row) {
- return
- }
- $("#moniEdit").modal()
- $scope.dialogData = $.extend(true, {}, row);
- }
- $scope.save = function () {
- //表单未校验通过不能提交
- if ($scope.moniEdit.$invalid) {
- return;
- }
- $http({
- method: 'POST',
- url: "/superadmin/editMoniApp",
- data: $scope.dialogData
- }).then(function (response) {
- $('#moniEdit').modal('hide');//弹窗消失
- toaster.pop("success", "提示", "保存成功!");
- $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
- }, function (response) {
- toaster.pop("error", "提示", "保存失败!");
- });
- }
- $scope.delete = function () {
- var rows = $scope.gridApi.selection.getSelectedRows();
- if (rows.length == 0) {
- toaster.pop("info", "提示", "请选择数据!");
- return;
- }
- var ids = [];
- for (var i = 0; i < rows.length; i++) {
- ids.push(rows[i].appId);
- }
- $.confirm({
- content: '确定删除?',
- buttons: {
- ok: {
- btnClass: 'btn-red',
- action: function () {
- $http({
- method: 'POST',
- url: '/superadmin/deleteMoniApp',
- data: {ids: ids}
- }).then(function (response) {
- initDataGrid();
- }, function (response) {
- toaster.pop("error", "提示", "删除失败!");
- });
- }
- },
- }
- });
- }
- }]);
|