default.js 4.86 KB
Newer Older
fukai committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
import commonFunctions from '~/mixin/commonFunctions.js';
import Api from '~/service/Api';
import moment from 'moment';
import commonDepend from "~/mixin/commonDepend";
import BigNumber from "bignumber.js";
export default {
	mixins: [commonFunctions, commonDepend],
	methods: {
		ameAmtChange() {
			this.model.swiadd.newamt = new BigNumber(this.model.olddidgrp.cbs.nom1.amt).plus(new BigNumber(this.model.swiadd.ameamt));
			this.model.didgrp.cbs.nom1.amt = this.model.swiadd.newamt;
			if(new BigNumber(this.model.swiadd.ameamt).comparedTo(new BigNumber(0))!=0){
				this.customAddModify(this.model.swiadd, 'ameamt');
				this.customAddModify(this.model.swiadd, 'newamt');
			}
			if(new BigNumber(this.model.olddidgrp.cbs.nom1.amt).comparedTo(new BigNumber(this.model.didgrp.cbs.nom1.amt))!=0){
				this.customAddModify(this.model.didgrp.cbs.nom1, 'amt');
			}
			this.defaultEngamtAndNewMaxmat();
			this.smallToBig();
		},
		newAmtChange(){
			this.model.swiadd.ameamt = new BigNumber(this.model.swiadd.newamt).minus(new BigNumber(this.model.olddidgrp.cbs.nom1.amt));
			if(new BigNumber(this.model.swiadd.ameamt).comparedTo(new BigNumber(0))!=0){
				this.customAddModify(this.model.swiadd, 'ameamt');
				this.customAddModify(this.model.swiadd, 'newamt');
			}
			this.defaultEngamtAndNewMaxmat();
		},
		newnomtopameChange(){
			if(this.model.swiadd.newnomtopame!=this.model.olddidgrp.rec.nomtop){
				this.customAddModify(this.model.didgrp.rec, 'nomtop');
			}
			this.defaultEngamtAndNewMaxmat();
		},
		newnomtonameChange(){
			if(this.model.swiadd.newnomtoname!=this.model.olddidgrp.rec.nomton){
				this.customAddModify(this.model.didgrp.rec, 'nomton');
			}
		},
		defaultEngamtAndNewMaxmat() {
			this.model.ditamep.maxamt = new BigNumber(this.model.swiadd.newamt).multipliedBy(new BigNumber(1).plus(new BigNumber(this.model.swiadd.newnomtopame).dividedBy(100))).toFormat(2).replace(/,/g, "");
			this.model.ditamep.engamt =  new BigNumber(this.model.ditamep.maxamt).minus(new BigNumber(this.model.olddidgrp.cbs.max.amt));
			this.model.didgrp.cbs.max.amt = this.model.ditamep.maxamt;
			this.model.didgrp.cbs.opn1.amt =  new BigNumber(this.model.olddidgrp.cbs.opn1.amt).plus(new BigNumber(this.model.ditamep.engamt));
			if(new BigNumber(this.model.didgrp.cbs.max.amt).comparedTo(this.model.olddidgrp.cbs.max.amt)!=0){
				this.customAddModify(this.model.didgrp.cbs.max, 'amt');
			}
			if(new BigNumber(this.model.didgrp.cbs.nom1.amt).comparedTo(this.model.olddidgrp.cbs.nom1.amt)!=0){
				this.customAddModify(this.model.didgrp.cbs.nom1, 'amt');
			}
		},
		// 将数字金额转换为大写金额
		smallToBig() {
			var money = new BigNumber(this.model.didgrp.cbs.nom1.amt).toFormat(2).replace(/,/g, "").toString();
			var cnNums = new Array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"); //汉字的数字
			var cnIntRadice = new Array("", "拾", "佰", "仟"); //基本单位
			var cnIntUnits = new Array("", "万", "亿", "兆"); //对应整数部分扩展单位
			var cnDecUnits = new Array("角", "分", "毫", "厘"); //对应小数部分单位
			var cnInteger = "整"; //整数金额时后面跟的字符
			var cnIntLast = "元"; //整数完以后的单位
			var integerNum; //金额整数部分
			var decimalNum; //金额小数部分
			//输出的中文金额字符串
			var chineseStr = "";
			var parts; //分离金额后用的数组,预定义
			if (money == "") {
				this.model.ditp.amt = "";
				return;
			}

			if (new BigNumber(money) == 0) {
				chineseStr = cnNums[0] + cnIntLast + cnInteger;
				this.model.ditp.amt = "人民币" + chineseStr;
				return;
			}
			//转换为字符串
			integerNum = money.substr(0, money.length - 3);
			decimalNum = money.substr(money.length - 2);
			//获取整型部分转换
			if (parseInt(integerNum, 10) > 0) {
				var zeroCount = 0;
				var IntLen = integerNum.length;
				for (var i = 0; i < IntLen; i++) {
					var n = integerNum.substr(i, 1);
					var p = IntLen - i - 1;
					var q = p / 4;
					var m = p % 4;
					if (n == "0") {
						zeroCount++;
					} else {
						if (zeroCount > 0) {
							chineseStr += cnNums[0];
						}
						//归零
						zeroCount = 0;
						chineseStr += cnNums[parseInt(n)] + cnIntRadice[m];
					}
					if (m == 0 && zeroCount < 4) {
						chineseStr += cnIntUnits[q];
					}
				}
				chineseStr += cnIntLast;
			}
			//小数部分
			if (decimalNum != "") {
				var decLen = decimalNum.length;
				for (var i = 0; i < decLen; i++) {
					var n = decimalNum.substr(i, 1);
					if (n != "0") {
						chineseStr += cnNums[Number(n)] + cnDecUnits[i];
					}
				}
			}
			if (chineseStr == "") {
				chineseStr += cnNums[0] + cnIntLast + cnInteger;
			} else if (decimalNum == "" || /^0*$/.test(decimalNum)) {
				chineseStr += cnInteger;
			}
			this.model.ditp.amt = "人民币" + chineseStr;
		},
		benDisabled(){
			if(this.model.didgrp.ben.ptytyp=="F"){
				this.$set(this.codes, 'bendisabled', true);
			}
		}
	},
}