/**
* Gitpdl Default规则
*/
import moment from 'moment';
import BigNumber from "bignumber.js";

export default {
	methods:{
		defaultFunc () {
			// 根据max2的值是否大于0判断是否勾选附加金额字段
			let oldMax2Amt = this.model.gidgrp.cbs.max2.amt
			if (Number(oldMax2Amt) != 0) {
				this.model.adaflg = 'X'
			}
		},
		// model.gidgrp.rec.expflg
		changeExpflg (){
			if (
        this.model.gidgrp.rec.expflg == "X" &&
        this.model.gidgrp.rec.hndtyp == "OC"
      ) {
        this.model.gidgrp.rec.liaflg = "X";
      }
		},
		// model.gidgrp.rec.gartyp
		changeGartyp (){
			if (this.model.gidgrp.rec.gartyp == "1") {
        this.model.gidgrp.rec.gtxinr = "<NILTXT>";
      }
		},
		// 初始化备份保函文本字段
		getGtxgidtxtMark () {
			this.$set(this.codes, 'gtxgidtxtMark', this.model.gidgrp.blk.gidtxt)
			this.$set(this.codes, 'gtxgidtxtcMark', this.model.gidgrp.blk.gidtxtc)
		},
		changeCfaflg() {
			if((this.model.cfagit.recgrp == null || this.model.cfagit.recgrp.bas.exguarancode == null || this.model.cfagit.recgrp.bas.exguarancode == '') || this.model.ameflg != 'Y') {
				this.model.cfagit.cfaflg = '4';
			}
		},
		formatTableData () {
			let list = this.model.decstm.rows || []
			let resList = []
			if (list) {
				list.map((item, ind) => {
					let tempItem = item.split("\t")
					resList.push({
						'IDX': ind,
						'修改次数': tempItem[0],
						'编号': tempItem[1],
						'币种': tempItem[2],
            '修改金额': tempItem[3],
            '附加金额变化值':tempItem[4],
						'修改日期': tempItem[5],
						'新有效期到期类型': tempItem[6],
            '新有效期': tempItem[7],
            '新有效期敞口': tempItem[8]==""?"":"Y",
            '新有效期到期条件': tempItem[9].replace(/<br>/g, "\n"),
            '新反担保有效期到期类型': tempItem[10],
            '新反担保有效期': tempItem[11],
            '新反担保有效期敞口': tempItem[12]==""?"":"Y",
            '新反担保有效期到期条件': tempItem[13].replace(/<br>/g, "\n"),
            'checked': (list.length === 1 || this.model.amenbr == tempItem[0])
					})
				})
			}
			if (resList && resList.length === 1) {
				this.decstmRowSelected(resList[0])
			}
			this.$set(this.codes, 'tableData', resList)
		},
		decstmRowSelected(row) {
			if (row === undefined) {
				return
			}
      this.model.amenbr = row.修改次数;
      this.model.amecur = row.币种;
      this.model.ameamt = row.修改金额;
      this.model.addamecur = row.币种;
      this.model.addameamt = row.附加金额变化值;
      this.model.amedat = moment(row.修改日期).format("YYYY-MM-DD");
      this.model.gidgrp.cbs.max.amt = new BigNumber(this.model.oldgidgrp.cbs.max.amt).plus(new BigNumber(this.model.ameamt)).toFormat(2).replace(/,/g, "");
      this.model.gidgrp.cbs.max2.amt = new BigNumber(this.model.oldgidgrp.cbs.max2.amt).plus(new BigNumber(this.model.addameamt)).toFormat(2).replace(/,/g, "");
      this.model.gidgrp.cbs.opn1.amt = new BigNumber(this.model.oldgidgrp.cbs.opn1.amt).plus(new BigNumber(this.model.ameamt)).toFormat(2).replace(/,/g, "");
      this.model.gidgrp.cbs.opn2.amt = new BigNumber(this.model.oldgidgrp.cbs.opn2.amt).plus(new BigNumber(this.model.addameamt)).toFormat(2).replace(/,/g, "");
      this.model.swiadd.addnewamt=this.model.gidgrp.cbs.max2.amt;
      this.model.swiadd.newamt=this.model.gidgrp.cbs.max.amt;
      if(this.model.gidgrp.cbs.max2.amt>0){
        this.model.adaflg="X";
      }
      this.model.ameflg = "Y";
      this.model.cfagit.dclflg == "X";
      if (row.新有效期 == "-"||row.新有效期 == "") {
        this.model.swiadd.newexpdat = "";
        this.model.gidgrp.rec.expdat = "";
      } else {
        this.model.swiadd.newexpdat = moment(row.新有效期).format(
          "YYYY-MM-DD"
        );
        this.model.gidgrp.rec.expdat = moment(row.新有效期).format(
          "YYYY-MM-DD"
        );
        this.date = moment(row.新有效期).format("YYYY-MM-DD");
      }
      this.model.swiadd.newexpflg=(row.新有效期敞口=="Y"?"X":"");
      this.model.swiadd.exptyp=row.新有效期到期类型;
      this.model.swiadd.exptxt=row.新有效期到期条件;
      this.model.gidgrp.rec.expflg=(row.新有效期敞口=="Y"?"X":"");
      this.model.gidgrp.rec.exptyp=row.新有效期到期类型;
      this.model.gidgrp.rec.exptxt=row.新有效期到期条件;

      if (row.新反担保有效期 == "-"||row.新反担保有效期 == "") {
        this.model.swiadd.newliadat = "";
        this.model.gidgrp.rec.liadat = "";
      } else {
        this.model.swiadd.newliadat = moment(row.新反担保有效期).format(
          "YYYY-MM-DD"
        );
        this.model.gidgrp.rec.liadat = moment(row.新反担保有效期).format(
          "YYYY-MM-DD"
        );
        this.date = moment(row.新反担保有效期).format("YYYY-MM-DD");
      }
      this.model.swiadd.newliaflg=(row.新反担保有效期敞口=="Y"?"X":"");
      this.model.swiadd.liatypc=row.新反担保有效期到期类型;
      this.model.swiadd.liatxtc=row.新反担保有效期到期条件;
      this.model.gidgrp.rec.liaflg=(row.新反担保有效期敞口=="Y"?"X":"");
      this.model.gidgrp.rec.liatypc=row.新反担保有效期到期类型;
      this.model.gidgrp.rec.liatxtc=row.新反担保有效期到期条件;
      

      this.changeAccp(this.date);
    }
	}
}
//你可以添加自动default处理