import commonFunctions from '../../../../../../mixin/commonFunctions.js';
import commonDepend from "../../../../../../mixin/commonDepend";
import Api from "~/service/Api"
import event from "../../tfb/event"
export default {
	mixins: [event,commonFunctions,commonDepend],
	methods:{
		
		async getRef(){
			if(this.model.recgrp.ads.banktrano.length == 0){
				this.$notify({
					title: "获取业务主键失败",
					message: "获取业务主键失败,请先输入银行业务编号",
					type: "title",
				});
				return;
			}
			let data = {
				rmbtyp:"TFB",
				banktrano:this.model.recgrp.ads.banktrano
			}
			let rtnmsg = await Api.post('/report/rmbsel/getRef', data);
			if (rtnmsg.respCode == SUCCESS) {
				this.model.recgrp.ads.levyno = rtnmsg.data
			}else{
				this.$notify({
					title: "失败",
					message: "获取业务主键失败",
					type: "error",
				});
			}
		},
		async checkTfb(){
			this.$refs['modelForm'].validate(async (validStatic) => {
				if (validStatic) {
					let data = {
						inr:"",
						ownextkey:this.model.rmbbut.ownextkey,
						reldat: this.model.pblmod.pbl.reldat,
						tfbgrp:this.model.recgrp
					}
					const loading = this.loading('正在校验数据');
					const rtnmsg = await Api.post('/report/rmb2103/validate2103', data);
					if (rtnmsg.respCode == SUCCESS) {
						const fieldErrors = rtnmsg.data;
						if (fieldErrors && Object.keys(fieldErrors).length == 0) {
							// 清除之前的校验状态
							this.$refs.modelForm.clearValidate();
							this.$notify({
								title: "成功",
								message: "校验成功",
								type: "success",
							});
							loading.close();
							return
						}
						const tab = this.showBackendErrors(fieldErrors);
						if (tab) {
							// 判断校验失败的表单不属于当前的tab,则切换tab到对应报错的tab页面
							if (tab.name !== this.tabVal) {
								this.tabClick(tab, '1');
							}
						}
						loading.close();
					}
				} else {
					// 前端校验失败
					this.$notify({
						title: '失败',
						message: '校验失败',
						type: 'error',
					});
				}
			})
		},
		async outtips(){
			this.$notify({
				title: "提示",
				message: "境内银行填写银行机构代码,人民币业务清算行及境外参加行填写SWIFT BIC   ",
				type: "error",
			})
		},
		async intips(){
			this.$notify({
				title: "提示",
				message: "境内银行填写银行机构代码,香港清算行、澳门清算行、香港参加行、澳门参加行、境外参加行填写SWIFT BIC	",
				type: "error",
			})
		},
		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;
			}
		},
	}
}