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


export default {
	mixins: [commonFunctions],
	methods: {

		// 获取记账机构下拉列表
		// async queryOrgList() {
		//   const loading = this.loading();
		//   let res = await Api.post('/business/userinfo/user/getAccBchList', {
		//     bchkeyinr: this.model.gidgrp.rec.bchkeyinr
		//   });
		//   loading.close();
		//   if (res.respCode === SUCCESS) {
		//     this.model.markOrgList = res.data;
		//     if (this.model.markOrgList.length == 1) {
		//       this.model.gidgrp.rec.bchkeyinr = this.model.markOrgList[0].inr;
		//     }
		//   }
		// },

		onExpflg() {
			if (this.model.gidgrp.rec.expdat == "") {
				this.model.gidgrp.rec.expflg = "X"
			} else {
				this.model.gidgrp.rec.expflg = "";
			}
		},

		//适用法律--gidgrp.rec.jurlaws20
		changeJurlaws20() {
			// this.model.gidgrp.rec.jurlaw = this.model.gidgrp.rec.jurlaws20
		},


		// 点击获取按钮拉取当前key字段下的表单数据
		queryFormData(key) {
			console.log(key);
		},
		//获取当前用户机构是否自贸区
		getZmqflg(){
			let _this = this
			if (_this.model.gidgrp.rec.oppbnk !== "")//如果对手行有信息就设置X
				_this.model.zmqflg = "X";
			else
				_this.model.zmqflg = JSON.parse(window.sessionStorage.accbch).zmqflg;
			//赋值opbnk
			if(this.model.zmqflg === "X" && this.model.gidgrp.iss.pts.extkey !== "")
				this.model.gidgrp.rec.oppbnk = this.model.gidgrp.iss.pts.extkey.slice(0, 11);
			},
		apprul() {
			if (this.isInDisplay) {
				return;
			}
			if (!this.model.spt) {
				if (this.model.gidgrp.rec.legfrm != 'STBY') {
					this.model.gidgrp.rec.reccnfdet = ''
				}
			}
			let modifyList = this.model.gidgrp.blk.modifySet
			if (this.model.gidgrp.rec.legfrm == 'DGAR') {
				if (!modifyList || (!!modifyList && !modifyList.includes('apprul'))) {
					this.model.gidgrp.blk.apprul = 'URDG'
				}
			} else if (this.model.gidgrp.rec.legfrm == 'STBY') {
				if (!modifyList || (!!modifyList && !modifyList.includes('apprul'))) {
					this.model.gidgrp.blk.apprul = 'OTHR'
				}
			} else {
				if (!modifyList || (!!modifyList && !modifyList.includes('apprul'))) {
					this.model.gidgrp.blk.apprul = 'NONE'
				}
			}
		},

		onInc760() {
			let purposin = this.model.gidgrp.rec.purposin;
			if (!this.model.gitp.inc760) {
				this.model.gidgrp.rec.purposin = ''
			}
			if (this.model.spt && this.model.spt.sta == 'INC') {
				this.model.gidgrp.rec.purposin = purposin;
			}
		},

		onPurposin() {
			if (this.model.gidgrp.rec.purposin == 'ISSU') {
				this.model.gidgrp.rec.purpos = 'ADVI',
					this.model.gidgrp.rec.hndtyp = 'FA'
			}
		},
		onPurpos() {
			if (this.model.gidgrp.rec.purpos == 'ADVI') {
				this.model.gidgrp.rec.hndtyp = 'FA'
			} else {
				this.model.gidgrp.rec.hndtyp = ''
			}
			this.onOrddat()
		},
		onApprul() {
			if (this.model.gidgrp.blk.apprul != 'OTHR') {
				this.model.gidgrp.blk.apprultxt = ''
			}
		},
		onExptyp() {
			let modifyList = this.model.gidgrp.rec.modifySet
			if ((!this.model.gidgrp.rec.exptyp) && (!modifyList || (!!modifyList && !modifyList.includes('exptyp')))) {
				if (this.model.gidgrp.rec.expflg != '') {
					this.model.gidgrp.rec.exptyp = 'OPEN'
				} else if (this.model.gidgrp.rec.expdat != '') {
					this.model.gidgrp.rec.exptyp = 'FIXD'
				}
			}
			if (this.model.gidgrp.rec.exptyp == '' || this.model.gidgrp.rec.exptyp == 'OPEN') {
				this.model.gidgrp.rec.expdat = ''
			}
			if (this.model.gidgrp.rec.exptyp != 'COND') {
				this.model.gitp.exptxtmodflg = ''
			}
			this.onExpflg()
			// if (this.model.gidgrp.rec.modifySet.includes('exptyp')) {
			//   if (this.model.gidgrp.rec.exptyp == 'OPEN') {
			//     this.model.gidgrp.rec.expflg = 'X'
			//   } else {
			//     this.model.gidgrp.rec.expflg = ''
			//   }
			// }
		},
		defaultVouflg() {
			//2122
			if (this.model.gidgrp.cbs.max.cur == "CNY") {
				if (!this.model.gidgrp.rec.cmtflg) {
					this.model.cnybop.vouflg = ""
				}
			}
		},
		async loadBopCtyList() {
			const loading = this.loading();
			let res = await Api.post('/business/gitopn/loadBopCtyList');
			loading.close();
			if (res.respCode === SUCCESS) {
				this.model.bopCtyList = res.data;
			}
		},
		change2122Rmbflg() {
			if (this.isInDisplay) {
				return;
			}
			if (this.model.spt.inr) {
			} else {
				if (this.model.gidgrp.cbs.max.cur == 'CNY') {
					if (this.model.gidgrp.rec.cmtflg && this.model.gidgrp.rec.cmtflg == 'X') {
						this.model.rmbbop.rmb2122.rmbflg = '1';
					} else {
						this.model.rmbbop.rmb2122.rmbflg = '2';
					}
				} else if (this.model.gidgrp.cbs.max.cur && this.model.gidgrp.cbs.max.cur != 'CNY') {
					this.model.rmbbop.rmb2122.rmbflg = '';
				} else {
					this.model.rmbbop.rmb2122.rmbflg = '2';
				}
			}
		},
		//   max2FlagChange(val) {
		//     if (val === '') {
		//         this.model.gidgrp.cbs.max2.amt = 0;
		//         this.model.gidgrp.cbs.max2.cur = '';
		//     }else{
		//       this.model.gidgrp.cbs.max2.cur = this.model.gidgrp.cbs.max.cur;
		//     }
		// },
		//保函币种--"gidgrp.cbs.max.cur"
		changeCur() {
			this.model.gidgrp.cbs.opn1.cur = this.model.gidgrp.cbs.max.cur;
			this.model.gidgrp.cbs.max2.cur = this.model.gidgrp.cbs.max.cur;
			this.calcName()
		},
		calcName() {
			this.model.gidgrp.cbs.opn1.amt = this.model.gidgrp.cbs.max.amt
			this.model.gidgrp.rec.nam = this.model.gidgrp.ben.pts.nam
		},
		onOrddat() {
			if (this.isInDisplay) {
				return;
			}
			this.onIss()
			let modifyList = this.model.gidgrp.rec.modifySet
			if (!modifyList || (!!modifyList && !modifyList.includes('orddat'))) {
				this.model.gidgrp.rec.orddat = moment().format('YYYY-MM-DD');
			}
		},
		onIss() {
			if (this.model.gidgrp.rec.hndtyp != 'FA') {
				this.model.gidgrp.iss.pts.ref = ""
			}
		}
	},
}
//你可以添加自动default处理