<template>
  <div class="eContainer">
    <c-page title="进口信用证通知">
      <el-form
        :model="model"
        :rules="rules"
        ref="modelForm"
        label-width="180px"
        label-position="right"
        size="small"
        :validate-on-rule-change="false">
        <c-tabs v-model="tabVal" ref="elment" type="card" @tab-click="tabClick">
          <el-tab-pane label="业务信息" name="ovwp">
            <c-content>
              <m-ovwp :model="model" :codes="codes" ref="ovwp"></m-ovwp>
            </c-content>
          </el-tab-pane>

          <el-tab-pane label="表外信息" name="engp">
            <c-content>
              <!-- 表外记账 -->
              <m-engp :model="model" :codes="codes" />
            </c-content>
          </el-tab-pane>

          <el-tab-pane label="费用/账务" name="setpan">
            <c-content>
              <m-setmod :model="model" :codes="codes" @changeSetmodModel="changeSetmodModel" />
            </c-content>
          </el-tab-pane>
          <!--PD000529 -->
          <el-tab-pane label="报文/面函" name="docpan">
            <c-content>
              <m-docpan :model="model" :codes="codes" />
            </c-content>
          </el-tab-pane>
        </c-tabs>
      </el-form>
      <!--底部按钮-->
      <c-function-btn
        :handleCheck="handleCheck"
        :handleStash="handleStash"
        :handleSubmit="handleSubmit"
        @handleSureWarning="handleSureWarning"
        ref="commonBtn"></c-function-btn>
      <el-dialog
        v-dialogDrag
        title="通知到单数据"
        :visible.sync="isDialogVisiable"
        width="60%"
        v-if="isDialogVisiable"
        @close="handleClose">
        <c-table
          :list="advDataArray"
          :columnsConfig="columns"
          :paginationShow="true"
          :total="advDataArray.length"
          @row-dblclick="pickDepItem">
          <el-table-column prop="op" label="OP" width="80" fixed="right">
            <template slot-scope="scope">
              <c-button style="margin-left: 0" size="small" type="primary" @click="pickDepItem(scope.row)">
                选择
              </c-button>
            </template>
          </el-table-column>
        </c-table>
      </el-dialog>
    </c-page>
  </div>
</template>
<script>
import CodeTable from "~/config/CodeTable";
import Litdav from "../model/index";
import Ovwp from "./Ovwp";
import Docpan from "~/components/business/docpan/views";
import Engp from "~/components/business/engp/views";
import operationFunc from "~/mixin/operationFunc";
import event from "../event";
import buildFn from "../event/buildCommons.js";
import Setmod from "~/components/business/setmod/views";
import check from "../model/check";
import Default from "../model/default";
import commonDepend from "~/mixin/commonDepend";
import Ptyp from "./Ptyp";

export default {
  name: "Litdav",
  components: {
    "m-engp": Engp,
    "m-docpan": Docpan,
    "m-setmod": Setmod,
    "m-ovwp": Ovwp,
    Ptyp,
  },
  provide() {
    return {
      root: this,
    };
  },
  mixins: [operationFunc, event, buildFn, check, Default, commonDepend], // 里面包含了Default、Check等的公共处理
  data() {
    return {
      tabVal: "ovwp",
      trnName: "litdav",
      model: new Litdav().data,
      codes: { ...CodeTable },
      ywxx: ["davp"],
      fyzw: ["engp"],
      activeNamesxyz: ["limitbody", "engp"],
      isDialogVisiable: false,
      advDataArray: [],
      columns: [
        {
          label: "INR",
          prop: "inr",
          width: 150,
        },
        {
          label: "Reference",
          prop: "ownref",
          width: 180,
        },
        {
          label: "Name",
          prop: "nam",
          width: 180,
        },
        {
          label: "Date",
          prop: "credat",
          width: 150,
        },
        {
          label: "Maturity",
          prop: "matdat",
          width: 150,
        },
        {
          label: "ADVDOCFLG",
          prop: "advdocflg",
          width: 150,
        },
        {
          label: "ETYEXTKEY",
          prop: "etyextkey",
          width: 150,
        },
        {
          label: "BCHKEYINR",
          prop: "bchkeyinr",
          width: 150,
        },
        {
          label: "BRANCHINR",
          prop: "branchinr",
          width: 150,
        },
        {
          label: "NGRCOD",
          prop: "ngrcod",
          width: 150,
        },
        {
          label: "SGDINR",
          prop: "sgdinr",
          width: 150,
        },
        {
          label: "BLNUM",
          prop: "blnum",
          width: 150,
        },
        {
          label: "SHGREF",
          prop: "shgref",
          width: 150,
        },
        {
          label: "GUAFLG",
          prop: "guaflg",
          width: 150,
        },
        {
          label: "TENMAXDAY",
          prop: "tenmaxday",
          width: 150,
        },
        {
          label: "STADAT",
          prop: "stadat",
          width: 150,
        },
        {
          label: "RPTREF",
          prop: "rptref",
          width: 150,
        },
        {
          label: "INVREF",
          prop: "invref",
          width: 150,
        },
        {
          label: "PRECHKDAT",
          prop: "prechkdat",
          width: 150,
        },
        {
          label: "ISCHKTYP",
          prop: "ischktyp",
          width: 150,
        },
        {
          label: "CFABRTFLG",
          prop: "cfabrtflg",
          width: 150,
        },
        {
          label: "CFABRTTXT",
          prop: "cfabrttxt",
          width: 150,
        },
        {
          label: "INVTYP",
          prop: "invtyp",
          width: 150,
        },
        {
          label: "OPPNAM",
          prop: "oppnam",
          width: 150,
        },
      ],
    };
  },
  methods: {
    initData(params) {
      this.init(params).then(async () => {
        this.$refs.ovwp.$refs.ptyp.initdocprbrolArray();
        if (this.model.brdgrp.rec.advtyp === "750") {
          this.fillDocdis();
        }
      });
    },
    pickDepItem(row) {
      this.isDialogVisiable = false;
      // 通过选中数据加载交易
      let params = {
        transName: this.trnName,
        lidgrp: {
          rec: {
            inr: this.$route.query.inr,
          },
        },
        brdgrp: {
          rec: {
            inr: row.inr,
          },
        },
      };
      this.initData(params);
    },
    handleClose() {
      this.$alert(
        "An existing contract is required to execute this transaction.\nEither no contract was passed or the passed contract is deleted.\nThe transaction cannot be executed. Please install the contract first.",
        "警告",
        {
          confirmButtonText: "OK",
        }
      ).then(async () => {
        this.$store.commit("delTagsArry", this.$route.path);
        this.$router.back();
      });
    },
  },
  mounted() {
    console.log("进入litdav交易");
    this.queryAdvData(this.$route.query.inr).then((result) => {
      this.advDataArray = result;
      if (this.advDataArray.length > 0) {
        // 有则提示是否选提货担保数据处理
        this.$confirm(
          "For this L/C some document sets have been advised while\nthe documents have not been received.  Do you want to select\none of those document sets to process their receipt ?",
          "提示",
          {
            confirmButtonText: "OK",
            cancelButtonText: "Cancel",
            type: "warning",
          }
        )
          .then(async () => {
            // 是则弹出到单数据
            this.isDialogVisiable = true;
          })
          .catch(() => {
            // 否则直接进入交易
            let params = {
              transName: this.trnName,
              lidgrp: {
                rec: {
                  inr: this.$route.query.inr,
                },
              },
            };
            this.initData(params);
          });
      } else {
        // 没有通知到单数据则直接初始化
        let params = {
          transName: this.trnName,
          lidgrp: {
            rec: {
              inr: this.$route.query.inr,
            },
          },
        };
        this.initData(params);
      }
    });
  },
  created() {},
};
</script>
<style></style>