<template>
  <div class="eibs">
    <c-collapse v-model="activeNames">
      <el-collapse-item title="Extend Usance" name="brteus">
        <m-brteus :model="model" :codes="codes" />
      </el-collapse-item>
      <el-collapse-item title="Liabilities" name="acceptlinep">
        <m-acceptlinep ref="setp" :model="model" :codes="codes" @changeMatdat="changeMatdat" />
      </el-collapse-item>
      <el-collapse-item title="Parties" name="ptyp">
        <m-ptyp :model="model" :codes="codes" />
      </el-collapse-item>
    </c-collapse>
  </div>
</template>

<script>
import event from "../event";
import Brteus from "./BrteusPanel";
import Ptyp from "./Ptyp";
import AcceptLine from "~/components/business/engp/views/AcceptLine.vue";
import moment from "moment";

export default {
  components: {
    "m-brteus": Brteus,
    "m-ptyp": Ptyp,
    "m-acceptlinep": AcceptLine,
  },
  inject: ["root"],
  props: ["model", "codes"],
  mixins: [event],
  data() {
    return {
      activeNames: ["brteus", "acceptlinep", "ptyp"],
      matdatChangeMap: {},
    };
  },
  methods: {
    changeMatdat(liaallg) {
      console.log("liaallg", liaallg);
      let matdat = liaallg.matdat;
      let pteinr = liaallg.pteinr;
      let cur = liaallg.cur;
      let amt = Number(liaallg.oldamt).toFixed(2);
      if (matdat !== "") {
        if (this.model.modifySet && this.model.modifySet.includes("strinf")) {
        } else {
          let oldMatdat = this.root.oldMatdatMap.get(pteinr);
          if (oldMatdat !== matdat) {
            let olddat = moment(oldMatdat).format("DD.MMMM.yyyy");
            let newdat = "";
            if (matdat !== null && matdat !== "") {
              newdat = moment(matdat).format("DD.MMMM.yyyy");
            }
            let str = "Maturity for " + cur + " " + amt + " has been changed from " + olddat + " to " + newdat + "\n";
            // 将变化信息保存到matdatChangeArray中
            this.matdatChangeMap.set(pteinr, str);
          } else {
            this.matdatChangeMap.delete(pteinr);
          }
          if (this.matdatChangeMap.size > 0) {
            let changeStr = "";
            for (let val of this.matdatChangeMap.values()) {
              changeStr = changeStr + val;
            }
            this.model.strinf = changeStr + this.root.oldStrinf;
          } else {
            this.model.strinf = this.root.oldStrinf;
          }
        }
        this.model.brdgrp.rec.matdat = matdat;
        let matDate = new Date(this.model.brdgrp.rec.matdat);
        this.model.brdgrp.rec.stadat = matDate.setDate(matDate.getDate() - Number(this.model.brdgrp.rec.tenmaxday));
      }
    },
  },
  created: function () {
    this.matdatChangeMap = new Map();
  },
};
</script>

<style></style>