import commonFunctions from '~/mixin/commonFunctions.js';
import moment from 'moment';
import Utils from "~/utils/index";
import Pts from '~/components/business/commonModel/Pts';
import Api from "~/service/Api";
export default {
  mixins: [commonFunctions],
  methods: {
    //获取卖方信用证编号
    async onDetpButgetref() {
      let ptainr = this.model.dedgrp.ben.pts.ptainr;
      let ownref = this.model.dedgrp.rec.ownref;
      let trnName = "DETOPN"
      const loading = this.loading();
      let res = await Api.post(`/Domlc/ref/ded?ptaInr=${ptainr}&ownref=${ownref}&trnName=${trnName}`);
      loading.close();
      if (res.respCode == SUCCESS) {
        this.model.dedgrp.rec.ownref = res.data;
      } else {
        this.$message.error(res.respMsg);
      }
    },
//自开自议
    async dedBydid() {
      if (this.model.spt.channel== 'ELC' || this.model.spt.channel == 'YPT') {
        this.dedBydidELC()
      }else{
    const loading = this.loading();
    let res = await Api.post("/Domlc/detopnRule/dedBydid", { ...this.model.dedgrp });
    if (res.respCode == SUCCESS) {
      loading.close();
      this.model.dedgrp = res.data.dedgrp;
      this.model.flg = res.data.flg;
      if(res.data.flg=="Y"){
        this.$notify({
          title: '成功',
          message: "获取开证信息成功",
          type: 'success',
        });
      }
      else if(res.data.flg=="S"){
        this.$notify({
          title: '失败',
          message: "非本机构数据",
          type: 'error',
        });
      }else{
        this.$notify({
          title: '失败',
          message: "未找到该笔开证",
          type: 'error',
        });
      }
    } else {
      loading.close();
    }
    this.smallToBig();
    this.OnAvbby();
    this.OnIsyifu();
    this.OnBdflg();
    // this.OnShppar();
    // this.OnFqzytgfw();
    this.OnTratyp();
    this.OnMytype();
    this.nomtopChange();
  }
},
    OnAvbby() {
      let modifyList = this.model.dedgrp.blk.modifySet
      if (this.model.dedgrp.rec.avbby == 'P') {
        this.model.dedgrp.rec.tenmaxday = 0
      }
      if (this.model.dedgrp.rec.avbby != 'D') {
        this.model.dedgrp.blk.defdet = ""
      }
      if (this.model.dedgrp.rec.avbby == 'P' || this.model.dedgrp.rec.avbby == 'N') {
        if (this.model.dedgrp.rec.avbby == 'P') {
          if (!modifyList || (!!modifyList && !modifyList.includes('dftat'))) {
            this.model.dedgrp.blk.dftat = "即期"
          }
        }
      } else {
        this.model.dedgrp.blk.dftat = ""
      }
    },
    async OnRejflg() {
      if (this.model.dedgrp.rec.rejflg == "ADRE" && !this.model.detp.dzlhhh) {
        let ptainr = this.model.dedgrp.ben.pts.ptainr;
        const loading = this.loading();
        let res = await Api.post(`/Domlc/detopnRule/getDzlhhh?ptainr=${ptainr}`);
        if (res.respCode == SUCCESS) {
          loading.close();
          this.model.detp.dzlhhh = res.data;
        } else {
          loading.close();
        }
      }
      if (this.model.dedgrp.rec.rejflg != "ADRE") {
        this.model.dedgrp.blk.rejadvrsn = ""
        this.model.detp.dzlhhh = ""
      }
    },
    OnIsyifu() {
      if (this.model.dedgrp.rec.isyifu != 'Y') {
        this.model.dedgrp.rec.avbwth = ""
        this.model.dedgrp.avb.pts.bankno = ""
        this.model.dedgrp.avb.pts.jigomc = ""
        this.model.dedgrp.avb.pts.dizhii = ""
      }
    },
    avbwthChange() {
      switch (this.model.dedgrp.rec.avbwth) {
        case "A":
          Utils.copyValueFromVoData(this.model.dedgrp.avb.pts, this.model.dedgrp.adv.pts);
          this.model.dedgrp.avb.pts.rol = "AVB";
          break;
        case "T":
          Utils.copyValueFromVoData(this.model.dedgrp.avb.pts, this.model.dedgrp.cmb.pts);
          this.model.dedgrp.avb.pts.rol = "AVB";
          break;
        case "I":
          Utils.copyValueFromVoData(this.model.dedgrp.avb.pts, this.model.dedgrp.iss.pts);
          this.model.dedgrp.avb.pts.rol = "AVB";
          break;
        case "C":
          Utils.copyValueFromVoData(this.model.dedgrp.avb.pts, this.model.dedgrp.rmb.pts);
          this.model.dedgrp.avb.pts.rol = "AVB";
          break;
        default:
          this.model.dedgrp.avb.pts = new Pts().data;
          this.model.dedgrp.avb.pts.rol = "AVB";
          break;
      }
    },
    OnBdflg() {
      if (this.model.dedgrp.rec.bdflg != 'Y') {
        this.model.dedgrp.rmb.pts.bankno = ""
        this.model.dedgrp.rmb.pts.jigomc = ""
        this.model.dedgrp.rmb.pts.dizhii = ""
      }
    },
    OnShppar() {
      if (this.model.dedgrp.rec.shppar != 'ALWD') {
        this.model.dedgrp.rec.fqzytgfw = "";
        this.model.dedgrp.rec.fqtime = ""
      }
    },
    OnFqzytgfw() {
      if (this.model.dedgrp.rec.fqzytgfw != 'Y') {
        this.model.dedgrp.rec.fqtime = ""
      }
    },
    OnTratyp() {
      if (this.model.dedgrp.rec.tratyp == '08' || this.model.dedgrp.rec.mytype == 'F') {
      } else {
        this.model.dedgrp.rec.sdsrfs = ""
      }
    },
    OnMytype() {
      let modifyList = this.model.dedgrp.rec.modifySet
      if (this.model.dedgrp.rec.mytype == 'F') {
        if (!modifyList || (!!modifyList && !modifyList.includes('stagod'))) {
          this.model.dedgrp.rec.stagod = '099'
        }
        this.model.dedgrp.rec.shptrs = "";
        this.model.dedgrp.rec.shpfro = "";
        this.model.dedgrp.rec.shpto = "";
        this.model.dedgrp.rec.tratyp = "";
      } else {
        if (!modifyList || (!!modifyList && !modifyList.includes('stagod'))) {
          this.model.dedgrp.rec.stagod = ''
        }
      }
      if (this.model.dedgrp.rec.mytype == 'H') {
        this.model.dedgrp.rec.shppro = "";
      }
    },
    nomtopChange() {
      this.OnMaxamt();
    },
    async getActList() {
      if (this.model.spt.channel == 'ELC' || this.model.spt.channel == 'YPT') {
      }else{
      if (this.model.dedgrp.ben.pts.ptyinr != "") {
        let datas = {
          ptyinr: this.model.dedgrp.ben.pts.ptyinr,
        }
        const loading = this.loading();
        let res = await Api.post(`/Domlc/detopnRule/getActList`, datas);
        if (res.respCode == SUCCESS) {
          loading.close();
          this.$set(this.codes, 'actset', res.data.actset);
          if (res.data.actset && res.data.actset.length >= 1) {
            this.model.dedgrp.ben.pts.extact = res.data.actset[0];
          }
        } else {
          loading.close();
        }
      }
    }
    },
  }
};