import Api from "~/service/Api";
import commonFunctions from "~/mixin/commonFunctions.js";
import Utils from "~/utils";
import BigNumber from "bignumber.js";

export default {
  mixins: [commonFunctions],
  methods: {
    getBigNumber() {
      // 配置BigNumber计算规则为保留两位小数,并向上舍入
      var BN = BigNumber.clone();
      BN.config({ DECIMAL_PLACES: 2, ROUNDING_MODE: 2 });
      return BN;
    },
    selectionChange(row) {
      var BN = this.getBigNumber();
      let item = row;
      this.model.amenbr = item.amenbr;
      this.model.amecur = item.engcur;
      this.model.reduceamt = item.chgAmt;
      this.model.amedat = item.amedat;
      this.model.ameflg = "Y";
      this.model.actameamt = item.actameamt;
      this.model.ameamt = item.engamt;
      this.model.ameaddamt = item.chgAddAmt;
      this.model.lidgrp.rec.expdat = item.expdat;
      this.model.swiadd.newexpdat = item.expdat;
      this.model.lidgrp.cbs.max2.amt = BN(this.model.oldlidgrp.cbs.max2.amt).plus(item.chgAddAmt).toFixed(2);
      if (Number(this.model.lidgrp.cbs.max2.amt) == Number("0.00")) {
        this.model.swiadd.addamtflg = "";
        this.model.swiadd.addamtcov = "";
        this.model.lidgrp.cbs.max2.amt = "0.00";
        this.model.lidgrp.cbs.opn2.amt = "0.00";
      } else {
        this.model.swiadd.addamtcov = this.model.lidgrp.cbs.max2.cur + " " + this.model.lidgrp.cbs.max2.amt;
      }
      this.model.swiadd.ameamt = item.actameamt;
      this.onSwiaddAmeamtChange();
    },
    onSwiaddAmeamtChange() {
      var BN = this.getBigNumber();
      this.model.swiadd.newamt = BN(this.model.oldlidgrp.cbs.nom1.amt).plus(this.model.swiadd.ameamt).toFixed(2);
      let rate = BN(this.model.swiadd.newnomtop).plus(100);
      this.model.litamep.maxamt = BN(this.model.swiadd.newamt).multipliedBy(rate).div(100).toFixed(2);
      this.model.litamep.engamt = BN(this.model.litamep.maxamt).minus(this.model.oldlidgrp.cbs.max.amt).toFixed(2);
      this.model.lidgrp.cbs.max.amt = this.model.litamep.maxamt;
      this.model.lidgrp.cbs.nom1.amt = this.model.swiadd.newamt;
    },
  },
};