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

    var postPositionController = function($scope,$modal,$http,$interval,dialogService,railwayService){
        $scope.$emit('navShow', 6);
        $scope.settingShow = 6;
        $scope.vm = {
            pageSize : 10,
            totalCount : 0
        }
        $scope.selectedCategoryList = [];
        angular.forEach($scope.allCategory,function(category){
            category.name = category.categoryName;
        });
        $scope.getList = function(){
            $scope.vm.categoryIdList = null;
            if($scope.selectedCategoryList.length > 0){
                $scope.vm.categoryIdList = [];
                for(var i in $scope.selectedCategoryList){
                    $scope.vm.categoryIdList.push($scope.selectedCategoryList[i].id);
                }
            }
            railwayService.findPostPosition($scope.vm).success(function(data){
                if (data.errors == null || data.errors.length > 0) {
                    dialogService.tip(data.errors);
                }else{
                    $scope.postPositionList = data.result;
                    $scope.vm.totalCount = data.totalCount;
                    $scope.settingShow = 6;
                }
            })
        }
        $scope.getList();

        $scope.doSearch = function(){
            $scope.vm.pageNumber = 1;
            $scope.getList();
        }

        $scope.doCreate = function(){
            window.location = "/admin/postPosition/create.vm";
        };

        $scope.doEdit = function(id){
            window.open("/admin/postPosition/edit.htm?id="+id);
        };

        $scope.doDelete = function(postPositionId){
            var dialogDefaults = {
                size:"sm"
            };
            var dialogOptions = {
                closeButtonText: "取消",
                actionButtonText: "删除",
                headerText: "删除",
                bodyText: "您确定要删除权限吗?",
                callback: function () {
                    railwayService.deletePostPosition({id:postPositionId}).success(function (data) {
                        if (data.errors == null || data.errors.length > 0) {
                            dialogService.tip(data.errors, null, null);
                        } else {
                            dialogService.tip([{message:"删除权限成功!"}],"/admin/postPosition/index.htm",1000);
                        }
                    });
                }
            };
            dialogService.confirm(dialogDefaults, dialogOptions);
        };
    }

    var postPositionCreateController = function($scope,$modal,$http,$interval,dialogService,railwayService){
        $scope.$emit('navShow', 6);
        $scope.settingShow = 6;
        $scope.vm = {
            pageSize : 10,
            totalCount : 0
        }
        /**
         * Created @ 0519
         * @type {Array}
         */
        $scope.cancel = function(){
            window.location = "/admin/postPosition/index.vm";
        };
        //查询车站信息
        $scope.postPositionSetting = {}

        railwayService.railwayLineStationFind($scope.vm).success(function (data) {
            if (data.errors === null || data.errors.length > 0) {
                dialogService.tip(data.errors, null, null);
            } else {
                $scope.postPositionSetting.lineList = data.lineList;
            }
        });

        $scope.doSave = function() {
            if($scope.postPositionSetting.name == "" || $scope.postPositionSetting.name == null){
                dialogService.tip([{"message": "权限名称不能为空,请填写后再保存!"}]);
                return;
            }
            railwayService.apiPermissionSave($scope.postPositionSetting).success(function(data){
                if (data.errors == null || data.errors.length > 0){
                    dialogService.tip(data.errors);
                }
                else {
                    dialogService.tip([{message:"创建成功!"}],"/admin/postPosition/index.htm",1000);
                    //关闭
                    //$modalInstance.close($scope.postPositionSetting);
                    //清空数据
                    $scope.postPositionSetting={};
                }
            })
        }
    }

    var postPositionEditController = function($scope,$modal,$http,$interval,$location,dialogService,toolsService,railwayService){
        $scope.$emit('navShow', 6);
        $scope.settingShow = 6;
        $scope.id = toolsService.parameter("id", $location.absUrl());
        $scope.vm = {
            id: $scope.id,
            pageSize : 10,
            totalCount : 0
        }
        $scope.cancel = function(){
            window.location = "/admin/postPosition/index.vm";
        };
        //查询车站信息
        $scope.postPositionSetting = {}
        railwayService.railwayPermissionFind($scope.vm).success(function (data) {
            if (data.errors === null || data.errors.length > 0) {
                dialogService.tip(data.errors, null, null);
            } else {
                $scope.postPositionSetting = data;
            }
        });
        $scope.doEditSave = function() {
            if($scope.postPositionSetting.name == "" || $scope.postPositionSetting.name == null){
                dialogService.tip([{"message": "权限名称不能为空,请填写后再保存!"}]);
                return;
            }
            railwayService.apiPermissionEditSave($scope.postPositionSetting).success(function(data){
                if (data.errors == null || data.errors.length > 0){
                    dialogService.tip(data.errors);
                }
                else {
                    dialogService.tip([{message:"编辑成功!"}],"/admin/postPosition/index.htm",1000);
                    //关闭
                    //$modalInstance.close($scope.postPositionSetting);
                    //清空数据
                    $scope.postPositionSetting={};
                }
            })
        }
    }

    angular.module("xn.page", ["xn.directive.form"])
        .controller("PostPositionController",["$scope","$modal","$http","$interval","dialogService","RailwayService",postPositionController])
        .controller("PostPositionCreateController",["$scope","$modal","$http","$interval","dialogService","RailwayService",postPositionCreateController])
        .controller("PostPositionEditController",["$scope","$modal","$http","$interval","$location","dialogService","toolsService","RailwayService",postPositionEditController])
})();