/**
* Hitdla Default规则
*/
import commonFunctions from '~/mixin/commonFunctions.js';
import moment from 'moment';
import BigNumber from "bignumber.js";
export default {
	mixins: [commonFunctions],
	methods:{
		// model.nidgrp.rec.expflg
		changeExpflg (){
			if (
        this.model.nidgrp.rec.expflg == "X" &&
        this.model.nidgrp.rec.hndtyp == "OC"
      ) {
        this.model.nidgrp.rec.liaflg = "X";
      }
		},
		// model.nidgrp.rec.gartyp
		changeGartyp (){
			if (this.model.nidgrp.rec.gartyp == "1") {
        this.model.nidgrp.rec.gtxinr = "<NILTXT>";
      }
		},
		// 初始化备份保函文本字段
		getGtxgidtxtMark () {
			this.$set(this.codes, 'gtxgidtxtMark', this.model.nidgrp.blk.gidtxt)
		},
		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]==""?"":"Y",
						'新反担保有效期': tempItem[7],
            			'新反担保有效期敞口': tempItem[8]==""?"":"Y",	
            			'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.amedat = moment(row.修改日期).format("YYYY-MM-DD");
	  this.model.swiadd.amedat = moment(row.修改日期).format("YYYY-MM-DD");
	  this.model.nidgrp.cbs.max.amt = new BigNumber(this.model.oldnidgrp.cbs.max.amt).plus(new BigNumber(this.model.ameamt)).toFormat(2).replace(/,/g, "");
      this.model.swiadd.newamt=this.model.nidgrp.cbs.max.amt; 
      //this.model.nidgrp.cbs.max.amt = new BigNumber(this.model.oldnidgrp.cbs.max.amt).plus(new BigNumber(this.model.ameamt)).toFormat(2).replace(/,/g, "");
      //this.model.nidgrp.cbs.opn1.amt = new BigNumber(this.model.oldnidgrp.cbs.opn1.amt).plus(new BigNumber(this.model.ameamt)).toFormat(2).replace(/,/g, "");
      this.model.ameflg = "Y";
      // this.model.cfagit.dclflg == "X";
      if (row.新到期日 == "-"||row.新有效期 == "") {
        this.model.swiadd.newexpdat = "";
        //this.model.nidgrp.rec.expdat = "";
      } else {
        this.model.swiadd.newexpdat = moment(row.新有效期).format(
          "YYYY-MM-DD"
        );
        // this.model.nidgrp.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.nidgrp.rec.expflg=(row.新有效期敞口=="Y"?"X":"");
	  if (row.新反担保有效期 == "-"||row.新反担保有效期 == "") {
        this.model.swiadd.newliadat = "";
      } else {
        this.model.swiadd.newliadat = moment(row.新反担保有效期).format(
          "YYYY-MM-DD"
        );
      }
	  this.model.swiadd.newliaflg=(row.新反担保有效期敞口=="Y"?"X":"");
	  
      this.changeAccp(this.date);
    }
	}
}
//你可以添加自动default处理