一段美丽的js代码

/**费用计算器超类*/
var RateMap = function() {
    this.rates = [];
    this.initRate();
}
RateMap.prototype = {
    rates:null,
    /**查找费率记录*/
    findRecord:function(con)
    {
        for (var i = 0; i < this.rates.length; i++)
        {
            var rate = this.rates[i];
            var allMatch = true;
            for (var key in con)
            {
                var match = false;
                if (typeof con[key] == "function")
                {
                    match = con[key].call(this, rate);
                } else
                {
                    match = (rate[key] == con[key]);
                }
                if (!match)
                {
                    allMatch = false;
                    break;
                }
            }
            if (allMatch)
            {
                return rate;
            }
        }
        return null;
    },
    initRate:function() {

    },
    addRate:function(defaultConfig, configs) {
        for (var i = 0; i < configs.length; i++)
        {
            var x = {};
            Ext.apply(x, defaultConfig);
            Ext.apply(x, configs[i]);
            this.rates.push(x);
        }
    }
}
/**XX保险产品的费用计算器*/
var gwcc_sl_RateMap = Ext.extend(RateMap, {
    /**计算费用*/
    cal:function(con) {
        //全年
        if (con.year)
        {
            return this.findYear(con);
        }
        //30-90天
        if (con.days > 30 && con.days < 90)
        {
            return this.periodFee(con);
        }
        //大于90天
        if (con.days >= 90)
        {
            return this.find90DaysFee(con);
        }
        //1-30天之间
        return this.findRecord({scope:con.scope,days:function(rate) {
            return rate.start <= con.days && rate.end >= con.days;
        }});
    },
    findYear:function(con) {
        return  this.findRecord({scope:con.scope,days:function(rate) {
            return rate.year;
        }})
    },
    periodFee:function(con) {
        var pr = this.findRecord({scope:con.scope,days:function(rate) {
            return rate.bigThan == 30; 
        }})
        var lr = this.findRecord({scope:con.scope,days:function(rate) {
            return rate.end == 30;
        }});
        var days = con.days - 30;
        var periods = Math.floor(days / 7) + (days % 7 > 0 ? 1 : 0);
        return {a:(lr.a + pr.a * periods),b:(lr.b + pr.b * periods),c:(lr.c + pr.c * periods)}
    },
    find90DaysFee:function(con) {
        return this.findRecord({scope:con.scope,days:function(rate) {
            return rate.bigThan == 90; 
        }})
    },
    /**初始化费率表*/
    initRate:function() {
        this.addRate({scope:"out"}, [{
            start:1,end:5,a:158,b:87,c:53
        },{
            start:6,end:10,a:237,b:130,c:80
        },{
            start:11,end:15,a:317,b:173,c:106
        },{
            start:16,end:20,a:396,b:217,c:133
        },{
            start:21,end:25,a:495,b:271,c:166
        },{
            start:26,end:30,a:593,b:325,c:199
        }]);

        this.addRate({scope:"inout"}, [{
            start:1,end:5,a:190,b:104,c:64
        },{
            start:6,end:10,a:285,b:156,c:96
        },{
            start:11,end:15,a:380,b:208,c:127
        },{
            start:16,end:20,a:475,b:260,c:159
        },{
            start:21,end:25,a:593,b:325,c:199
        },{
            start:26,end:30,a:712,b:390,c:239
        }])

        this.addRate({scope:"out"}, [{
            year:true,a:1980,b:1080,c:660
        }]);
        this.addRate({scope:"inout"}, [{
            year:true,a:2380,b:1300,c:790
        }]);

        this.addRate({scope:"out"}, [{
            bigThan:90,a:989,b:542,c:332
        }]);
        this.addRate({scope:"inout"}, [{
            bigThan:90,a:1187,b:650,c:398
        }]);

        this.addRate({scope:"out"}, [{
            bigThan:30,a:40,b:22,c:13
        }]);
        this.addRate({scope:"inout"}, [{
            bigThan:30,a:47,b:26,c:16
        }]);
    }
})

你可能感兴趣的:(C++,c,ext,prototype,C#)