import Api from '~/service/Api';
import buildFn from '../event/buildCommons.js';
import Utils from "~/utils/index"
import commonFunctions from '~/mixin/commonFunctions.js';
import Pts from '~/components/business/commonModel/Pts';
import dateFormat from '@/util/date/dateFormat.js';
import commonDepend from "~/mixin/commonDepend";
import index2 from "./index2";

export default {
	mixins: [commonFunctions, buildFn, index2],
	methods: {
		// 点击获取按钮拉取当前key字段下的表单数据
		queryFormData(key) {
		},
		// model.gidgrp.rec.ownref
		// 业务信息=》基本信息=》保函编号-----获取保函编号
		queryOwnref() {
			let params = this.model.gidgrp.rec;
			params.ownref = this.model.gitp.tempOwnref;
			let ptainr = ""
			let msg = ""
			//转开取受益人
			if (this.model.gidgrp.rec.hndtyp == 'OT') {
				ptainr = this.model.gidgrp.ben.pts.ptainr;
				msg = "请检查BEN信息!"
			} else {
				if (this.model.gidgrp.ctr.pts.ptainr != "") {
					//取经办机构
					ptainr = this.model.gidgrp.ctr.pts.ptainr;
					msg = "请检查CTR信息!"
				}
				if (ptainr == "") {
					//取经办机构
					ptainr = this.model.gidgrp.apl.pts.ptainr;
					msg = "请检查APL信息!"
				}
			}
			if (!ptainr) {
				this.$notify.warning({
					title: "提示",
					message: msg
				});
				return
			}
			const loading = this.loading();
			let trnName = this.root.trnName.toUpperCase();
			Api.post(`/business/ref/gid?ptaInr=${ptainr}&trnName=${trnName}`, params).then(res => {
				loading.close();
				if (res.respCode === SUCCESS) {
					this.model.gidgrp.rec.ownref = res.data;
					this.model.gitp.tempOwnref = res.data;
				} else {
          this.$message.error(res.respMsg);
        }
			}).catch(() => {
				loading.close();
			});
		},
		//申报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/rmbbopgid/rmbbop2122Cal', rmbbop).then(res => {
					if (res.respCode === SUCCESS) {
						this.model.rmbbop.rmb2122 = res.data.rmb2122;
						this.model.rmbbop.rmb2122.recgrp.ads.opertype = '1';
					}
				});
			}
		},
		// 获取地区机构号
		async getOwnExtkeyCondition1() {
			const loading = this.loading();
			let body = { ownExtKey: "" };
			if (this.model.trnInfo && this.model.trnInfo.sdhflg == "X" && this.model.cfagit.ownextkey) {
				body.ownExtKey = this.model.cfagit.ownextkey;
			}
			let res = await Api.post('/business/bch/getBranchListByownExtKey', body);
			loading.close();
			if (res.respCode === SUCCESS) {
				this.ownExtkeyList = res.data;
			}
		},
		getCfap() {
			let trnName = this.root ? this.root.trnName : this.trnName;
			if (this.model.cfagit.cfaflg === '1') {
				let cfap = this.buildCfap(this.model, trnName);
				if (cfap.recgrp.dcl == null || cfap.recgrp.dcl.length == 0) {
					var a = [{
						exguarancode: "",
						actiontype: "",
						wabachandate: "",
						basere: "",
						remark: "",
						actiondesc: "",
						acp: "",
					}];
					cfap.recgrp.dcl = a;
				}
				if (this.model.cfagit.recgrp.dcl == null || this.model.cfagit.recgrp.dcl.length == 0) {
					var a = [{
						exguarancode: "",
						actiontype: "",
						wabachandate: "",
						basere: "",
						remark: "",
						actiondesc: "",
						acp: "",
					}];
					this.model.cfagit.recgrp.dcl = a;
				}
				Api.post('/business/gid/cfaMapping', cfap).then(rtnmsg => {
					if (rtnmsg.respCode == SUCCESS) {
						Utils.copyValueFromVoData(this.model.cfagit.recgrp, rtnmsg.data.recgrp);
						if (rtnmsg.data.ownextkey != null && rtnmsg.data.ownextkey != "") {
							this.model.cfagit.ownextkey = rtnmsg.data.ownextkey
						}
						this.model.cfagit.cfatyp = "A";
						this.model.cfagit.recgrp.bas.actiontype = "A";
						this.model.cfagit.recgrp.bas.acp = "X";
						this.model.cfagit.recgrp.dcl[0].actiontype = "A";
						this.model.cfagit.recgrp.dcl[0].acp = "X";
					}
				});
			}
		},
		onCfaCurDate() {
			var moment = require('moment');
			this.model.cfagit.recgrp.bas.contractdate = this.model.gidgrp.rec.opndat;
			this.model.cfagit.recgrp.bas.maturity = this.model.gidgrp.rec.opndat;
			this.model.cfagit.recgrp.bas.maturity = moment(this.model.gidgrp.rec.opndat).add(20, "years").format("YYYY-MM-DD HH:mm:ss");
			this.model.cfagit.recgrp.bas.guarancurr = this.model.gidgrp.cbs.max.cur;
			this.model.cfagit.recgrp.bas.guaranamount = this.model.gidgrp.cbs.max.amt;
			this.model.cfagit.recgrp.dcl[0].wabachandate = this.model.cfagit.recgrp.bas.contractdate;
			this.model.cfagit.recgrp.dcl[0].basere = this.model.gidgrp.cbs.max.amt;
		},
		// "gitp.liatxtcmodflg"
		onLiatxtcmodflg() {
			if (this.model.gitp.liatxtcmodflg !== "") {
				this.model.gidgrp.rec.liatxtcmodflg = this.model.gitp.liatxtcmodflg;
			}
			let gtxchk = "";
			let chk = "";
			if (this.model.gitp.liatxtc !== "" || this.model.gidgrp.rec.atxinr.charAt(0) === "<") {
				if (this.model.gidgrp.rec.atxinr === "<INCMSG>") {
					gtxchk = "";
					chk = this.model.gitp.liatxtc();
					if (this.model.gitp.liatxtcmodflg !== "") {
						if (this.model.gidgrp.blk.atxliatxtc === "") {
							this.model.gidgrp.blk.atxliatxtc = this.model.gitp.liatxtc;
						}
					}
				} else {
					chk = this.model.gitp.liatxtc;
					if (this.model.gidgrp.rec.purpos.slice(2, 4) === "CO" && this.model.gidgrp.rec.atxinr) {
						gtxchk = this.model.gitp.atx.preinstxt;
					} else {
						gtxchk = "";
					}
				}
			} else {
				chk = this.model.gitp.oldliatxtc;
				gtxchk = this.model.oldatxliatxtc;
			}
			let que = false;
			if (this.model.gitp.liatxtcmodflg === "") {
				if (this.model.gidgrp.blk.liatxtc !== chk) {
					if (this.model.gidgrp.rec.atxinr === "<INCMSG>") {
						que = true;
						if (que !== 1) {
							this.model.gitp.liatxtcmodflg = "X";
						} else {
							this.model.gidgrp.blk.liatxtc = chk;
							this.model.gidgrp.blk.atxliatxtc = gtxchk;
						}
					}
				}
				if (this.model.gidgrp.blk.liatxtc === this.model.gitp.liatxtc) {
					this.model.gidgrp.rec.liatxtcmodflg = "";
				}
			}
		},

		// model.gidgrp.rec.gartyp
		handleChangeGartyp() {
			let _this = this
			let data = {
				gtxpurpos: _this.model.gidgrp.rec.purpos,
				gartyp: _this.model.gidgrp.rec.gartyp,
				hndtyp: _this.model.gidgrp.rec.hndtyp,
				gtxinr: _this.model.gidgrp.rec.gtxinr,
				giduil: _this.model.gidgrp.rec.giduil,
				segtyp: _this.model.gidgrp.ghd.segtyp,
				objinr: _this.model.trnmod.swiadd.objinr || "",
				msgtyp: ""
			}
			Api.post(`/business/gitopn/defaultGidgrpRecGtxinrN1000`, data).then(res => {
				_this.model.atxinrList = res.data
				let oldAtxinr = _this.model.gidgrp.rec.atxinr;
				if (res.data != null && res.data.length > 0) {
					_this.model.gidgrp.rec.atxinr = res.data[0].value
				}
				if (_this.model.gidgrp.rec.atxinr !== oldAtxinr) {
					_this.changeAtxinr(_this.model.gidgrp.rec.atxinr)
				}
			})

			// _this.defaultGidgrpCbsMaxCurN1000();
		},
		handleChangeGartypc() {
			let _this = this
			let data = {
				gtxpurpos: _this.model.gidgrp.rec.purpos,
				legfrmc: _this.model.gidgrp.rec.legfrmc,
				liatypc: _this.model.gidgrp.rec.liatypc,
				purpos: _this.model.gidgrp.rec.purpos,
				gartypc: _this.model.gidgrp.rec.gartypc,
				hndtyp: _this.model.gidgrp.rec.hndtyp,
				stdwrduilc: _this.model.gidgrp.rec.stdwrduilc,
				apcPtsPtyInr: _this.model.gidgrp.apc.pts.ptyinr,
				becPtsPtyInr: "",
				issPtsPtyInr: "",
			}
			Api.post(`/business/gitopn/defaultGidgrpRecGtxinrcN200`, data).then(res => {
				_this.model.atxinrcList = res.data
				let oldAtxinrc = _this.model.gidgrp.rec.gtxinrc;
				if (res.data != null && res.data.length > 0) {
					_this.model.gidgrp.rec.gtxinrc = res.data[0].value
				}
				if (_this.model.gidgrp.rec.gtxinrc !== oldAtxinrc) {
					_this.changeAtxinrc(_this.model.gidgrp.rec.gtxinrc)
				}
			})

			// _this.defaultGidgrpCbsMaxCurN1000();
		},
		updateOwnref() {
			let ownref = this.model.gidgrp.rec.ownref;
			if (ownref === '') {
				//编号为空,不处理,需要点击获取按钮得到业务编号
				return;
			}
			let gartyp = this.model.gidgrp.rec.gartyp;
			if (gartyp === '') {
				return;
			}
			if (gartyp === 'V') {
				let flag = ownref.substr(8, 1);
				if (flag !== 'X') {
					ownref = ownref.substr(0, 8) + 'X' + ownref.substr(8);
					this.model.gidgrp.rec.ownref = ownref;
				}
			} else {
				let flag = ownref.substr(8, 1);
				if (flag === 'X') {
					ownref = ownref.substr(0, 8) + ownref.substr(9);
					this.model.gidgrp.rec.ownref = ownref;
				}
			}
		},
		// model.gidgrp.rec.gartyp
		changeGartyp() {
			let _this = this;
			// 如果选择了语言种类,清空ptap组件
			// const lan = _this.model.gidgrp.rec.giduil;
			// if (lan) {
			// const t = _this.model.gidgrp;
			// for (let key in t) {
			//   if (t[key] && t[key].pts) {
			//     t[key].pts.adrblk = '';
			//     t[key].pts.extkey = '';
			//   }
			// }
			// }
			this.updateOwnref();
			if (_this.model.gidgrp.rec.purposin == "ISCO" && _this.model.gidgrp.rec.atxinr == "" && _this.model.gidgrp.blk.gidtxt != "") {
				//来报模板不替换
			} else {
				if (_this.model.gidgrp.rec.gartyp === "1") {
					_this.model.gidgrp.rec.atxinr = "<NILTXT>";
				} else {
					_this.model.gidgrp.rec.atxinr = "";
				}
				_this.handleChangeGartyp(1);
			}
		},
		changeGartypc() {
			let _this = this;
			if (_this.model.gidgrp.rec.gartyp === "1") {
				_this.model.gidgrp.rec.gtxinrc = "<NILTXT>";
			} else {
				_this.model.gidgrp.rec.gtxinrc = "";
			}
			_this.handleChangeGartypc(1);
		},
		changeLegfrm() {
			switch (this.model.gidgrp.rec.legfrm) {
				case "458":
				case "758":
				case "DGAR":
					// this.model.gidgrp.blk.apprul = "URDG";
					break;
				case "URG":
					// this.model.gidgrp.blk.apprul = "";
					break;
				case "ISP":
				case "GUO":
				case "UCP":
				case "URB":
				case "UNC":
				case "STBY":
					// this.model.gidgrp.blk.apprul = "OTHR";
					if (this.model.gidgrp.rec.reccnfdet === "") {
						this.model.gidgrp.rec.reccnfdet = "W"
					}
					// if (this.model.gidgrp.rec.cnfdet == "") {
					//   this.model.gidgrp.rec.cnfdet = "W"
					// }
					break;
				default:
					this.model.gidgrp.blk.apprul = "";
					break;
			}
			this.model.gidgrp.blk.apprul = "";
			this.change759();
			this.seqBSynToSeqB();
		},
		change759() {
			if (this.model.gidgrp.rec.legfrm == 'DEPU') {
				if (this.model.gidgrp.rec.purpos == 'ISCO' || this.model.gidgrp.rec.purpos == 'ICCO') {
					this.model.gidgrp.rec.liatypc = 'COND'
				} else {
					this.model.gidgrp.rec.exptyp = 'COND'
				}
			}
		},
		// Our Liability Until默认为Validity Until+15日,可更改。
		changeLiatypc() {
			if (this.model.gidgrp.rec.liatypc !== '' && this.model.gidgrp.rec.liatypc !== 'OPEN' && this.model.gidgrp.rec.expdat !== '') {
				if (this.model.gidgrp.rec.liadat === '') {
					var nowDateObj = new Date(this.model.gidgrp.rec.expdat + " 00:00:00");
					var nowTimeStem = nowDateObj.getTime();
					var endTimeStem = nowTimeStem + 24 * 60 * 60 * 1000 * 15;
					var endDateObj = new Date(endTimeStem);
					// console.log(dateFormat(endDateObj, "YYYY-MM-DD"))
					this.model.gidgrp.rec.liadat = dateFormat(endDateObj, "YYYY-MM-DD");
					this.model.gidgrp.rec.liaflg = "";
				}
			} else {
				this.model.gidgrp.rec.liadat = "";
			}
			if (this.model.gidgrp.rec.liatypc === 'FIXD') {
				this.model.gidgrp.rec.liaflg = "";
				this.model.gidgrp.blk.atxliatxtc = "";
				this.model.gitp.liatxtcmodflg = "";
				this.model.addbcb.bccls1 = '2';
			}
			if (this.model.gidgrp.rec.liatypc === 'COND') {
				this.model.gidgrp.rec.liaflg = "X";
				this.model.gitp.liatxtcmodflg = "X";
			}
			if (this.model.gidgrp.rec.liatypc === 'OPEN') {
				this.model.gidgrp.rec.liaflg = "X";
				this.model.gidgrp.blk.atxliatxtc = "";
				this.model.gitp.liatxtcmodflg = "";
			}
		},
		changeExptyp() {
			if (this.model.gidgrp.rec.exptyp !== 'FIXD') {
				this.model.gidgrp.rec.expdat = "";
				this.model.gidgrp.blk.atxexptxt = "";
				this.model.gitp.exptxtmodflg = "";
				this.root.$refs.modelForm.clearValidate(["gidgrp.rec.expdat", "gidgrp.blk.atxexptxt"])
			}
			if (this.model.gidgrp.rec.exptyp === 'FIXD') {
				this.model.gidgrp.rec.expflg = "";
				this.model.gidgrp.blk.atxexptxt = "";
				this.model.gitp.exptxtmodflg = "";
				this.model.addbcb.bccls1 = '2';
				this.root.$refs.modelForm.clearValidate(["gidgrp.rec.expflg", "gidgrp.blk.atxexptxt"])
			}
			if (this.model.gidgrp.rec.exptyp === 'COND') {
				this.model.gidgrp.rec.expflg = "X";
				this.model.gitp.exptxtmodflg = "X";
			}
			if (this.model.gidgrp.rec.exptyp === 'OPEN') {
				this.model.gidgrp.rec.expflg = "X";
				this.model.gidgrp.blk.atxexptxt = "";
				this.model.gitp.exptxtmodflg = "";
				this.root.$refs.modelForm.clearValidate(["gidgrp.rec.expflg", "gidgrp.blk.atxexptxt"])
			}
			// this.handleSynExpflg();
		},
		// "gidgrp.blk.atxexptxt"
		onAtxexptxt() {
			if (this.model.gidgrp.rec.purpos === "ISCO") {
				// this.model.gidgrp.blk.exptxt = this.model.gidgrp.blk.atxexptxt;
			}
		},
		handleChangeFingua() {
			if (this.model.gidgrp.rec.fingua !== "Y") {
				this.model.gidgrp.rec.cfaguatyp = "";
				this.model.rmbbop.rmb2122.rmbflg = "2";
				this.model.cfagit.cfaflg = "";
				this.model.cfagit.basflg = "";
				this.model.cfagit.dclflg = "";
				this.model.cfagit.ownextkey = "";
			}
			if (this.model.gidgrp.cbs.max.cur === "CNY") {
				if (this.model.gidgrp.rec.fingua === "Y") {
					this.model.gidgrp.rec.cmtflg = "X"
				} else {
					this.model.gidgrp.rec.cmtflg = ""
				}
				this.defaultVouflgN1000();
			} else {
				this.model.gidgrp.rec.cmtflg = ""
			}
			if (this.model.gidgrp.cbs.max.cur === "CNY") {
				if (this.model.gidgrp.rec.fingua === "Y") {
					this.model.rmbbop.rmb2122.rmbflg = "1";
				} else {
					this.model.rmbbop.rmb2122.rmbflg = "2";
				}
			} else if (this.model.gidgrp.cbs.max.cur !== "CNY" && this.model.gidgrp.cbs.max.cur !== "") {
				if (this.model.gidgrp.rec.fingua === "Y" && this.model.gidgrp.rec.cfaguatyp.slice(0, 2) === "11") {
					this.model.rmbbop.rmb2122.rmbflg = "1";
				} else {
					this.model.rmbbop.rmb2122.rmbflg = "2";
				}
			} else {
				this.model.rmbbop.rmb2122.rmbflg = "2";
			}
			if (this.model.cfagit) {
				this.model.cfagit.recgrp.bas.guarantype = this.model.gidgrp.rec.cfaguatyp;
				if (this.model.cfagit.cfaflg === '1') {
					this.getCfap();
				}
			}
			this.calcName()
		},
		defaultCfaGITFieldsN1200() {
			if (this.model.gidgrp.rec.fingua === "Y") {
				this.model.cfagit.basflg = "X"
			} else {
				this.model.gidgrp.rec.cmtflg = ""
			}
		},
		calcName() {
			this.model.gidgrp.cbs.mac.amt = this.model.gidgrp.cbs.max.amt;
			this.model.gidgrp.cbs.opn1.cur = this.model.gidgrp.cbs.max.cur;
			this.model.gidgrp.cbs.mac.cur = this.model.gidgrp.cbs.max.cur;
			this.model.gidgrp.cbs.max2.cur = this.model.gidgrp.cbs.max.cur;
			this.model.gidgrp.cbs.opn2.cur = this.model.gidgrp.cbs.max.cur;
			this.model.gidgrp.cbs.total2.cur = this.model.gidgrp.cbs.max.cur;
			this.model.gidgrp.cbs.total.cur = this.model.gidgrp.cbs.max.cur;
			// if (this.model.gitp.aamp.addamtflg === "X") {
			//     this.model.gidgrp.cbs.opn1.amt = parseFloat(this.model.gidgrp.cbs.max.amt) + parseFloat(this.model.gidgrp.cbs.max2.amt);

			// } else {
			this.model.gidgrp.cbs.opn1.amt = this.model.gidgrp.cbs.max.amt
			// }
			if (this.model.gidgrp.cbs.max2.amt == "") {
				this.model.gidgrp.cbs.total.amt = parseFloat(this.model.gidgrp.cbs.max.amt);
			} else {
				this.model.gidgrp.cbs.total.amt = parseFloat(this.model.gidgrp.cbs.max.amt) + parseFloat(this.model.gidgrp.cbs.max2.amt);
			}
			let model = this.model;
			this.model.gidgrp.rec.nam = model.gidgrp.cbs.max.cur + " " +
				model.gidgrp.cbs.max.amt + " " +
				(model.gidgrp.rec.stacty || "") + "." +
				model.gidgrp.apl.pts.nam
			// this.onCfaCurDate()
		},
		defaultVouflgN1000() {
			//2122
			//--暂时只有保函开立交易用--
			//2017-4人行 要求2122对保函开立交易开放外币申报
			if (this.model.gidgrp.cbs.max.cur === "CNY") {
				if (this.model.gidgrp.rec.cmtflg === "X") {
					this.model.cnybop.vouflg = ""
				} else {
					this.model.cnybop.vouflg = "2"
				}
				if (this.model.gidgrp.rec.fingua === "Y") {
					this.model.gidgrp.rec.cmtflg = "X"
				}
			} else {
				if (this.model.gidgrp.rec.fingua === "Y") {
					this.model.cnybop.vouflg = "1"
				} else {
					this.model.cnybop.vouflg = "2"
				}
			}
		},
		// "gidgrp.blk.atxliatxtc"
		onAtxliatxtc() {
			this.model.gidgrp.blk.liatxtc = this.model.gidgrp.blk.atxliatxtc;
		},
		// "cfagit.cfaflg"
		onCfaflg(e) {
			if (e === undefined) {
				return
			}
			switch (this.model.cfagit.cfaflg) {
				case "1":
					this.model.cfagit.basflg = 'X';
					this.model.cfagit.dclflg = 'X';
					// if (!this.model.cfagit.ownextkey) {
					//   this.ownextkey = this.codes.ownextkey1;
					//   this.model.cfagit.ownextkey = this.codes.ownextkey1[0].value;
					//   // this.ownextkey= getValues('cfagit.ownextkey','ownextkey1');
					// }
					break;
				case "2":
					this.model.cfagit.basflg = 'X';
					this.model.cfagit.dclflg = '';
					break;
				case "3":
					this.model.cfagit.basflg = '';
					this.model.cfagit.dclflg = 'X';
					break;
				case "5":
					this.model.cfagit.vrfflg = 'X';
					this.model.cfagit.dclflg = 'X';
					break;
				default:
					this.model.cfagit.basflg = '';
					this.model.cfagit.vrfflg = '';
					this.model.cfagit.dclflg = '';
			}
			// if (this.model.cfagit.cfaflg === "1") {
			// 		this.getCfap()
			// 		this.$emit('changeCfagit', {
			// 			code: 'cfaflg'
			// 		})
			// }
			if (this.model.cfagit.cfaflg === "4" || this.model.cfagit.cfaflg === "") {
				this.model.cfagit.ownextkey = "";
			}
		},
		// model.gidgrp.rec.jurlaws20
		changeJurlaws20() {
			// if (this.model.gidgrp.rec.jurlaws20 === "GB") {
			//     this.model.gidgrp.rec.jurlaw = "GB"
			// } else if (this.model.gidgrp.rec.jurlaws20 === "CN") {
			//     this.model.gidgrp.rec.jurlaw = "CN"
			// } else if (this.model.gidgrp.rec.jurlaws20 === "HK") {
			//     this.model.gidgrp.rec.jurlaw = "HK"
			// }
			if (this.model.gidgrp.rec.jurlaws20 === "") {
				this.model.gidgrp.rec.jurlaw = "";
				this.model.gidgrp.rec.jurplc = "";
			}
			this.seqBSynToSeqB();
		},
		changeJurlawc() {
			// if (this.model.gidgrp.rec.jurlawc === "GB") {
			//     this.model.gidgrp.rec.jurlawtxtc = "GB"
			// } else if (this.model.gidgrp.rec.jurlawc === "CN") {
			//     this.model.gidgrp.rec.jurlawtxtc = "CN"
			// } else if (this.model.gidgrp.rec.jurlawc === "HK") {
			//     this.model.gidgrp.rec.jurlawtxtc = "HK"
			// }
			if (this.model.gidgrp.rec.jurlawc === "") {
				this.model.gidgrp.rec.jurlawtxtc = "";
				this.model.gidgrp.rec.jurplcc = "";
			}
			this.seqBSynToSeqB();
		},
		// model.gidgrp.rec.expflg
		changeExpflg() {

			if (
				this.model.gidgrp.rec.expflg === "X" &&
				this.model.gidgrp.rec.hndtyp === "OC"
			) {
				this.model.gidgrp.rec.liaflg = "X";
			}
			this.defaultGidgrpRecSndtoN950();
		},

		defaultGidgrpCbsMaxCurN1000() {
			//银关保函和加贸保函目前只支持CNY业务
			if (this.model.gidgrp.rec.gartyp === "X" || this.model.gidgrp.rec.gartyp === "U") {
				this.model.gidgrp.cbs.max.cur = "CNY"
			}
			this.handleChangeFingua()
		},
		changeAtxinr(e) {
			if (e === undefined || this.isInDisplay) {
				return
			}
			this.model.gidgrp.blk.gidtxt = "";
			if (this.model.gidgrp.blk.modifySet) {
				this.model.gidgrp.blk.modifySet = this.model.gidgrp.blk.modifySet.filter(key => key != 'gidtxt')
			}
			for (let item of this.model.atxinrList) {
				if (e === item.value) {
					this.model.gidgrp.blk.gtxgidtxt = item.atxtxt;
					this.model.gidgrp.blk.gidtxt = item.atxtxt;
					// 备份字段
					this.$set(this.codes, 'gtxgidtxtMark', item.atxtxt)
				}
			}
			this.getConfigData(this.model.gidgrp.rec.atxinr).then(() => {
				if (!this.isInDisplay) {
					this.root.templateToText('gidtxtp')
				}
			})
		},
		changeAtxinrc(e) {
			if (e === undefined || this.isInDisplay) {
				return;
			}
			this.model.gidgrp.blk.gidtxtc = "";
			if (this.model.gidgrp.blk.modifySet) {
				this.model.gidgrp.blk.modifySet = this.model.gidgrp.blk.modifySet.filter(key => key != 'gidtxtc')
			}
			for (let item of this.model.atxinrcList) {
				if (e === item.value) {
					this.model.gidgrp.blk.gtxgidtxtc = item.atxtxt;
					this.model.gidgrp.blk.gidtxtc = item.atxtxt;
					// 备份字段
					this.$set(this.codes, 'gtxgidtxtcMark', item.atxtxt);
					break;
				}
			}
			this.getConfigData(this.model.gidgrp.rec.gtxinrc, true).then(() => {
				if (!this.isInDisplay) {
					this.root.templateToText('gidtxtpc')
				}
			})
		},
		// model.gidgrp.rec.purpos
		// 支出目的修改--联动保函开立类型
		handleChangePurpos(purposOld) {
			if (purposOld === 'ISSU') {
				this.model.gidgrp.rec.hndtyp = "OL"
			}
			if (purposOld === 'ISCO' || purposOld === 'ICCO') {
				this.model.gidgrp.rec.hndtyp = "OC"
			}
			if (this.model.gidgrp.rec.purpos.indexOf("CO") > -1) {
				// ok, Seq. C fields still allowed
				// this.model.gitp.covgodsrvmodflg = "";
				this.model.gidgrp.blk.atxcovgodsrv = ""
				this.model.gidgrp.cbs.mac.amt = this.model.gidgrp.cbs.max.amt;
				this.model.gidgrp.cbs.mac.cur = this.model.gidgrp.cbs.max.cur;

				let pts = new Pts().data;
				Utils.copyValueFromVO(this.model.gidgrp.ben.pts, pts);
			} else {
				// DNGDEV 1770 clear fields in Sequence C
				this.model.gidgrp.rec.accc = "";
				this.model.gidgrp.rec.deloric = "";
				this.model.gidgrp.rec.deloritxtc = "";
				this.model.gidgrp.rec.deltoc = "";
				this.model.gidgrp.rec.demandc = "";
				this.model.gidgrp.rec.gartypc = "";
				// DNGDEV.003055
				this.model.gitp.covgodsrvcmodflg = "";
				this.model.gitp.liatxtcmodflg = "";
				this.model.gitp.prepercmodflg = "";
				this.model.gitp.gidtxtmodflgc = "";
				this.model.gidgrp.rec.gtxinrc = "";
				this.model.gidgrp.rec.jurlawc = "";
				this.model.gidgrp.rec.jurlawtxtc = "";
				this.model.gidgrp.rec.jurplcc = "";
				this.model.gidgrp.rec.legfrmc = "";
				this.model.gidgrp.rec.liatypc = "";
				this.model.gidgrp.rec.liadat = "";
				this.model.gidgrp.rec.liaflg = "";
				this.model.gidgrp.blk.atxliatxtc = "";
				this.model.gidgrp.rec.opndatc = "";
				this.model.gidgrp.rec.orcamtc = "0";
				this.model.gidgrp.rec.orccurc = "";
				this.model.gidgrp.rec.orcdatc = "";
				this.model.gidgrp.rec.orcratc = "";
				this.model.gidgrp.rec.orcrefc = "";
				// this.model.gidgrp.rec.stdwrduilc = "";
				this.model.gidgrp.rec.tenclsdatc = "";
				this.model.gidgrp.rec.tendatc = "";
				this.model.gidgrp.rec.tenrefc = "";
				this.model.gidgrp.rec.trmdatc = "";
				this.model.gidgrp.blk.addamtcovc = "";
				this.model.gidgrp.blk.addinfc = "";
				this.model.gidgrp.blk.atxliatxtc = "";
				this.model.gidgrp.blk.atxcovgodsrvc = "";
				this.model.gidgrp.blk.apprulc = "";
				this.model.gidgrp.blk.covgodsrvc = "";
				this.model.gidgrp.blk.feetxtc = "";
				this.model.gidgrp.blk.gartyptxtc = "";
				this.model.gidgrp.blk.gtxgidtxtc = "";
				this.model.gidgrp.blk.liatxtc = "";
				this.model.gidgrp.blk.orcplcc = "";
				this.model.gidgrp.blk.preperc = "";
				this.model.gidgrp.cbs.mac.cur = "";
				this.model.gidgrp.cbs.mac.amt = '0.00';
				// this.model.gidgrp.cbs.max2.cur = "";
				// this.model.gidgrp.cbs.max2.amt = '0.00';
				// this.model.gitp.aacp.addamtflg = "";

				let pts = new Pts().data;
				Utils.copyValueFromVO(this.model.gidgrp.apc.pts, pts);
				Utils.copyValueFromVO(this.model.gidgrp.ctc.pts, pts);
				Utils.copyValueFromVO(this.model.gidgrp.iss.pts, pts);
				Utils.copyValueFromVO(this.model.gidgrp.bec.pts, pts);
			}
			this.handleSndto();
		},
		defaultGidgrpRecFinguaN1000() {
			//$hndtyp = GIDGRP\\REC\\HNDTYP
			let extkey = this.model.gidgrp.adv.pts.extkey;
			//if $hndtyp = "OT" then
			//= "N"
			//else
			if (extkey !== "") {
				if (extkey.length >= 7 && extkey.substr(4, 2) === "CN") {
					this.model.gidgrp.rec.fingua = "N"
				} else {
					this.model.gidgrp.rec.fingua = "Y"
				}
			}
			this.defaultGidgrpRecSndtoN950();
		},
		defaultGidgrpRecSndtoN950() {
			if (this.model.gidgrp.rec.purpos === 'ISCO' || this.model.gidgrp.rec.purpos === 'ICCO') {
				Utils.copyValueFromVO(this.model.gidgrp.apc, this.model.gidgrp.apl);
				this.model.gidgrp.apc.pts.rol = "APC";
			}
			if (this.model.gidgrp.rec.purpos === 'ISCO') {
				Utils.copyValueFromVO(this.model.gidgrp.iss, this.model.gidgrp.ben);
				this.model.gidgrp.apc.pts.rol = "APC";
				this.model.gidgrp.iss.pts.rol = "ISS";
			}
			if (this.model.gidgrp.ben && this.model.gidgrp.ben.pts && this.model.gidgrp.ben.pts.ennam && this.model.gidgrp.ben.pts.enadr) {
				this.model.gidgrp.benadrlin = this.model.gidgrp.ben.pts.ennam.replace(/[\n]/g, ",") + "," + this.model.gidgrp.ben.pts.enadr.replace(/[\n]/g, ",");
			}
			this.handleSndto();
			//赋值opbnk
			if(this.model.zmqflg === "X" && this.model.gidgrp.atb.pts.extkey !== "")
				this.model.gidgrp.rec.oppbnk = this.model.gidgrp.atb.pts.extkey.substring(0, 11);
		},
		onBccls1() {
			if (this.model.addbcb.bccls1 === '2') {
				if (this.model.gidgrp.rec.purpos == 'ISCO' || this.model.gidgrp.rec.purpos == 'ICCO') {
					this.model.addbcb.expdat = this.model.gidgrp.rec.liadat;
				} else {
					this.model.addbcb.expdat = this.model.gidgrp.rec.expdat;
				}
				this.model.addbcb.preexpdat = "";
			} else if (this.model.addbcb.bccls1 === '1') {
				// if (this.model.gidgrp.rec.purpos == 'ISSU') {
				//   this.model.addbcb.preexpdat = this.model.gidgrp.rec.expdat;
				// } else {
				//   this.model.addbcb.preexpdat = this.model.gidgrp.rec.liadat;
				// }
				this.model.addbcb.expdat = "";
			}
		},
		onIscrotra() {
			if (!(this.model.gidgrp.rec.hndtyp === 'OT' && this.model.gidgrp.rec.gartyp !== 'F')) {
				this.model.gidgrp.rec.iscrotra = ""
			}
		},
		handleSndto() {
			if (this.model.gidgrp.atb && this.model.gidgrp.atb.pts && this.model.gidgrp.atb.pts.extkey) {
				this.model.gidgrp.rec.sndto = "ATB";
			} else if (this.model.gidgrp.rec.purpos === "ISCO" || this.model.gidgrp.rec.purpos === "ICCO") {
				if (this.model.gidgrp.ben && this.model.gidgrp.ben.pts && this.model.gidgrp.ben.pts.extkey) {
					this.model.gidgrp.rec.sndto = "BEN";
				} else if (this.model.gidgrp.iss && this.model.gidgrp.iss.pts && this.model.gidgrp.iss.pts.extkey) {
					this.model.gidgrp.rec.sndto = "ISS";
				} else {
					this.model.gidgrp.rec.sndto = "";
				}
			} else {
				this.model.gidgrp.rec.sndto = "";
			}
		},
		max2FlagChange(val) {
			if (val === '') {
				this.model.gidgrp.cbs.max2.amt = 0;
				this.model.gidgrp.cbs.max2.cur = '';
				this.model.gidgrp.cbs.opn2.amt = 0;
				this.model.gidgrp.cbs.opn2.cur = '';
				this.model.gidgrp.cbs.total2.amt = 0;
				this.model.gidgrp.cbs.total2.cur = '';
			}
			this.changeMax2();
		},

		// preInput 原ovwp1面板
		changePurposin() {
			this.model.gidgrp.rec.purpos = "";
			this.model.gidgrp.rec.legfrm = '';
			if (this.model.gidgrp.rec.purposin === "ISCO") {
				this.model.gidgrp.rec.purpos = "ISSU";
				this.model.gidgrp.rec.hndtyp = "OT"
			}
			if (this.model.gidgrp.rec.purposin === "ICCO") {
				this.model.gidgrp.rec.purpos = "ISCO";
				this.model.gidgrp.rec.hndtyp = "OT"
			}
			this.changePurpos()
		},
		changeInc760() {
			if (this.model.gitp.inc760 !== "X") {
				this.model.gidgrp.rec.purposin = "";
				this.changePurposin()
			}
		},
		changePurpos() {
			this.handleChangePurpos(this.model.gidgrp.rec.purpos);

			if (this.model.gidgrp.rec.purpos === 'ISCO' || this.model.gidgrp.rec.purpos === 'ICCO') {
				this.model.gidgrp.rec.legfrm = this.model.gidgrp.rec.legfrm === "DEPU" ? "" : this.model.gidgrp.rec.legfrm;
			}

			this.model.gitp.prepercmodflg = '';
			this.model.gitp.covgodsrvcmodflg = '';
			if (this.model.gidgrp.rec.purposin === "ISCO") {
				this.model.gidgrp.rec.hndtyp = "OT"
				this.model.gitp.covgodsrvcmodflg = 'X';
				this.model.gitp.prepercmodflg = 'X';
			} else if (this.model.gidgrp.rec.purpos === 'ISCO' || this.model.gidgrp.rec.purpos === 'ICCO') {
				this.model.gidgrp.rec.hndtyp = "OC";
				this.defaultGidgrpRecSndtoN950();
				if (this.model.gidgrp.rec.purpos === 'ICCO') {
					this.model.gitp.covgodsrvcmodflg = 'X';
					this.model.gitp.prepercmodflg = 'X';
					let pts = new Pts().data;
					Utils.copyValueFromVO(this.model.gidgrp.iss.pts, pts);
				}
			} else if (this.model.gidgrp.rec.purpos === 'ISSU') {
				this.model.gidgrp.rec.hndtyp = "OL";
				this.model.gitp.prepermodflg = "X"
				this.model.gitp.covgodsrvmodflg = "X"
			} else if (this.model.gidgrp.rec.purpos === 'ACNF') {
				this.model.gidgrp.rec.hndtyp = "FI";
			} else if (this.model.gidgrp.rec.purpos === 'ADVI') {
				this.model.gidgrp.rec.hndtyp = "FA";
			} else {
				this.model.gidgrp.rec.hndtyp = "FR";
			}
			this.handleSndto();
			this.onAtxexptxt();
			this.change759();
      this.seqBSynToSeqB();
      this.changeGartyp();
		},
		handleChangeExpflg() {
			this.model.gidgrp.rec.expdat = '';
			// this.handleSynExpflg();
			this.changeExpflg();
		},
		// handleSynExpflg() {
		//     if (this.model.gidgrp.rec.purpos == 'ISCO' || this.model.gidgrp.rec.purpos == 'ICCO') {
		//       this.model.gidgrp.rec.liatypc = this.model.gidgrp.rec.exptyp
		//       this.model.gidgrp.rec.liaflg = this.model.gidgrp.rec.expflg
		//       if(this.model.gidgrp.rec.liaflg=="X"){
		//         this.handleChangeLiaflg()
		//       }else{
		//         this.changeLiatypc()
		//       }
		//     }
		// },

		// preInput 原ptyp面板
		handleChangeApl() {
			if (this.model.gidgrp.rec.purposin != 'ISCO') {
				// this.model.gidgrp.rec.ownref = "";
			}
			this.defaultGidgrpRecSndtoN950();
		},
		handleChangeCtr() {
			if (this.model.gidgrp.rec.purposin != 'ISCO') {
				// this.model.gidgrp.rec.ownref = "";
			}
			this.defaultGidgrpRecSndtoN950();
		},
		handleChangeBen() {
			if (this.model.gidgrp.rec.hndtyp == 'OT') {
				// this.model.gidgrp.rec.ownref = "";
			}
			this.defaultGidgrpRecSndtoN950();
		},
		// preInput 原aamp20面板
		changeMax2() {
			this.model.gidgrp.cbs.opn2.amt = this.model.gidgrp.cbs.max2.amt;
			this.model.gidgrp.cbs.opn2.cur = this.model.gidgrp.cbs.max2.cur;
			if (this.model.gidgrp.cbs.opn1.amt != "" && this.model.gidgrp.cbs.opn2.amt != "") {
				this.model.gidgrp.cbs.total2.amt = parseFloat(this.model.gidgrp.cbs.opn1.amt) + parseFloat(this.model.gidgrp.cbs.opn2.amt);
			} else {
				this.model.gidgrp.cbs.total2.amt = parseFloat(this.model.gidgrp.cbs.opn1.amt)
			}
			this.model.gidgrp.cbs.total2.cur = this.model.gidgrp.cbs.max2.cur;
			this.model.gidgrp.blk.addamtcovs20 = this.model.gidgrp.cbs.max2.cur + this.model.gidgrp.cbs.max2.amt;
			this.calcName()
		},

		// seqb 原ptyp面板
		handleChangeIss() {
			this.defaultGidgrpRecSndtoN950();
			this.handleSndto();
		},
		// seqb 原ptypc面板
		handleChangeBec() {
			this.handleSndto();
		},

		//seqb  原preperp面板
		handleChangeDelto() {
			this.model.gidgrp.blk.deltoadr = ""
			if (this.model.gidgrp.rec.delto === 'BENE') {
				this.model.gidgrp.blk.deltoadr = this.model.gidgrp.ben.pts.adrblk
			}
			if (this.model.gidgrp.rec.delto === 'OBLI') {
				this.model.gidgrp.blk.deltoadr = this.model.gidgrp.ctr.pts.adrblk
			}
		},
		changePrepermodflg() {
			if (this.model.gitp.prepermodflg === '' && this.model.gidgrp.blk.atxpreper !== "") {
				this.$confirm('Do you really want to redefault the standard text?\nIf you confirm all modifications are lost', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.model.gidgrp.blk.atxpreper = "";
				}).catch(() => {
					this.model.gitp.prepermodflg = 'X'
				});
			}
		},
		changeOpndat() {
			this.model.gidgrp.rec.orddat = this.model.gidgrp.rec.opndat
		},
		handleChangeLiadat() {
			if (this.model.gidgrp.rec.liatypc == "COND") {
				if (this.model.gidgrp.rec.liadat == null || this.model.gidgrp.rec.liadat == "") {
					this.model.gidgrp.rec.liaflg = "X"
				} else {
					this.model.gidgrp.rec.liaflg = ""
				}
			}
		},
		handleChangeExpdat() {
			if (this.model.gidgrp.rec.exptyp == "COND") {
				if (this.model.gidgrp.rec.expdat == null || this.model.gidgrp.rec.expdat == "") {
					this.model.gidgrp.rec.expflg = "X"
				} else {
					this.model.gidgrp.rec.expflg = ""
				}
			}
		},
		//seqb 原ovwp1面板
		handleChangeLiaflg() {
			this.model.gidgrp.rec.liadat = '';
			this.defaultGidgrpRecSndtoN950();
		},
		changeCovgodsrvmodflg() {
			if (this.model.gitp.covgodsrvmodflg === '' && this.model.gidgrp.blk.atxcovgodsrv !== "") {
				this.$confirm('Do you really want to redefault the standard text?\nIf you confirm all modifications are lost', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.model.gidgrp.blk.atxcovgodsrv = "";
				}).catch(() => {
					this.model.gitp.covgodsrvmodflg = 'X'
				});
			}
		},
		//seqc  原preperpc面板
		handleChangeDeltoc() {
			this.model.gidgrp.blk.deltoadrc = ""
			if (this.model.gidgrp.rec.deltoc === 'BENE') {
				this.model.gidgrp.blk.deltoadrc = this.model.gidgrp.bec.pts.adrblk
			}
		},
		//seqc  原ovwpc面板
		changeApprulc() {
			if (this.model.gidgrp.blk.apprulc !== 'OTHR') {
				this.model.gidgrp.blk.apprultxtc = '';
			}
		},
		//seqc  原ptypc面板
		handleChangeIssc() {
			this.handleSndto();
		},
		copyValueToCountrycod(val) {
			this.ejectOitWarning('cty', val, 'gidgrp.rec.countrycod');
			this.model.gidgrp.rec.countrycod = val;
			if (this.model.cfagit) {
				this.model.cfagit.recgrp.bas.bencountrycode = val;
				if (this.model.cfagit.recgrp.bas.modifySet) {
					if (!this.model.cfagit.recgrp.bas.modifySet.includes("bencountrycode")) {
						this.model.cfagit.recgrp.bas.modifySet.push("bencountrycode");
					}
				} else {
					this.model.cfagit.recgrp.bas.modifySet = ["bencountrycode"];
				}
			}
			if (this.model.rmbbop.rmb2122) {
				this.model.rmbbop.rmb2122.recgrp.ads.voucheecountrycode = val;
			}
		},
		apprulChange(val) {
			if (val !== 'OTHR') {
				this.model.gidgrp.blk.apprultxt = ''
			}
			this.seqBSynToSeqB();
		},
		deloriChange(val) {
			if (val !== 'OTHR' && val !== 'COUR') {
				this.model.gidgrp.rec.deloritxt = '';
			}
			this.seqBSynToSeqB();
		},
		deloricChange(val) {
			if (val !== 'OTHR' && val !== 'COUR') {
				this.model.gidgrp.rec.deloritxtc = '';
			}
		},
		checkGidtxt() {
			this.$nextTick(() => {
				this.root.$refs['modelForm'].validateField(['gidgrp.blk.gidtxt']);
			})
		},
		checkGidtxtc() {
			this.$nextTick(() => {
				this.root.$refs['modelForm'].validateField(['gidgrp.blk.gidtxtc']);
			})
		},

		async agreementSigning() {
			let data = {
				ftynum: this.model.gitp.yptgimod.img[0].ftynum
			}
			let res = await Api.post('/business/gitopn/agreementSigning', data);
			if (res.respCode == "AAAAAA") {

				this.model.gitp.xyflg = res.data;
				this.$notify({
					title: "成功",
					message: "协议盖章成功!",
					type: "success",
				});


			}
			else {
				this.$notify({
					title: '失败',
					message: '协议盖章调用失败,错误信息:' + res.respMsg,
					type: 'error',
				});
			}
		},

		// 切换cnfdet为WITHOUT时,清空con
		handleChangeCnfdet (e) {
			if (e === 'W') {
				this.$nextTick(() => {
					this.model.gidgrp.con.pts.extkey = ''
					if (this.$refs.ptapCon) {
						this.$refs.ptapCon.extkeyInput()
					}
				})
			}
		}
	},
};