app.controller('dealerManageCtrl', ['$scope', "$localStorage", "$state", '$stateParams', '$http', '$timeout', 'uiGridConstants', 'i18nService', 'toaster', 'md5', 'QRCodeOptions', function ($scope, $localStorage, $state, $stateParams, $http, $timeout, uiGridConstants, i18nService, toaster, MD5, QRCodeOptions) { i18nService.setCurrentLang("zh-cn"); var agentId = $stateParams.agentId; $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: "", agentId: agentId }; //枚举常量 $scope.enum = {}; //事件 $scope.event = { search: function () { $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize); } }; $scope.ngEvent = { exportExcelOpen: false, //导出 exportExcel: function () { var params = { }; if (condition.searchKey != "") { params.searchKey = condition.searchKey } if (condition.agentId) { params.agentId = condition.agentId } if ($scope.ngEvent.exportExcelOpen) { toaster.pop("info", "提示", "有一份报表正在生成,请稍候!"); return; } else { $scope.ngEvent.exportExcelOpen = true; } $http.get('/manager/exportDealerDetailList', {params: params}).then(function (data) { data = data.data $scope.ngEvent.exportExcelOpen = false; if (data.result == 1) { var payload = data.payload; toaster.pop("success", data.description); $state.go('app.tool.offlineTask', { searchKey: payload }); } }).catch(function (data) { $scope.ngEvent.exportExcelOpen = false; if (data.status == 504) { toaster.pop("error", "计算超时,请前往任务->执行离线生成报表"); } else { toaster.pop("error", "系统错误,请重试"); } }); } }; function setColumnDefs() { var cols = $scope.gridOptions.columnDefs = [ {field: 'name', displayName: '商家名称'}, { field: 'devTotalNum', minWidth: '200', displayName: '设备数量', cellTemplate: '
' }, {field: 'tel', displayName: '联系方式'}, { field: 'dateTimeAdded', displayName: '注册时间', cellTemplate: '
' }, { field: 'lineCoins', minWidth: '118', displayName: '今日线下投币', cellTemplate: '
' }, { field: 'payIncome', minWidth: '118', displayName: '今日在线收入', cellTemplate: '
' }, { field: 'todayRechargeIncome', minWidth: '80', displayName: '今日扫码充值', }, { field: 'todayChargeCardIncome', minWidth: '80', displayName: '今日卡充值', }, { field: 'userCount', minWidth: '80', displayName: '用户总数', }, { field: 'userCountAddedThisMonth', minWidth: '80', displayName: '本月新增用户', }, { field: 'balance', displayName: '商家余额', cellTemplate: '
' }, { field: 'agentInfo', displayName: '代理商', }, { field: 'detail', displayName: '详细信息', cellTemplate: '
{{row.entity.detail}}
' }, ]; $scope.showBalance = function (entity) { if (entity.detail) { var detail = {} try { detail = JSON.parse(entity.detail) } catch (e) { } return '¥' + (detail.balance || "0.00") } return '未知' } var feature_map = $localStorage.feature_map if (feature_map && feature_map.disableDevice) { cols.push( { field: 'disableDevice', displayName: '禁用设备权限', cellTemplate: '
{{row.entity.disableDevice?\'有权限\':\'无权限\'}}
' } ) } var operCol = { field: 'operation', displayName: '操作', enableFiltering: false, enableSorting: false, enableHiding: false,//禁止在列选择器中隐藏 enableColumnMenu: false,// 是否显示列头部菜单按钮 minWidth: 256, cellTemplate: '
' + ((feature_map && feature_map.disableDevice) ? ('') : ('')) + '' + '
' }; $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'] = 100; } } } // 切换禁用状态 $scope.disableDeviceToggle = function (entity) { $http.get('/manager/dealerDisableDevice', { params: {id: entity.id, disable: !entity.disableDevice} }).then(function (data) { data = data.data if (data.result == 1) { entity.disableDevice = !entity.disableDevice toaster.pop("success", "操作成功!"); } }).catch(function (data) { 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) { if ($scope.gridOptionsLoading) { return; } var params = { pageSize: pageSize, pageIndex: curPage }; if (condition.searchKey != "") { params.searchKey = condition.searchKey } if (condition.agentId) { params.agentId = condition.agentId } $scope.gridOptionsLoading = true; $http.get('/dealer/getDealerDetailList', { params: params }).then(function (data) { $scope.gridOptionsLoading = false; $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.showInfoDetail = function (title, content) { $scope.infoDetail = {title: title, content: JSON.parse(content)}; $("#detailInfoPanel").modal(); }; $scope.closeDetailInfoPanel = function () { $("#detailInfoPanel").modal("hide"); }; //添加 $scope.add = function () { //重置表单状态 $scope.dealerForm.$setPristine(); $scope.dealerForm.$setUntouched(); $scope.dialogName = "代理商开户"; $scope.dialogData = {}; $("#dealerPanel").modal(); }; //编辑 $scope.edit = function () { //重置表单状态 $scope.dealerForm.$setPristine(); $scope.dealerForm.$setUntouched(); $scope.dialogName = "编辑经销商信息"; 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({}, item); $("#dealerPanel").modal(); }; //提交表单保存 $scope.saveData = function () { //表单未校验通过不能提交 if ($scope.dealerForm.$invalid) { return; } var url = "/manager/editDealer"; $http({ method: 'POST', url: url, data: { id: $scope.dialogData.id, name: $scope.dialogData.name, tel: $scope.dialogData.tel, openId: $scope.dialogData.openId } }).then(function (response) { $('#dealerPanel').modal('hide');//弹窗消失 $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize); }, function (response) { toaster.pop("error", "提示", "保存失败!"); }); }; //编辑 $scope.editOtherAPI = function () { //重置表单状态 $scope.otherAPIForm.$setPristine(); $scope.otherAPIForm.$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]; if (!item.hasZJFirePlatform) { toaster.pop("warning", "提示", "该经销商没有权限配置"); return; } $scope.dialogFireData = $.extend(true, {id: item.id}, item.ZJFirePlatform); $("#otherAPIForm").modal(); }; $scope.saveOtherAPIForm = function () { if ($scope.otherAPIForm.$invalid) { return; } var url = "/manager/editDealerZJFirePlatform"; $http({ method: 'POST', url: url, data: $scope.dialogFireData }).then(function (response) { $('#otherAPIForm').modal('hide'); $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize); }, function (response) { toaster.pop("error", "提示", "保存失败!"); }); } //查看经销商 $scope.checkDevice = function (entity) { $scope.nowDealerName = entity.name; $("#dealerDevList").modal(); // todo 由于ui-grid 之前隐藏,表格渲染有问题 setTimeout(function () { // 刷新设备 $scope.$broadcast("initDevList", {dealerId: entity.id}); }, 100); }; $scope.closeDevice = function () { $("#dealerDevList").modal('hide'); }; //编辑密码 默认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.savePassword = function () { //表单未校验通过不能提交 if ($scope.passwordForm.$invalid) { return; } var url = "/manager/editDealerPassword"; 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.unlock = function () { 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]; var url = "/manager/unlockDealer"; $http({ method: 'POST', url: url, data: { id: item.id } }).then(function (response) { toaster.pop("info", "提示", "解锁成功!") $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize); }, function (response) { toaster.pop("error", "提示", "解锁失败!"); }); } }]);