customization.js 4.69 KB
var initApp = function () {
    "use strict";
    var ref = [
        "xn.common",
        //"xn.service.foundation",
        "xn.directive.top",
        "xn.customization.filter",
        "xn.customization.service",
        "xn.service.interceptor",

        "xn.page",

        //"xn.customization.opeItem",
        //"xn.customization.demand.room",
        //"xn.customization.supply.item",
        //"xn.customization.supply.storeRoom",
        //"xn.customization.combine",
        //"xn.customization.setting",
        ////report
        //"xn.customization.ship.report",
        //"xn.customization.index",
        //"xn.customization.report",


        "ui.bootstrap",
        "ui.sortable",
        "xn.directive.loading",
        "xn.directive.select",
        //"xn.directive.form",
        "xn.directive.location",
        "xn.directive.card",
        "ngCookies",
        "xn.directive.attachment",
        "xn.directive.import"
    ];
    var app=angular.module("xn", ref);

    app.value("xnConfig", xnConfig);

    app.config(["$httpProvider", function ($httpProvider) {
        $httpProvider.interceptors.push("httpInterceptor");
    }]);

    // 全局配置 form提交验证
    //app.config(["xnValidatorProvider", function (xnValidatorProvider) {
    //
    //    // 全局配置
    //    xnValidatorProvider.config({
    //        blurTrig   : false,
    //        showError  : false,
    //        removeError: false
    //    });
    //
    //    xnValidatorProvider.setRules({
    //        giveItemQuantity:{
    //            required: "赠送数量应大于零,且为正数!"
    //        }
    //    });
    //}]);
    app.controller("BodyController",["$scope",function($scope){
        //关闭错误
        $scope.closeAlert = function (index,form) {
            form.splice(index,1);
        };

        $scope.$on('navShow', function (e, newNavShow) {
            $scope.navShow = newNavShow;
        });
        $scope.maxPageSize=5;

        $scope.isNullValue = function(value){
            if(value === 0 || value === "0"){
                return false;
            }
            if(value){
                return false;
            }
            return true;
        };

        $scope.foregroundPaging  = function(param){
            var allList = param.allList;
            var fieldList = param.fieldList;
            var value = param.value;
            var pageSize = param.pageSize;
            var pageNumber = param.pageNumber;

            if(!allList || allList.length == 0){
                return {list:[],totalCount:0};
            }

            if(!pageSize){
                pageSize = 10
            }
            if(!pageNumber){
                pageNumber = 1;
            }
            var lastPageNumber = parseInt(allList.length / pageSize);
            if (allList.length % pageSize != 0) {
                lastPageNumber++;
            }
            if (pageNumber > lastPageNumber) {
                pageNumber = lastPageNumber;
            }
            var minIndex = (pageNumber - 1) * pageSize;
            var maxIndex = pageNumber * pageSize;

            var list = [];
            var num = 0;

            var returnValue = {result:list};
            if(!$scope.isNullValue(value)){
                var valueLength = value.length;
                for(var i=0;i<allList.length;i++){
                    var flag = false;

                    for(var k=0;k<fieldList.length;k++){
                        var field = fieldList[k];
                        var fieldValue = allList[i][field];
                        if (fieldValue == undefined) {
                            fieldValue = "";
                        }
                        var fieldLength = fieldValue.length;

                        for(var j=0;j<(fieldLength-valueLength+1);j++){
                            if(value == fieldValue.substring(j,j+valueLength)){
                                if(num >= minIndex && num < maxIndex){
                                    list.push(allList[i]);
                                }
                                num++;
                                flag = true;
                                break;
                            }
                        }
                        if(flag){
                            break;
                        }
                    }
                }
                returnValue.totalCount = num;
            } else {
                if(maxIndex > allList.length){
                    maxIndex = allList.length;
                }
                for(var i=minIndex;i<maxIndex;i++){
                    list.push(allList[i]);
                }
                returnValue.totalCount = allList.length;
            }
            return returnValue;
        }
    }]);
};