'use strict'; /** * controller for User Profile Example */ app.controller('deptlistCtrl', ["$rootScope","$scope", "$state", "$timeout", "$interval", "$modal", "SweetAlert", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_user_data", function ($rootScope, $scope, $state, $timeout, $interval, $modal, SweetAlert, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_user_data) { $scope.langs=i18nService.getAllLangs(); $scope.lang = 'zh-cn'; i18nService.setCurrentLang($scope.lang); var loginUser=$rootScope.user; $scope.gridOptions = {}; $scope.gridOptions.data = 'myData'; $scope.gridOptions.enableColumnResizing = true; $scope.gridOptions.enableFiltering = true; $scope.gridOptions.enableGridMenu = false; $scope.gridOptions.enableRowSelection = true; $scope.gridOptions.showGridFooter = true; $scope.gridOptions.showColumnFooter = false; $scope.gridOptions.fastWatch = true; $scope.gridOptions.useExternalFiltering=true; $scope.gridOptions.useExternalPagination = true; $scope.gridOptions.paginationPageSizes = [10]; $scope.gridOptions.paginationPageSize = 10; $scope.gridOptions.multiSelect = false; //$scope.gridOptions.rowTemplate= "
"; $scope.gridOptions.rowIdentity = function(row) { return row.id; }; $scope.gridOptions.getRowIdentity = function(row) { return row.id; }; $scope.gridOptions.columnDefs = [ { name:'id', displayName:'编号', width:100, enableFiltering:false}, { name:'pcode', displayName:'部门标识', width:100, enableFiltering:false}, { name:'dept', displayName:'部门', width:300, enableFiltering:false}, { name:'parent.dept', displayName:'上级部门', width:200, enableFiltering:false}, { name:'修改', cellTemplate:'' + '' , width:100,enableFiltering:false} ]; $scope.saveData = function(selectdata){ var modalInstance = $modal.open({ templateUrl: 'assets/views/system/tpl/deptchange.html', controller: function($scope, $modalInstance, api_user_data){ $scope.deptdata={}; $scope.deptdata=selectdata; $scope.deptchoice={}; var filterData = {"idx":0,"sum":100}; api_user_data.fetchDataList('department',filterData).then(function(data){ $scope.deptchoice = Restangular.stripRestangular(data).list; }) $scope.cancel = function() { $modalInstance.dismiss('cancel'); }; $scope.savercode = function(deptdata){ var fildata={"department":{"id":deptdata.id,"pcode":deptdata.pcode,"dept":deptdata.dept,"parent":{"id":deptdata.parent.id}}} api_user_data.updData('department',fildata).then(function(response){ if(response){ if(response.status==200){ SweetAlert.swal({ title:"修改成功!", type:"success" },function(){ // console.log($scope.serverdata) }) }else{ SweetAlert.swal({ title:"修改失败!", type:"error" }) } $modalInstance.close(); } }) } } }); } $scope.addData = function(){ var modalInstance = $modal.open({ templateUrl: 'assets/views/system/tpl/deptchange.html', controller: function($scope, $modalInstance, api_user_data){ var filterData = {"idx":0,"sum":100}; api_user_data.fetchDataList('department',filterData).then(function(data){ $scope.deptchoice = Restangular.stripRestangular(data).list; }) $scope.cancel = function() { $modalInstance.dismiss('cancel'); }; $scope.savercode = function(deptdata) { $modalInstance.close(deptdata); }; } }); modalInstance.result.then(function(selectedItem) { if(selectedItem){ // angular.forEach($scope.myData,function(item){ // if(item.dept==selectedItem.parent.dept){ // selectedItem.parent.id=item.id; // } // }) var fildata={"department":{"pcode":selectedItem.pcode,"dept":selectedItem.dept,"parent":{"id":selectedItem.parent.id}}} api_user_data.addData('department',fildata).then(function(response){ if(response){ if(response.status==200){ SweetAlert.swal({ title:"新增成功!", type:"success" },function(){ $scope.refreshData('expand-right', defaultFilterData); }) }else{ SweetAlert.swal({ title:"新增失败!", type:"error" }) } } }) } }); } $scope.removeData = function(){ var rmvList = [$scope.selected.items.id] if(rmvList.length>0){ api_user_data.rmvData('department',rmvList).then(function(response){ if(response.status==200){ SweetAlert.swal({ title: "删除成功!", type: "success", confirmButtonColor: "#007AFF" },function(){ $scope.myData = _.reject($scope.myData, function(o) { return _.includes(rmvList,o.id); }); $scope.selected = { items:[] }; }); }else{ SweetAlert.swal({ title: "操作异常!", text: "系统异常,请稍后重试,或者联系管理员!", type: "error" }); } }) } } $scope.selected = { items:[] } $scope.editted = { items:[] } $scope.gridOptions.onRegisterApi = function(gridApi){ $scope.gridApi = gridApi; // gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef, newValue, oldValue){ // // console.log(rowEntity); // }); gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) { var filtersData = $scope.memoryfilterData; filtersData.idx=newPage-1; filtersData.sum=pageSize; $scope.refreshData('expand-right',filtersData); }); gridApi.selection.on.rowSelectionChanged($scope, function(scope){ scope.grid.appScope.selected.items=scope.entity }); }; var defaultFilterData = { "idx":0, "sum":10 }; $scope.memoryfilterData = { "idx":0, "sum":10 } $scope.ldloading = {}; $scope.refreshData = function(style,filterData){ $scope.ldloading[style.replace('-', '_')] = true; if(angular.isUndefined(filterData)){ filterData = defaultFilterData; } $scope.myData = []; api_user_data.fetchDataList('department',filterData).then(function(data){ var myData = Restangular.stripRestangular(data); $scope.gridOptions.totalItems = myData.totalNum; $scope.myData = myData.list; $scope.ldloading[style.replace('-', '_')] = false; },function(){ $scope.ldloading[style.replace('-', '_')] = false; }); }; $scope.refreshData('expand-right', defaultFilterData); }]);