123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425 |
- // 'use strict';
- /**
- * controller for User Profile Example
- */
- app.controller('adminUserListCtrl_requ', ["$rootScope","$scope","$http", "$state","FileUploader", "$timeout", "$interval", "$modal", "SweetAlert", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_user_data", function ($rootScope, $scope,$http, $state,FileUploader, $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.allright=false;
- //$scope.allrightnot=true;
- $scope.gridOptions = {};
- $scope.gridOptions.data = 'myData';
- $scope.gridOptions.enableColumnResizing = true;
- $scope.gridOptions.enableFiltering = false;
- $scope.gridOptions.enableGridMenu = false;
- $scope.gridOptions.enableRowSelection = true;
- $scope.gridOptions.showGridFooter = true;
- $scope.gridOptions.showColumnFooter = false;
- $scope.gridOptions.fastWatch = true;
- $scope.gridOptions.useExternalPagination = true;
- $scope.gridOptions.paginationPageSizes = [10];
- $scope.gridOptions.paginationPageSize = 10;
- $scope.gridOptions.multiSelect = false;
-
- //$scope.gridOptions.rowTemplate= "<div ng-dblclick=\"grid.appScope.onDblClick(row)\" ng-repeat=\"(colRenderIndex, col) in colContainer.renderedColumns track by col.uid\" ui-grid-one-bind-id-grid=\"rowRenderIndex + '-' + col.uid + '-cell'\" class=\"ui-grid-cell\" ng-class=\"{ 'ui-grid-row-header-cell': col.isRowHeader }\" role=\"{{col.isRowHeader ? 'rowheader' : 'gridcell'}}\" ui-grid-cell></div>";
-
- $scope.gridOptions.rowIdentity = function(row) {
- return row.id;
- };
- $scope.gridOptions.getRowIdentity = function(row) {
- return row.id;
- };
- $scope.transferRole = function(roles){
- var tempValue="";
- angular.forEach(roles,function(item){
- if(tempValue!=""){
- tempValue = tempValue + "/" ;
- }
- tempValue = tempValue + item.role;
- })
- return tempValue;
- }
- //remote data
- $scope.gridOptions.columnDefs = [
- { name:'name', displayName:'姓名', width:100},
- { name:'account', displayName:'工号', width:140},
- { name:'deptName', displayName:'部门', width:140,enableFiltering:false},
- { name:'mphone', displayName:'电话', width:120,enableFiltering:false},
- { name:'编辑', cellTemplate:'<a class="btn btn-sm btn-info" ng-click="grid.appScope.saveData(row.entity)" tooltip="编辑">' +
- '<i class="fa fa-pencil-square-o"/></a>' , width:100,enableFiltering:false}
- ];
- var importUploader = $scope.importUploader = new FileUploader({
- url:api_user_data.importData().getRequestedUrl(),
- });
- // importUploader.filters.push({
- // name: 'customFilter',
- // fn: function(item /*{File|FileLikeObject}*/ , options) {
- // var type = item.name.slice(item.name.lastIndexOf('.') + 1);
- // //var type = '|' + item.type.slice(item.type.lastIndexOf('/') + 1) + '|';
- // return (type == 'xlsx');
- // }
- // });
- importUploader.onWhenAddingFileFailed = function(item /*{File|FileLikeObject}*/ , filter, options) {
- console.info('onWhenAddingFileFailed', item, filter, options);
- };
- importUploader.onAfterAddingFile = function(fileItem) {
- console.info('onAfterAddingFile', fileItem);
- };
- importUploader.onAfterAddingAll = function(addedFileItems) {
- console.info('onAfterAddingAll', addedFileItems);
- };
-
- importUploader.onProgressItem = function(fileItem, progress) {
- console.info('onProgressItem', fileItem, progress);
- };
- importUploader.onProgressAll = function(progress) {
- console.info('onProgressAll', progress);
- };
- importUploader.onSuccessItem = function(fileItem, response, status, headers) {
- if(response.status==200){
- SweetAlert.swal({
- title: "导入成功!",
- confirmButtonColor: "#007AFF",
- type: "success"
- },function(){
- $scope.ldloading.expand_right= false;
- $scope.refreshData('expand-right', defaultFilterData);
- // $scope.scheduleClass = {};
- // $scope.calendarView = 'month';
- // $scope.calendarDate = moment().startOf('month').toDate();
- // $scope.calendarTitle;
- // $scope.externalEvents = [];
- // api_bpm_schedule.getScheduleClass().then(function(response){
- // if(response.status == 200){
- // var scheduleClassList = response.list;
- // angular.forEach(scheduleClassList,function(item){
- // item.startsAt=moment(item.startTime).format('HH:mm:ss');
- // item.endsAt=moment(item.endTime).format('HH:mm:ss');
- // $scope.scheduleClass[item['code']]=item;
- // var templateEvent = {
- // title:item['description'],
- // type:item['code'],
- // startTime:item.startsAt,
- // //starts_at:
- // endTime:item.endsAt,
- // //ends_at:
- // draggable: true
- // };
- // $scope.externalEvents.push(templateEvent);
- // })
- // }
- // })
- });
- }else{
- $scope.ldloading.expand_right= false;
- SweetAlert.swal({
- title: "导入失败!",
- text: response.error,
- type: "error"
- })
- }
- console.info('onSuccessItem', fileItem, response, status, headers);
- };
- importUploader.onErrorItem = function(fileItem, response, status, headers) {
- console.info('onErrorItem', fileItem, response, status, headers);
- SweetAlert.swal({
- title: "系统错误!",
- text: "系统错误,请稍候重试!",
- type: "error"
- });
- };
- importUploader.onCancelItem = function(fileItem, response, status, headers) {
- console.info('onCancelItem', fileItem, response, status, headers);
- };
- importUploader.onCompleteItem = function(fileItem, response, status, headers) {
- console.info('onCompleteItem', fileItem, response, status, headers);
- };
- importUploader.onCompleteAll = function() {
- console.info('onCompleteAll');
- };
- $scope.ldloading = {};
- $scope.import = function(){
- $scope.ldloading.expand_right = true;
- importUploader.onBeforeUploadItem = function(item) {
- angular.extend(item.headers,$rootScope.getSession());
- item.formData.push({'filename':item.file.name});
- item.formData.push({'type':"requester"});
- console.info('onBeforeUploadItem',item);
- };
- importUploader.uploadAll();
- }
- $scope.download=function(){
- var type="requester";
- var month=0;
- $http({
- url : api_user_data.downDataModel(type,month).getRequestedUrl(),
- method : 'GET',
- headers : {
- // 'Content-type' : 'application/xls',
- 'Accept': '*/*'
- },
- responseType : 'arraybuffer'
- }).success(function(data, status, headers, config) {
- var file = new Blob([ data ], {
- // type : 'application/octet-stream'
- type : 'application/vnd.ms-excel'
- });
- //trick to download store a file having its URL
- var fileURL = URL.createObjectURL(file);
- var a = document.createElement('a');
- a.href = fileURL;
- a.target = '_blank';
- a.download = "请求人";
- document.body.appendChild(a);
- a.click();
- }).error(function(data, status, headers, config) {
- console.log(data);
- });
- }
- $scope.downloadtwo=function(){
- var type="requester";
- var month=1;
- $http({
- url : api_user_data.downDataModel(type,month).getRequestedUrl(),
- method : 'GET',
- headers : {
- // 'Content-type' : 'application/xls',
- 'Accept': '*/*'
- },
- responseType : 'arraybuffer'
- }).success(function(data, status, headers, config) {
- var file = new Blob([ data ], {
- type : 'application/octet-stream'
- // type : 'application/vnd.ms-excel'
- });
- //trick to download store a file having its URL
- var fileURL = URL.createObjectURL(file);
- var a = document.createElement('a');
- a.href = fileURL;
- a.target = '_blank';
- a.download = "请求人.xlsx";
- document.body.appendChild(a);
- a.click();
- }).error(function(data, status, headers, config) {
- console.log(data);
- });
- }
- $scope.saveData = function(data){
- $scope.requesterdata={};
- var filterData = {"idx":0,"sum":100};
- var modalInstance = $modal.open({
- templateUrl: 'assets/views/system/tpl/systemuser.html',
- controller: function($scope, $modalInstance, api_user_data){
- $scope.requesterdata=data;
- // $scope.falemchoice=[{id:1,gender:'男'},{id:2,gender:'女'}];
- $scope.cancel = function() {
- $modalInstance.dismiss('cancel');
- };
- $scope.savercode = function(requesterdata){
- var fildata={"requester":{
- "id":requesterdata.id,
- "account":requesterdata.account,
- "name":requesterdata.name,
- "gender":requesterdata.gender,
- "email":requesterdata.email,
- "mphone":requesterdata.mphone,
- "telephone":requesterdata.telephone,
- "deptName":requesterdata.deptName
- }}
- api_user_data.updData('requester',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();
- }
- })
- }
- }
- });
- // $state.go('app.system.form_requester',{formKey:'system_edit_requester', service:'api_user_data', model : JSON.stringify(modelData)}
- // );
- };
- $scope.addData = function(){
- var modalInstance = $modal.open({
- templateUrl: 'assets/views/system/tpl/systemuser.html',
- controller: function($scope, $modalInstance, api_bpm_data){
- $scope.cancel = function() {
- $modalInstance.dismiss('cancel');
- };
- $scope.savercode = function(requesterdata) {
- $modalInstance.close(requesterdata);
- };
- }
- });
- modalInstance.result.then(function(selectedItem) {
- if(selectedItem){
- var fildata={"requester":{
- "account":selectedItem.account,
- "name":selectedItem.name,
- "gender":selectedItem.gender,
- "email":selectedItem.email,
- "mphone":selectedItem.mphone,
- "telephone":selectedItem.telephone,
- "deptName":selectedItem.deptName}}
- api_user_data.addData('requester',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]
- var rmvList = [];
- angular.forEach($scope.selected.items,function(item){
- rmvList.push(item.id);
- });
- if(rmvList.length>0){
- api_user_data.rmvData('requester',rmvList).then(function(response){
- if(response.data){
- 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(data){
- data.grid.appScope.selected.items=data.entity
- console.log(data);
- });
- // gridApi.core.on.filterChanged( $scope, function() {
- // var grid = this.grid;
- // var filtersData = {
- // idx:0,
- // sum:10
- // };
- // angular.forEach(grid.columns,function(item){
- // if(item.enableFiltering){
- // if(angular.isDefined(item.filters[0].term)&&item.filters[0].term!=''){
- // if(angular.isUndefined(filtersData['requester'])){
- // filtersData['requester']={};
- // }
- // filtersData['requester'][item.field]=item.filters[0].term;
- // }
- // }
- // });
- // // $scope.memoryfilterData = filterData
- // $scope.refreshData('expand-right', filtersData);
- // });
- };
-
- 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;
- }
- if(angular.isDefined($scope.searchTypes)){
- filterData['searchType'] = $scope.searchTypes;
- }
- $scope.myData = [];
- api_user_data.fetchDataList('requester',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);
- }]);
|