<commit_before>import ValidatorFactory from '../../utils/util';
import {productCat} from '../../consts/const.js';

/**
 * 计算每月还款数量
 * 计算规则 ==================>>>>
 * 选择保险：
 * 月还款金额=借款金额*（月利率+月服务费+月账户管理费率）*（1+月利率+月服务费+月账户管理费率）^期数/（（1+月利率+月服务费+月账户管理费率）^期数-1）
 * 不选择保险：
 * 月还款金额=借款金额*（月利率+月服务费+月账户管理费率+月保险手续费率）*（1+月利率+月服务费+月账户管理费率+月保险手续费率）^期数/（（1+月利率+月服务费+月账户管理费率+月保险手续费率）^期数-1）
 * 还款随心包=20元/月
 * @param  {[type]} totalLoan [description]
 * @return {[type]}           [description]
 */
function calculateMonthLoan(totalLoan) {
    totalLoan = parseInt(totalLoan, 10);
    var monthService = 0,
        monthRate = 0.015,
        monthManage = 0,
        stage = +this.loan.stage,
        monthEnsurance = this.loan.ensurance ?  0.006 : 0,
        packages = this.loan.package ?  20 : 0;

    var numerator = totalLoan * (monthEnsurance + monthManage + monthRate + monthService) * (Math.pow(1 + monthEnsurance + monthManage + monthRate + monthService, stage));
    var denominator = Math.pow(1 + monthEnsurance + monthManage + monthRate + monthService, stage) - 1;
    // 随心包改成+20 ---- 2016.9.30
    var res = Math.round(numerator / denominator) + packages;
    if(res !== res || res === Infinity ||　res < 0) res = 0;
    return res;
}

let localStorage;



class LoanCtrl{
    /* @ngInject */
    constructor(localStorageService, $scope, $rootScope, $state) {
        let basicInfo = localStorageService.get('basic');
        if(!basicInfo) $state.go('applicationForm.basic');
        localStorage = localStorageService;

        let loan = {
            productCat: '0',
            stage : '',
            ensurance : true,
            package : true,
            productName: '',
            productPrice: '',
            loanMoney: '',
            instalments: '0',
            bankNum: '',
            accountName: ''
        };
        // 贷款数据
        this.loan = localStorageService.get('loan') || loan;
        this.loan.orderNum = localStorageService.get('orderNum');

        this.productCat = productCat;

        /**
         * 提示信息弹出层
         * @type {Boolean}
         */
        this.isShow = false;
        this.msg = '';

        $scope.$watch('this.loan.loanMoney', () => {
            console.log(123)
            this.loan.instalments = calculateMonthLoan.call(this, this.loan.loanMoney);
        });

        $scope.$watch('this.loan.ensurance', () => {
            console.log(123)
            this.loan.instalments = calculateMonthLoan.call(this, this.loan.loanMoney);
        });

        $scope.$watch('this.loan.package', () => {
            console.log(123)
            this.loan.instalments = calculateMonthLoan.call(this, this.loan.loanMoney);
        });

        $scope.$watch('this.loan.stage', () => {
            console.log(123)
            this.loan.instalments = calculateMonthLoan.call(this, this.loan.loanMoney);
        });
    }

    init() {

    }



    showMsg(msg) {<commit_msg>fix the watched property this => vm<commit_after>import ValidatorFactory from '../../utils/util';
import {productCat} from '../../consts/const.js';

/**
 * 计算每月还款数量
 * 计算规则 ==================>>>>
 * 选择保险：
 * 月还款金额=借款金额*（月利率+月服务费+月账户管理费率）*（1+月利率+月服务费+月账户管理费率）^期数/（（1+月利率+月服务费+月账户管理费率）^期数-1）
 * 不选择保险：
 * 月还款金额=借款金额*（月利率+月服务费+月账户管理费率+月保险手续费率）*（1+月利率+月服务费+月账户管理费率+月保险手续费率）^期数/（（1+月利率+月服务费+月账户管理费率+月保险手续费率）^期数-1）
 * 还款随心包=20元/月
 * @param  {[type]} totalLoan [description]
 * @return {[type]}           [description]
 */
function calculateMonthLoan(totalLoan) {
    totalLoan = parseInt(totalLoan, 10);
    var monthService = 0,
        monthRate = 0.015,
        monthManage = 0,
        stage = +this.loan.stage,
        monthEnsurance = this.loan.ensurance ?  0.006 : 0,
        packages = this.loan.package ?  20 : 0;

    var numerator = totalLoan * (monthEnsurance + monthManage + monthRate + monthService) * (Math.pow(1 + monthEnsurance + monthManage + monthRate + monthService, stage));
    var denominator = Math.pow(1 + monthEnsurance + monthManage + monthRate + monthService, stage) - 1;
    // 随心包改成+20 ---- 2016.9.30
    var res = Math.round(numerator / denominator) + packages;
    if(res !== res || res === Infinity ||　res < 0) res = 0;
    return res;
}

let localStorage;

// 这里应该把controller的函数体都写入constructor,
// 因为controller是个单例的函数，只会实例化一次，同时也不需要继承和被继承，
// 因此可以不用把函数体挂在原型上．

class LoanCtrl{

    /*@ngInject*/
    constructor(localStorageService, $scope, $rootScope, $state) {
        let basicInfo = localStorageService.get('basic');
        if(!basicInfo) $state.go('applicationForm.basic');
        localStorage = localStorageService;

        let loan = {
            productCat: '0',
            stage : '',
            ensurance : true,
            package : true,
            productName: '',
            productPrice: '',
            loanMoney: '',
            instalments: '0',
            bankNum: '',
            accountName: ''
        };
        // 贷款数据
        this.loan = localStorageService.get('loan') || loan;
        this.loan.orderNum = localStorageService.get('orderNum');

        this.productCat = productCat;

        /**
         * 提示信息弹出层
         * @type {Boolean}
         */
        this.isShow = false;
        this.msg = '';

        $scope.$watch('vm.loan.loanMoney', () => {
            this.loan.instalments = calculateMonthLoan.call(this, this.loan.loanMoney);
        });

        $scope.$watch('vm.loan.ensurance', () => {
            this.loan.instalments = calculateMonthLoan.call(this, this.loan.loanMoney);
        });

        $scope.$watch('vm.loan.package', () => {
            this.loan.instalments = calculateMonthLoan.call(this, this.loan.loanMoney);
        });

        $scope.$watch('vm.loan.stage', () => {
            this.loan.instalments = calculateMonthLoan.call(this, this.loan.loanMoney);
        });
    }

    init() {

    }



    showMsg(msg) {
{'fraction_non_alphanumeric': 0.16110255093305942, 'fraction_numerical': 0.015750727615134394, 'mean_word_length': 2.3516924842226046, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5514976', 'n_tokens_mistral': 2261, 'n_tokens_neox': 2272, 'n_words': 306}