import commonFunctions from '~/mixin/commonFunctions.js';
import Api from '~/service/Api';
import moment from 'moment';
import commonDepend from "~/mixin/commonDepend";
export default {
  mixins: [commonFunctions, commonDepend],
  methods: {
    defaultDat(){
      this.model.cpdgrp.rec.paydat = moment(new Date()).format("YYYY-MM-DD");
      this.model.cpdgrp.rec.valdat = moment(new Date()).format("YYYY-MM-DD");
      this.model.cpdgrp.rec.opndat = moment(new Date()).format("YYYY-MM-DD");
    },
    defaultCptrou() {
      if (this.model.cpdgrp.rec.cptrou == '') {
        this.model.cpdgrp.rec.cptrou = 'SWIFT';
      }
    },
    cptrouChange(e) {
      if (e === undefined) {
        return
      }
      this.model.cpdgrp.rec.swftyp = '';
      this.model.cptp.isomsgtyp = '';
      //语种控制
      if (this.model.cpdgrp.rec.cptrou == 'SWIFT' || this.model.cpdgrp.rec.cptrou == 'CIPS') {
        this.model.cptp.payuil = 'EN';
      } else {
        this.model.cptp.payuil = 'CN';
      }
      this.setCips();
      this.setCur();
      this.setDetchgcod();
      this.setChato();
      if (this.model.cpdgrp.rec.cptrou == "JNWB" || this.model.cpdgrp.rec.cptrou == "HNHZ") {
        if (this.model.cpdgrp.res.pts.inr == '') {
          this.model.cpdgrp.res = this.model.ownpts;
        }
      }
    },
    setPayuil() {
      if(!this.model.cptp.payuil){
        //语种控制
        if (this.model.cpdgrp.rec.cptrou == 'SWIFT' || this.model.cpdgrp.rec.cptrou == 'CIPS') {
          this.model.cptp.payuil = 'EN';
        } else {
          this.model.cptp.payuil = 'CN';
        }
      }
    },
    setCips() {
      this.model.cipmod.reconebch = '';
      this.model.cipmod.reconebchnam = '';
      if (this.model.cpdgrp.rec.cptrou == "CIPS") {
        this.model.cipmod.reconebch = 'EVERCNBJXXX';
        this.model.cipmod.reconebchnam = '中国光大银行股份有限公司';
      }
    },
    setCur() {
      //汇款币种控制
      if ((this.model.cpdgrp.rec.cptrou == "CIPS" || this.model.cpdgrp.rec.cptrou == "OTHER") && !this.model.cpdgrp.cbs.nom1.cur) {
        this.model.cpdgrp.cbs.nom1.cur = 'CNY';
      }
      if ((this.model.cpdgrp.rec.cptrou == "CIPS" && this.model.cpdgrp.cbs.nom1.cur != 'CNY' && this.model.cpdgrp.cbs.nom1.cur != 'HKD') ||
        (this.model.cpdgrp.rec.cptrou == "OTHER" && this.model.cpdgrp.cbs.nom1.cur != 'CNY') ||
        ((this.model.cpdgrp.rec.cptrou == "SWIFT" || this.model.cpdgrp.rec.cptrou == "JNWB" ) && this.model.cpdgrp.cbs.nom1.cur == 'CNY') ||
        (this.model.cpdgrp.rec.cptrou == "HNHZ" && this.model.cpdgrp.rec.manbod =="0" && this.model.cpdgrp.cbs.nom1.cur == 'CNY')) {
        this.model.cpdgrp.cbs.nom1.cur = '';
        this.model.cpdgrp.cbs.nom1.amt = '';
      }
    },
    setDetchgcod() {
      if (this.model.cpdgrp.rec.cptrou == 'CIPS') {
        if (!this.model.cpdgrp.rec.detchgcod || this.model.cpdgrp.rec.detchgcod == "BEN" || this.model.cpdgrp.rec.detchgcod == "OUR" || this.model.cpdgrp.rec.detchgcod == "SHA") {
          this.model.cpdgrp.rec.detchgcod = "SHAR";
        }
      } else {
        if (!this.model.cpdgrp.rec.detchgcod || this.model.cpdgrp.rec.detchgcod == "DEBT" || this.model.cpdgrp.rec.detchgcod == "CRED" || this.model.cpdgrp.rec.detchgcod == "SHAR" || this.model.cpdgrp.rec.detchgcod == "SLEV") {
          this.model.cpdgrp.rec.detchgcod = "BEN";
        }
      }
    },
    async loadBopCtyList() {
      const loading = this.loading();
      let res = await Api.post(`/${this.moduleRouter()}/bopcty/loadBopCtyList`);
      loading.close();
      if (res.respCode === SUCCESS) {
        this.model.bopCtyList = res.data;
      }
    },
    changeYwlxdm(){
      if(this.model.attp.ywlxdm){
        if(this.model.attp.ywlxdm == 'A100'){
          this.model.cpdgrp.rec.detchgcod = 'OUR';
        }else{
          this.model.cpdgrp.rec.detchgcod = '';
          if(this.model.attp.ywlxdm == 'A200'){
            this.model.attp.bustyp = '09110';
          }else if(this.model.attp.ywlxdm == 'A311'){
            this.model.attp.bustyp = '09108';
          }else if(this.model.attp.ywlxdm == 'A105'){
            this.model.attp.bustyp = '02108';
          }
        }
      }
    },
    setChato(){
      if(this.model.cpdgrp.rec.detchgcod!= '' && (this.model.cpdgrp.rec.detchgcod=='OUR'||this.model.cpdgrp.rec.detchgcod=='DEBT')){
        this.model.cpdgrp.rec.chato = 'B';
      }else{
        this.model.cpdgrp.rec.chato = 'U';
      }
    }
  },
}