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

export default {
	mixins: [commonFunctions],
	methods: {
    initGedmod() {
      if (this.model.gedmod.zjly === '1') {
        let trnName = this.trnName;
        if (this.root) {
          trnName = this.root.trnName;
        }
        let curtxt = '';
        let pty_ecifnotxt = '';
        if (trnName === 'cptopn') {
          curtxt = this.model.cpdgrp.cbs.nom1.cur;
          pty_ecifnotxt = this.model.cpdgrp.orc.pts.extkey;
        } else if (trnName === 'brtset' || trnName === 'brtset1') {
          curtxt = this.model.brdgrp.cbs.max.cur;
          pty_ecifnotxt = this.model.brdgrp.apl.pts.extkey;
        } else if (trnName === 'bctset' || trnName === 'bctset1') {
          curtxt = this.model.bcdgrp.cbs.max.cur;
          pty_ecifnotxt = this.model.bcdgrp.dre.pts.extkey;
        } else if (trnName === 'jstopn') {
          curtxt = this.model.jsdgrp.cbs.max.cur;
          pty_ecifnotxt = this.model.jsdgrp.apl.pts.extkey;
        }
        this.model.gedmod.dzghxx.cur = curtxt;
        if (pty_ecifnotxt) {
          pty_ecifnotxt = pty_ecifnotxt.substring(0, 10);
        }
        this.model.gedmod.dzghxx.ecifno = pty_ecifnotxt;
      } else {
        this.resetDzghxx();
      }
    },
    resetDzghxx(){
      this.model.gedmod.dzghxx.cur = '';
      this.model.gedmod.dzghxx.amtgwf = '';
      this.model.gedmod.dzghxx.amt = '';
      this.model.gedmod.dzghxx.amtunfrez = '';
      this.model.gedmod.dzghxx.khzhlx = '';
      this.model.gedmod.dzghxx.rmzhlx = '';
      this.model.gedmod.dzghxx.kehuzh = '';
      this.model.gedmod.dzghxx.ecifno = '';
      this.model.gedmod.dzghxx.ghedbh = '';
      this.model.gedmod.dzghxx.wibzhh = '';
      this.model.gedmod.dzghxx.edusta = '';
      this.model.gedmod.dzghxx.paytyp = '';
      this.model.gedmod.dzghxx.rmbzhh = '';
    },
    async queryGhedbh(){
      if (this.model.gedmod.dzghxx.ghedbh === '') {
        this.$alert('购汇额度编号为空,请录入购汇额度编号再查询', '提示', {
          confirmButtonText: '确定'
        });
        return;
      }
      if (this.model.gedmod.dzghxx.ecifno === '') {
        this.$alert('客户号为空,请录入客户号再查询', '提示', {
          confirmButtonText: '确定'
        });
        return;
      }
      let request = {
        ecifno: this.model.gedmod.dzghxx.ecifno,
        businessno: this.model.gedmod.dzghxx.ghedbh
      }
      let loading = this.loading('正在请求Ge34接口');
      let rtnmsg = await Api.post(`/${this.moduleRouter()}/gedmod/callGe34`, request);
			if (rtnmsg.respCode === SUCCESS) {
          if (rtnmsg.data.errorMsg !== '' && rtnmsg.data.errorMsg !== null) {
            this.$alert(rtnmsg.data.errorMsg, '提示', {
              confirmButtonText: '确定'
            });
          } else {
            this.model.gedmod.dzghxx.ghedbh = rtnmsg.data.businessno;
            this.model.gedmod.dzghxx.cur = rtnmsg.data.currency;
            this.model.gedmod.dzghxx.amtgwf = rtnmsg.data.havegwfed;
            this.model.gedmod.dzghxx.edusta = rtnmsg.data.applystatus;
            this.model.gedmod.dzghxx.wibzhh = rtnmsg.data.cuswbzh;
            this.model.gedmod.dzghxx.rmbzhh = rtnmsg.data.duifzh;
            this.model.gedmod.dzghxx.paytyp = rtnmsg.data.paytype;
          }
      }
      loading.close();
    },
  }
}