credit.js 9.06 KB
(function () {
    "use strict";


    /**
     *    支付渠道费日汇总报表
     */
    var setCreditController = function ($scope, $http, $modal, saleService, hrService, dialogService, wosaicustomizationService) {
        $scope.$emit('navShow', 3);

        $scope.vm = {
            pageNumber: 1,
            pageSize: 10,
        };
        //获取员工
        $scope.getEmployeeLists = function (backdata) {
            var param = {
                keyword: backdata.data.keyword,
                pageNumber: backdata.data.pageNumber,
                pageSize: backdata.data.pageSize
            };
            //获取法律实体
            hrService.apiHrEmployeeFindIndex(param).success(function (data) {
                if (data.errors == null || data.errors.length > 0) {
                    dialogService.tip(data.errors);
                }
                else {
                    backdata.deferred.resolve({itemList: data.result, totalCount: data.totalCount});
                }
            });
        }
        //类型
        $scope.typeList = [{key: "AREA", val: "区域"}, {key: "CITY", val: "城市"}, {key: "BD", val: "业务拓展员"}];
        $scope.getList = function () {
            wosaicustomizationService.apiEmployeeCreditFind($scope.vm).success(function (data) {
                if (data.errors === null || data.errors.length > 0) {
                    dialogService.tip(data.errors, null, 0);
                } else {
                    $scope.employeeCreditList = data.result;
                    $scope.vm.totalCount = data.totalCount;

                }
            });
        }
        $scope.doFind = function () {
            $scope.vm.pageNumber = 1;
            $scope.vm.pageSize = 10;
            $scope.vm.employeeName = $scope.vm.employee ? $scope.vm.employee.name : null;
            $scope.vm.type = $scope.vm.type ? $scope.vm.type : null;
            $scope.getList();
        };
        //创建员工
        $scope.addEmployee = function () {
            var modalInstance = $modal.open({
                templateUrl: "addEmployee.htm",
                controller: addEmployeeController,
                size: "",
                resolve: {
                    items: function () {
                        return {operatingUnitList: $scope.operatingUnitList};
                    }
                }
            });
            modalInstance.result.then(function () {
                $scope.getList();
            });
        };
        //编辑
        $scope.editEmployee = function (employeeCredit) {
            var modalInstance = $modal.open({
                templateUrl: "editEmployee.htm",
                controller: editEmployeeController,
                size: "",
                resolve: {
                    items: function () {
                        return employeeCredit;
                    }
                }
            });
            modalInstance.result.then(function () {
                $scope.getList();
            });
        };
        //删除
        $scope.deleteEmployee = function (id) {
            $scope.employeeCredit = {
                id: id
            };
            var dialogDefaults = {
                size: "sm"
            };
            var dialogOptions = {
                closeButtonText: "取消",
                actionButtonText: "确定删除",
                headerText: "继续....?",
                bodyText: "您确定要删除吗?",
                callback: function () {
                    wosaicustomizationService.apiEmployeeCreditDelete($scope.employeeCredit).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 addEmployeeController = ["$scope", "$modalInstance", "items", "HrService", "SystemService", "dialogService","WosaicustomizationService",
        function ($scope, $modalInstance, items, HrService, SystemService, dialogService,wosaicustomizationService) {
            $scope.$emit('navShow', 3);

            $scope.vm = {
                pageNumber: 1,
                pageSize: 10,
            };
            //获取员工
            $scope.getEmployeeLists = function (backdata) {
                var param = {
                    keyword: backdata.data.keyword,
                    pageNumber: backdata.data.pageNumber,
                    pageSize: backdata.data.pageSize
                };
                //获取法律实体
                HrService.apiHrEmployeeFindIndex(param).success(function (data) {
                    if (data.errors == null || data.errors.length > 0) {
                        dialogService.tip(data.errors);
                    }
                    else {
                        backdata.deferred.resolve({itemList: data.result, totalCount: data.totalCount});
                    }
                });
            }
            $scope.employee = $scope.vm.employee;
            $scope.changeState = function (employee) {
                $scope.vm.organizationName = $scope.vm.employee ? $scope.vm.employee.organizationName : null;
            };
            $scope.$watch("vm.employee", function (employee) {
                $scope.vm.organizationName = $scope.vm.employee ? $scope.vm.employee.organizationName : null;
            }, true);

            //类型
            $scope.typeList = [{key: "AREA", val: "区域"}, {key: "CITY", val: "城市"}, {key: "BD", val: "业务拓展员"}];


            //保存
            $scope.ok = function () {
                if (!$scope.vm.employee) {
                    dialogService.tip([{message: "请填写员工!"}]);
                    return;
                }
                if (!$scope.vm.type) {
                    dialogService.tip([{message: "请填写类型!"}]);
                    return;
                }
                if (!$scope.vm.initCredit) {
                    dialogService.tip([{message: "请填写额度限制!"}]);
                    return;
                }
                $scope.vm.employeeName = $scope.vm.employee ? $scope.vm.employee.name : null;
                wosaicustomizationService.apiEmployeeCreditCreate($scope.vm).success(function (data) {
                    if (data.errors === null || data.errors.length > 0) {
                        dialogService.tip(data.errors, null, 0);
                    } else {
                        dialogService.tip([{"message": "添加成功!"}]);
                        $modalInstance.close();

                    }
                });
            };


            //关闭窗口
            $scope.cancel = function () {
                $modalInstance.dismiss('cancel');
            };
        }];
    /**
     *   编辑
     */
    var editEmployeeController = ["$scope","$modalInstance", "items", "HrService", "SystemService", "dialogService","WosaicustomizationService",
        function ($scope, $modalInstance, items, HrService, SystemService, dialogService,wosaicustomizationService) {
            $scope.$emit('navShow', 3);
            $scope.vm = {};
            if (items != null) {
                $scope.title = "编辑编辑额度";
                $scope.employeeCredit = items;
                $scope.vm.id = $scope.employeeCredit.id;
                $scope.vm.employeeName = $scope.employeeCredit.employeeName;
                $scope.vm.organizationName = $scope.employeeCredit.organizationName;
                $scope.vm.type = $scope.employeeCredit.type;
                $scope.vm.initCredit = $scope.employeeCredit.initCredit;
                $scope.vm.currentCredit = $scope.employeeCredit.currentCredit;
            }

            //保存
            $scope.ok = function () {
                if (!$scope.vm.initCredit) {
                    dialogService.tip([{message: "请填写额度限制!"}]);
                    return;
                }
                if (!$scope.vm.currentCredit) {
                    dialogService.tip([{message: "请填写剩余额度!"}]);
                    return;
                }
                wosaicustomizationService.apiEmployeeCreditUpdate($scope.vm).success(function (data) {
                    if (data.errors === null || data.errors.length > 0) {
                        dialogService.tip(data.errors, null, 0);
                    } else {
                        dialogService.tip([{"message": "保存成功!"}]);
                        $modalInstance.close();

                    }
                });
            };
            //关闭窗口
            $scope.cancel = function () {
                $modalInstance.dismiss('cancel');
            };
        }];
    angular.module("xn.page", [])

        .controller("SetCreditController", ["$scope", "$http", "$modal", "SaleService", "HrService", "dialogService", "WosaicustomizationService", setCreditController])

})();