import Api from '~/service/Api';
import commonFunctions from '~/mixin/commonFunctions.js';
import buildFn from './buildCommons.js';
export default {
  mixins: [commonFunctions, buildFn],
  methods: {
    // 点击获取按钮拉取当前key字段下的表单数据
    queryFormData(key) {},
    // 业务信息=》基本信息=》保函编号-----获取保函编号
    queryOwnref() {
      let params = this.model.nidgrp.rec
      if (!this.model.nidgrp.ben.pts.ptainr || !this.model.nidgrp.rec.hndtyp) {
        return
      }
      let ptainr = this.model.nidgrp.ben.pts.ptainr;
      const loading = this.loading();
      let trnName = this.root.trnName.toUpperCase()
      Api.post(`/business/ref/nid?ptaInr=${ptainr}&trnName=${trnName}`, params).then(res => {
      	loading.close();
        if (res.respCode == SUCCESS) {
          this.model.nidgrp.rec.ownref = res.data;
        } else {
			this.$message.error(res.respMsg);
		}
      }).catch(() => {
        loading.close();
      });
		},
		// 保函模板转文本
		templateToText () {
			let gtxinr = this.model.nidgrp.rec.gtxinr
			let textTempData = this.model.textTempData
			this.formatTxtp(this.model.nidgrp.blk.gtxgidtxt, gtxinr, 'gtx', textTempData, 'nidgrp')
		},
		changeTxt () {
			this.templateToText()
		},
		//申报2122报文
		query2122() {
			let trnName = this.root ? this.root.trnName : this.trnName;
			if (this.model.rmbbop.rmb2122.rmbflg === '1') {
				let rmbbop = this.buildRobbop(this.model, trnName);
				Api.post('/business/rmbbopnid/rmbbop2122Cal', rmbbop).then(res => {
					if (res.respCode === SUCCESS) {
            this.model.rmbbop.rmb2122 = res.data.rmb2122;
            this.model.rmbbop.rmb2122.recgrp.ads.opertype = '1';
					}
				});
			}
		},

		changeOpndat(){
			this.model.nidgrp.rec.orddat = this.model.nidgrp.rec.opndat
		},
		checkGidtxt() {
			this.$nextTick(() => {
				this.root.$refs['modelForm'].validateField(['nidgrp.blk.gidtxt']);
			})
		},
	  //设置通知行change事件
	  setIssBankChange(){
		  //赋值opbnk
		  if(this.model.zmqflg === "X" && this.model.nidgrp.iss.pts.extkey !== "")
			  this.model.nidgrp.rec.oppbnk = this.model.nidgrp.iss.pts.extkey.slice(0, 11);
	  },
		// changeRmbflg() {
		// 	if (this.model.nidgrp.cbs.max.cur == "CNY") {
		// 		if (this.model.nidgrp.rec.cmtflg == "X") {
		// 			this.model.rmbbop.rmb2122.rmbflg = "1";
		// 		}else {
		// 			this.model.rmbbop.rmb2122.rmbflg = "2";
		// 		}
		// 	} else if() {
    //     this.model.rmbbop.rmb2122.rmbflg = "";
    //   } else {
		// 		this.model.rmbbop.rmb2122.rmbflg = "2";
		// 	}
		// },
  },
};