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

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

        // 获取地区机构号列表
        async getOwnExtkeyCondition() {
            const loading = this.loading();
            let body = { ownExtKey: "" };
			let res = await Api.post('/business/bch/getBranchListByownExtKey',body);
			loading.close();
			if (res.respCode === SUCCESS) {
				this.ownExtkeyList = res.data;
            }
		},

        //签约变动勾选控制 + 采集标志赋值
        onCfaflgeca(e) {
			if (e === undefined) {
				return
			}
			switch (this.model.cfaeca.cfaflg) {
				case "1":
					this.model.cfaeca.basflg = 'X';
                    this.model.cfaeca.dclflg = 'X';
                    this.model.cfaeca.cfatyp = 'A';
					break;
				case "2":
					this.model.cfaeca.basflg = 'X';
                    this.model.cfaeca.dclflg = '';
                    this.model.cfaeca.cfatyp = 'M';
					break;
				case "3":
					this.model.cfaeca.basflg = '';
                    this.model.cfaeca.dclflg = 'X';
                    this.model.cfaeca.cfatyp = 'S';
					break;
				case "4":
					this.model.cfaeca.basflg = '';
                    this.model.cfaeca.dclflg = '';
                    this.model.cfaeca.cfatyp = '';
					break;
				default:
					this.model.cfaeca.basflg = '';
                    this.model.cfaeca.dclflg = '';
                    this.model.cfaeca.cfatyp = '';
			}
			
			if (this.model.cfaeca.cfaflg === "4" || this.model.cfaeca.cfaflg === "") {
                this.model.cfaeca.ownextkey = "";
                this.model.cfaeca.cdaflg = '';
			}
        },
        
        onCfaflgead(e) {
			if (e === undefined) {
				return
			}
			switch (this.model.cfaead.cfaflg) {
				case "1":
					this.model.cfaead.basflg = 'X';
                    this.model.cfaead.dclflg = 'X';
                    this.model.cfaead.cfatyp = 'A';
				
					break;
				case "2":
					this.model.cfaead.basflg = 'X';
                    this.model.cfaead.dclflg = '';
                    this.model.cfaead.cfatyp = 'M';
					break;
				case "3":
					this.model.cfaead.basflg = '';
                    this.model.cfaead.dclflg = 'X';
                    this.model.cfaead.cfatyp = 'S';
					break;
				case "4":
					this.model.cfaead.basflg = '';
                    this.model.cfaead.dclflg = '';
                    this.model.cfaead.cfatyp = '';
					break;
				default:
					this.model.cfaead.basflg = '';
                    this.model.cfaead.dclflg = '';
                    this.model.cfaead.cfatyp = '';
			}
			
			if (this.model.cfaead.cfaflg === "4" || this.model.cfaead.cfaflg === "") {
				this.model.cfaead.ownextkey = "";
			}
        },
        
        onCfaflgeaf(e) {
			if (e === undefined) {
				return
			}
			switch (this.model.cfaeaf.cfaflg) {
				case "1":
					this.model.cfaeaf.basflg = 'X';
                    this.model.cfaeaf.dclflg = 'X';
                    this.model.cfaeaf.cfatyp = 'A';
                    this.model.cfaeaf.cfabrttxt = '';
					break;
				case "2":
					this.model.cfaeaf.basflg = 'X';
                    this.model.cfaeaf.dclflg = '';
                    this.model.cfaeaf.cfatyp = 'M';
                    this.model.cfaeaf.cfabrttxt = '';
					break;
				case "3":
					this.model.cfaeaf.basflg = '';
                    this.model.cfaeaf.dclflg = 'X';
                    this.model.cfaeaf.cfatyp = 'S';
                    this.model.cfaeaf.cfabrttxt = '';
					break;
				case "4":
					this.model.cfaeaf.basflg = '';
                    this.model.cfaeaf.dclflg = '';
                    this.model.cfaeaf.cfatyp = '';
					break;
				default:
					this.model.cfaeaf.basflg = '';
                    this.model.cfaeaf.dclflg = '';
                    this.model.cfaeaf.cfatyp = '';
                    this.model.cfaeaf.cfabrttxt = '';
                    
			}
			
			if (this.model.cfaeaf.cfaflg === "4" || this.model.cfaeaf.cfaflg === "") {
				this.model.cfaeaf.ownextkey = "";
			}
        },

        onCfaflgcda(e) {
			if (e === undefined) {
				return
			}
			if(this.model.cfaeca.cdaflg!=='X'){
                this.model.cfaeca.cda.inr = '';
                this.model.cfaeca.cda.trninr = '';
                this.model.cfaeca.cda.cfeogudamount = '';
                this.model.cfaeca.cda.cfeogudcurr = '';
                this.model.cfaeca.cda.useofunds = '';
                this.model.cfaeca.cda.cfeogudad = '';
            }
        },
        
        //试算数据 进页签会触发
        async initCfabop(requestParams) {
            let cfabop = this.model.cfabop;
            if(cfabop == null){
                cfabop = this.model;
            }
            cfabop.buildParams = requestParams
           
            return this.queryCfabop(cfabop.buildParams);


        },

        //资本项目试算方法
        async queryCfabop(requestParams) {
            let cfabop = this.model.cfabop;
            if(cfabop == null){
                cfabop = this.model;
            }
            if (requestParams) {
                cfabop.buildParams = requestParams
            }
            //设置试算参数
            let cfaboppar = this.buildCfabop();
            //设置业务类型
            let busTyp = requestParams.transName.substr(0, 2) + "d";

            //调用后端试算接口
            let rtnmsg = await Api.post(`/${this.moduleRouter()}/${busTyp}/calcCfabop`, cfaboppar);
            if (rtnmsg.respCode == SUCCESS) {
                if(cfabop.cfaeca.basflg === 'X' || cfabop.cfaeca.dclflg === 'X'){
                    Utils.copyValueFromVoData(cfabop.cfaeca, rtnmsg.data.cfaeca);
                }
                if(cfabop.cfaead.basflg === 'X' || cfabop.cfaead.dclflg === 'X'){
                    Utils.copyValueFromVoData(cfabop.cfaead, rtnmsg.data.cfaead);
                }
                if(cfabop.cfaeaf.basflg === 'X' || cfabop.cfaeaf.dclflg === 'X'){
                    Utils.copyValueFromVoData(cfabop.cfaeaf, rtnmsg.data.cfaeaf);
                }
                
            }

            return rtnmsg;
        },

        //构建参数组
        buildCfabop() {
            let cfabop = this.model.cfabop;
            if(cfabop == null){
                cfabop = this.model;
            }

            let params = {
                ...cfabop.buildParams,
                cfaeca: cfabop.cfaeca,
                cfaead: cfabop.cfaead,
                cfaeaf: cfabop.cfaeaf,
            };
            return params;
        },

        
    }
}