starter.directive('payBillList', function () {
    return {
        restrict: "E",
        scope: {
            bills: "=bills",
            loading: "=loading"
        },
        templateUrl: 'templates/template-payBillList.html',
        controller: function ($scope, $state, global) {
            $scope.user = global.user.usrid;
            $scope.todetails = function (id) {
                $state.go('paybilldetails', {
                    id: id
                })
            }
        }
    }
})

.directive('filterBar', function () {
    return {
        restrict: "E",
        scope: {
            setuser: "&",
            selClick: "&",
            centerData: "=",
            userId: "="
        },
        templateUrl: "templates/template-filterbar.html",
        controller: function ($scope, $state, formatFilter, Member) {
            setdata();
            $scope.$watch('userId', function (newValue, oldValue) {
                if (newValue === oldValue) return;
                if (Member.selectedemplst.length > 0) {
                    $scope.values.user_id = Member.selectedemplst[0].user_id;
                    $scope.right_title = Member.selectedemplst[0].username;
                    $scope.right_data[1].name = "选择单个成员" + formatFilter("({0})", Member.selectedemplst[0].username);
                    $scope.selClick($scope.values);
                }
            });

            $scope.selectclick = function (item, index) {
                $scope.acitve_indexs[$scope.key] = index;
                $scope.Ishidded = !$scope.Ishidded;
                if ($scope.key == "R" && index == 1) {
                    Member.routename = "";
                    Member.titlename = "选择单个成员";
                    Member.selectedemplst = [];
                    $state.go('selectsinglemember');
                    return;
                } else if ($scope.key == "R" && index == 0) {
                    Member.selectedemplst = [];
                    $scope.setuser();
                    $scope.right_title = $scope.right_data[0].name = "全部成员";
                    $scope.right_data[1].name = "选择单个成员";
                }
                $scope.key == "L" ? $scope.values.date = $scope.left_data[index].key : ($scope.key == "C" ? $scope.values.status = $scope.centerData[index].key : $scope.values.user_id = $scope.right_data[index].key);
                $scope.selClick($scope.values);
            };

            $scope.headerclick = function (key) {
                if ($scope.key == key) {
                    $scope.Ishidded = !$scope.Ishidded;
                } else {
                    $scope.key = key;
                    $scope.Ishidded = false;
                }
            };

            function setdata() {
                $scope.acitve_indexs = {"L": 0, "C": 0, "R": 0};
                $scope.key = "L";
                $scope.Ishidded = true;
                $scope.left_data = [];
                var year = new Date().getFullYear();
                $scope.left_data.push({"key": null, "name": "全部时间", "check": true});
                for (var y = year; y >= year - 1; y--) {
                    $scope.left_data.push({"key": formatFilter('{0}', y), "name": formatFilter('{0}年 全年', y), "check": false});
                    for (var m = 1; m < 13; m++) {
                        $scope.left_data.push({"key": formatFilter('{0}-{1}', y, m), "name": formatFilter('{0}年 {1}月', y, m), "check": false})
                    }
                }
                $scope.right_data = [{"key": null, "name": "全部成员", "check": true}, {"key": null, "name": "选择单个成员", "check": false}];
                $scope.data = {"L": $scope.left_data, "C": $scope.centerData, "R": $scope.right_data};
                $scope.values = {"date": _.find($scope.left_data, {check: true}).key, "status": _.find($scope.centerData, {check: true}).key, "user_id": _.find($scope.right_data, {check: true}).key};
                $scope.right_title = $scope.right_data[0].name;
            }
        }
    }
})