import commonFunctions from "~/mixin/commonFunctions.js";
import Api from "~/service/Api";

import Pts from "~/page/Model/Common/Pts"

export default {
  mixins: [commonFunctions],
  methods: {
    async getOwnref() {
      if (this.model.ftdgrp.rec.fttyp == "") {
        this.$notify.warning({
          title: '提示',
          message: '请先选择定存拆借类型!'
        });
        return;
      }
      const loading = this.loading();
      let res = await Api.post(`/${this.moduleRouter()}/fttfcm/getRef`, this.model);
      loading.close();
      if (res.respCode !== SUCCESS) {
        this.$message.error(res.respMsg);
        return;
      }
      this.model.ftdgrp.rec.ownref = res.data;
    },

    async onFttypChange() {
      console.log("--------+++++---")
      if (this.model.ftdgrp.rec.fttyp =='LI'||
              this.model.ftdgrp.rec.fttyp =='DI'){
                this.model.ftdgrp.tri.pts=new Pts().data;
               
              }else if(this.model.ftdgrp.rec.fttyp =='LO'||
              this.model.ftdgrp.rec.fttyp =='DO'){
                this.model.fttp.troact='';
                this.model.ftdgrp.tro.pts=new Pts().data;
  
              }else{
                this.model.fttp.troact='';
                this.model.fttp.triact='';
                this.model.ftdgrp.tro.pts=new Pts().data;
                this.model.ftdgrp.tri.pts=new Pts().data;
                this.model.ftdgrp.act.pts=new Pts().data;
              }

      this.defaultSwtn99N1000();
    },

    async onMaxcurChange() {
      
      this.model.ftdgrp.cbs.ins.cur =this.model.ftdgrp.cbs.max.cur
      
      this.defaultFttpTroactN1200();
      this.defaultFttpTriactN1200();
      this.defaultSwtn99N1000();
    },


    async onMaxamtChange() {
      if (this.model.ftdgrp.cbs.max.amt !== "" && this.model.ftdgrp.cbs.max.amt !== null &&this.model.ftdgrp.cbs.max.amt !=0) {
        this.model.ftdgrp.cbs.ins.amt =this.model.ftdgrp.cbs.max.amt
      }

      this.defaultSwtn99N1000();
    },

  
    async onOpndatChange() {
      if (this.model.ftdgrp.rec.opndat !== "" && this.model.ftdgrp.rec.opndat !== null) {
        if (this.model.ftdgrp.rec.valdat == "" || this.model.ftdgrp.rec.valdat == null){
          this.model.ftdgrp.rec.valdat=this.model.ftdgrp.rec.opndat ;
        } 
      }
    },

    async onTriChange() {
     
    },

    async onTroChange() {
      this.defaultFttpTroactN1200();
    },

    async onTriRefChange() {
      console.log("--------+++++onTriRefChange")
      this.defaultSwtn99N1000();
    },

    async onTroRefChange() {
      console.log("--------+++++onTroRefChange")
      this.defaultSwtn99N1000();
    },


    
    async onActChange() {
      this.defaultFttpTriactN1200();
      
    },

    async onTriactChange() {
      this.defaultSwtn99N1000();
    },


    async onValdatChange() {
      this.defaultSwtn99N1000();
    },

    async onMatdatChange() {
      this.defaultSwtn99N1000();
    },

    async onInscurChange() {
      this.defaultSwtn99N1000();
    },

    async onInsamtChange() {
      this.defaultSwtn99N1000();
    },

    async onRatChange() {
      this.defaultSwtn99N1000();
    },


    async onCntfraChange() {
      console.log("--------+++++")
      this.defaultSwtn99N1000();
    },

    async defaultSwtn99N1000(){
      if (this.model.fttp.msgtyp !='199' && this.model.fttp.msgtyp !='299'){
        return;
      }


      const loading = this.loading();
      let res = await Api.post(`/${this.moduleRouter()}/fttfcm/defaultSwtn99N1000`, this.model);
      loading.close();
      if (res.respCode !== SUCCESS) {
        this.$message.info(res.respMsg);
        return;
      }
      
      this.model.narblk = res.data.narblk;
      this.model.relref = res.data.relref;
      
    },



    async defaultFttpTroactN1200(){
      console.log("--------defaultFttpTroactN1200()")
      if (this.model.ftdgrp.act.pts.ptainr == ""||this.model.ftdgrp.act.pts.ptainr == undefined) {
        return;
      }
      if (this.model.ftdgrp.cbs.max.cur == ""||this.model.ftdgrp.cbs.max.cur == undefined) {
          return;
      }
      
      const loading = this.loading();
      let res = await Api.post(`/${this.moduleRouter()}/fttfcm/defaultFttpTroactN1200`, this.model);
      loading.close();
      if (res.respCode !== SUCCESS) {
          this.$message.info(res.respMsg);
          return;
      }
      this.troActlist=res.data;
      if(this.troActlist.length>0 && (this.model.troact ==""||this.model.troact ==undefined)){
        this.model.troact=troActlist[0];
      }
    },

    async defaultFttpTriactN1200(){
      console.log("--------defaultFttpTriactN1200()")
      if (this.model.ftdgrp.act.pts.ptainr == ""||this.model.ftdgrp.act.pts.ptainr == undefined) {
        return;
      }
      if (this.model.ftdgrp.cbs.max.cur == ""||this.model.ftdgrp.cbs.max.cur == undefined) {
          return;
      }
      const loading = this.loading();
      let res = await Api.post(`/${this.moduleRouter()}/fttfcm/defaultFttpTriactN1200`, this.model);
      loading.close();
      if (res.respCode !== SUCCESS) {
          this.$message.info(res.respMsg);
          return;
      }
      this.triActlist=res.data;
      if(this.triActlist.length>0 && (this.model.triact ==""||this.model.triact ==undefined)){
        this.model.triact=triActlist[0];
      }
      
    },


  },
};