常用公共js

var USERAGENT = '', IEversion = 0;

var Safariversion=0;
var ua = navigator.userAgent.toLowerCase();
if(window.openDatabase){
	if(ua.match(/version\/([\d.]+)/)!=null && ua.match(/version\/([\d.]+)/)!='null'){
		Safariversion = ua.match(/version\/([\d.]+)/)[1];
	}
}

function ieversion(){
	USERAGENT = navigator.userAgent.toLowerCase();
	USERAGENT.replace(/compatible;\smsie\s(\d+)\.\d+;.+/ig, function($0, $1) {
		IEversion = parseInt($1);
	});
	if(IEversion ==0 && USERAGENT.indexOf('trident') !== -1) {
		USERAGENT.replace(/mozilla\/\d+\.\d+\s\(windows.*?rv\:(\d+)\.\d+\) like gecko/ig, function($0, $1) {
			IEversion = parseInt($1);
		});
	}
	return IEversion;
}
ieversion();

function IEDOM(){
	if(IEversion >0){
		$('body').addClass('ie ie_'+IEversion);
	}
}

/**
 *   location.href 兼容性處理
 *	 用法保持一致
 */
function location_href(url){
	var hosts = HOST;
	if(url.indexOf(HOST) == 0){
		hosts = '';
	}
	if(url.indexOf('./') == 0){
		url = url.substring(2);
	}
	window.location.href = hosts+url;
}

/**
 *   JS調試函數
 */
function debug(data){
	if(typeof data =='object'){
		data = JSON.stringify(data);//debug
	}
	console.log(data);//debug
}
/*關閉下載提示*/
function closeUptip(){
    $('.js-updateBrowser').hide();
}


/**
 *   AJAX請求列表數據爲空時輸出統一格式數據
 */
function list_emp(column,text){
	if(!text) text = '暫無數據';
	text = '<div class="cl list_emp">'+text+'</div>';
	if(column){
		text = '<tr class="list_emp_tr"><td colspan="'+column+'" class="list_emp_td">'+text+'</td></tr>';
	}
	return text;
}


/**
 *   獲取對象數組元素個數
 */
function arrayCount(dt){
	var i = 0;
	if(dt && typeof(dt) =='object'){
		for(K in dt){
			i ++;
		}
	}
	return i;
}


/**
 *	四捨五入處理
 *	val=處理對象(傳入帶小數的float)  n=保留位數  s=是否用0自動補充小數位(string)
 */
function Num_round(val, n, s) {
	val = parseFloat(val);
	n = parseInt(n);
	var s = 1;
	if(n > 0) {
		for(i = 0; i < n; i++) {
			s = s * 10;
		}
		val = Math.round(val * s) / s;
	} else {
		val = Math.round(val);
	}
	if(s && Math.ceil(val) == val){
		var u = '';
		for(i = 0; i < n; i++) {
			u += '0';
		}
		val = val+'.'+u;
	}
	return val;
}

/**
 *   表單模擬點擊狀態重建函數
 */
function Buttons_checkbox(obj) {
	obj = $(obj);
	obj.each(function(index, ele) {
		ele = $(ele);
		if(ele.find('input').prop('checked') == true) {
			ele.addClass('a');
		} else {
			ele.removeClass('a');
		}
	});
	$(obj).click(function(e) {
//		e.preventDefault();
		var T = $(this);
		var In = T.find('input');
		if(T.hasClass('a')) {
			In.prop('checked', false);
			T.removeClass('a');
		} else {
			In.prop('checked', true);
			T.addClass('a');
		}
	});
}

/**
 *   表單模擬點擊狀態重建函數
 */
function Buttons_radiobox(obj) {
	obj = $(obj);
	obj.each(function(index, ele) {
		ele = $(ele);
		if(ele.find('input').prop('checked') == true) {
			ele.addClass('a');
		} else {
			ele.removeClass('a');
		}
	});
	$(obj).click(function() {
		var T = $(this);
		var In = T.find('input');
		$('input[name="' + In.attr('name') + '"]').prop('checked', false);
		$('input[name="' + In.attr('name') + '"]').parent('.button_radio').removeClass('a');
		In.prop('checked', true);
		T.addClass('a');
	});
}

/**
 *	TAB切換函數
 *	id=ID標識 / num=當前序號 / Max=TAB數量
 用法:
	<li id="test_1" οnclick="showTab('test',1,3)" class="a">TAB 1</li>
	<li id="test_2" οnclick="showTab('test',2,3)">TAB 1</li>
	<li id="test_3" οnclick="showTab('test',3,3)">TAB 1</li>
	
	<div id="test_1_c"></div>
	<div id="test_2_c" style="display:none"></div>
	<div id="test_3_c" style="display:none"></div>
 */
function showTab(id, Num, Max) {
	for(i = 1; i <= Max; i++) {
		$('#' + id + '_' + i).removeClass('a');
		$('#' + id + '_' + i + '_c').hide();
	}
	$('#' + id + '_' + Num + '_c').show();
	$('#' + id + '_' + Num).addClass('a');
}
function Times(Val) {
    var Times = new Date(); //中國標準時間
    if(Val) {
		
		Val = Val.toString();
		if(/^[0-9]+$/.test(Val)){//如果是純數字 則對其進行處理
			if(Val.length ==10){//如果位數剛好10位則追加爲13位
				Val = parseInt(Val);
				Val = Val * 1000;
			}else{//轉int類型
				Val = parseInt(Val);
			}
		}else{//非數字型Y-m-d 格式化爲 Y/m/d
			Val = Val.toString();
			Val = Val.replace(/-/g,'/');
		}
		
        Times = new Date(Val);
    }
    var D = {
        Y: Times.getFullYear(), //年
        M: Times.getMonth() + 1, //月
        D: Times.getDate(), //日
        H: Times.getHours(), //時
        I: Times.getMinutes(), //分
        S: Times.getSeconds(), //秒,
        W: Times.getDay(), //周(原生)
        timestamp: 0
    };
	D.timestamp = Times_to_Timestamp(D.Y, D.M, D.D, D.H, D.I, D.S);
    return D;
}
/*function Times(Val) {
	var Times = new Date(); //中國標準時間
	if(Val) {
		if(IEversion && Val){
			Val = Val.toString();
			Val = Val.replace(/-/g,'/');
			if(/^[0-9]+$/.test(Val)){
				Val = parseInt(Val);
			}
		}
		Times = new Date(Val);
	}
	var D = {
		Y: Times.getFullYear(), //年
		M: Times.getMonth() + 1, //月
		D: Times.getDate(), //日
		H: Times.getHours(), //時
		I: Times.getMinutes(), //分
		S: Times.getSeconds(), //秒,
		W: Times.getDay(), //周(原生)
		timestamp: 0
	};
	D.timestamp = Times_to_Timestamp(D.Y, D.M, D.D, D.H, D.I, D.S);
	return D;
}*/

/**
 *   返回指定時間的10位時間戳
 */
function Times_to_Timestamp(y, m, d, h, i, s) {
	
	if(!arguments.length) {
		//如果沒有傳入則調當前系統時間
		var dt = Times();
		y = dt.Y;
		m = dt.M;
		d = dt.D;
		h = dt.H;
		i = dt.I;
		s = dt.S;
	} else {
		if(y) y = y.toString();
		if(m) m = m.toString();
		if(d) d = d.toString();
		if(h) h = h.toString();
		if(i) i = i.toString();
		if(s) s = s.toString();
	}

	if(y && (y.indexOf('-') != -1 || y.indexOf('/') != -1)) {

		var dt = Times(y);
		y = dt.Y;
		m = dt.M;
		d = dt.D;
		h = dt.H;
		i = dt.I;
		s = dt.S;
	}
	var x = '-';
	if(IEversion || Safariversion) {
		x = '/';
	}
	var t = (y + x + (m ? m : '01') + x + (d ? d : '01') + ' ' + (h ? h : '00') + ':' + (i ? i : '00') + ':' + (s ? s : '00'));
	return Math.round(Date.parse(t) / 1000);
}

/**
 *   10位時間戳轉日期正常日期
 */
function Timestamp_to_Times(t, s) {
	if(t) {
		t = parseInt(t) * 1000;
	}
	var dt = Times(t);
	if(dt) {
		dt.M = dt.M < 10 ? parseInt('0' + dt.M) : dt.M;
		dt.D = dt.D < 10 ? parseInt('0' + dt.D) : dt.D;
		dt.H = dt.H < 10 ? parseInt('0' + dt.H) : dt.H;
		dt.I = dt.I < 10 ? parseInt('0' + dt.I) : dt.I;
		dt.S = dt.S < 10 ? parseInt('0' + dt.S) : dt.S;

		if(s) {
			s = s.replace(/y/i, dt.Y);
			s = s.replace(/m/i, dt.M);
			s = s.replace(/d/i, dt.D);
			s = s.replace(/h/i, dt.H);
			s = s.replace(/i/i, dt.I);
			s = s.replace(/s/i, dt.S);
			return s;
		} else {
			return dt.Y + '-' + dt.M + '-' + dt.D + ' ' + dt.H + ':' + dt.I + ':' + dt.S;
		}
	}
}

/*	倒計時函數
 *	Author:cr180
 *	V = 傳入日期格式 2016-09-01 01:00:00
 *	callFun = 回調函數 返回JSON {Y:*,M:*,D:*,H:*,I:*,S:*}
 */

function Down_Time(V, callFun) {
	if(IEversion || Safariversion) {
		V = V.replace(/-/g, '/');
	}
	var Time = Date.parse(new Date(V));
	//把時間戳轉換爲日期格式
	var Auto;
	var Start = function() {
		Time = Time - 1000;
		var D = Times(Time);

		var i;
		for(i in D) {
			if(D[i] < 10) {
				D[i] = '0' + D[i];
			}
		}
		if(callFun && typeof(callFun) == 'function') {
			callFun(D, Auto);
		}
	}
	Start();
	Auto = window.setInterval(function() {
		Start();
	}, 1000);
}

/*	canvas畫圓
 *	BOX 對象ID , WIDTH 圓圈寬度 , N畫圓百分比
 */
function Angle_m(BOX, N, LineW, Color) {
	var canvas = document.getElementById(BOX),
		width = canvas.width,
		height = canvas.height,
		OBJ = canvas.getContext('2d');
	var Step, Start, End, Add = Math.PI * 2 / 100;

	OBJ.shadowOffsetX = 0; // 設置水平位移
	OBJ.shadowOffsetY = 0; // 設置垂直位移
	OBJ.shadowBlur = 10; // 設置模糊度
	OBJ.lineWidth = LineW ? LineW : 2; // 線寬度
	//圓心位置
	var X = canvas.width / 2;

	//圓邊緣衰減
	var R = X - (OBJ.lineWidth / 2);
	var S = 5;
	var Int;

	var Step = 1;
	var Start = 0;
	OBJ.strokeStyle = Color ? Color : '#000'; //圓圈顏色

	Int = setInterval(function() {
		if(Step <= N) {
			End = Start + Add;
			ARC(Start, End);
			Start = End;
			Step++;
		} else {
			clearInterval(Int);
		}
	}, S);

	var ARC = function(s, e) {
		OBJ.beginPath();
		OBJ.arc(X, X, R, s, e, false);
		OBJ.stroke();
	}
}

var WIN_ZINDEX = 200;

function hideshowWin(K, Remove) {
	$('#' + K).fadeOut(200, function() {
		if(Remove) {
			$('#' + K).remove();
		}
	});
	var cover = $('#' + K + '_showcover');
	if(cover.length) {
		if(Remove) {
			cover.remove();
		} else {
			cover.remove();
		}
	}
}

function dragMenu(menuObj, e, op) {
	var Obj = $('#' + menuObj);
	e = e ? e : window.event;
	var posX;
	var posY;
	var Move = function(e) {
		if(e == null)
			e = window.event; //IE
		Obj.css('left', (e.clientX - posX) + "px");
		Obj.css('top', (e.clientY - posY) + "px");
	}
	Obj.mousedown(function(e) {
		e = e ? e : window.event;
		posX = e.clientX - parseInt(Obj.offset().left);
		posY = e.clientY - parseInt(Obj.offset().top);
		$(document).bind('mousemove', Move);
	});
	Obj.mouseup(function() {
		$(document).unbind('mousemove', Move);
	});
}

function showWin_error(IDobj, msg) {
	var IDobj = $('#' + IDobj);
	if(IDobj.length) {
		var msg = '<div class="win_error_c">' + msg + '</div>';
		var errOBJ = IDobj.find('.win_error');

		errOBJ.html(msg);
		errOBJ.fadeIn(300);
		window.setTimeout(function() {
			errOBJ.html(msg).fadeOut(1000);
		}, 1000);
	}
}

function showWin(ID, title, Url) {
	var K = ID;
	var Msg = '';
	var Class = '';
	var IDobj = $('#' + ID);
	if(IDobj.length && IDobj.attr('prepend') != '1') {
		WIN_ZINDEX++;
		Msg = IDobj.html();
		Class = IDobj.attr('class');
		IDobj.remove();
		IDobj = null;
	}
	if(!IDobj.length || IDobj.attr('prepend') != '1') {
		var obj = document.createElement('div');
		obj.id = ID;
		obj.className = 'winbox';
		obj.style.display = 'none';
		$('#append_parent').append(obj);
		IDobj = $(obj);
		obj = null;

		var title = title ? title : IDobj.attr('title');

		if(!IDobj.hasClass('winbox')) IDobj.addClass('winbox');

		var H = '<div class="win_t" style="cursor:move" οnmοusedοwn="dragMenu(\'' + K + '\', event, 1)" οndblclick="hideshowWin(\'' + K + '\')">';
		H += '<a href="javascript:;" class="win_close" οnclick="hideshowWin(\'' + K + '\')">x</a>';
		H += '<div class="win_tit ' + Class + '">' + title + '</div>';
		H += '</div>';
		H += '<div class="win_c" id="win_' + K + '_c">' + Msg + '</div>';
		if(Url) {
			_Ajax(Url, {}, function(data) {
				$('#win_' + K + '_c').html(data);
			}, {
				dataType: 'XML'
			});
		}
		IDobj.prepend(H).attr('prepend', 1);
	}
	var M_left = ($(window).outerWidth() - IDobj.outerWidth(true)) / 2;
	var M_top = ($(window).outerHeight() - IDobj.outerHeight(true)) / 2;

	IDobj.fadeIn(200).css({
		'left': M_left + 'px',
		'top': M_top + 'px'
	});
	IDobj.css('z-index', WIN_ZINDEX);
}

/*	全局消息提示類
 *	Author:cr180
 *	參數:
 *	1. ID = 唯一標識或box ID,如IDbox已存在,則讀取該模型中的HTML插入到showbox中
 *	2. Title = 框架標題
 *	3. Msg = 提示內容
 *	4. Mod = 模式	值(0||null=普通HTML / 1=操作成功提示類 / 2=操作失敗類 / 3=警告提示類) Msg參數必須存在
 *	5. TimeOut = 自動關閉該提示框時間(秒)  0=不自動關閉
 *	6. CallFun = 回調函數,運行結束後的回調,傳入function(obj){... obj爲當前box jQuery對象}
 *	7. isConfirm = 確認提示框按鈕模式,0=否 1=自動追加一個確認按鈕 2=自動追加確認與取消按鈕
 *				兩個按鈕的觸發事件在回調函數中自定義,取消按鈕默認關閉當前窗口
 */
function showDialog(ID, Title, Msg, Mod, TimeOut, CallFun, isConfirm) {
	var K = ID;
	var obj = $('#' + ID);
	if(obj.length>0){
		return false;
	}
	if(ID && !Msg && obj.length) {
		Msg = obj.html();
		obj.remove();
		obj = null;
	} else if(Mod && Msg) {
		Msg = '<div class="showmsg_c">' + Msg + '</div>';
	}
	obj = document.createElement('div');
	obj.id = ID;
	obj.className = 'showbox' + (Mod && Msg ? ' showmsgmod showmsgmod_' + Mod : '');
	obj.style.display = 'none';
	$('#append_parent').append(obj);
	obj = $(obj);

	var H = '<div class="show_t">';
	H += '<a href="javascript:;" class="show_close" οnclick="hideshowWin(\'' + K + '\',1)">x</a>';
	if(!Mod) {
		H += '<div class="show_tit">' + Title + '</div>';
	}
	H += '</div>';
	if(Mod) {
		H += '<div class="show_modtit">' + Title + '</div>';
	}
	H += '<div class="show_c" id="win_' + K + '_c">' + Msg + '</div>';
	if(isConfirm && (isConfirm == 1 || isConfirm == 2)) {
		H += '<div class="cl show_btn ' + (isConfirm == 2 ? 'show_btn_float' : '') + '">';
		H += '<a href="javascript:;" class="btn show_submit">確 定</a>';
		if(isConfirm == 2) {
			H += '<a href="javascript:;" class="btn show_exit" οnclick="hideshowWin(\'' + K + '\',1)">取 消</a>';
		}
		H += '</div>';
	}
	obj.html(H);
	var M_left = ($(window).outerWidth() - obj.outerWidth(true)) / 2;
	var M_top = ($(window).outerHeight() - obj.outerHeight(true)) / 2;

	obj.fadeIn(200).css({
		'left': M_left + 'px',
		'top': M_top + 'px'
	});

	WIN_ZINDEX++;
	$('#append_parent').append('<div id="' + K + '_showcover" class="showcover" style="z-index:' + (WIN_ZINDEX) + '"></div>');
	WIN_ZINDEX++;
	obj.css('z-index', WIN_ZINDEX);
	if(TimeOut > 0) {
		TimeOut = TimeOut - 1;
		window.setTimeout(function() {
			hideshowWin(K, 1);
			if(CallFun && typeof CallFun == 'function') {
				CallFun($('#' + ID));
			}
		}, TimeOut * 1000);
	} else {
		if(CallFun && typeof CallFun == 'function') {
			CallFun($('#' + ID));
		}
	}
}

/**
 *   全局迷你提示
 *	鼠標經過顯示,離開移除
 */
function showTips(obj,Html){
	obj = $(obj);
	var O = document.createElement('div');
	O = $(O);
	obj.hover(function(){
			O.addClass('ptips').html(Html).css({left: $(this).offset().left -20, top: $(this).offset().top + obj.outerHeight(true)});
			$('#append_parent').append(O);
	},function(){
		O.remove();
	});
}

function showMenu(ID, AutoHide) {
	var X;
	var Obj = $('#' + ID);
	var To = $('#' + ID + '_menu');
	var L = Obj.offset().left;
	var T = Obj.offset().top + Obj.outerHeight(true);
	if(To.css('display') != 'none') {
		if(X)
			clearTimeout(X);
		To.fadeOut(100);
		Obj.removeClass('a');
		return;
	}

	if($(window).outerWidth(true) - (L + To.outerWidth(true)) < 10) {
		L -= To.outerWidth(true);
		L += Obj.outerWidth(true);
	}
	To.css({
		'left': L,
		'top': T
	}).fadeIn(100);
	Obj.addClass('a');
	var Hover = function(o) {
		o.hover(function() {
			clearTimeout(X);
			Obj.addClass('a');
		}, function() {
			clearTimeout(X);
			X = window.setTimeout(function() {
				To.fadeOut(100);
				Obj.removeClass('a');
			}, 100);

		});
	}
	if(AutoHide) {
		Hover(Obj);
		Hover(To);
	}
}

function cp_showDialog(msg, outTime) {
	if(msg == 'close') {
		$('#showLoadding ,#showLoadding_bg').remove();
	} else {
		msg = msg ? msg : '請稍後...';
		$('#append_parent').append('<div id="showLoadding" class="showLoadding"><span>' + msg + '</span></div><div id="showLoadding_bg" class="showLoadding_bg"></div>');
		$('#showLoadding ,#showLoadding_bg').fadeIn(200, function() {
			$(this).addClass('a');
		});
		outTime = parseInt(outTime);
		if(outTime) {
			setTimeout(function() {
				cp_showDialog('close');
			}, outTime * 1000);
		}
	}
}

function cp_ajaxPOST(Formobj) {
	var Formobj = $(Formobj);
	$.ajax({
		type: "POST",
		dataType: "json",
		url: Formobj.attr('action'),
		data: Formobj.serialize(),
		success: function(result) {
			alert(result);
		},
		error: function(status) {
			alert('Error:' + status);
		}
	});
	return false;
}

/*
 *	貨幣轉換函數
 *	傳入int值(支持浮點小數點)
 */
function money_Format(V) {
	if(V) {
		V = ('' + V + '');
		var Z; //小數點
		//提取小數點位
		if(/\./g.test(V)) {
			V.replace(/(\d+)\.(\d+)/g, function($1, $2, $3) {
				V = $2;
				Z = $3;
			});
		}
		V = V + '#';
		var re = /\d{3}#/;
		var S = '';
		while(re.test(V)) {
			V = V.replace(/(\d{3})#/, function($1, $2) {
				return '#' + $2 + S;
			});
			S = ',';
		}
		V = V.replace(/#/, '');
		if(Z) {
			V = V + '.' + Z;
		}
		return V;
	}
}


/**
 * 工具函數
 */
var utils = {
	/**
	 * 處理進度數據
	 * @param {type} data
	 */
	handleProgressData: function handleProgressData(data) {
		var data = Number(data) * 100;
		if(data > 0 && data <= 1) {
			data = 1
		} else if(data <= 99) {
			data = Math.floor(data)
		} else if(data < 100) {
			data = 99
		} else {
			data = 100
		}
		return data + "%"
	},
	/**
	 * 得到url的查詢字符
	 * @param {string} name
	 */
	getQueryString : function getQueryString(name) {
		if(name != null && name.toString().length > 1) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
			var r = window.location.search.substr(1).match(reg);
			if(r != null){
				return unescape(r[2]);
			} 				
		}
		return "";		
	},
	getCookie : function getCookie(c_name){
		if (document.cookie.length>0){
		  var c_start=document.cookie.indexOf(c_name + "=");
		  if (c_start!==-1){ 
		    c_start=c_start + c_name.length+1 ;
		    var c_end=document.cookie.indexOf(";",c_start);
		    if (c_end===-1){
		        c_end=document.cookie.length;
		    }
		    return unescape(document.cookie.substring(c_start,c_end));
		    } 
		}
		return "";
	},
	formatMoney:function formatMoney(value){
		if(value!=""&&value!=null){  
            var num = value + "";  
            num = num.toString().replace(/\$|\,/g,'');    
            // 獲取符號(正/負數)     
            sign = (num == (num = Math.abs(num)));      
            // 把指定的小數位先轉換成整數.多餘的小數位四捨五入    
            num = Math.floor(num*Math.pow(10,2)+0.50000000001);   
            // 求出小數位數值                     
            cents = num%Math.pow(10,2);    
            // 求出整數位數值                     
            num = Math.floor(num/Math.pow(10,2)).toString();    
            // 把小數位轉換成字符串,以便求小數位長度                    
            cents = cents.toString();                 
            // 補足小數位到指定的位數     
            while(cents.length<2)    
            cents = "0" + cents;    
            // 對整數部分進行千分位格式化.     
            for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)    
            num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3));    
            return (((sign)?'':'-') + num + '.' + cents);    
        }else{  
            if(value=='0'){  
                    return '0.00';  
            }else{  
                return value;  
            }  
        }
	}

}

/**
 * 系統值
 */
var sys = {
	//  預期收益計算公式
	Interest : {
		/**
		 * 按月付息到期還本
		 */
		interest: function(amount, year_ratio, month) {

			var month_ratio = year_ratio / 100 / 12;
			var total_interest = amount * month_ratio * month;
			return {
				total_interest: total_interest.toFixed(2),
				total: (amount + total_interest).toFixed(2)
			};
		},

		/**
		 * 一次性還本付息
		 */
		bullet_repayment: function(amount, year_ratio, month, days) {
			var month_ratio = year_ratio / 100 / 12;
			var day_ratio = year_ratio / 100 / 365;
			var total_interest = amount * month_ratio * month + amount * day_ratio * days;
			return {
				total_interest: total_interest.toFixed(2),
				total: (amount + total_interest).toFixed(2)
			};
		},

		/**
		 * 等額本息
		 */
		equal_installment: function(amount, year_ratio, month) {
			var month_ratio = year_ratio / 100 / 12;
			var repay_monthly = amount * ((month_ratio * Math.pow(1 + month_ratio, month)) / (Math.pow(1 + month_ratio, month) - 1));
			var total_interest = repay_monthly * month - amount;
			return {
				total_interest: total_interest.toFixed(2),
				repay_monthly: repay_monthly.toFixed(2),
				total: (amount + total_interest).toFixed(2)
			};
		},

		/**
		 * 等額本金
		 */
		equal_principal: function(amount, year_ratio, month) {
			var month_ratio = year_ratio / 100 / 12;
			var principal_monthly = amount / month;
			var total_interest = 0;
			var repay_first = principal_monthly;
			for(var i = 0; i < month; i++) {
				total_interest += ((amount - principal_monthly * i) * month_ratio);
				if(i === 0) {
					repay_first += total_interest;
				}
			}
			return {
				total_interest: total_interest.toFixed(2), // 總利息
				repay_first: repay_first, // 首次還款金額
				total: (amount + total_interest).toFixed(2) // 本息合計
			};
		},

		calc: function(amount, year_radio, month, days, repayment) {
			var result,
				othis=this;
			if(repayment === 'INTEREST') {
				result = sys.Interest.interest(amount, year_radio, month);
			} else if(repayment === 'BULLET_REPAYMENT') {
				if(month !== 0) {
					result = sys.Interest.bullet_repayment(amount, year_radio, month, 0);
				} else {
					result = sys.Interest.bullet_repayment(amount, year_radio, 0, days);
				}
			} else if(repayment === 'EQUAL_INSTALLMENT') {
				result = sys.Interest.equal_installment(amount, year_radio, month);
			} else if(repayment === 'EQUAL_PRINCIPAL') {
				result = sys.Interest.equal_principal(amount, year_radio, month);
			}
			return result;
		}
	}
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章