app.controller('devBindCtrl', ['$scope', '$filter', '$http', '$stateParams', '$timeout', 'uiGridConstants', 'i18nService', 'toaster', 'FileUploader', function ($scope, $filter, $http, $stateParams, $timeout, uiGridConstants, i18nService, toaster, FileUploader) { 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.event = { search: function () { $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize); } }; function setColumnDefs() { $scope.gridOptions.columnDefs = [ {field: 'logicalCode', displayName: '逻辑编号'}, {field: 'devTypeName', displayName: '设备类型'}, {field: 'imei', displayName: 'imei'}, {field: 'inputTime', displayName: '录入时间',}, {field: 'createdTime', displayName: '注册时间',}, {field: 'dealerName', displayName: '商户名称'}, {field: 'dealerTel', displayName: '商户电话'}, {field: 'groupName', displayName: '场地'}, ]; 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, curPage, pageSize) { 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('/manager/getInputEquipment', { 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.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].logicalCode); } $scope.selectedIds = ids; return ids } $scope.dialogData = {}; $scope.add = function () { $scope.dialogData = {}; $('#inputPanel').modal() } $scope.saveAdd = function () { //表单未校验通过不能提交 if ($scope.inputPanel.$invalid) { return; } var url = "/manager/inputEquipment"; $http({ method: 'POST', url: url, data: { logicalCode: $scope.dialogData.logicalCode, } }).then(function (response) { var data = response.data; if (data.result == 1) { toaster.pop("success", "提示", "录入成功!"); $timeout(function () { $scope.dialogData = {}; }, 200) } $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize); }, function (response) { toaster.pop("error", "提示", "操作失败!"); }); } /***********excel上传工具*******************/ var uploader2 = $scope.uploader2 = new FileUploader({ url: '/manager/file/uploadLogicalExcel', queueLimit: 1, //文件个数 removeAfterUpload: true //上传后删除文件 }); //注册上传事件 uploader2.onCompleteItem = function (fileItem, response, status, headers) { if (response) { toaster.pop("success", "提示", "批量录入成功!"); } clearUploader2(); }; uploader2.onErrorItem = function (fileItem, response, status, headers) { toaster.pop("error", "提示", "上传失败,请重试"); clearUploader2(); }; /*恢复上传框初始状态*/ function clearUploader2() { $("#fileUpload2").val(""); uploader2.clearQueue(); uploader2.cancelAll(); } $scope.addMore = function () { $('#excelForm').modal() } $scope.delete = function () { var ids = getSelectRows() if (!ids) { return } $.confirm({ content: '确定删除?', buttons: { ok: { btnClass: 'btn-red', action: function () { $http({ method: 'POST', url: '/manager/deleteInputEquipment', data: {logicalCode: ids} }).then(function (response) { initDataGrid(); }, function (response) { toaster.pop("error", "提示", "删除失败!"); }); } }, } }); } }]);