user.js 2.77 KB
(function () {
    "use strict";
    var app =angular.module("xn.page", []);
    app.controller("NavCtrl", function ($scope) {
        $scope.navShow = 4;
    });
    // 全局配置 form提交验证
    app.config(["xnValidatorProvider", function (xnValidatorProvider) {
        xnValidatorProvider.setRules({
            mobilePhone: {
                pattern: "手机格式不正确!"
            }
        });
    }]);

    //个人信息页面
    app.controller("UserInformationCtrl", ["$scope", "$http", "SystemService", "$location", "toolsService" ,"dialogService",
        function ($scope, $http, SystemService, $location, toolsService,dialogService) {
            SystemService.getUserInformation().success(function (data) {
                if(data.errors == null || data.errors.length > 0){
                    dialogService.tip(data.errors);
                }else{
                    $scope.user = data.user;
                }
            });

            /**
             *图片保存的功能
             */
            $scope.showPicture=function(){
                var fileId=document.getElementById("imgFile");
                fileId.onchange=function(){
                    var fileList = document.getElementById("imgFile").files;
                    var file = fileList[0];
                    var fileReader = new FileReader();
                    fileReader.readAsDataURL(file);
                    fileReader.onload=function(){
                        document.getElementById("spanImage").src = fileReader.result;
                    };
                    SystemService.uploadAvatar(file,$scope.user.id).success(function(data) {
                        $scope.updateLogoData={
                            avatarId:data.id,
                            userId:$scope.user.id
                        };
                        SystemService.updateAvatar($scope.updateLogoData).success(function(data) {
                            if(data.errors === null || data.errors.length > 0){
                                dialogService.tip(data.errors);
                            }else{
                                dialogService.tip([{"message":"上传成功!" }]);
                            }
                        });
                    });
                };
            };

            /**
             * 编辑用户信息后保存
             */
            $scope.doSave = function () {
                SystemService.userEditSave($scope.user).success(function (data) {
                    if(data.errors === null || data.errors.length > 0){
                        dialogService.tip(data.errors);
                    }else{
                        dialogService.tip([{"message":"保存成功!" }],"/profile_view.htm");
                    }
                });
            };
        }]);
})();