<template>
  <div class="eibs-tab">
    <el-collapse v-model="activeNames" @change="handleChange">

      <el-collapse-item title="外管信息" name="wg" >
        <!-- 详情 -->
        <m-wg :model="model" :codes="codes" />
      </el-collapse-item>

<!--      v-if="model.trtcre.crefinflg"-->
      <el-collapse-item title="融资款项" name="rzkx" v-model="model.trtcre.crefinflg" v-if="model.trtcre.crefinflg">
        <m-rzkx :model="model" :codes="codes" />
      </el-collapse-item>

<!--      v-if="(this.model.bopmod.basflg == 'X' && this.model.bopmod.szflg == '1')"-->
      <el-collapse-item title="对外付款/承兑通知书-基础信息" name="basp" v-if="(this.model.bopmod.basflg == 'X' && this.model.bopmod.szflg == '1')"
                        >
        <!-- 当事人 -->
        <m-basp :model="model" :codes="codes" />
      </el-collapse-item>
<!--      v-if="(this.model.bopmod.basflg == 'X' && this.model.bopmod.szflg == '2')"-->
      <el-collapse-item title="境内付款/承兑通知书-基础信息" name="basp1" v-if="(this.model.bopmod.basflg == 'X' && this.model.bopmod.szflg == '2')"
                        >
        <!-- 当事人 -->
        <m-basp1 :model="model" :codes="codes" />
      </el-collapse-item>

<!--      v-if="model.trtcre.crefinflg"-->
      <el-collapse-item title="定向收付" name="dxzfp" v-if="model.trtcre.crefinflg">
        <!-- 货物 -->
        <m-dxzfp :model="model" :codes="codes" />
      </el-collapse-item>
      <el-collapse-item title="跨境人民币申报" name="cnyp">
        <!-- 单据 -->
        <m-cnyp :model="model" :codes="codes" />
      </el-collapse-item>
<!--      v-if="model.cnybop.outflg == '1'"-->
      <el-collapse-item title="2111跨境支出信息" name="outp" v-if="model.cnybop.outflg == '1'">
        <!-- 附加条款 -->
        <m-outp :model="model" :codes="codes" />
      </el-collapse-item>
      <el-collapse-item title="资本项目" name="cfactlp" >
        <!-- 货物 -->
        <m-cfactlp :model="model" :codes="codes" />
      </el-collapse-item>

<!--      v-if="model.trnmod.cmtflg=='P'"-->
      <el-collapse-item title="Cips" name="cips" v-if="model.trnmod.cmtflg=='P'">
        <!-- 货物 -->
        <m-cips :model="model" :codes="codes" />
      </el-collapse-item>

<!--      v-if="model.trnmod.cmtflg=='P'"-->
      <el-collapse-item title="Cips要素" name="cips2" v-if="model.trnmod.cmtflg=='P'">
        <!-- 货物 -->
        <m-cips2 :model="model" :codes="codes" />
      </el-collapse-item>

    </el-collapse>
  </div>

</template>

<script>
import Rzkx from "./Rzkx";
import Wg from "./Wg";
import Basp from "./Basp";
import Basp1 from "./Basp1";
import Dxzfp from "./Dxzfp";
import Cnyp1 from "./Cnyp1";
import Outp from "./Outp";
import Cfactlp from "./Cfactlp";
import Cips from "./Cips";
import Cips2 from "./Cips2";
import commonProcess from "@/mixin/commonProcess";
import Event from "@/model/Litopn/Event";

const tabNameToRulePathMapping = {
    "basp": "bopmod.dbfp.basp",
    "basp1": "bopmod.dbcp.basp",
    "outp": "cnybop.outp"
  }
  
export default {
  components: {
    "m-rzkx": Rzkx,
    "m-wg": Wg,
    "m-basp": Basp,
    "m-basp1": Basp1,
    "m-dxzfp": Dxzfp,
    "m-cnyp": Cnyp1,
    "m-outp": Outp,
    "m-cfactlp": Cfactlp,
    "m-cips": Cips,
    "m-cips2": Cips2,
  },
  inject: ["root"],
  props: ["model", "codes"],
  mixins: [commonProcess],
  data() {
    return {
      flag: true,
      activeNames: ["wg"],
    }
  },
  methods: {
    ...Event,
    open(val) {
      if (
          val === "" &&
          !(
              this.model.lidgrp.cbs.max2.amt == "0.000" &&
              this.model.lidgrp.cbs.opn2.amt == "0.000" &&
              this.model.lidgrp.blk.addamtcov === ""
          )
      ) {
        this.$confirm(
            "是否确定要删除此合同的附加金额?",
            "提示",
            {
              confirmButtonText: "是",
              cancelButtonText: "否",
              type: "warning",
              showClose: false,
            }
        )
            .then(() => {
              //yes的执行在这里写
              this.model.lidgrp.cbs.max2.amt = "0.000";
              this.model.lidgrp.blk.addamtcov = "";
              this.model.lidgrp.cbs.opn2.amt = "0.000";
              this.$message({
                type: "success",
                message: "删除成功!",
              });
            })
            .catch(() => {
              //No的功能在这里写
              this.model.litp.aamp.aammod.addamtflg = "X";
              this.$message({
                type: "info",
                message: "已取消删除",
              });
            });
      }
    },
    handleChange(names) {
            if (this.isInDisplay) {
              return
            }
            const arr = [];
            for (let i = 0; i < names.length; i++) {
              const n = names[i];
              const path = tabNameToRulePathMapping[n]
              if (path) {
                arr.push(path)
              }
            }
            let rulePath = arr.join(",");
            if (!!rulePath) {//rulePath不为空串
              this.executeRule(rulePath).then((res) => {
                if (res.respCode == SUCCESS) {
                  this.updateModel(res.data);
                }
              });
            }
          },
        myTabClick(tab) {
          this.tabClick(tab);
          let name = tab.name;
          let rulePath;
          if (name === "basp") {
            rulePath = "bopmod.dbfp.basp";
          }
          if (name === "basp1") {
            rulePath = "bopmod.dbcp.basp";
          }
          if (name === "outp") {
            rulePath = "cnybop.outp";
          }
          if (!!rulePath) {
            this.executeRule(rulePath).then((res) => {
              if (res.respCode == SUCCESS) {
                this.updateModel(res.data);
              }
            });
          }
        },
  },
  watch: {
    "model.lidgrp.rec.apprul": {
      immediate: true,
      handler(val, oldVal) {
        if (val == "OTHR") {
          this.flag = false;
        } else {
          this.flag = true;
        }
      },
    },
  },
  computed: {
    flag1() {
      return this.model.lidgrp.apl.pts.extkey == "";
    },
  },
}
</script>

<style scoped>

</style>