<template>
  <div class="eibs">

<!-- ============左边================= -->
<c-col :span="12" style="padding-right: 20px;">
        <c-col :span="24">
          <el-form-item
            label="信用证号码"
            prop="ledgrp.rec.ownref"
            style="width: 100%"
          >
            <c-fullbox>
              <c-input
                v-model="model.ledgrp.rec.ownref"
                maxlength="16"
                placeholder="请输入编号"
                style="width: 95%"
                :disabled="true"
              >
              </c-input>
              <template slot="footer">
                <c-button
                  style="margin: 0 10px 0 0; padding: 0 12px"
                  size="small"
                  type="primary"
                  @click="onSeainf"
                >
                  <i class="el-icon-info" style="font-size:15px"></i>
                </c-button>
                <c-button
                  style="margin: 0 0"
                  size="small"
                  type="primary"
                  :disabled="
                    model.ledgrp.ben.pts.adrblk && !model.ledgrp.rec.ownref
                      ? false
                      : true
                  "
                  @click="onLetpButgetref"
                >
                  获取
                </c-button>
              </template>
            </c-fullbox>
          </el-form-item>
        </c-col>

        <!-- Form of L/C -->
        <c-col :span="24">
          <el-form-item label="是否可以转让" prop="ledgrp.rec.lcrtyp">
            <c-select
              v-model="model.ledgrp.rec.lcrtyp"
              style="width: 100%"
              placeholder="请选择"
              :code="codes.lcrtyp"
            >
            </c-select>
          </el-form-item>
        </c-col>

        <!-- responsible user -->
        <c-col :span="24">
          <c-col :span="20">
            <el-form-item label="所属客户经理" prop="letp.usr.extkey">
              <c-fullbox>
                <c-input
                  v-model="model.letp.usr.extkey"
                  maxlength="8"
                  placeholder="请输入所属客户经理"
                  disabled
                ></c-input>
                <template slot="footer">
                  <c-button
                    style="margin-left: 10px; padding: 0 10px"
                    size="small"
                    icon="el-icon-search"
                    type="primary"
                  ></c-button>
                </template>
              </c-fullbox>
            </el-form-item>
          </c-col>
          <c-col :span="4">
            <c-checkbox
              :disabled="true"
              v-model="model.ledgrp.rec.collflg"
              style="margin-left: 10px"
              >抵押信用证</c-checkbox
            >
          </c-col>
        </c-col>

        <!-- nominal amount -->
        <c-col :span="24">
          <c-col :span="13">
            <el-form-item label="信用证金额" prop="ledgrp.cbs.nom1.cur">
              <c-select
                v-model="model.ledgrp.cbs.nom1.cur"
                style="width: 100%"
                placeholder="请选择币种"
                :code="codes.curtxt1"
              >
              </c-select>
            </el-form-item>
          </c-col>
          <c-col :span="7">
            <el-form-item label="" label-width="5px" prop="ledgrp.cbs.nom1.amt">
              <c-input-currency
                v-model="model.ledgrp.cbs.nom1.amt"
                style="text-align: left; width: 100%"
                placeholder="请输入信用证金额"
                @keyup.enter.native="$event.target.blur()"
              ></c-input-currency>
            </el-form-item>
          </c-col>

          <c-col :span="4">
            <c-checkbox
              v-model="model.letp.aamp.aammod.addamtflg"
              @change="openAddAmount"
              style="margin-left: 10px"
              >附加金额</c-checkbox
            >
          </c-col>
        </c-col>

        <c-col :span="24">
          <c-col :span="13">
            <c-form-item label="金额浮动 +/-" prop="ledgrp.rec.nomtop">
              <c-input
                v-model.number="model.ledgrp.rec.nomtop"
                maxlength="2"
                style="width: 100%"
                placeholder="0"
                @change="nomtopChange"
                @keyup.enter.native="$event.target.blur()"
                
              ></c-input>
            </c-form-item>
          </c-col>
          <c-col :span="7">
            <el-form-item label="" label-width="5px" prop="ledgrp.rec.nomton">
              <c-input
                v-model.number="model.ledgrp.rec.nomton"
                maxlength="2"
                style="width: 100%"
                placeholder="0"
                @keyup.enter.native="$event.target.blur()"
                
              ></c-input>
            </el-form-item>
          </c-col>
          <c-col :span="4">
          </c-col>
        </c-col>

        <c-col :span="24">
          <c-col :span="20">
            <el-form-item label="适用金额规范" prop="ledgrp.rec.nomspc">
              <c-select
                v-model="model.ledgrp.rec.nomspc"
                style="width: 100%"
                placeholder="请选择适用金额规范"
                :code="codes.nomspc"
                disabled
              >
              </c-select>
            </el-form-item>
          </c-col>

          <!-- Incoming Transfer -->
          <c-col :span="4">
            <c-checkbox
              v-model="model.ledgrp.rec.inctrf"
              style="margin-left: 10px"
              >传入传输</c-checkbox
            >
          </c-col>
        </c-col>

        <!-- Maximum Amount -->
        <c-col :span="13">
          <el-form-item label="信用证最大金额" prop="ledgrp.cbs.max.cur">
            <c-select
              v-model="model.ledgrp.cbs.max.cur"
              style="width: 100%"
              placeholder="请选择币种"
              :code="codes.curtxt1"
              disabled
            >
            </c-select>
          </el-form-item>
        </c-col>
        <c-col :span="11">
          <el-form-item label="" label-width="5px" prop="ledgrp.cbs.max.amt">
            <c-input-currency
              disabled
              v-model="model.ledgrp.cbs.max.amt"
              placeholder="请输入最大金额"
              class="m-input-currency"
            ></c-input-currency>
          </el-form-item>
        </c-col>

        <c-col :span="14">
          <el-form-item label="开证日期" prop="ledgrp.rec.opndat">
            <c-date-picker
              type="date"
              v-model="model.ledgrp.rec.opndat"
              style="width: 90%"
              placeholder="请选择开证日期"
            ></c-date-picker>
          </el-form-item>
        </c-col>
        <c-col :span="10">
          <el-form-item
            label="预通知日期"
            label-width="80px"
            prop="ledgrp.rec.preadvdt"
          >
            <c-date-picker
              type="date"
              v-model="model.ledgrp.rec.preadvdt"
              style="width: 100%"
              placeholder="请选择日期"
              disabled
            ></c-date-picker>
          </el-form-item>
        </c-col>

        <c-col :span="14">
          <el-form-item label="装运日期" prop="ledgrp.rec.shpdat">
            <c-date-picker
              type="date"
              v-model="model.ledgrp.rec.shpdat"
              style="width: 90%"
              placeholder="请选择装运日期"
              :disabled="model.ledgrp.blk.shpper!=''"
            ></c-date-picker>
          </el-form-item>
        </c-col>

        <c-col :span="10">
          <el-form-item
            label="通知日期"
            label-width="80px"
            prop="ledgrp.rec.advdat"
          >
            <c-date-picker
              type="date"
              v-model="model.ledgrp.rec.advdat"
              style="width: 100%"
              placeholder="请选择通知日期"
              disabled
            ></c-date-picker>
          </el-form-item>
        </c-col>

        <c-col :span="14">
          <el-form-item label="到期日" prop="ledgrp.rec.expdat">
            <c-date-picker
              type="date"
              v-model="model.ledgrp.rec.expdat"
              style="width: 90%"
              placeholder="请选择到期日"
            ></c-date-picker>
          </el-form-item>
        </c-col>
        <c-col :span="10"></c-col>

        <c-col :span="24">
          <el-form-item label="有效地点" prop="ledgrp.rec.expplc">
            <c-input
              v-model="model.ledgrp.rec.expplc"
              maxlength="29"
              placeholder="有效地点"
            ></c-input>
          </el-form-item>
        </c-col>

        <c-col :span="24">
          <el-form-item label="确认接收指示" prop="ledgrp.rec.cnfdet">
            <c-select
              v-model="model.ledgrp.rec.cnfdet"
              style="width: 100%"
              placeholder="请选择确认接收指示"
              :code="codes.cnfins"
            >
            </c-select>
          </el-form-item>
        </c-col>

        <c-col :span="24">
          <el-form-item label="适用规则" prop="ledgrp.rec.apprul">
            <c-select
              v-model="model.ledgrp.rec.apprul"
              style="width: 100%"
              placeholder="请选择适用规则"
              :code="codes.apprul1"
              @change="apprulChange"
            >
            </c-select>
          </el-form-item>
        </c-col>

        <c-col :span="24">
          <el-form-item label="其他规则" prop="ledgrp.rec.apprultxt">
            <c-input
              v-model="model.ledgrp.rec.apprultxt"
              maxlength="35"
              placeholder="请输入其他规则"
              :disabled="model.ledgrp.rec.apprul === 'OTHR' ? false : true"
            ></c-input>
          </el-form-item>
        </c-col>
        <c-col :span="24">
          <el-form-item label="分批装运" prop="ledgrp.rec.shppar">
            <c-select
              v-model="model.ledgrp.rec.shppar"
              style="width: 100%"
              placeholder="请选择分批装运"
              :code="codes.shptrss18"
            >
            </c-select>
          </el-form-item>
        </c-col>

        <c-col :span="24">
          <el-form-item label="转运" prop="ledgrp.rec.shptrss18">
            <c-select
              v-model="model.ledgrp.rec.shptrss18"
              style="width: 100%"
              placeholder="请选择是否转运"
              :code="codes.shptrss18"
            >
            </c-select>
          </el-form-item>
        </c-col>
      </c-col>

        <!-- ============右边================= -->
        <c-col :span="12" style="padding-left: 20px;">
        <c-col :span="24">
          <el-form-item label="摘要" prop="ledgrp.rec.nam">
            <c-input
              text-align="middle"
              v-model="model.ledgrp.rec.nam"
              maxlength="40"
              placeholder="请输入"
              disabled
            >
            </c-input>
          </el-form-item>
        </c-col>

        <c-col :span="24">
          <c-ptap
            :model="model"
            :argadr="{
              title: '受益人',
              grp: 'ledgrp',
              rol: 'ben',
            }"
            :disabled="true"
            @onSeainf="onSeainf"
            @onAplpDet="onBenpDet"
          >
          </c-ptap>
        </c-col>

        <c-col :span="24">
          <c-ptap
            :model="model"
            :argadr="{
              title: '开证行',
              grp: 'ledgrp',
              rol: 'iss',
            }"
            :disabled="true"
            @onSeainf="onSeainf"
            @onAplpDet="onIsspDet"
          >
          </c-ptap>
        </c-col>

        <c-col :span="24">
          <c-ptap
            :model="model"
            :argadr="{
              title: '申请人',
              grp: 'ledgrp',
              rol: 'apl',
            }"
            @onSeainf="onSeainf"
            @onAplpDet="onAplpDet"
          >
          </c-ptap>
        </c-col>

        <c-col :span="24">
        <c-col :span="12">
          <el-form-item label=" " prop="ledgrp.rec.revflg" label-width="120px" style=" float:left;">
          <c-checkbox v-model="model.ledgrp.rec.revflg" @change="openRevolvingDetails"
            >循环信用证</c-checkbox
          >
        </el-form-item>
        </c-col>

        <!-- Authorization to Debit -->
        <c-col :span="12" >
          <el-form-item label=" " prop="ledgrp.rec.dbtflg" label-width="120px" style=" float:right;">
          <c-checkbox v-model="model.ledgrp.rec.dbtflg">借记授权书</c-checkbox>
        </el-form-item>
        </c-col>
      </c-col>

        <!-- Non-Bank Issuer -->
        <c-col :span="12" >
          <el-form-item label=" " prop="ledgrp.rec.nonban" label-width="120px" style=" float:left;">
          <c-checkbox v-model="model.ledgrp.rec.nonban"
            >非银行发行人</c-checkbox
          >
        </el-form-item>
        </c-col>

        <!-- Test Key Unconfirmity -->
        <c-col :span="12" class="centerLable marginLable">
          <el-form-item label=" " prop="ledgrp.rec.teskeyunc" label-width="120px" style=" float:right;">
          <c-checkbox v-model="model.ledgrp.rec.teskeyunc">测试密钥</c-checkbox>
        </el-form-item>
        </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 "~/model/Letopn/Event";
import Utils from "~/utils";
import Ptap from "~/views/Public/Ptap";
// import Amtpanl from "~/views/Public/Amtpanl";

export default {
  components: { "c-ptap": Ptap },
  inject: ["root"],
  props: ["model", "codes"],
  mixins: [commonProcess],
  data() {
    return {};
  },
  watch:{
    "model.ledgrp.rec.nomtop":function(val){
      this.model.ledgrp.rec.nomtop = val.replace(/\D/g, '');
    },
    "model.ledgrp.rec.nomton":function(val){
      this.model.ledgrp.rec.nomton = val.replace(/\D/g, '');
    }
  },
  methods: {
    ...Event,
    nomtopChange(){
      this.executeDefault("ledgrp.cbs.max.amt").then((res) => {
        if ((res.respCode == SUCCESS)) {
          Utils.copyValueFromVO(this.model, res.data);
        }
      });
      },
    apprulChange(v) {
      if (v !== "OTHR") {
        this.model.ledgrp.rec.apprultxt = "";
      }
    },
    openAddAmount(val){
      if(val ==='' && !(this.model.ledgrp.cbs.max2.amt =='0.000'&& this.model.ledgrp.blk.addamtcov === '') ){
        this.$confirm('是否确定要删除此合同的附加金额?','提示',{
            confirmButtonText: '是',
            cancelButtonText: '否',
            type: 'warning',
            showClose:false
          }).then(() => {//yes的执行在这里写
            this.executeRule('letp.aamp.aammod.addamtflg').then(res => {
                if (res.respCode == SUCCESS) {
                    this.updateModel(res.data)
                }
            })
            // this.model.ledgrp.cbs.max2.amt ='0.000';
            // this.model.ledgrp.blk.addamtcov = '';
            // this.$message({
            //       type: 'success',
            //       message: '删除成功!'
            // });
          }).catch(() => {//No的功能在这里写
            this.model.letp.aamp.aammod.addamtflg ='X'
                // this.$message({
                //   type: 'info',
                //   message: '已取消'
                // });  
          }); 
      }
    },
    openRevolvingDetails(val){
    if(val ==='' && !(this.model.ledgrp.rec.revtyp ===''&& this.model.ledgrp.rec.revtimes == '0' && this.model.ledgrp.rec.revdat ===''
      &&this.model.ledgrp.rec.revcum ===''&&this.model.ledgrp.blk.revcls ===''&&this.model.ledgrp.blk.revnotes ==='') ){
        this.$confirm('是否确定要删除输入的循环详细信息?','提示',{
            confirmButtonText: '是',
            cancelButtonText: '否',
            type: 'warning',
            showClose:false
          }).then(() => {//yes的执行在这里写
            this.executeRule('ledgrp.rec.revflg').then(res => {
                if (res.respCode == SUCCESS) {
                    this.updateModel(res.data)
                }
            })
            // this.model.ledgrp.rec.revtyp ='';
            // this.model.ledgrp.rec.revtimes = '0';
            // this.model.ledgrp.rec.revdat ='';
            // this.model.ledgrp.rec.revcum ='';
            // this.model.ledgrp.blk.revcls ='';
            // this.model.ledgrp.blk.revnotes ='';
            // this.$message({
            //       type: 'success',
            //       message: '删除成功!'
            // });
          }).catch(() => {//No的功能在这里写
            this.model.ledgrp.rec.revflg ='X'
                // this.$message({
                //   type: 'info',
                //   message: '已取消'
                // });  
          }); 
    }
  }
  },
  created: function () {},
};
</script>
<style>
.marginLable {
  padding-left: 160px;
}
</style>