merchantManagerCtrl.js 13.2 KB
(function(angular) {
	function merchantManagerCtrl($scope, DTOptionsBuilder, DTColumnBuilder, systemService, $uibModal,$http, $filter, $state,Utils,$rootScope) {
		$scope.merchantTypeList = [{'name':'全部',value:''},{'name':'批发/零售商',value:'1'},{'name':'4S店',value:'2'},
		                           {'name':'综合汽贸店',value:'3'},{'name':'综合后服务门店',value:'4'},{'name':'厂家',value:'5'},
		                           {'name':'园区店',value:'6'},{'name':'服务商',value:'7'},{'name':'虚拟园区店',value:'8'}];
		$scope.merchantAddressTypeList = [{'name':'全部',value:''},{'name':'有',value:'1'},{'name':'无',value:'2'}];
		
		$scope.accountEnabledFlag = [{'name':'全部',value:''},{'name':'正常',value:'Y'},{'name':'未启用',value:'N'},{'name':'已注销',value:'C'}];
		
        $scope.dtColumns = [
            DTColumnBuilder.newColumn('userId').withOption('width',60).withTitle('用户ID'),
            DTColumnBuilder.newColumn('accountName').withOption('width',60).withTitle('登录账号'),
            DTColumnBuilder.newColumn('merchantId').withOption('width',60).withTitle('商户号'),
            DTColumnBuilder.newColumn('merchantName').withOption('width',80).withTitle('商户名称'),
            DTColumnBuilder.newColumn('shortName').withOption('width',80).withTitle('商户简称'),
            DTColumnBuilder.newColumn('userType').withOption('width',60).withTitle('商户类型').renderWith(function(data, dt, node, config){
            	var u = $filter('filter')($scope.allUserTypeList, {'confKey':data}, false);
            	if(u && u.length > 0){
            		return u[0].confValue;
            	}
            	return "";
            }),
            DTColumnBuilder.newColumn('contactName').withOption('width',40).withTitle('联系人'),
            DTColumnBuilder.newColumn('phone').withOption('width',70).withTitle('手机号'),
			DTColumnBuilder.newColumn('sap').withOption('width',40).withTitle('SAP'),
			DTColumnBuilder.newColumn('roleDTOs').withOption('width',60).withTitle('角色权限').renderWith(function(data, dt, node, config){
               if(node.role){
            	   return node.role.name;
               }
               return "";
            }),
            DTColumnBuilder.newColumn('address').withOption('width',70).withTitle('商户地址').renderWith(function(data, dt, node, config){
                if(node.address){
             	   return node.address;
                }
                return "—";
             }),
            DTColumnBuilder.newColumn('parentMerchantId').withOption('width',80).withTitle('上级商户号'),
            DTColumnBuilder.newColumn('parentMerchantName').withOption('width',80).withTitle('上级商户名称'),
            DTColumnBuilder.newColumn('createdDate').withOption('width',80).withTitle('注册时间').renderWith(function(e, dt, node, config){
                return $filter('date')(new Date(node.createdDate), 'yyyy-MM-dd HH:mm:ss');
            }),
            DTColumnBuilder.newColumn('enabledFlag').withOption('width',60).withTitle('账号状态').renderWith(function(e, dt, node, config){
            	var u = $filter('filter')($scope.accountEnabledFlag, {'value':node.enabledFlag}, false);
            	if(u && u.length > 0){
            		return u[0].name;
            	}
            	return "";
            }),
            DTColumnBuilder.newColumn('updatedDate').withOption('width',80).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="merchantManager" fc-attrname="resetMerchantPasswordBtn" ng-click="resetPwd('+ data.merchantId +')">重置密码</a></div>';
                str +='<div class="form-group"><a class="btn btn-link" ng-click="getByMerchantId(\''+ data.merchantId +'\')">查看与修改</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="eidtCompanyAccount('+ data.merchantId +')">对公账户</a></div>';
                    str +='<div class="form-group"><a class="btn btn-link" ng-click="bWebappManager(\''+ data.accountName +'\')">小程序功能</a></div>';
                    str +='<div class="form-group"><a class="btn btn-link" ng-click="eidtUserEnabledFlag(\''+ data.userId +'\',\'' + data.enabledFlag + '\')">修改账号状态</a></div>';
                }
                str += '</div>';
                return str;
            })
        ];

        $scope.dtOptions = DTOptionsBuilder.newOptions()
            .withOption('id','categoryCode')
            .withFixedColumns({
                leftColumns: 0,
                rightColumns: 1
            })
            .withOption('lengthMenu', [20,40,60,100])
            .withOption('num', true);

        $scope.dtInstance = {
            serverData: systemService.getMerchantList
        }

        $scope.init = function () {
            $scope.merchant ={};
			$scope.merchant.sap='';
			$scope.fieldName='merchantId';
            $scope.fieldName1='parentMerchantId';
            $scope.fieldName2='accountName';
            systemService.getAllUserTypeList(function (res) {
                $scope.allUserTypeList = res.data;
            });
            
            systemService.getCreateAccoutsByCurUserId(function (res) {
                $scope.userTypeList = res.data;
                $scope.userTypeList.unshift({confValue: '全部', confKey: ''})
            });
            $scope.checkPhone = '';
            systemService.getMerchantCompanyCheckPhone(function(res){
    			if(res.returnCode == 0){
    				$scope.checkPhone= res.data;
    			}
    		});
        }
        $scope.init();

        $scope.getParams = function () {
            var obj = {};
            if($scope.userType){
            	obj.userType = $scope.userType.confKey;
            }
            if($scope.fieldName2){
                if($scope.fieldValue2){
                	obj[$scope.fieldName2] = $scope.fieldValue2;
                }else {
                    obj[$scope.fieldName2] = '';
                }
            }
            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.fieldName1){
                if($scope.fieldValue1){
                	if($scope.fieldName1 == 'parentMerchantId'){
                		var m = -1;
                		if(/^[1-9]\d*$/.test($scope.fieldValue1)){
                			m = parseInt($scope.fieldValue1) || -1;
                    		if(m > 2147483647){
                    			m = -1;
                    		}
                		}
                		obj[$scope.fieldName1] = m;
                	}else{
                		obj[$scope.fieldName1] = $scope.fieldValue1;
                	}
                }else {
                    obj[$scope.fieldName1] = '';
                }
            }
            if($scope.merchant.contactName){
            	obj.contactName = $scope.merchant.contactName;
            }
            if($scope.merchant.phone){
            	obj.phone = $scope.merchant.phone;
            }
            if($scope.merchantType){
            	obj.merchantType = $scope.merchantType.value;
            }
            if($scope.merchantAddressType){
            	obj.merchantAddressType = $scope.merchantAddressType.value;
            }
            if($scope.enabledFlag){
            	obj.enabledFlag = $scope.enabledFlag.value;
            }
            if ($scope.merchant.sap && $scope.merchant.sap != '') {
            	obj.sap = $scope.merchant.sap;
			}
            return obj;
        }

        $scope.select = function () {
            var params = $scope.getParams();
            $scope.dtInstance.query(params);
        }

        $scope.add = function () {
            $state.go('system.userAdmin.addMerchant')
        };

        $scope.getByMerchantId = function (merchantId) {
            $state.go('system.userAdmin.merchantDetail',{merchantId:merchantId})
        };

        $scope.exportExcel=function(){
            var params = $scope.getParams();
            Utils.exportExcel2('system/merchantManager/export',params,'下级商户列表');
        };
        $scope.resetPwd = function(merchantId){
	   		var modalInstance = $uibModal.open({
		    	animation: true,
		        templateUrl: 'resetMerchantPwdModal',
		        controller: 'resetMerchantPwdModalCtrl',
		        size: 'sm',
		        resolve: {
		        	'merchantId': merchantId
		        }
		    });
	   	}
        $scope.toUpateRoleRight=function(roleId){
        	$state.go('system.userAdmin.roleEdit',{id:roleId});
        }
        
        $scope.eidtCompanyAccount = function (merchantId) {
	        $uibModal.open({
	            templateUrl: 'biz/system/view/merchantCompanyEdit.html',
	            controller: 'merchantCompanyEditCtrl',
	            size: 'lg',
	            resolve: {
	                params: function () {
	                    return {'merchantId':merchantId,checkPhone:$scope.checkPhone}
	                }
	            }
	        }).result.then(function (data) {
	        	$scope.select();
	        },function(){
	        	$scope.select();
	        })
	    };
	    
	    $scope.eidtUserEnabledFlag = function (userId,enabledFlag) {
	        $uibModal.open({
	            templateUrl: 'biz/system/view/userEnabledFlagEdit.html',
	            controller: 'userEnabledFlagEditCtrl',
	            size: 'lg',
	            resolve: {
	                params: function () {
	                    return {'userId':userId,'enabledFlag':enabledFlag}
	                }
	            }
	        }).result.then(function (data) {
	        	$scope.select();
	        },function(){
	        	$scope.select();
	        })
	    };
	    
	    $scope.bWebappManager = function(accountName){
	    	$uibModal.open({
	            templateUrl: 'biz/system/view/userAppOpen.html',
	            controller: 'userAppOpenCtrl',
	            size: 'lg',
	            resolve: {
	                params: function () {
	                    return {'accountName':accountName}
	                }
	            }
	        });
	    };
	    $scope.batchUpdateMerchantCompany = function() {
	        $uibModal.open({
	          templateUrl: 'biz/system/view/systemImportModal.html',
	          controller: 'systemImportModalCtrl',
	          //size : 'md',
	          scope: $scope,
	          resolve: {
	            importConfig: function() {
	              return {
	                pageTitle: '批量导入对公账户', //弹框标题
	                ajaxUrl: 'system/merchantManager/importMerchantCompany', //导入服务地址
	                downloadType: '17', //下载导入模板类型
	                importTemplate: '批量导入对公账户-模版', //下载导入模板文件名
	                errorDown: '批量导入对公账户报错下载.xlsx',
	                checkPhone:$scope.checkPhone,
	              };
	            }
	          }
	        }).result.then(function() {
	          //关闭弹框后执行方法
	        }, function() {
	          $scope.dtInstance.query();
	        });
	      };
	}
	function resetMerchantPwdModalCtrl($scope, $uibModalInstance, systemService, merchantId,$uibModal){
		$scope.confirm = function() {
	    	$scope.isWorking = true;
	    	systemService.resetMerchantPwd({'merchantId':merchantId}, 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('merchantManagerCtrl', merchantManagerCtrl)
	.controller('resetMerchantPwdModalCtrl', resetMerchantPwdModalCtrl)
})(angular);