import commonFunctions from '~/mixin/commonFunctions.js';
import buildFn from '../event/buildCommons.js';
import Utils from '~/utils';
import Api from '~/service/Api';
import Pts from '~/components/business/commonModel/Pts';
export default {
  mixins: [commonFunctions, buildFn],
  methods: {
    // 此方法为了占位使用,为了后续替换成对应的change方法
    queryFormData (key) { },
    changeFreFlg () {
      if (this.model.ncdgrp.rec.frepayflg == 'C') {
        this.model.nidgrp.rec.cmtflg = "O";
        this.model.cmtflg = '';
        this.model.paypsb = '';
      }
    },
    changeCmtFlg () {
      if (this.model.nidgrp.rec.cmtflg == 'O') {
        this.model.cmtflg = '';
      }
    },

    calcName () {
      this.model.ncdgrp.rec.nam = this.model.ncdgrp.cbs.max.cur + " " + this.model.ncdgrp.cbs.max.amt + " " + this.model.ncdgrp.apl.pts.nam;
      this.model.ncdgrp.rec.nam = this.model.ncdgrp.rec.nam.slice(0, 40);
    },
    // ncdgrp.rec.docprbrol
    calcPrb () {
      let prbref = this.model.ncdgrp.prb.pts.ref;
      switch (this.model.ncdgrp.rec.docprbrol) {
        case "ADV":
          Utils.copyValueFromVoData(this.model.ncdgrp.prb.pts, this.model.nidgrp.adv.pts);
          this.model.ncdgrp.prb.pts.rol = "PRB";
          if (prbref == "" && this.model.nidgrp.adv.pts.ref != "") {
            this.model.ncdgrp.prb.pts.ref = this.model.nidgrp.adv.pts.ref;
          }
          else {
            this.model.ncdgrp.prb.pts.ref = prbref;
          }
          break;
        case "BEN":
          Utils.copyValueFromVoData(this.model.ncdgrp.prb.pts, this.model.nidgrp.ben.pts);
          this.model.ncdgrp.prb.pts.rol = "PRB";
          this.model.ncdgrp.prb.pts.ref = this.model.ncdgrp.ben.pts.ref;
          break;
        case "ISS":
          Utils.copyValueFromVoData(this.model.ncdgrp.prb.pts, this.model.nidgrp.iss.pts);
          this.model.ncdgrp.prb.pts.rol = "PRB";
          if (prbref == "" && this.model.nidgrp.iss.pts.ref != "") {
            this.model.ncdgrp.prb.pts.ref = this.model.nidgrp.iss.pts.ref;
          }
          else {
            this.model.ncdgrp.prb.pts.ref = prbref;
          }
          break;
        case "ATB":
          Utils.copyValueFromVoData(this.model.ncdgrp.prb.pts, this.model.nidgrp.atb.pts);
          this.model.ncdgrp.prb.pts.rol = "PRB";
          if (prbref == "" && this.model.nidgrp.atb.pts.ref != "") {
            this.model.ncdgrp.prb.pts.ref = this.model.nidgrp.atb.pts.ref;
          }
          else {
            this.model.ncdgrp.prb.pts.ref = prbref;
          }
          break;
        case "AT2":
          Utils.copyValueFromVoData(this.model.ncdgrp.prb.pts, this.model.nidgrp.at2.pts);
          this.model.ncdgrp.prb.pts.rol = "PRB";
          if (prbref == "" && this.model.nidgrp.at2.pts.ref != "") {
            this.model.ncdgrp.prb.pts.ref = this.model.nidgrp.at2.pts.ref;
          }
          else {
            this.model.ncdgrp.prb.pts.ref = prbref;
          }
          break;
        case "PRB":
          this.model.ncdgrp.prb.pts = new Pts().data;
          this.model.ncdgrp.prb.pts.rol = "PRB";
          this.model.ncdgrp.prb.pts.ref = prbref;
          break;
      }
    },
    // ncdgrp.rec.payrol
    calcOth () {
      switch (this.model.ncdgrp.rec.payrol) {
        case "APL":
          Utils.copyValueFromVoData(this.model.ncdgrp.oth.pts, this.model.nidgrp.apl.pts);
          this.model.ncdgrp.oth.pts.rol = "OTH";
          break;
        case "ISS":
          Utils.copyValueFromVoData(this.model.ncdgrp.oth.pts, this.model.nidgrp.iss.pts);
          this.model.ncdgrp.oth.pts.rol = "OTH";
          break;
        case "OTH":
          this.model.ncdgrp.oth.pts = new Pts().data;
          this.model.ncdgrp.oth.pts.rol = "OTH";
          break;
      }
    },
    changeChkTyp () {
      if (this.model.ischktyp == 'N') {
        this.model.prechkdat = '';
      }
      this.$nextTick(() => {
        this.root.$refs['modelForm'].validateField(['prechkdat']);
      })
    },
    onClsflg () {
      if ((this.model.setmod.docamt == this.model.ncdgrp.cbs.opn1.amt + this.model.ncdgrp.cbs.opn2.amt) || (this.model.paypsb == "")) {
        this.model.clsflg = "C"
      } else {
        this.model.clsflg = "O"
      }
    },
    //申报2111报文
    //申报2111报文
    query2111 () {
      let trnName = this.root.trnName.toUpperCase()
      if (this.model.rmbbop.rmbbop2111Vo.rmbflg == '1') {
        let rmbbop = this.buildRobbop(this.model, trnName);
        Api.post('/business/rmbbopncd/rmbbop2111Cal', rmbbop).then(res => {
          Utils.copyValueFromVoData(this.model.rmbbop.rmbbop2111Vo, res.data.rmbbop2111Vo);
          this.model.rmbbop.rmbbop2111Vo.recgrp.ads.opertype = '1';
        });
      } else {
        this.model.rmbbop.rmbbop2111Vo.newnum = 0;
      }
    },
    //申报2123报文
    query2123 () {
      let trnName = this.root ? this.root.trnName : this.trnName
      if (this.model.rmbbop.rmbbop2123Vo.rmbflg == '1') {
        let rmbbop = this.buildRobbop(this.model, trnName);
        Api.post('/business/rmbbopncd/rmbbop2123Cal', rmbbop).then(res => {
          Utils.copyValueFromVoData(this.model.rmbbop.rmbbop2123Vo, res.data.rmbbop2123Vo);
          this.model.rmbbop.rmbbop2123Vo.recgrp.ads.opertype = '1';
        });
      }
    },
    //跨境人民币清算模式--"trnmod.cmtflg"
    changeCmtflg () {
      if (this.model.cmtflg == "P") {
        this.model.swftyp = "CIV"
      }
    },
    //免费付款--"ncdgrp.rec.frepayflg"
    changeFrepayflg () {
      if (this.model.paypsb == "X" && this.model.ncdgrp.rec.frepayflg == "X") {
        this.model.paypsb = "";
        this.model.clsflg = "C"
      }
      else if (this.model.ncdgrp.rec.frepayflg == "C") {
        this.model.paypsb = "";
      } else if (this.model.ncdgrp.rec.frepayflg == "O") {
        this.model.paypsb = "";
      }
    },
    //未支付申请人--"paypsb"
    changePaypsb () {
      if (this.model.paypsb == "X") {
        this.model.clsflg = "O"
      } else if (this.model.paypsb == "") {
        this.model.clsflg = "C"
      }
    },
    //申报类型--"bopmod.szflg"
    changeSzflg () {
      if (this.model.bopmod.szflg == "3") {
        this.model.bopmod.acttyp = "";
        this.model.bopmod.ownextkey = '';
      }
      if (this.model.bopmod.szflg == "2") {
        this.model.bopmod.acttyp = "";
        this.model.bopmod.ownextkey = JSON.parse(window.sessionStorage.currentOrg).departmentNumber;
      }
      if (this.model.bopmod.szflg == "1") {
        this.model.bopmod.ownextkey = JSON.parse(window.sessionStorage.currentOrg).departmentNumber;
      }
    },
    resetCipmod () {
      if (this.model.cipmodVo.covflg == '' || this.model.swftyp != 'P') {
        this.model.cipmodVo.cfkkhh = ''
        this.model.cipmodVo.cfkkhm = ''
        this.model.cipmodVo.cfkrzh = ''
        this.model.cipmodVo.cfkrmc = ''
        this.model.cipmodVo.cfkdz1 = ''
        this.model.cipmodVo.cfkdz2 = ''
        this.model.cipmodVo.cfkdz3 = ''
        this.model.cipmodVo.cfkdz4 = ''
        this.model.cipmodVo.cfkdz5 = ''
        this.model.cipmodVo.cfkdz6 = ''
        this.model.cipmodVo.cfkdz7 = ''
        this.model.cipmodVo.cskkhh = ''
        this.model.cipmodVo.cskkhm = ''
        this.model.cipmodVo.cskrzh = ''
        this.model.cipmodVo.cskrmc = ''
        this.model.cipmodVo.cskdz1 = ''
        this.model.cipmodVo.cskdz2 = ''
        this.model.cipmodVo.cskdz3 = ''
        this.model.cipmodVo.cskdz4 = ''
        this.model.cipmodVo.cskdz5 = ''
        this.model.cipmodVo.cskdz6 = ''
        this.model.cipmodVo.cskdz7 = ''
        this.model.cipmodVo.czjjg1 = ''
        this.model.cipmodVo.czj1mc = ''
        this.model.cipmodVo.covfuy = ''
        this.model.cipmodVo.covfy2 = ''
        this.model.cipmodVo.covfy3 = ''
        this.model.cipmodVo.covfy4 = ''
      }
    },
    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';
          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 = '';
      }
      if (this.model.cfagit.cfaflg === "5") {
        this.getCfap()
      }
    },
    async getOwnExtkeyCondition () {
      const loading = this.loading();
      let res = await Api.post('/business/nitopnRule/getOwnExtkeyCondition');
      loading.close();
      if (res.respCode === SUCCESS) {
        this.ownExtkeyList = res.data;
      }
    },
    getCfap () {
      let trnName = this.root ? this.root.trnName : this.trnName;
      if (this.model.cfagit.cfaflg === '5') {
        let cfap = this.buildCfap(this.model, trnName);
        if (cfap.recgrp.dcl == null || cfap.recgrp.dcl.length == 0) {
          var a = [{
            exguarancode: "",
            actiontype: "",
            wabachandate: "",
            basere: "",
            remark: "",
            actiondesc: "",
            acp: "",
          }];
          cfap.recgrp.dcl = a;
        }
        if (cfap.recgrp.vrf == null || cfap.recgrp.vrf.length == 0) {
          var b = [{
            exguarancode: '',
            complianceno: '',
            actiontype: '',
            actiondesc: '',
            guarantorcode: '',
            buscode: '',
            bencode: '',
            bename: '',
            benamen: '',
            guperdate: '',
            gupercurr: '',
            guperamount: '',
            pguperamount: '',
            remark: '',
            acp: '',
          }];
          cfap.recgrp.vrf = b;
        }
        Api.post('/business/ncd/cfaMapping', cfap).then(res => {
          if (res.respCode === SUCCESS) {
            this.model.cfagit.recgrp = res.data.recgrp;
            if (res.data.ownextkey) {
              this.model.cfagit.ownextkey = res.data.ownextkey;
            }
            this.model.cfagit.cfatyp = "S";
            this.model.cfagit.recgrp.vrf[0].actiontype = "A";
            this.model.cfagit.recgrp.vrf[0].acp = "X";
            this.model.cfagit.recgrp.dcl[0].actiontype = "A";
            this.model.cfagit.recgrp.dcl[0].acp = "X";
            // this.onCfaCurDate();
          }
        });
      }
    },
    changeCmtflgSelect () {
      if (this.model.cmtflg == 'P') {
        this.model.swftyp = 'CIV';
        this.model.cipmodVo.bustyp = "FTFX"
        this.model.cipmodVo.commen = this.model.nidgrp.rec.ownref
      } else {
        this.model.swftyp = '';
      }
    },
    changeNcdOpn1(){
      if(Number(this.model.ncdgrp.cbs.opn1.amt) != Number(this.model.ncdgrp.cbs.max.amt)){
        this.model.clsflg = "O";
      }
    },
  },
};