import commonFunctions from '~/mixin/commonFunctions.js';
import Api from '~/service/Api';
import buildFn from './buildCommons.js';
import Utils from '~/utils';
export default {
  mixins: [commonFunctions,buildFn],
  methods: {
    addamtflgChange(){
      if(this.model.swiadd.addamtflg==""){
        this.model.swiadd.addamtcovs20="";
        this.model.swiadd.addamt="0.00";
      }
    },
    addamtChange(){
      if(this.addamtcovs20Flg!="X"&&this.model.swiadd.addamt!=""&&this.model.swiadd.addamt!="0.00"){
        this.model.swiadd.addamtcovs20=this.model.swiadd.addcur+" "+this.model.swiadd.addamt;
        this.model.gidgrp.cbs.max2.amt=this.model.swiadd.addamt;
        this.model.gidgrp.cbs.max2.cur=this.model.swiadd.addcur;
        this.model.gidgrp.blk.addamtcovs20= this.model.swiadd.addamtcovs20
      }
    },
    addamtcovs20Change(){
      this.addamtcovs20Flg="X";
      this.model.gidgrp.blk.addamtcovs20= this.model.swiadd.addamtcovs20
    },
    //到期条件
		ChangeExptxt(){
			//default GIDGRP\BLK\EXPTXT order 1200
			//如果swiadd的到期条件是空,就把oldgidgrp的到期条件传给gidgrp
			if(this.model.swiadd.exptxt!=""){
				this.model.gidgrp.blk.exptxt = this.model.swiadd.exptxt;
			}else{
				this.model.gidgrp.blk.exptxt = this.model.oldgidgrp.blk.exptxt;
			}
		},
    //Ameps20页面
		ChangeNewamt(){
			if(!this.model.swiadd.newamt || this.model.swiadd.newamt == "-"){
				this.model.swiadd.newamt = "0"
			}
			this.model.swiadd.ameamt = new BigNumber(this.model.swiadd.newamt).minus(new BigNumber(this.model.oldgidgrp.cbs.max.amt));
			//DNGDEV.000389
			this.model.gidgrp.cbs.max.amt = this.model.swiadd.newamt ; 		
		},
    //到期类型
		ChangeExptyp() {
			//default order 2500
			if(this.model.swiadd.exptyp){
				this.model.gidgrp.rec.exptyp = this.model.swiadd.exptyp;
			}else{
				this.model.gidgrp.rec.exptyp = this.model.oldgidgrp.rec.exptyp
			}
			//类型切换的时候把条件和到期日置为空
			this.model.swiadd.exptxt = '';
			this.model.swiadd.newexpdat = '';	
    },
    //责任类型
		ChangeLiatypc(){
			//default GIDGRP\REC\LIATYPC order 2500
			if(this.model.swiadd.liatypc!=""){
				this.model.gidgrp.rec.liatypc = this.model.swiadd.liatypc;
			}else{
				this.model.gidgrp.rec.liatypc = this.model.oldgidgrp.rec.liatypc;
      }
      if(this.model.swiadd.liatypc=="OPEN"){
        this.model.gidgrp.rec.liaflg="X";
      }
      else{
        this.model.gidgrp.rec.liaflg="";
      }
			//类型切换的时候把条件和到期日置为空
			this.model.swiadd.newliadat = '';
			this.model.swiadd.liatxtc = '';
    },
    //责任截止日
		ChangeLiadat(){
			//default GIDGRP\REC\LIADAT order 10000
			// if(this.model.swiadd.newliadat || this.model.swiadd.liatypc == 'OPEN'){
			// 	this.model.gidgrp.rec.liadat = '';
			// }else{
			// 	if(this.model.swiadd.newliadat){
			// 		this.model.gidgrp.rec.liadat = this.model.swiadd.newliadat ; 
			// 	}else{
			// 		if(this.model.swiadd){

			// 		}
			// 	}
					
			// }

			this.model.gidgrp.rec.liadat = this.model.swiadd.newliadat;
		},
		//责任条件
		ChangeLiatxtc(){
			this.model.gidgrp.blk.liatxtc = this.model.swiadd.liatxtc;
		},
		//预计到期日
		ChangeDtaappexpdat(){
			this.model.gidgrp.blk.dtaappexpdat = this.model.swiadd.newdtaappexpdat;
    },
    //到期日
		ChangeExpdat(){
			this.model.gidgrp.rec.expdat = this.model.swiadd.newexpdat;
    },
    //概要面板初始化,适用法律--gidgrp.rec.jurlaws20
		changeJurlaws20() {
			this.model.gidgrp.rec.jurlaw =this.model.gidgrp.rec.jurlaws20;
    },
    // amemsgdonflgChange(){
    //   if(this.model.swiadd.amemsgdonflg==""){
    //     this.model.gitamep.ametxtflg="";
    //   }
    // },
    onApprul(){

    },
    // 获取记账机构下拉列表
		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.markOrgList = res.data;
			}
    },
  
		async getApprulList() {
			let data = {
				dbcode: 'apprul',
        transName: 'GETAME',
        legfrm: this.model.gidgrp.rec.legfrm       
			}
			const loading = this.loading();
			let res = await Api.post('/business/getameRule/getApprulData', data);
			loading.close();
			if (res.respCode === SUCCESS) {
				this.apprulList = res.data;
			}
		},
		async onAmebutButtxmsel() {
				const rtnmsg = await Api.post('/business/getame/buttxmsel', this.model);
				if (rtnmsg.respCode === SUCCESS) {
						//TODO 处理数据逻辑

				} else {
						this.$notify.error({title: '错误', message: '服务请求失败!'});
				}
		},
		async query2122(){
			let trnName = this.root ? this.root.trnName : this.trnName
			if (this.model.rmbbop.rmb2122.rmbflg == '1') {
				let rmbbop = this.buildRobbop(this.model, trnName);
        let opertype = "2";
        let rtnmsg = await Api.post('/business/rmbbopgid/rmbbop2122Cal', rmbbop);
        if (rtnmsg.respCode == SUCCESS) {
          Utils.copyValueFromVoData(this.model.rmbbop.rmb2122,rtnmsg.data.rmb2122);
          this.model.rmbbop.rmb2122.recgrp.ads.opertype = opertype;
        }
			}
		},

  },
};