<template>
  <div class="eibs-tab">
    <c-col :span="24" style="padding-top: 20px">
      <!-- ========================左边======================== -->
      <c-col :span="12" style="padding-right: 20px">
        <c-col :span="24">
          <el-form-item label="Available with(41)" prop="lidgrp.rec.avbwth">
            <c-select
              v-model="model.lidgrp.rec.avbwth"
              style="width: 100%"
              placeholder="请选择"
              dbCode="avbwth"
              :filterKey="['A', 'C', 'I', 'O', 'S']"
              @change="onAvbwthChange">
            </c-select>
          </el-form-item>
        </c-col>
        <c-col :span="24" class="fieldName" v-if="model.lidgrp.rec.avbwth != 'O'">
          <c-ptap
            :argadr="{ title: '', grp: 'lidgrp', rol: 'avb' }"
            :haveAdrLabel="true"
            :isAdrblk="true"
            :model="model"
            bchinr="00000036"
            ptytyp="B"
            :requiredExtkey="true"
            :disabledExtkey="
              this.model.lidgrp.rec.avbwth == 'A' ||
              this.model.lidgrp.rec.avbwth == 'C' ||
              this.model.lidgrp.rec.avbwth == ''
            "
            :disabled="
              this.model.lidgrp.rec.avbwth == 'I' ||
              this.model.lidgrp.rec.avbwth == 'A' ||
              this.model.lidgrp.rec.avbwth == 'C' ||
              this.model.lidgrp.rec.avbwth == ''
            "
            :isLabel120="false"></c-ptap>
        </c-col>

        <c-col :span="24" v-if="model.lidgrp.rec.avbwth == 'O'">
          <el-form-item label="Available in(41)" prop="lidgrp.blk.avbwthtxt" style="margin-bottom: 0px">
            <c-input
              type="textarea"
              v-model="model.lidgrp.blk.avbwthtxt"
              maxlength="140"
              :rows="4"
              show-word-limit
              placeholder="请输入Available in"></c-input>
          </el-form-item>
        </c-col>

        <c-col :span="12">
          <el-form-item label="Available by(41)" prop="lidgrp.rec.avbby">
            <c-select
              v-model="model.lidgrp.rec.avbby"
              style="width: 100%"
              placeholder="请选择兑付方式"
              dbCode="avbby0"
              @change="onAvbbyChange">
            </c-select>
          </el-form-item>
        </c-col>
        <c-col :span="12">
          <el-form-item label="Tenor day" prop="lidgrp.rec.tenmaxday">
            <c-input
              :disabled="this.model.lidgrp.rec.avbby == 'P'"
              v-model="model.lidgrp.rec.tenmaxday"
              placeholder="请输入天数"></c-input>
          </el-form-item>
        </c-col>

        <c-col :span="24">
          <el-form-item
            label="Negotiation/Deferred Payment Details(42P)"
            prop="lidgrp.blk.defdet"
            :rules="[
              {
                type: 'string',
                required: !(
                  this.model.lidgrp.rec.avbby == 'P' ||
                  this.model.lidgrp.rec.avbby == 'M' ||
                  this.model.lidgrp.rec.avbby == 'A' ||
                  this.model.lidgrp.rec.avbby == 'N' ||
                  this.model.lidgrp.rec.avbby == ''
                ),
                message: '必输项',
              },
              { max: 140, message: '长度不能超过140' },
            ]">
            <c-mul-row-input
              type="textarea"
              :disabled="
                this.model.lidgrp.rec.avbby == 'P' ||
                this.model.lidgrp.rec.avbby == 'M' ||
                this.model.lidgrp.rec.avbby == 'A' ||
                this.model.lidgrp.rec.avbby == ''
              "
              v-model="model.lidgrp.blk.defdet"
              :rows="4"
              :cols="35"
              :autosize="{ minRows: 2, maxRows: 2 }"
              show-word-limit
              :charmod="2"
              placeholder="请输入指示内容"></c-mul-row-input>
          </el-form-item>
        </c-col>
        <c-col :span="24">
          <el-form-item
            label="Mixed Payment Details(42M)"
            prop="lidgrp.blk.mixdet"
            :rules="[
              {
                required: this.model.lidgrp.rec.avbby == 'M',
                message: '必输项',
              },
            ]">
            <c-mul-row-input
              type="textarea"
              :disabled="
                this.model.lidgrp.rec.avbby == 'D' ||
                this.model.lidgrp.rec.avbby == 'N' ||
                this.model.lidgrp.rec.avbby == 'P' ||
                this.model.lidgrp.rec.avbby == 'A' ||
                this.model.lidgrp.rec.avbby == ''
              "
              v-model="model.lidgrp.blk.mixdet"
              :rows="4"
              :cols="35"
              :autosize="{ minRows: 2, maxRows: 2 }"
              show-word-limit
              :charmod="2"
              placeholder="请输入混合付款指示"></c-mul-row-input>
          </el-form-item>
        </c-col>

        <c-col :span="24">
          <c-ptap-commons
            :cols="35"
            :rows="3"
            :minRows="2"
            :maxRows="2"
            :model="model"
            :disabledButton="
              this.model.lidgrp.rec.avbby == 'D' ||
              this.model.lidgrp.rec.avbby == 'M' ||
              this.model.lidgrp.rec.avbby == ''
            "
            :extCodes="['lidgrp', 'blk']"
            lastModel="dftat"
            :charmod="2"
            title="Drafts at(42C)">
          </c-ptap-commons>
        </c-col>
        <c-col :span="24" class="fieldName">
          <c-ptap
            :disabled="
              model.lidgrp.rec.avbby === '' ||
              model.lidgrp.rec.avbby === 'D' ||
              model.lidgrp.rec.avbby === 'M' ||
              (typeof this.model.trnInfo !== 'undefined' && this.model.trnInfo.sptHldflg === 'X')
            "
            :disabledExtkey="
              model.lidgrp.rec.avbby === '' ||
              model.lidgrp.rec.avbby === 'D' ||
              model.lidgrp.rec.avbby === 'M' ||
              (typeof this.model.trnInfo !== 'undefined' && this.model.trnInfo.sptHldflg === 'X')
            "
            :disabledDetailTrn="
              model.lidgrp.rec.avbby === '' || model.lidgrp.rec.avbby === 'D' || model.lidgrp.rec.avbby === 'M'
            "
            :disabledAdrblk="
              model.lidgrp.rec.avbby === '' || model.lidgrp.rec.avbby === 'D' || model.lidgrp.rec.avbby === 'M'
            "
            :argadr="{ title: 'Drawee(42A/D)', grp: 'lidgrp', rol: 'drw' }"
            :haveAdrLabel="true"
            :isAdrblk="true"
            :model="model"
            bchinr="00000036"
            ptytyp="B,C"
            :isLabel120="false"></c-ptap>
        </c-col>
      </c-col>

      <!-- ========================右边======================== -->
      <c-col :span="12" style="padding-left: 20px">
        <c-col :span="24">
          <el-form-item label="" label-width="30px" style="margin-bottom: 0px !important">
            <span style="font-family: Helvetica, sans-serif; font-size: 12px"
              >Place of taking in Charge/Dispatch from/Place of Receipt(44A)</span
            >
          </el-form-item>
        </c-col>
        <c-col :span="20">
          <el-form-item label="" label-width="30px" prop="lidgrp.rec.shpfro" style="margin-bottom: 0px !important">
            <c-mul-row-input
              type="textarea"
              v-model="model.lidgrp.rec.shpfro"
              :rows="65"
              :cols="30"
              :autosize="{ minRows: 2, maxRows: 2 }"
              show-word-limit
              :charmod="3"
              placeholder="请输入装船/发运地"></c-mul-row-input>
          </el-form-item>
        </c-col>
        <c-col :span="24">
          <el-form-item label="" label-width="30px" style="margin-bottom: 0px !important; margin-top: 20px">
            <span style="font-family: Helvetica, sans-serif; font-size: 12px"
              >Port of Loading/Airport of Departure(44E)</span
            >
          </el-form-item>
        </c-col>
        <c-col :span="20">
          <el-form-item label="" label-width="30px" prop="lidgrp.rec.porloa" style="margin-bottom: 0px !important">
            <c-mul-row-input
              type="textarea"
              v-model="model.lidgrp.rec.porloa"
              :rows="65"
              :cols="30"
              :autosize="{ minRows: 2, maxRows: 2 }"
              show-word-limit
              :charmod="3"
              placeholder="请输入始发(航空)站"></c-mul-row-input>
          </el-form-item>
        </c-col>
        <c-col :span="24">
          <el-form-item label="" label-width="30px" style="margin-bottom: 0px !important; margin-top: 20px">
            <span style="font-family: Helvetica, sans-serif; font-size: 12px"
              >Port of Discharge/Airport of Destination(44F)</span
            >
          </el-form-item>
        </c-col>
        <c-col :span="20">
          <el-form-item label="" label-width="30px" prop="lidgrp.rec.pordis" style="margin-bottom: 0px !important">
            <c-mul-row-input
              type="textarea"
              v-model="model.lidgrp.rec.pordis"
              :rows="65"
              :cols="30"
              :autosize="{ minRows: 2, maxRows: 2 }"
              show-word-limit
              :charmod="3"
              placeholder="请输入终点(航空)站"></c-mul-row-input>
          </el-form-item>
        </c-col>
        <c-col :span="24">
          <el-form-item label="" label-width="30px" style="margin-bottom: 0px !important; margin-top: 20px">
            <span style="font-family: Helvetica, sans-serif; font-size: 12px"
              >Place of Final Destination/For Transportation to/Place of Delivery(44B)</span
            >
          </el-form-item>
        </c-col>
        <c-col :span="20">
          <el-form-item label="" label-width="30px" prop="lidgrp.rec.shpto">
            <c-mul-row-input
              type="textarea"
              v-model="model.lidgrp.rec.shpto"
              :rows="65"
              :cols="30"
              :autosize="{ minRows: 2, maxRows: 2 }"
              show-word-limit
              :charmod="3"
              placeholder="请输入最终目的地"></c-mul-row-input>
          </el-form-item>
        </c-col>

        <c-col :span="24">
          <el-form-item label="" label-width="30px" style="margin-bottom: 0px !important; margin-top: 20px">
            <span style="font-family: Helvetica, sans-serif; font-size: 12px">适用业务类型</span>
          </el-form-item>
        </c-col>
        <c-col :span="20">
          <el-form-item
            label=""
            label-width="30px"
            prop="appbt"
            :rules="[
              {
                type: 'string',
                required: this.model.idtyp === '1',
                message: '必输项',
              },
            ]">
            <c-select v-model="model.appbt" style="width: 100%" placeholder="请选择" :code="apptp"> </c-select>
          </el-form-item>
        </c-col>
      </c-col>
    </c-col>
  </div>
</template>
<script>
import Api from "~/service/Api";
import commonProcess from "~/mixin/commonProcess";
import CodeTable from "~/config/CodeTable";
import event from "../event";
import { getCodetable } from "~/service/business/codeTable";
import Pts from "~/components/business/commonModel/Pts.js";
import { cloneDeep } from "lodash";

export default {
  inject: ["root"],
  props: ["model", "codes"],
  mixins: [commonProcess, event],
  data() {
    return {
      disabledExtkey: false,
      drwDisabledAll: true,
      apptp: [
        { label: "货物贸易", value: "01" },
        { label: "服务贸易", value: "02" },
      ],
      dbCodes: {
        avbwth: [],
      },
    };
  },
  methods: {
    getCodeTableValue(value, codenam) {
      const codeobj = this.dbCodes[codenam].find((obj) => obj.value === value);
      return codeobj ? codeobj.label : value;
    },

    onAvbbyChange() {
      let val = this.model.lidgrp.rec.avbby;
      if (val == "D") {
        this.model.lidgrp.blk.mixdet = "";
        this.drwDisabledAll = true;
        this.model.lidgrp.blk.defdet = "days after B/L date";
        this.model.lidgrp.blk.dftat = "";
      } else if (val == "N") {
        this.model.lidgrp.blk.mixdet = "";
        this.drwDisabledAll = false;
        this.model.lidgrp.blk.defdet = "days after B/L date";
        this.model.lidgrp.blk.dftat = "Sight for 100PCT of Invoice Value";
      } else if (val == "P") {
        this.model.lidgrp.blk.mixdet = "";
        this.drwDisabledAll = false;
        this.model.lidgrp.rec.tenmaxday = "0";
        this.model.lidgrp.blk.defdet = "";
        this.model.lidgrp.blk.dftat = "";
      } else if (val == "M") {
        this.drwDisabledAll = true;
        this.model.lidgrp.blk.defdet = "";
        this.model.lidgrp.blk.dftat = "";
      } else if (val == "A") {
        this.model.lidgrp.blk.mixdet = "";
        this.drwDisabledAll = false;
        this.model.lidgrp.blk.defdet = "";
        if (this.model.lidgrp.rec.cnfdet == "C" || this.model.lidgrp.rec.cnfdet == "W") {
          this.model.lidgrp.blk.dftat = "Days after sight for 100PCT of Invoice Value ";
        } else {
          this.model.lidgrp.blk.dftat = "";
        }
      } else {
        this.drwDisabledAll = true;
        this.model.lidgrp.blk.mixdet = "";
        this.model.lidgrp.blk.defdet = "";
        this.model.lidgrp.blk.dftat = "";
      }

      if (this.drwDisabledAll) {
        this.model.lidgrp.drw.pts.extkey = "";
        this.model.lidgrp.drw.pts.adrblk = "";
        this.model.lidgrp.drw.pts.nam = "";
        this.model.lidgrp.drw.pts.ptainr = "";
        this.model.lidgrp.drw.pts.ptyinr = "";
        this.model.lidgrp.drw.pts.rol = "";
      }
    },
  },
  mounted() {
    this.getdbCode("avbwth", "EN", "avbwth");
  },
  created: function () {},
};
</script>
<style>
.marginLable {
  padding-left: 160px;
}
.custom-label {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  display: inline-block;
  width: 100%;
}
</style>