import commonFunctions from '~/mixin/commonFunctions.js';
import buildFn from '../event/buildCommons.js';
import Api from '~/service/Api';
import Pts from '~/components/business/commonModel/Pts';
import Utils from '~/utils';

export default {
  mixins: [commonFunctions, buildFn],
  methods: {
    //索赔编号
    queryOwnref () {
      let params = this.model.gcdgrp.rec
      if (!this.model.gcdgrp.apl.pts.ptainr) {
        return
      }
      let ptainr = this.model.gcdgrp.apl.pts.ptainr;
      const loading = this.loading();
      Api.post(`/business/ref/gcd?ptaInr=${ptainr}`, params).then(res => {
				loading.close();
        if (res.respCode == SUCCESS) {
          this.model.gcdgrp.rec.ownref = res.data;
        }
      }).catch(() => {
        loading.close();
      });
    },
    // 此方法为了占位使用,为了后续替换成对应的change方法
    queryFormData (key) { },
    changeFreFlg () {
      if (this.model.gcdgrp.rec.frepayflg == 'X') {
        if (this.model.gidgrp.rec.cmtflg == 'X') {
          this.model.cmtflg = 'O';
        }
        this.model.paypsb = '';
      }
      if (!!this.model.gcdgrp.rec.frepayflg || this.model.gidgrp.rec.hndtyp == 'OT') {
        this.model.paypsb = '';
      }
    },
    changeTrnmodCmtflg () {
      if (this.model.cmtflg != "P") {
        this.model.swftyp = ''
      }
      if (this.model.cmtflg == 'P') {
        this.model.swftyp = 'CIV'
        this.model.cipmodVo.bustyp = "FTFX"
        this.model.cipmodVo.commen = this.model.gidgrp.rec.ownref
      }
    },
    calcName () {
      this.model.gcdgrp.rec.nam = this.model.gcdgrp.cbs.max.cur + " " + this.model.gcdgrp.cbs.max.amt + " " + this.model.gcdgrp.apl.pts.nam;
      this.model.gcdgrp.rec.nam = this.model.gcdgrp.rec.nam.slice(0, 40);
    },
    gcdgrpBenRefBlur () {
      if (this.model.gcdgrp.rec.docprbrol == "BEN") {
        this.model.gcdgrp.prb.pts.ref = this.model.gcdgrp.ben.pts.ref;
      }
    },
    gcdgrpPrbRefBlur () {
      if (this.model.gcdgrp.rec.docprbrol == "BEN") {
        this.model.gcdgrp.ben.pts.ref = this.model.gcdgrp.prb.pts.ref;
      }
    },
    // gcdgrp.rec.docprbrol
    calcPrb () {
      console.log("this.model.gcdgrp.rec.docprbrol-->" + this.model.gcdgrp.rec.docprbrol);
      switch (this.model.gcdgrp.rec.docprbrol) {

        case "ADV":
          Utils.copyValueFromVoData(this.model.gcdgrp.prb.pts, this.model.gidgrp.adv.pts);
          this.model.gcdgrp.prb.pts.rol = "PRB";
          break;
        case "BEN":
          Utils.copyValueFromVoData(this.model.gcdgrp.prb.pts, this.model.gidgrp.ben.pts);
          this.model.gcdgrp.prb.pts.rol = "PRB";
          break;
        case "ISS":
          Utils.copyValueFromVoData(this.model.gcdgrp.prb.pts, this.model.gidgrp.iss.pts);
          this.model.gcdgrp.prb.pts.rol = "PRB";
          break;
        case "ATB":
          Utils.copyValueFromVoData(this.model.gcdgrp.prb.pts, this.model.gidgrp.atb.pts);
          this.model.gcdgrp.prb.pts.rol = "PRB";
          break;
        case "AT2":
          Utils.copyValueFromVoData(this.model.gcdgrp.prb.pts, this.model.gidgrp.at2.pts);
          this.model.gcdgrp.prb.pts.rol = "PRB";
          break;
        default:
          Utils.copyValueFromVoData(this.model.gcdgrp.prb.pts, "");
          this.model.gcdgrp.prb.pts.rol = "PRB";
          break;
      }
    },
    // gcdgrp.rec.payrol
    calcOth () {
      switch (this.model.gcdgrp.rec.payrol) {
        case "APL":
          Utils.copyValueFromVoData(this.model.gcdgrp.oth.pts, this.model.gidgrp.apl.pts);
          this.model.gcdgrp.oth.pts.rol = "OTH";
          break;
        default:
          Utils.copyValueFromVoData(this.model.gcdgrp.oth.pts, new Pts());
          this.model.gcdgrp.oth.pts.extkey = ''
          this.model.gcdgrp.oth.pts.enadr = ''
          this.model.gcdgrp.oth.pts.ennam = ''
          this.model.gcdgrp.oth.pts.rol = "OTH";
          break;
      }
    },
    changeLimitbody (emitParams) {
      let limitbodyRequest = buildFn.buildLimitbody(this.model, this.trnName);
      switch (emitParams.code) {
        case 'trial':
          this.trialLimitbody(limitbodyRequest);
          break
        case 'query':
          this.queryLimitbody(limitbodyRequest);
          break
        default:
          return
      }

    },
    query2111 () {
      let trnName = this.root.trnName.toUpperCase()
      if (this.model.rmbbop.rmb2111.rmbflg == '1') {
        let rmbbop = this.buildRobbop(this.model, trnName);
        Api.post('/business/rmbbopgcd/rmbbop2111Cal', rmbbop).then(res => {
          Utils.copyValueFromVoData(this.model.rmbbop.rmb2111, res.data.rmb2111);
          this.model.rmbbop.rmb2111.recgrp.ads.opertype = '1';
        });
      } else {
        this.model.rmbbop.rmb2111.newnum = 0;
      }
    },
    //申报2123报文
    query2123 () {
      let trnName = this.root ? this.root.trnName : this.trnName
      if (this.model.rmbbop.rmb2123.rmbflg == '1') {
        let rmbbop = this.buildRobbop(this.model, trnName);
        Api.post('/business/rmbbopgcd/rmbbop2123Cal', rmbbop).then(res => {
          Utils.copyValueFromVoData(this.model.rmbbop.rmb2123, res.data.rmb2123);
          this.model.rmbbop.rmb2123.recgrp.ads.opertype = '1';
        });
      }
    },
    changePaypsb () {
      if (!this.model.paypsb && this.model.gcdgrp.cbs.opn1.amt == this.model.setmod.docamt) {
        this.model.clsflg = 'C';
        this.isDisabled = true;
      } else {
        this.model.clsflg = 'O';
        this.isDisabled = false;
      }
    },
    // 获取地区机构号
    async getOwnExtkeyCondition () {
      const loading = this.loading();
      let res = await Api.post('/business/nitopnRule/getOwnExtkeyCondition');
      loading.close();
      if (res.respCode === SUCCESS) {
        this.ownExtkeyList = res.data;
      }
    },
    changeCmtflg () {
      if (this.model.gidgrp.rec.cmtflg != 'X') {
        this.model.cmtflg = '';
      } else {
        if (this.model.gcdgrp.rec.frepayflg == 'X') {
          this.model.cmtflg = 'O';
        }
      }
    },
    changeIschktyp () {
      if (this.model.ischktyp == 'N') {
        this.model.prechkdat = '';
      }
    },
    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()
      }
    },
    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/gcd/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";
          }
        });
      }
    },
    changeGcdOpn1(){
      if(Number(this.model.gcdgrp.cbs.opn1.amt) != Number(this.model.gcdgrp.cbs.max.amt)){
        this.model.clsflg = "O";
      }
    },
  },
};