import Api from '~/service/Api';
import commonFunctions from '~/mixin/commonFunctions.js';
import buildFn from './buildCommons.js';
import Utils from "~/utils";
import Pts from '~/components/business/commonModel/Pts';
import moment from "moment";

export default {
  mixins: [commonFunctions],
  methods: {
    // rmbrol角色改变,则将相应的角色的值赋值给偿付信息的rmbrmb角色
    rmbrolChange(){

      switch (this.model.rmbclm.rmbrol) {
        case "ADV":
          Utils.copyValueFromVoData(this.model.rmbclm.rmbrmb.pts, this.model.ledgrp.adv.pts);
          break;
        case "AVB":
          Utils.copyValueFromVoData(this.model.rmbclm.rmbrmb.pts, this.model.ledgrp.avb.pts);
          break;
        case "ISS":
          Utils.copyValueFromVoData(this.model.rmbclm.rmbrmb.pts, this.model.ledgrp.iss.pts);
          break;
        case "CON":
          Utils.copyValueFromVoData(this.model.rmbclm.rmbrmb.pts, this.model.ledgrp.con.pts);
          break;
        case "RMB":
          Utils.copyValueFromVoData(this.model.rmbclm.rmbrmb.pts, this.model.ledgrp.rmb.pts);
          break;
        case "OTH":
          this.model.rmbclm.rmbrmb.pts = new Pts().data;
          break;
        default:
          this.model.rmbclm.rmbrmb.pts = new Pts().data;
          break;
      }

      if(this.model.rmbclm.rmbrmb.pts.ptainr!=''){
        this.model.rmbclm.rmbrmb.pts.rol = "RMBRMB";
      }
    },

    // 如果rmbclnow的值改变,且rmbrol的角色没有被修改过,如果rmbclnow没有被选中,则rmbrol为“ISS”,如果选中了,则修改rmbrol值为“RMB”
    // 值改变时,addphr的值需要改变
    rmbclmnowChange(){

      if(this.model.rmbclmnow ==='X'){
        // rmbrol is not modifed
        if(this.model.rmbclm.modifySet==null || !this.model.rmbclm.modifySet.includes("rmbrol")){
          this.model.rmbclm.rmbrol = "RMB";
          this.rmbrolChange();
        }
      } else{
        this.model.rmbclm.rmbrol = "";
        this.rmbrolChange();
      }

      this.defaultBedsndAddphrN1000();

    },

    // 值改变时,addphr的值需要改变
    rmbclmlateChange(){
      this.defaultBedsndAddphrN1000();
    },

    // matdat改变,如果不为空,则会disable matper,且清空其值
    matdatChanged(value){
      if(value != null && value != '' || this.model.bedgrp.rec.doctypcod == 'P'){
        this.model.bedgrp.blk.matper = '';
      }

      // 到期日matdat 小于 交单日rcvdat,给出提示
      if (value != '' && value != null) {

        if (this.model.bedgrp.rec.rcvdat != '' && this.model.bedgrp.rec.rcvdat != null) {

          if (moment(value).diff(moment(this.model.bedgrp.rec.rcvdat), 'days') <0) {

            this.$confirm('The Maturity Date is before the Received on date, are you sure? ', '', {
              confirmButtonText: 'Yes',
              cancelButtonText: 'No',
              type: 'warning',
              showClose: false
            }).then(() => {//yes的执行在这里写
              // do nothing
            }).catch(() => {//No的功能在这里写
              // clear the matdat
              this.model.bedgrp.rec.matdat = ''
            });
          }
        }

      }

    },

    // matper改变,如果不为空,则会disable matdat,且清空其值
    matperChanged(value){
      if(value != '' || this.model.bedgrp.rec.doctypcod == 'P'){
        this.model.bedgrp.rec.matdat = '';
      }
    },

    docrolChange(value){

      switch (this.model.bedgrp.rec.docrol) {
        case "APL":
          Utils.copyValueFromVoData(this.model.bedgrp.doc.pts, this.model.ledgrp.apl.pts);
          break;
        case "BEN":
          Utils.copyValueFromVoData(this.model.bedgrp.doc.pts, this.model.ledgrp.ben.pts);
          break;
        case "ADV":
          Utils.copyValueFromVoData(this.model.bedgrp.doc.pts, this.model.ledgrp.adv.pts);
          break;
        case "AVB":
          Utils.copyValueFromVoData(this.model.bedgrp.doc.pts, this.model.ledgrp.avb.pts);
          break;
        case "ISS":
          Utils.copyValueFromVoData(this.model.bedgrp.doc.pts, this.model.ledgrp.iss.pts);
          break;
        case "CON":
          Utils.copyValueFromVoData(this.model.bedgrp.doc.pts, this.model.ledgrp.con.pts);
          break;
        case "RMB":
          Utils.copyValueFromVoData(this.model.bedgrp.doc.pts, this.model.ledgrp.rmb.pts);
          break;
        case "TRB":
          Utils.copyValueFromVoData(this.model.bedgrp.doc.pts, this.model.ledgrp.trb.pts);
          break;
        case "A2B":
          Utils.copyValueFromVoData(this.model.bedgrp.doc.pts, this.model.ledgrp.a2b.pts);
          break;
        case "APB":
          Utils.copyValueFromVoData(this.model.bedgrp.doc.pts, this.model.ledgrp.apb.pts);
          break;
        case "DRW":
          Utils.copyValueFromVoData(this.model.bedgrp.doc.pts, this.model.ledgrp.drw.pts);
          break;
        case "OTH":
          this.model.bedgrp.doc.pts = new Pts().data;
          break;
        default:
          this.model.bedgrp.doc.pts = new Pts().data;
          break;
      }

      // 如果doc角色有值,则将其角色赋值为'DOC'
      if(this.model.bedgrp.doc.pts.extkey!=''){
        this.model.bedgrp.doc.pts.rol = "DOC";
      }
    },

    /**
     *   source:betsnd.0034.script
     */

    defaultBedsndAddphrN1000(){

      if(!this.model.bedsnd.modifySet || (this.model.bedsnd.modifySet!=null && !this.model.bedsnd.modifySet.includes("addphr")))
      {
        if( this.model.rmbclmlate!=null && this.model.rmbclmlate!='' )
        {
          this.model.bedsnd.addphr = 'WE SHALL CLAIM ON THE REIMBURSING BANK ACCORDING TO YOUR INSTRUCTIONS';
        }
        else
        {
          if( this.model.rmbclmnow!=null && this.model.rmbclmnow!='' )
          {
            this.model.bedsnd.addphr = 'WE HAVE TODAY CLAIMED ON THE REIMBURSING BANK ACCORDING TO YOUR INSTRUCTIONS';
          }
        }
      }
    }

  },
};