safeMessage.js 3.2 KB
/**
 * Created by cjl on 2018/4/23.
 */
(function () {
    "user strict";

    var safeMessageController = function($scope,$modal,$http,$interval,dialogService,railwayService){
        $scope.settingShow = 8;
        $scope.vm = {
            totalCount : 0,
            pageNumber : 1,
            pageSize : 10,
            userId : ''
        }
        $scope.getList = function(){
            railwayService.findSafeMessage($scope.vm).success(function(data){
                if (data.errors == null || data.errors.length > 0) {
                    dialogService.tip(data.errors);
                }else{
                    $scope.safeMessageList = data.result;
                    $scope.vm.totalCount = data.totalCount;
                }
            })
        };
        $scope.doSave = function(){
            if (!$scope.vm.description) {
                $scope.validateForm.$errors.push("内容不能为空");
            }
            railwayService.addSafeMessage($scope.vm).success(function(data){
                if (data.errors == null || data.errors.length > 0){
                    dialogService.tip(data.errors);
                }
                else {
                    dialogService.tip([{message:"创建成功!"}],"/admin/safeMessage/index.htm",1000);
                    //清空数据
                }
            })
        };
        $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 () {
                    railwayService.deleteSafeMessage({id:id}).success(function (data) {
                        if (data.errors == null || data.errors.length > 0) {
                            dialogService.tip(data.errors, null, null);
                        } else {
                            dialogService.tip([{message:"删除成功!"}],"/admin/safeMessage/index.htm",1000);
                        }
                    });
                }
            };
            dialogService.confirm(dialogDefaults, dialogOptions);
        };
    }

    var safeMessageOpenController = function($scope,$modal,$http,$location,dialogService,railwayService,toolsService){
        $scope.id = toolsService.parameter("id", $location.absUrl());
        $scope.vm={};
        railwayService.getSafeMessage({id:$scope.id}).success(function(data){
            if (data.errors == null || data.errors.length > 0) {
                dialogService.tip(data.errors);
            }else{
                $scope.vm = data.safeMessage;
            }
        })
    }

    angular.module("xn.page", ["xn.directive.form"])
        .controller("SafeMessageController",["$scope","$modal","$http","$interval","dialogService","RailwayService",safeMessageController])
        .controller("SafeMessageOpenController",["$scope","$modal","$http","$location","dialogService","RailwayService","toolsService",safeMessageOpenController])
})();