index.js 6.48 KB
/**
 * Created by 王冠伦 on 2018/2/26.
 */
(function () {
    "user strict";

    var railwayController = function($scope,$modal,$http,$interval,dialogService,railwayService){
        $scope.$emit('navShow', 5);
        $scope.vm = {
            pageSize : 0,
            totalCount : 0,
            type:"LAID_ON"
        }
        $scope.getList = function(){
            railwayService.findEscortAttendance($scope.vm).success(function(data){
                if (data.errors == null || data.errors.length > 0) {
                    dialogService.tip(data.errors);
                }else{
                    $scope.escortAttendanceList = data.result;
                    for(var i =0 ;i< $scope.escortAttendanceList.length;i++){
                        if ($scope.escortAttendanceList[i].laidTime != null) {
                            var time = new Date(Number($scope.escortAttendanceList[i].laidTime));
                            $scope.escortAttendanceList[i].laidTime = time.format("yyyy-MM-dd hh:mm:ss ");
                        }
                    }
                    $scope.vm.totalCount = data.totalCount;
                }
            })
        }
        $scope.getList();
        var timer=$interval(function(){
            $scope.getList();
        },10000);   //间隔2秒定时执行

        timer.then(function(){ console.log('查询成功')},
            function(){ console.log('查询不成功')});

        $scope.doAddTag = function(){
            var vm = {};
            var modalInstance = $modal.open({
                templateUrl: "create.html",
                controller:createTagController,
                size:"md",
                resolve: {
                    items: function () {
                        return vm;
                    }
                }
            });
            modalInstance.result.then(function () {
                $scope.getList();
            });
        }
        $scope.doEdit = function (id) {
            var vm = {
                id:id
            };
            var modalInstance = $modal.open({
                templateUrl: "create.html",
                controller:editTagController,
                size:"md",
                resolve: {
                    items: function () {
                        return vm;
                    }
                }
            });
            modalInstance.result.then(function () {
                $scope.getList();
            });
        }
        $scope.doSearch = function(){
            $scope.vm.pageNumber = 1;
            $scope.getList();
        }
        $scope.doDelete = function(id){
            var dialogDefaults = {
                size: "sm"
            };
            var dialogOptions = {
                closeButtonText: "取消",
                actionButtonText: "确定",
                headerText: "提示",
                bodyText: "确认删除吗",
                callback: function () {
                    PartnerService.deleteTag({id:id}).success(function(data){
                        if (data.errors == null || data.errors.length > 0) {
                            dialogService.tip(data.errors);
                        }else{
                            dialogService.tip([{"message": "删除成功!" }]);
                            $scope.getList();
                        }
                    })
                }
            };
            dialogService.confirm(dialogDefaults, dialogOptions);
        }
    }

    var createTagController = ["$scope","$modalInstance","dialogService","PartnerService","items",
        function($scope,$modalInstance,dialogService,PartnerService,items){
            $scope.headTitle = "新增标签";
            //关闭弹出窗
            $scope.clean = function () {
                $modalInstance.close();
            };
            //关闭错误
            $scope.closeAlert = function (index,form) {
                form.splice(index,1);
            };
            $scope.vm = {
                type : "PARTNER",
                orderIndex : 0
            };
            //保存方法
            $scope.doSave = function () {
                if ($scope.vm.name==null || $scope.vm.name==""){
                    $scope.validateForm.$errors.push("标签的名称不能为空");
                    return;
                }
                PartnerService.createTag($scope.vm).success(function(data){
                    if (data.errors == null || data.errors.length > 0) {
                        $scope.validateForm.$errors.push(data.errors[0].message);
                        //dialogService.tip(data.errors);
                    } else{
                        dialogService.tip([{"message": "创建成功"}]);
                        $scope.clean();
                    }
                })
            }
        }];

    var editTagController = ["$scope","$modalInstance","dialogService","PartnerService","items",
        function($scope,$modalInstance,dialogService,PartnerService,items){
            $scope.headTitle = "编辑标签";
            var id = items.id;
            //关闭弹出窗
            $scope.clean = function () {
                $modalInstance.close();
            };
            //关闭错误
            $scope.closeAlert = function (index,form) {
                form.splice(index,1);
            };
            $scope.getTag = function(){
                PartnerService.getTag({id:id}).success(function(data){
                    if (data.errors == null || data.errors.length > 0) {
                        dialogService.tip(data.errors);
                    }else{
                        $scope.vm = data.tag;
                    }
                })
            }
            $scope.getTag();
            //保存方法
            $scope.doSave = function () {
                if ($scope.vm.name==null || $scope.vm.name==""){
                    $scope.validateForm.$errors.push("标签的名称不能为空");
                    return;
                }
                PartnerService.updateTag($scope.vm).success(function(data){
                    if (data.errors == null || data.errors.length > 0) {
                        $scope.validateForm.$errors.push(data.errors[0].message);
                    } else{
                        dialogService.tip([{"message": "编辑成功"}]);
                        $scope.clean();
                    }
                })
            }
        }];

    angular.module("xn.page", ["xn.directive.form"])
        .controller("RailwayController",["$scope","$modal","$http","$interval","dialogService","RailwayService",railwayController])
})();