'use strict';

angular.module('app').controller('UserController', ['$scope', '$state', function($scope, $state) {

    //lxtalkClient.Invoke('{FB60F992-A0FD-47B3-AAA7-E80DF209C5A4}', '_Register', '', $scope);

    // $scope.user = {
    //     name: '陆趣趣',
    //     l: '0578+0-lslqq',
    //     shotL: 'lslqq',
    //     comp: '浙江万赛软件科技有限公司',
    //     branch: '运维部',
    //     sex: '0',
    //     mob: '15215756180',
    //     sMob: '666666',
    //     tel: '2189026',
    //     duty: '运维部经理',
    //     officeID: '运维室001',
    //     email: 'lqq@wswin.cn',
    //     shortL: 'lszhangzhangzhang'
    // };

    $scope.getSex = function(sex) {
        if ($scope.user === undefined)
            return '保密';
        if ($scope.user.sex == 0)
            return '男';
        else if ($scope.user.sex == 1)
            return '女';
        else
            return '保密';
    }

    $scope.isActive = $state.$current.name == 'details-new.info' ? true : false;
    $scope.$on('$stateChangeStart',
        function(event, toState, toParams, fromState, fromParams, options) {
            $scope.isActive = toState.name == 'details-new.info' ? true : false;
        });

    $scope.update = function(userJson) {
        userJson = userJson.replace(/ /g, " ");
        userJson = userJson.replace(/\t/g, "\\t");
        var user = JSON.parse(userJson);
        $scope.user = user;
        var reg = /-([\W\w]*)/;
        var group = reg.exec($scope.user.l);
        $scope.user.shortL = group == null ? $scope.user.l : group[1];

        //宁夏企税通企业版使用
        // if ($state.current.name == 'simple-enterprise' || $state.current.name == 'simple') {
        //   // alert($state.current.name);
        //   if ($scope.user.l.length >= 15 && $state.current.name !== 'simple-enterprise')
        //     $state.go('simple-enterprise');
        //   else if ($scope.user.l.length < 15 && $state.current.name !== 'simple')
        //     $state.go('simple');
        // }
        // else if ($state.current.name == 'details-enterprise' || $state.current.name == 'details')
        // {
        //   if ($scope.user.l.length >= 15 && $state.current.name !== 'details-enterprise')
        //     $state.go('details-enterprise');
        //   else if ($scope.user.l.length < 15 && $state.current.name !== 'details')
        //     $state.go('details');
        // }
    }
}]);