app.controller('replaceDeviceCtrl', ['$scope', '$filter', '$http', '$stateParams', '$timeout', 'uiGridConstants', 'i18nService', 'toaster', function ($scope, $filter, $http, $stateParams, $timeout, uiGridConstants, i18nService, toaster) { 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: "" }; $scope.dialogData = {}; //枚举常量 $scope.enum = {}; //事件 $scope.event = { search: function () { dealerId = "";//清空跳转带入的条件 $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize); } }; function setColumnDefs() { $scope.gridOptions.columnDefs = [ { field: 'newLogicalCode', displayName: '新逻辑码', cellTemplate: '
{{row.entity.newLogicalCode}}
' }, {field: 'oldLogicalCode', displayName: '旧逻辑码'}, {field: 'devNo', displayName: '电子标签'}, {field: 'devType', displayName: '设备类型'}, { field: 'createdTime', displayName: '操作时间', cellTemplate: '
' }, { field: 'oper', displayName: '操作', enableFiltering: false, enableSorting: false, enableHiding: false,//禁止在列选择器中隐藏 enableColumnMenu: false,// 是否显示列头部菜单按钮 width: 180, cellTemplate: '
' + '' + '
' }, ]; var fields = $scope.gridOptions.columnDefs; for (var index in fields) { var item = fields[index]; if (item && item['minWidth'] == null) { item['minWidth'] = 100; } } } $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 }; if (condition.searchKey != "") { params.searchKey = condition.searchKey } $http.get('/superadmin/getDeviceReplacements', { 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.rollback = function (entity) { $.confirm({ content: '确定回滚该操作?', buttons: { ok: { btnClass: 'btn-red', action: function () { $http({ method: 'POST', url: "/superadmin/rollbackDeviceReplacement", data: {id: entity.id} }).then(function (response) { $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize); toaster.pop("info", "提示", "操作成功!"); }, function (response) { toaster.pop("error", "提示", "操作失败!"); }); } }, } }); } //添加 $scope.addRollback = function () { //重置表单状态 $scope.rollbackPanel.$setPristine(); $scope.rollbackPanel.$setUntouched(); $scope.dialogName = "设备换绑"; $scope.dialogData = {}; $("#rollbackPanel").modal(); }; // 确认添加并保存 $scope.saveRollback = function () { if ($scope.rollbackPanel.$invalid) { return } var url = "/superadmin/replaceDevice "; $http({ method: 'POST', url: url, data: $scope.dialogData }).then(function (response) { //保存成功 弹窗消失 $('#rollbackPanel').modal('hide'); $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize); }, function (response) { toaster.pop("error", "提示", "保存失败!"); }); }; }]);