employeeCtrl.js 7.26 KB
(function(angular) {
	function employeeCtrl($scope, DTOptionsBuilder, DTColumnBuilder, systemService, $uibModal, $filter, $state,Utils,$rootScope) {		
		$scope.openCardStatusList = [{id:true,name:'开通'},{id:false,name:'未开通'}];
		$scope.fieldName='merchantId';
		$scope.fieldName1='accountName';
		$scope.dtColumns = [
		    DTColumnBuilder.newColumn('userId').withOption('width',60).withTitle('用户ID'),
		    DTColumnBuilder.newColumn('accountName').withOption('width',60).withTitle('登录账号'),
		    DTColumnBuilder.newColumn('duty').withOption('width',80).withTitle('主要职务'),
		    DTColumnBuilder.newColumn('name').withOption('width',80).withTitle('姓名/名称'),
		    DTColumnBuilder.newColumn('isOpenCard').withOption('width',80).withTitle('小程序名片').renderWith(function(e, dt, node, config) {
		    	if(node.isOpenCard == '1'){
		    		return "开通";
		    	}
		    	return "未开通";
		    }),
		    DTColumnBuilder.newColumn('photo').withOption('width',80).withTitle('头像').renderWith(function(e, dt, node, config){
            	if(node.photo){
            		return '<img src="' + node.photo + '" style="width: 100%;height:60px;">';
            	}
            	return "";
            }),
		    DTColumnBuilder.newColumn('phone').withOption('width',100).withTitle('手机号'),
		    DTColumnBuilder.newColumn('wechatNum').withOption('width',80).withTitle('微信号'),
		    DTColumnBuilder.newColumn('customerNum').withOption('width',60).withTitle('客户数'),
		    DTColumnBuilder.newColumn('merchantId').withOption('width',80).withTitle('所属商户号'),
		    DTColumnBuilder.newColumn('merchantName').withOption('width',80).withTitle('所属商户名称'),
		    DTColumnBuilder.newColumn('roleList').withOption('width',100).withTitle('角色权限').renderWith(function(e, dt, node, config){
            	if(node.role){
            		return node.role.name;
            	}
            	return "";
            }),
            DTColumnBuilder.newColumn('updatedDate').withOption('width',120).withTitle('更新时间').renderWith(function(e, dt, node, config){
            	return $filter('date')(new Date(node.updatedDate), 'yyyy-MM-dd HH:mm:ss');
            }),
            DTColumnBuilder.newColumn(null).withTitle(function(){
            	return '操作';
            }).withOption('width', 180).withClass('text-center').renderWith(function(data, type, full, oSettings) {
            	var str = '<div class="form-inline">'
	                +'<div class="form-group"><a class="btn btn-link" functional-contrl fc-menu="employee" fc-attrname="resetPasswordBtn" ng-click="resetPwd('+ data.employeeId +')">重置密码</a></div>'
	                +'<div class="form-group"><a class="btn btn-link" ng-click="addOrUpdate('+ data.employeeId +')">修改资料</a></div>';
            	if(data.role && !data.role.isSuper){
                	str +='<div class="form-group"><a class="btn btn-link" functional-contrl fc-menu="role" ng-click="toUpateRoleRight('+ data.role.id +')">修改角色权限</a></div>';
                }
            	if($rootScope.loginUser.isSuper){
                    str +='<div class="form-group"><a class="btn btn-link" ng-click="bWebappManager(\''+ data.accountName +'\')">小程序功能</a></div>';
                }
	            str += '</div>';
                return str;
            })
        ];
		$scope.dtOptions = DTOptionsBuilder.newOptions()
		.withOption('id','categoryCode')
		.withFixedColumns({
                leftColumns: 0,
                rightColumns: 1
            })

		$scope.dtInstance = {
			serverData : systemService.getEmployeePageList
		};

		function getParams(){
			var obj = {};
			if($scope.name){
				obj.name = $scope.name;
			}
			if($scope.fieldName1){
                if($scope.fieldValue1){
                	obj[$scope.fieldName1] = $scope.fieldValue1;
                }else {
                    obj[$scope.fieldName1] = '';
                }
            }
			if($scope.fieldName){
                if($scope.fieldValue){
                	if($scope.fieldName == 'merchantId'){
                		var m = -1;
                		if(/^[1-9]\d*$/.test($scope.fieldValue)){
                			m = parseInt($scope.fieldValue) || -1;
                    		if(m > 2147483647){
                    			m = -1;
                    		}
                		}
                		obj[$scope.fieldName] =  m;
                	}else{
                        obj[$scope.fieldName] = $scope.fieldValue;
                	}
                }else {
                    obj[$scope.fieldName] = '';
                }
            }
			if($scope.isOpenCard){
            	obj.isOpenCard = $scope.isOpenCard.id;
            }
			return obj;
		}


		//查询
		$scope.submitForm = function(){
			$scope.dtInstance.query(getParams());
		}
		
		$scope.addOrUpdate = function (employeeId) {
	        $uibModal.open({
	            templateUrl: 'biz/system/view/employeeAdd.html',
	            controller: 'employeeAddCtrl',
	            size: 'lg',
	            resolve: {
	                params: function () {
	                    return {'employeeId':employeeId}
	                }
	            }
	        }).result.then(function (data) {
	        	$scope.dtInstance.query(getParams());
	        },function(){
	        	$scope.dtInstance.query(getParams());
	        })
	    };
	    
	    $scope.resetPwd = function(employeeId){
	   		var modalInstance = $uibModal.open({
		    	animation: true,
		        templateUrl: 'resetPwdModal',
		        controller: 'resetPwdModalCtrl',
		        size: 'sm',
		        resolve: {
		        	'employeeId': employeeId
		        }
		    });
	   	}
	    
	    $scope.exportExcel=function(){
            var params = getParams();
            Utils.exportExcel2('system/employee/export',params,'员工列表');
        };
        $scope.toUpateRoleRight=function(roleId){
        	$state.go('system.userAdmin.roleEdit',{id:roleId});
        };
        $scope.bWebappManager = function(accountName){
	    	$uibModal.open({
	            templateUrl: 'biz/system/view/userAppOpen.html',
	            controller: 'userAppOpenCtrl',
	            size: 'lg',
	            resolve: {
	                params: function () {
	                    return {'accountName':accountName}
	                }
	            }
	        });
	    };
	}
	
	function resetPwdModalCtrl($scope, $uibModalInstance, systemService, employeeId,$uibModal){
		$scope.confirm = function() {
	    	$scope.isWorking = true;
	    	systemService.resetEmployeePwd({'employeeId':employeeId}, function(result){
	    		if(result.returnCode == '0'){
		    		$uibModalInstance.close();
		    		$uibModal.open({
						templateUrl: 'biz/system/view/clipboard.html',
						controller: 'clipboardCtrl',
						size: 'md',
						resolve: {
							params: function () {
								return {
									message: '重置后的密码为:'+ result.data,
									content:result.data,
								}
							}
						}
					});
		    		
    			}else{
    				$uibModalInstance.close();
    				swal({type: 'error',title: '',text: result.message,closeOnConfirm: false,confirmButtonText: "确定" });
    			}
    			$scope.isWorking = false;
	    	});
	    };
	    $scope.cancel = function() {
	        $uibModalInstance.dismiss('cancel');
	    };
	}

	angular.module('system').controller('employeeCtrl', employeeCtrl)
	.controller('resetPwdModalCtrl', resetPwdModalCtrl)
})(angular);