import Api from '~/service/Api';
import commonFunctions from '~/mixin/commonFunctions.js';
import buildFn from './buildCommons.js';
import moment from 'moment';

export default {
	mixins: [commonFunctions,buildFn],
	methods: {
		defaultVouflgN1000() {
      //2122
      //--暂时只有保函开立交易用--
      //2017-4人行 要求2122对保函开立交易开放外币申报
      if (this.model.gidgrp.cbs.max.cur == "CNY") {
        if (this.model.gidgrp.rec.cmtflg == "X") {
          this.model.cnybop.vouflg = ""
        } else {
          this.model.cnybop.vouflg = "2"
        }
        if (this.model.gidgrp.rec.fingua == "Y") {
          this.model.gidgrp.rec.cmtflg = "X"
        }
      } else {
        if (this.model.gidgrp.rec.fingua == "Y") {
          this.model.cnybop.vouflg = "1"
        } else {
          this.model.cnybop.vouflg = "2"
        }
      }
		},
    //申报2122报文
    query2122() {
      let trnName = this.root ? this.root.trnName : this.trnName
      if(this.model.rmbbop.rmb2122.rmbflg == '1') {
        let rmbbop = this.buildRobbop(this.model, trnName);
        Api.post('/business/rmbbopgid/rmbbop2122Cal', rmbbop).then(res => {
            this.model.rmbbop.rmb2122 = res.data.rmb2122;
          });
        }
		},
		// "cfagit.cfaflg"
    onCfaflg(e) {
      if(e == undefined) {
        return
      } 
      switch (this.model.cfagit.cfaflg) {
        case "1":
          this.model.cfagit.basflg = 'X';
          this.model.cfagit.dclflg = 'X';
          // if (!this.model.cfagit.ownextkey) {
          //   this.ownextkey = this.codes.ownextkey1;
          //   this.model.cfagit.ownextkey = this.codes.ownextkey1[0].value;
          //   // this.ownextkey= getValues('cfagit.ownextkey','ownextkey1');
          // }
          break;
        case "2":
          this.model.cfagit.basflg = 'X';
					if(this.model.ameamt) {
						this.model.cfagit.dclflg = 'X';
					}else {
						this.model.cfagit.dclflg = '';
					}
          break;
        case "3":
          this.model.cfagit.basflg = '';
          this.model.cfagit.dclflg = 'X';
          break;
        case "5":
          this.model.cfagit.vrfflg = 'X';
          this.model.cfagit.dclflg = 'X';
          break;
        default:
          this.model.cfagit.basflg = '';
          this.model.cfagit.vrfflg = '';
          this.model.cfagit.dclflg = '';
      }
		},
		// 获取地区机构号
    async getOwnExtkeyCondition1() {
      let body = {ownExtKey: ""};
      if(this.model.cfagit.ownextkey) {
        body.ownExtKey = this.model.cfagit.ownextkey;
      }
      let res = await Api.post('/business/bch/getBranchListByownExtKey', body);
      if (res.respCode === SUCCESS) {
          this.ownExtkeyList = res.data;
      }
    },
		// 减额接受
		changeAccp(date) {
      if(this.isInDisplay){
        return;
      }
			if(this.model.gidgrp.rec.fingua=='Y') {
        if(this.model.ameamt > 0) {
          if(this.model.cfagit.recgrp != null && this.model.cfagit.recgrp.bas.exguarancode != null && this.model.cfagit.recgrp.bas.exguarancode != '') {
            this.model.cfagit.cfaflg = '4';
          }
          if(this.model.rmbbop.rmb2122.recgrp.ads.levyno != null && this.model.rmbbop.rmb2122.recgrp.ads.levyno != "") {
            this.model.rmbbop.rmb2122.rmbflg = '2';
          }
        } else {
          // 对外担保
          if(this.model.cfagit.recgrp != null && this.model.cfagit.recgrp.bas.exguarancode != null && this.model.cfagit.recgrp.bas.exguarancode != '') {
            if(this.model.cfagit.recgrp.bas.exguarancode) {
              this.model.cfagit.cfaflg = '2';
              // if(this.model.gidgrp.rec.expdat) {
              //   this.model.cfagit.recgrp.bas.maturity = this.model.gidgrp.rec.expdat;
              // } else {
              //   this.model.cfagit.recgrp.bas.maturity = moment(this.model.cfagit.recgrp.bas.contractdate).add(20, "years").format("YYYY-MM-DD");
              // }			
              if(this.model.cfagit.recgrp.bas.sta == 'S') {
                this.model.cfagit.recgrp.bas.actiontype = "C";
              } else {
                this.model.cfagit.recgrp.bas.actiontype = "A";
              }
              this.model.cfagit.basflg = 'X';
              if(this.model.cfagit.recgrp.dcl == null || this.model.cfagit.recgrp.dcl.length == 0) {
                var a = [{
                  exguarancode: "",
                  actiontype: "",
                  wabachandate: "",
                  basere: "",
                  remark: "",
                  actiondesc: "",
                  acp: "",
                }];
                this.model.cfagit.recgrp.dcl = a;
              }
              if(this.model.ameamt) {
                this.model.cfagit.dclflg = 'X';
                // this.model.cfagit.recgrp.dcl[0].actiontype = 'A';
                // this.model.cfagit.recgrp.dcl[0].wabachandate = moment(new Date()).format('YYYY-MM-DD');
                // this.model.cfagit.recgrp.bas.guaranamount = Number(this.model.gidgrp.cbs.max.amt) + Number(this.model.ameamt);
                // this.model.cfagit.recgrp.dcl[0].basere = Number(this.model.gidgrp.cbs.max.amt) + Number(this.model.ameamt);
                // this.model.cfagit.recgrp.dcl[0].exguarancode = this.model.cfagit.recgrp.bas.exguarancode;
                // this.model.cfagit.recgrp.dcl[0].acp = 'X';
              } else {
                this.model.cfagit.dclflg = '';
              }
            }
          }
          // 人民币
          if(this.model.rmbbop.rmb2122.recgrp.ads.levyno != null && this.model.rmbbop.rmb2122.recgrp.ads.levyno != "") {
            if(this.model.rmbbop.rmb2122.recgrp.ads.levyno) {
              this.model.rmbbop.rmb2122.rmbflg = '1';
              this.model.rmbbop.rmb2122.recgrp.ads.opertype = '2';
              // this.model.rmbbop.rmb2122.recgrp.ads.vouchamt = Number(this.model.gidgrp.cbs.max.amt) + Number(this.model.ameamt);
              // if(this.model.gidgrp.rec.expdat) {
              //   this.model.rmbbop.rmb2122.recgrp.ads.vouchenddate = this.model.gidgrp.rec.expdat;
              // } else {
              //   this.model.rmbbop.rmb2122.recgrp.ads.vouchenddate = moment(this.model.rmbbop.rmb2122.recgrp.ads.vouchefficientdate).add(20, "years").format("YYYY-MM-DD");
              // }
            }
          }
        }
			}
		},
	},
};