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

export default {
	mixins: [commonFunctions],
	methods: {
		buildEntmod(requestParams){
			let trnName = this.trnName;
      if (this.root) {
        trnName = this.root.trnName;
      }
      let rec = {}
      rec.transName = trnName.toUpperCase();
      rec.ptsList = requestParams.ptsList;
      if ("-CPTOPN-CPTREP-CPTADV-CPTATO-CPTATI-".includes(trnName.toUpperCase())) {
         rec.doccur = this.model.cpdgrp.cbs.max.cur;
         rec.docamt = this.model.cpdgrp.cbs.max.amt;
         if ("-CPTOPN-CPTATO-".includes(trnName.toUpperCase())) {
            rec.rol = 'ORC';
         } else {
            rec.rol = 'PYE';
         }
      }
      if ("BOTSET".includes(trnName.toUpperCase())) {
         rec.doccur = this.model.setmod.doccur;
         rec.docamt = this.model.setmod.docamt;
         rec.rol = 'DRR';
      }
      if ("BOTDAV1".includes(trnName.toUpperCase())) {
        rec.doccur = this.model.bodgrp.cbs.max.cur;
        rec.docamt = this.model.bodgrp.cbs.max.amt;
        rec.rol = 'DRR';
      }
      if ("BCTDAV1".includes(trnName.toUpperCase())) {
        rec.doccur = this.model.bcdgrp.cbs.max.cur;
        rec.docamt = this.model.bcdgrp.cbs.max.amt;
        rec.rol = 'DRE';
      }
      if ("BCTSET1-BCTACC1".includes(trnName.toUpperCase())) {
        if ("BCTSET1".includes(trnName.toUpperCase())) {
          rec.doccur = this.model.setmod.doccur;
          rec.docamt = this.model.setmod.docamt;
        }
        rec.rol = 'DRE';
      }
      if ("LITOPN1".includes(trnName.toUpperCase())) {
        rec.doccur = this.model.lidgrp.cbs.max.cur;
        rec.docamt = this.model.lidgrp.cbs.max.amt;
        rec.rol = 'APL';
        if (this.model.lidgrp.rec.dkflg === 'X') {
          rec.rol = 'APO';
        }
      }
      if ("LITAME1".includes(trnName.toUpperCase())) {
        rec.doccur = this.model.litamep.maxcur;
        rec.docamt = this.model.litamep.maxamt;
        if (this.model.lidgrp.rec.dkflg === 'X') {
          rec.rol = 'APO';
        } else {
          rec.rol = 'APL';
        }
      }
      if ("BETSET".includes(trnName.toUpperCase())) {
        rec.doccur = this.model.setmod.doccur;
        rec.docamt = this.model.setmod.docamt;
        rec.rol = 'BEN';
      }
      if ("TRTOPN".includes(trnName.toUpperCase())) {
        rec.doccur = this.model.trdgrp.cbs.max.cur;
        rec.docamt = this.model.trdgrp.cbs.max.amt;
        rec.rol = 'FIP';
      }
      if ("BPTOPN".includes(trnName.toUpperCase())) {
        rec.doccur = this.model.bpdgrp.cbs.max.cur;
        rec.docamt = this.model.bpdgrp.cbs.max.amt;
        rec.rol = 'FIA';
      }
      if ("BRTUDP1-BRTSET1".includes(trnName.toUpperCase())) {
        rec.doccur = this.model.setmod.doccur;
        rec.docamt = this.model.setmod.docamt;
        if (this.model.lidgrp.rec.dkflg === 'X') {
          rec.rol = 'APO';
        } else {
          rec.rol = 'APL';
        }
      }
      if ("LETOPN-LETRSV1-LETDRW1".includes(trnName.toUpperCase())) {
        if ("LETOPN".includes(trnName.toUpperCase())) {
          rec.doccur = this.model.ledgrp.cbs.max.cur;
          rec.docamt = this.model.ledgrp.cbs.max.amt;
        }
        rec.rol = 'BEN';
      }
      if ("LTTOPN1-LTTAME1".includes(trnName.toUpperCase())) {
        rec.rol = 'BE1';
      }
      if ("BTTSET".includes(trnName.toUpperCase())) {
        rec.doccur = this.model.setmod.doccur;
        rec.docamt = this.model.be1amt;
        rec.rol = 'BE1';
      }
      if ("JSTOPN-JSTOPT".includes(trnName.toUpperCase())) {
        rec.doccur = this.model.jsdgrp.cbs.max.cur;
        rec.docamt = this.model.jsdgrp.cbs.max.amt;
        rec.rol = 'APL';
			}
			return rec
		},
		async processEntmod(requestParams){
			let loading = this.loading('正在查询企业名录');
      let request = this.model.entmod;
      request.rec = this.buildEntmod(requestParams)
      request.errorMsg = '';
      let rtnmsg = await Api.post(`/${this.moduleRouter()}/entmod/search`, request);
			if (rtnmsg.respCode === SUCCESS) {
				this.model.entmod = rtnmsg.data;
				if (rtnmsg.data.errorMsg !== '' && rtnmsg.data.errorMsg !== null) {
          this.$alert(rtnmsg.data.errorMsg, '提示', {
            confirmButtonText: '确定'
          });
        }else{
					if (this.root){
						this.root.$refs["modelForm"].validateField([`entmod.rtyflg`]);
					}else{
						this.$refs["modelForm"].validateField([`entmod.rtyflg`]);
					}
				}
			}
			loading.close();
			return rtnmsg;
      
		},
		async getData(){
			let requestParams = this.root.buildCommonData(this.model, this.root.trnName);
			await this.processEntmod(requestParams)
		}

  }
}