<template>
  <div class="eibs-tab">
    <c-col :span="24">
      <c-col :span="12" style="padding-right: 20px">
        <c-col :span="24">
          <el-form-item label="业务编号(20)" prop="cpdgrp.rec.ownref" style="width: 100%">
            <c-fullbox>
              <c-input v-model="model.cpdgrp.rec.ownref" maxlength="16" placeholder="请输入业务编号" disabled>
              </c-input>
              <template slot="footer">
                <c-button style="margin: 0 10px 0 10px; padding: 0 12px; height: 32px" size="small" type="primary"
                  icon="el-icon-search">
                </c-button>
                <c-button style="margin: 0 0" size="small" type="primary" :disabled="model.cpdgrp.orc.pts.ptainr == ''"
                  @click="getOwnref()">
                  获取
                </c-button>
              </template>
            </c-fullbox>
          </el-form-item>
        </c-col>
        <c-col :span="24">
          <c-col :span="24" class="custom-box-wrap">
            <div style="width: 200px;">
              <el-form-item label="汇款金额(32a)" prop="cpdgrp.cbs.nom1.cur">
                <c-select-cur v-model="model.cpdgrp.cbs.nom1.cur" style="width:100%" dbCode="CURTXT" sort="SRT"
                  placeholder="请选择币种" @change="nom1CurSwftChange()" :expKey="['CNY']" :isShowKeyAndLabel="true">
                </c-select-cur>
              </el-form-item>
            </div>
            <div style="width: calc(100% - 200px);">
              <c-fullbox>
                <div style="display: flex;margin-right: 5px;">
                  <el-form-item label-width="5px" prop="cpdgrp.cbs.nom1.amt" style="width: 50%;">
                    <c-input-currency :currency="model.cpdgrp.cbs.nom1.cur" v-model="model.cpdgrp.cbs.nom1.amt"
                      placeholder="请输入汇款金额" @blur="nom1AmtSwftBlur()" :disabled="model.calflg == 'Y'">
                    </c-input-currency>
                  </el-form-item>
                  <el-form-item label-width="5px" style="width: 50%;">
                    <c-input-currency currency="CNY" v-model="model.cnyamt" placeholder="等值人民币购汇汇出"
                      @blur="cnyamtBlur()" :disabled="model.calflg != 'Y'"></c-input-currency>
                  </el-form-item>
                </div>
                <template slot="footer">
                  <el-tooltip effect="dark" content="等值人民币购汇汇出" placement="top" size="large">
                    <c-checkbox v-model="model.calflg" true-label="Y" false-label="N" @change="calflgChange()">
                    </c-checkbox>
                  </el-tooltip>
                </template>
              </c-fullbox>
            </div>
          </c-col>
        </c-col>
        <c-col :span="24">
          <el-form-item label="费用承担方(71a)" prop="cpdgrp.rec.detchgcod">
            <c-select placeholder="请选择费用承担方" style="width:100%" v-model="model.cpdgrp.rec.detchgcod" dbCode="FEECOD"
              uil="CN" sort="SRT" :filterKey="['SHA','BEN','OUR']" :isShowKeyAndLabel="true">
            </c-select>
          </el-form-item>
        </c-col>

        <c-col :span="24" v-if="model.cpdgrp.rec.swftyp == '103' || model.cpdgrp.rec.swftyp == '202'">
          <c-col :span="24" class="custom-box-wrap">
            <div style="width: 200px;">
              <el-form-item label="原始金额(33b)" prop="cpdgrp.rec.curf33b"
                :rules="[{required: (model.cpdgrp.rec.swftyp == '103' || model.cpdgrp.rec.swftyp == '202') && model.cpdgrp.rec.detchgcod == 'BEN'}]">
                <c-select v-model="model.cpdgrp.rec.curf33b" style="width:100%" dbCode="CURTXT" sort="SRT"
                  placeholder="请选择币种" :disabled="model.cpdgrp.rec.detchgcod != 'BEN'" :expKey="['CNY']" :isShowKeyAndLabel="true">
                </c-select>
              </el-form-item>
            </div>
            <div style="width: calc(100% - 200px);">
              <el-form-item label-width="5px" prop="cpdgrp.rec.amtf33b"
                :rules="[{required: (model.cpdgrp.rec.swftyp == '103' || model.cpdgrp.rec.swftyp == '202') && model.cpdgrp.rec.detchgcod == 'BEN'}]">
                <c-input-currency :currency="model.cpdgrp.rec.curf33b" v-model="model.cpdgrp.rec.amtf33b"
                  :maxlength="18" style="width:100%;" placeholder="请输入原始金额" :disabled="model.cpdgrp.rec.detchgcod != 'BEN'">
                </c-input-currency>
              </el-form-item>
            </div>
          </c-col>
        </c-col>
        <c-col :span="24" v-if="model.cpdgrp.rec.swftyp == '103' || model.cpdgrp.rec.swftyp == '202'">
          <el-form-item label="汇率(36)" prop="cpdgrp.rec.f36">
            <c-input-currency :precision='6' v-model="model.cpdgrp.rec.f36" placeholder="请输入汇率"
              :disabled="f36Disabled()"></c-input-currency>
          </el-form-item>
        </c-col>
        <c-col :span="24" v-if="model.cpdgrp.rec.swftyp == '103' || model.cpdgrp.rec.swftyp == '202'">
          <c-col :span="24" class="custom-box-wrap">
            <div style="width: 200px;">
              <el-form-item label="发报行扣费金额(71f)" prop="cpdgrp.rec.cur71f"
                :rules="[{required: (model.cpdgrp.rec.swftyp == '103' || model.cpdgrp.rec.swftyp == '202') && model.cpdgrp.rec.detchgcod == 'BEN'}]">
                <c-select-cur v-model="model.cpdgrp.rec.cur71f" style="width:100%" dbCode="CURTXT" sort="SRT"
                  placeholder="请选择币种" :disabled="model.cpdgrp.rec.detchgcod != 'BEN'" :expKey="['CNY']" :isShowKeyAndLabel="true">
                </c-select-cur>
              </el-form-item>
            </div>
            <div style="width: calc(100% - 200px);">
              <el-form-item label-width="5px" prop="cpdgrp.rec.amt71f"
                :rules="[{required: (model.cpdgrp.rec.swftyp == '103' || model.cpdgrp.rec.swftyp == '202') && model.cpdgrp.rec.detchgcod == 'BEN'}]">
                <c-input-currency :currency="model.cpdgrp.rec.cur71f" v-model="model.cpdgrp.rec.amt71f" :maxlength="18"
                  style="width:100%;" placeholder="请输入发报行扣费金额" :disabled="model.cpdgrp.rec.detchgcod != 'BEN'">
                </c-input-currency>
              </el-form-item>
            </div>
          </c-col>
        </c-col>
        <c-col :span="24" v-if="model.cptp.qsfysd == '1' && model.cpdgrp.rec.swftyp == '103'">
          <el-form-item label="服务提供银行" prop="cptp.fwtgyh"
            :rules="[{required: model.cptp.qsfysd == '1' && model.cpdgrp.rec.swftyp == '103'}]">
            <c-select v-model="model.cptp.fwtgyh" style="width:100%" placeholder="请选择服务提供银行">
              <el-option v-for="item in model.fwtgyhSet" :key="item.value" :value="item.value" :label="`${item.value}`">
              </el-option>
            </c-select>
          </el-form-item>
        </c-col>
        <c-col :span="24">
          <c-col :span="5" v-if="model.cpdgrp.rec.swftyp == '200'">
            <el-form-item prop="trtcre.crefinflg" class="checkbox-left">
              <c-checkbox v-model="model.trtcre.crefinflg" @change="onCrefinflgChangeSwt" true-label="X" false-label="">融资</c-checkbox>
            </el-form-item>
          </c-col>
          <c-col :span="5" v-if="model.cpdgrp.rec.swftyp == '200'">
            <el-form-item prop="dftcre.dfflag" class="checkbox-left">
              <c-checkbox v-model="model.dftcre.dfflag" :disabled="model.trtcre.crefinflg !== 'X'" true-label="X" false-label="">委托方代付</c-checkbox>
            </el-form-item>
          </c-col>
          <c-col :span="5" v-if="model.cpdgrp.rec.swftyp == '200'">
            <el-form-item prop="cpdgrp.rec.tsnflg" class="checkbox-left">
              <c-checkbox v-model="model.cpdgrp.rec.tsnflg" true-label="X" false-label="">同名划转</c-checkbox>
            </el-form-item>
          </c-col>
        </c-col>

      </c-col>

      <!-- ======================= 右边 ========================= -->
      <c-col :span="12" style="padding-left: 20px">
        <c-col :span="24">
          <el-form-item label="汇款方式" prop="cpdgrp.rec.paytype">
            <c-select v-model="model.cpdgrp.rec.paytype" style="width:100%" placeholder="请选择汇款方式" dbCode="CPATYP"
              uil="CN" sort="SRT">
            </c-select>
          </el-form-item>
        </c-col>
        <c-col :span="24">
          <el-form-item label="汇款性质" prop="cpdgrp.rec.trntyp">
            <c-select v-model="model.cpdgrp.rec.trntyp" style="width:100%" placeholder="请选择汇款性质" dbCode="CTRTYE"
              uil="CN" sort="SRT" :filterKey="['01','02','03','04','05','06','07','08','09','10']">
            </c-select>
          </el-form-item>
        </c-col>
        <c-col :span="24">
          <el-form-item label="是否需要核验" prop="cpdgrp.rec.ischktyp">
            <c-select v-model="model.cpdgrp.rec.ischktyp" style="width:100%" placeholder="请选择是否需要核验" dbCode="ISYN"
              uil="CN" sort="SRT" @change="ischktypSwftChange()">
            </c-select>
          </el-form-item>
        </c-col>
        <c-col :span="24">
          <el-form-item label="预计核验日期" prop="cpdgrp.rec.prechkdat"
            :rules="[{required: model.cpdgrp.rec.ischktyp == 'Y'}]">
            <c-date-picker type="date" v-model="model.cpdgrp.rec.prechkdat" style="width:100%" placeholder="请选择预计核验日期"
              :disabled="model.cpdgrp.rec.ischktyp != 'Y'">
            </c-date-picker>
          </el-form-item>
        </c-col>
        <c-col :span="24">
          <el-form-item label="汇款语种" prop="cptp.payuil">
            <c-select placeholder="请选择汇款语种" style="width:100%" v-model="model.cptp.payuil" dbCode="PAYUIL" uil="CN"
              sort="SRT" disabled>
            </c-select>
          </el-form-item>
        </c-col>
        <c-col :span="24">
          <c-business-code
            v-model="model.boprem.dbbgrp.dcl.txcode"
            label="交易编码"
            prop="boprem.dbbgrp.dcl.txcode"
            :required="false"
            placeholder="请输入交易编码"
          ></c-business-code>
        </c-col>
        <c-col :span="24">
          <c-col :span="5" v-if="model.cpdgrp.rec.swftyp == '103' || model.cpdgrp.rec.swftyp == '202'">
            <el-form-item prop="trtcre.crefinflg" class="checkbox-left">
              <c-checkbox v-model="model.trtcre.crefinflg" @change="onCrefinflgChangeSwt" true-label="X" false-label="">融资</c-checkbox>
            </el-form-item>
          </c-col>
          <c-col :span="5" v-if="model.cpdgrp.rec.swftyp == '103' || model.cpdgrp.rec.swftyp == '202'">
            <el-form-item prop="dftcre.dfflag" class="checkbox-left">
              <c-checkbox v-model="model.dftcre.dfflag" :disabled="model.trtcre.crefinflg !== 'X'" true-label="X" false-label="">委托方代付</c-checkbox>
            </el-form-item>
          </c-col>
          <c-col :span="5" v-if="model.cpdgrp.rec.swftyp == '103' || model.cpdgrp.rec.swftyp == '202'">
            <el-form-item prop="cpdgrp.rec.tsnflg" class="checkbox-left">
              <c-checkbox v-model="model.cpdgrp.rec.tsnflg" true-label="X" false-label="">同名划转</c-checkbox>
            </el-form-item>
          </c-col>
          <c-col :span="5" v-if="model.cpdgrp.rec.swftyp == '103'">
            <el-form-item prop="cptp.qsfysd" class="checkbox-left">
              <c-checkbox v-model="model.cptp.qsfysd" true-label="1" false-label="0" @change="qsfysdSwftChange()">
                清算费用锁定服务
              </c-checkbox>
            </el-form-item>
          </c-col>
        </c-col>
      </c-col>
    </c-col>
    {{calcCuramt71f}}
    {{calcCuramt33b}}
  </div>
</template>
<script>
  import event from "../../event";
  import Default from "../../model/default";
  import BigNumber from 'bignumber.js';

  export default {
    inject: ["root"],
    props: ["model", "codes", "rules"],
    mixins: [event, Default],
    data() {
      return {};
    },
    methods: {
      onCrefinflgChangeSwt() {
      if (this.model.trtcre.crefinflg !== "X") {
          this.model.dftcre.dfflag = "";
        }
      },

    },
    created() {},
    computed: {
      calcCuramt71f() {
        let amt71f = 0;
        let cur71f = "";
        if ((this.model.cpdgrp.rec.swftyp == '103' || this.model.cpdgrp.rec.swftyp == '202') && this.model.cpdgrp.rec
          .detchgcod == 'BEN') {
          for (let index in this.model.setmod.setfeg.setfel) {
            let setfel = this.model.setmod.setfeg.setfel[index];
            if (setfel.rol === 'PYE' && setfel.dsp === 'X' && setfel.cur === this.model.cpdgrp.cbs.nom1.cur && Number(
                setfel.amt) > 0) {
              amt71f = new BigNumber(amt71f).plus(setfel.amt);
            }
          }
          cur71f = this.model.cpdgrp.cbs.nom1.cur;
        }
        this.model.cpdgrp.rec.amt71f = amt71f;
        this.model.cpdgrp.rec.cur71f = cur71f;
      },
      calcCuramt33b() {
        let amt33b = 0;
        let cur33b = "";
        if ((this.model.cpdgrp.rec.swftyp == '103' || this.model.cpdgrp.rec.swftyp == '202') && this.model.cpdgrp.rec
          .detchgcod == 'BEN') {
          amt33b = this.model.cpdgrp.cbs.nom1.amt;
          cur33b = this.model.cpdgrp.cbs.nom1.cur;
        }
        this.model.cpdgrp.rec.amtf33b = amt33b;
        this.model.cpdgrp.rec.curf33b = cur33b;
      },
    },
  };
</script>
<style scoped lang="less">
  .box-card {
    margin-bottom: 10px;

    /deep/ .el-form-item--mini.el-form-item,
    .el-form-item--small.el-form-item {
      margin-bottom: 10px;
    }

    /deep/ .el-card__body {
      padding: 10px 10px 10px 0px;
    }
  }

  .el-textarea .el-textarea__inner {
    height: 100px;
  }
</style>