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

export default{
	mixin: [commonFunctions],
	methods: {
		buildForexmod (requestParams) {
			let trnName = this.trnName.toUpperCase()
      if (this.root) {
        trnName = this.root.trnName.toUpperCase()
      }
			let ptyinr = ''
			if ('CPTOPN'.includes(trnName)) {
				ptyinr = this.model.cpdgrp.orc.pts.ptyinr
			}
			if ('CPTADV'.includes(trnName)) {
				ptyinr = this.model.cpdgrp.pye.pts.ptyinr
			}
			if ('JSTOPN_JSTOPT_JSTOPM_JSTSET_LITOPN_LITOPN1_BRTSET_BRTSET1'.includes(trnName)) {
				let grp = this.model.gsdgrp || this.model.lidgrp ||this.model.brdgrp
				ptyinr = grp.apl.pts.ptyinr
			}
			if ('LETOPN_LETDRW_LETDRW1_LETRSV_BETSET_LETRSV1'.includes(trnName)) {
				let grp = this.model.ledgrp || this.model.bedgrp
				ptyinr = grp.ben.pts.ptyinr
			}
			if ('BCTDAV_BCTDAV1_BCTSET_BCTSET1'.includes(trnName)) {
				ptyinr = this.model.bcdgrp.dre.pts.ptyinr
			}
			if ('BOTDAV_BOTSET_BOTDAV1'.includes(trnName)) {
				ptyinr = this.model.bodgrp.drr.pts.ptyinr
			}
			if ('BPTOPN_BPTSET'.includes(trnName)) {
				ptyinr = this.model.bpdgrp.fia.pts.ptyinr
			}
			if ('TRTOPN_TRTSET'.includes(trnName)) {
				ptyinr = this.model.trdgrp.fip.pts.ptyinr
			}
			if ('GITOPN_GITSET_GITPOP_GETOPN_GETSET'.includes(trnName)) {
				if (this.model.gidgrp.rec.hndtyp == 'OT' || this.model.gidgrp.rec.hndtyp.startsWith('F')) {
					ptyinr = this.model.gidgrp.ben.pts.ptyinr
				} else {
					ptyinr = this.model.gidgrp.apl.pts.ptyinr
				}
			}
			return ptyinr
    },
		async processForexmod(requestParams) {
			let ptyinr = this.buildForexmod()
			let loading = this.loading('正在查询外汇展业');
			let rtnmsg = await Api.post(`/${this.moduleRouter()}/forexmod/search`, {ptyinr:ptyinr});
			if(rtnmsg.respCode === SUCCESS){
				if(rtnmsg.data.errorMsg){
					this.$alert(rtnmsg.data.errorMsg, '提示', {
            confirmButtonText: '确定'
					});
				}
				this.model.forexmod = rtnmsg.data
			}
			loading.close()
			return rtnmsg;
		},
	}
}