'use strict';

angular.module('app').controller('WebMangerController', ['$scope', '$filter', function($scope, $filter) {

    //lxtalkClient.Invoke('{FB60F992-A0FD-47B3-AAA7-E80DF209C5A4}', '_Register', '', $scope);
    $scope.now = new Date();
    $scope.nowDate = $filter("date")($scope.now, "yyyy-MM-dd HH:mm:ss");
    $scope.createDate = $scope.nowDate;
    $scope.currentPage = 1;
    $scope.totalItems = 100;
    $scope.maxSize = 5; //最多显示7页其他的用···代替
    $scope.animateFirst = true;
    $scope.user = {
        name: '客服一',
        password: '12345678',
        loginname: 'kehu01',
        sex: 0,
        mob: '15906422850',
        tel: '0578-2021088',
        email: 'kehu01@wswin.cn',
    };

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

    $scope.save = function($event) {
        var activeClick = $($event.target);
        console.log(activeClick);
    };

    $scope.checkedTr = function($event) {
        var activeClick = $($event.target);
        var checked = activeClick[0].checked;
        console.log(activeClick);
        if (checked == true)
            $(activeClick[0].parentElement.parentElement).addClass("activebcolor");
        else if (checked == false)
            $(activeClick[0].parentElement.parentElement).removeClass("activebcolor");
    };

    $scope.checkedTotal = function() {
        if ($scope.checkedtotal == true)
            angular.element(".Tr").addClass("activebcolor");
        else if ($scope.checkedtotal == false)
            angular.element(".Tr").removeClass("activebcolor");
    };

    $scope.animate = function($event) {
        var animate = $($event.target);
        console.log(animate);
        if (animate[0].innerText == "投诉建议" && $scope.animateFirst)
            return;
        else if (animate[0].nodeName == "A") {
            angular.element(".slip").removeClass("animate");
            animate.addClass("animate");
        } else if (animate[0].nodeName == "SPAN") {
            angular.element(".slip").removeClass("animate");
            $(animate[0].parentElement).addClass("animate");
        }
        $scope.animateFirst = false;
    };

    $scope.imgPreview = function(fileDom) {
        //判断是否支持FileReader
        if (window.FileReader) {
            var reader = new FileReader();
        } else {
            alert("您的设备不支持图片预览功能，如需该功能请升级您的设备！");
        }

        //获取文件
        var file = fileDom.files[0];
        var imageType = /^image\//;
        //是否是图片
        if (!imageType.test(file.type)) {
            alert("请选择图片！");
            return;
        }
        //读取完成
        console.log(file);
        reader.onload = function(e) {
            // //获取图片dom
            // var img = document.getElementById("preview");
            // //图片路径设置为读取的图片
            //img.src = e.target.result;
            console.log("e.target.result");
            $("#imgadd").append('<a href="#" class="thumbnail"><img src="' + e.target.result + '"></a>');
        };
        reader.readAsDataURL(file);
    };

}]);