<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="基础交易编号" prop="bpdgrp.rec.pntref">
            <c-input v-model="model.bpdgrp.rec.pntref" maxlength="16" disabled placeholder="请输入基础交易编号"></c-input>
          </el-form-item>
        </c-col>

        <c-col :span="24">
          <el-form-item label="融资业务编号" prop="bpdgrp.rec.ownref">
            <c-fullbox>
              <c-input v-model="model.bpdgrp.rec.ownref" disabled @change="defaultFinCodN1000" placeholder="请输入融资业务编号"></c-input>
              <template slot="footer">
                <c-button :disabled="model.bpdgrp.rec.fintyp=='' || model.bpdgrp.fia.pts.ptyinr==''" style="margin-left: 10px" size="small" type="primary" @click="queryOwnref">获取</c-button>
              </template>
            </c-fullbox>
          </el-form-item>
        </c-col>

        <!-- <c-col :span="24" v-if="model.bpdgrp.rec.fintyp=='F' || model.bpdgrp.rec.fintyp=='G'">
					<el-form-item label="福费廷业务编号" prop="fpdgrp.rec.ownref">
						<c-input v-model="model.fpdgrp.rec.ownref" maxlength="16" disabled placeholder="请输入福费廷业务编号"></c-input>
					</el-form-item>
				</c-col> -->

        <c-col :span="24">
          <el-form-item label="经办柜员" prop="bptp.usr.extkey">
            <c-input v-model="model.bptp.usr.extkey" maxlength="8" disabled placeholder="请输入经办柜员"></c-input>
          </el-form-item>
        </c-col>

        <c-col :span="24">
          <el-form-item label="抵押标志" prop="bpdgrp.rec.guaflg">
            <c-select dbCode="guaflg" v-model="model.bpdgrp.rec.guaflg" style="width:100%" placeholder="请选择抵押标志">
            </c-select>
          </el-form-item>
        </c-col>

        <c-col :span="24">
          <c-col :span="12">
            <el-form-item label="融资类型" prop="bpdgrp.rec.fintyp">
              <c-select v-model="model.bpdgrp.rec.fintyp" dbCode="BPDTYP" sort="SRT" :filterKey="model.fintypCT" @change="fintypChange" style="width:100%" placeholder="请选择融资类型">
              </c-select>
            </el-form-item>
          </c-col>
          <c-col :span="12" v-if="model.bpdgrp.rec.fintyp=='P' || model.bpdgrp.rec.fintyp=='M'">
            <el-form-item label-width="5px" prop="bptp.purtyp">
              <c-select dbCode="PURTYP" :filterKey="setPurtyp" sort="SRT" v-model="model.bptp.purtyp" @change="purtypChange" style="width:100%" placeholder="请选择">
              </c-select>
            </el-form-item>
          </c-col>
          <c-col :span="12" v-if="model.bpdgrp.rec.fintyp=='D' || model.bpdgrp.rec.fintyp=='T'">
            <el-form-item label-width="5px" prop="bptp.distyp">
              <c-select dbCode="DISTYP" v-model="model.bptp.distyp" @change="distypChange" style="width:100%" placeholder="请选择">
              </c-select>
            </el-form-item>
          </c-col>
        </c-col>

        <c-col :span="24" v-if="model.finmod.intprd=='7' && (model.bpdgrp.rec.fintyp=='F' || model.bpdgrp.rec.fintyp=='G')">
          <el-form-item label="福费廷转卖类型" prop="bpdgrp.rec.ffttyp">
            <c-select v-model="model.bpdgrp.rec.ffttyp" dbCode="FFTTYP" :filterKey="['0']" @change="ffttypChange" maxlength="16" placeholder="请选择福费廷转卖类型"></c-select>
          </el-form-item>
        </c-col>

        <c-col :span="24" v-if="model.bpdgrp.rec.fortyp=='2' && model.bpdgrp.rec.fintyp=='F'">
          <c-col :span="12">
            <el-form-item label="信用证金额" prop="ledgrp.cbs.nom1.cur">
              <c-select-cur v-model="model.ledgrp.cbs.nom1.cur" dbCode="curtxt" sort="SRT" style="width:100%" placeholder="请选择信用证币种">
              </c-select-cur>
            </el-form-item>
          </c-col>
          <c-col :span="12">
            <el-form-item label-width="5px" prop="ledgrp.cbs.nom1.amt">
              <c-input-currency v-model="model.ledgrp.cbs.nom1.amt" placeholder="请输入信用证金额"></c-input-currency>
            </el-form-item>
          </c-col>
        </c-col>

        <c-col :span="24" v-if="model.bpdgrp.rec.fortyp=='2' && model.bpdgrp.rec.fintyp=='G'">
          <c-col :span="12">
            <el-form-item label="信用证金额" prop="dedgrp.cbs.nom1.cur">
              <c-select-cur v-model="model.dedgrp.cbs.nom1.cur" dbCode="curtxt" sort="SRT" style="width:100%" placeholder="请选择信用证币种">
              </c-select-cur>
            </el-form-item>
          </c-col>
          <c-col :span="12">
            <el-form-item label-width="5px" prop="dedgrp.cbs.nom1.amt">
              <c-input-currency v-model="model.dedgrp.cbs.nom1.amt" placeholder="请输入信用证金额"></c-input-currency>
            </el-form-item>
          </c-col>
        </c-col>

        <c-col :span="24" v-if="isDisableCur">
          <c-col :span="12">
            <el-form-item label="可融资单据余额" prop="tensetcur">
              <c-select disabled dbCode="curtxt" v-model="model.tensetcur" style="width:100%" placeholder="请选择币种">
              </c-select>
            </el-form-item>
          </c-col>
          <c-col :span="12">
            <el-form-item label-width="5px" prop="tensetamt">
              <c-input-currency disabled v-model="model.tensetamt" placeholder="请输入金额"></c-input-currency>
            </el-form-item>
          </c-col>
        </c-col>

        <c-col :span="24" v-if="model.bpdgrp.rec.fintyp=='F' || (model.bpdgrp.rec.fintyp=='D' && model.bptp.distyp=='DIS') || (model.bpdgrp.rec.fintyp=='P' && model.bptp.purtyp=='NB0')">
          <el-form-item label="基础贸易是/否跨境货物贸易" prop="bpdgrp.rec.iscrotra">
            <c-select dbCode="ISCROT" v-model="model.bpdgrp.rec.iscrotra" maxlength="16" placeholder="请输入基础贸易是/否跨境货物贸易"></c-select>
          </el-form-item>
        </c-col>

        <c-col :span="24" v-if="model.bpdgrp.rec.pnttyp=='' && ((model.bpdgrp.rec.fintyp=='P' && model.bptp.purtyp!='BO') || model.bpdgrp.rec.fintyp=='D')">
          <el-form-item label="基础交易编号" prop="bedgrp.rec.ownref">
            <c-input v-model="model.bedgrp.rec.ownref" maxlength="16" placeholder="请输入基础交易编号"></c-input>
          </el-form-item>
        </c-col>

        <c-col :span="24" v-if="model.bpdgrp.rec.pnttyp=='' && model.bpdgrp.rec.fintyp=='P' && model.bptp.purtyp=='BO'">
          <el-form-item label="基础交易编号" prop="bodgrp.rec.ownref">
            <c-input v-model="model.bodgrp.rec.ownref" maxlength="16" placeholder="请输入基础交易编号"></c-input>
          </el-form-item>
        </c-col>

        <c-col :span="24" v-if="model.onlybptflg=='Y' && model.bpdgrp.rec.fintyp=='G' && model.bptp.fortyp=='1'">
          <el-form-item label="基础交易编号" prop="bodgrp.rec.ownref">
            <c-input v-model="model.bfdgrp.rec.ownref" maxlength="16" placeholder="请输入基础交易编号"></c-input>
          </el-form-item>
        </c-col>

        <!-- <c-col :span="24" v-if="model.bpdgrp.rec.pnttyp!=''">
					<c-istream-table ref="table" :list="model.liaall.tenstm.rows || []" :columns="stmData.columns" :showSelection="true" prop="liaall.tenstm">
					</c-istream-table>
				</c-col> -->

      </c-col>

      <!-- ============右边================= -->
      <c-col :span="12" style="padding-left: 20px">
        <c-col :span="24">
          <c-ptap :model="model" :argadr="{title:'融资申请人', grp: 'bpdgrp', rol: 'fia'}" ptytyp="C" :disabledExtkey="model.onlybptflg!='Y'" :disabled="model.onlybptflg!='Y'" @handleChange="partyChange" @clear="partyChange" v-if="model.bpdgrp.rec.pnttyp!='BFD'"></c-ptap>
          <el-card class="box-card" v-if="model.bpdgrp.rec.pnttyp==='BFD'">
            <c-ptap3 :model="model" :argadr="{
              title: '融资申请人',
							grp: 'bpdgrp',
							rol: 'fia'
						}" @handleChange="partyChange" @clear="partyChange" :isShowCard="false" :requiredExtkey="true" :isShowNam="true" :isShowAdr="true" :disabledExtkey="model.onlybptflg!='Y'" :isDisabled="true" :disabledNamelc="true" :disabledAdrelc="true" ptytyp='C'>
            </c-ptap3>
          </el-card>
        </c-col>

        <c-col :span="24" v-if="model.bpdgrp.rec.fintyp!='T' && model.bpdgrp.rec.fintyp!='M' && model.bpdgrp.rec.fintyp!='G' && model.bpdgrp.rec.fintyp!='F' && model.bpdgrp.rec.fortyp!='2'">
          <el-form-item label="" prop="dftcre.dfflag">
            <c-checkbox class="checkbox-left" true-label="X" false-label="" v-model="model.dftcre.dfflag">委托方代付</c-checkbox>
          </el-form-item>
        </c-col>

        <c-col :span="24" v-if="model.bpdgrp.rec.pntref==''">
          <el-form-item label="贸易合同号" prop="bpdgrp.rec.mycontno">
            <c-input v-model="model.bpdgrp.rec.mycontno" maxlength="35" placeholder="请输入贸易合同号"></c-input>
          </el-form-item>
        </c-col>

        <c-col :span="24">
          <el-form-item label="中文货物描述" prop="bpdgrp.rec.goddspcn">
            <c-input v-model="model.bpdgrp.rec.goddspcn" type="textarea" show-word-limit maxlength="100" placeholder="请输入中文货物描述"></c-input>
          </el-form-item>
        </c-col>

      </c-col>

      <c-col :span="24" v-if="model.bpdgrp.rec.pnttyp!='' && !this.isInfo">
        <el-table :data="model.liaall.tenorSettles" :columns="columns" :showButtonFlg="true">
          <!-- <el-table-column label="Cur" prop="cur" align="left" min-width="150" :show-overflow-tooltip="true" sortable>
        </el-table-column> -->
          <el-table-column v-for="(item, key) in columns" :key="key" :label="item.label" :width="item.width">
            <template slot-scope="scope">
              <span>{{ ['oldamt'].includes(item.prop) ? moneyFormat(scope.row[item.prop], scope.row.cur) : scope.row[item.prop] }}</span>
            </template>
          </el-table-column>
        </el-table>
        <!-- <c-istream-table ref="table" :list="model.liaall.tenstm.rows || []" :columns="stmData.columns" :showSelection="true" prop="liaall.tenstm">
				</c-istream-table> -->
      </c-col>
    </c-col>
  </div>
</template>

<script>
import event from "../event";
import Default from "../model/default";

export default {
  inject: ["root"],
  props: ["model", "codes"],
  mixins: [event, Default],
  data() {
    return {
      columns: [
        {
          label: "Type",
          prop: "cbtpfx"
        },
        {
          label: "Dbt",
          prop: "rol"
        },
        {
          label: "Cbt",
          prop: "cdtrol"
        },
        {
          label: "Cur",
          prop: "cur"
        },
        {
          label: "Amt",
          prop: "oldamt"
        },
        {
          label: "Mat.Dat.",
          prop: "matdat"
        }
      ]
    };
  },
  methods: {
    iscrotraChange() {
      if (
        this.model.bpdgrp.rec.fintyp != "F" &&
        (this.model.bpdgrp.rec.fintyp != "D" ||
          this.model.bptp.distyp != "DIS") &&
        (this.model.bpdgrp.rec.fintyp != "P" || this.model.bptp.purtyp != "NB0")
      ) {
        this.model.bpdgrp.rec.iscrotra = "";
      }
    },
    defaultFinCodN1000() {
      // 事件
      // 一个业务参考号下只能对应一笔借据号,因此简单用业务参考号赋值即可
      this.finmod.fincod = this.model.bpdgrp.rec.ownref;
      this.model.bpdgrp.rec.fincod = this.finmod.fincod;
    },
    //客户变更
    async partyChange() {
      // if (this.isBundFftmsg) {
      //   this.$alert("请先解绑LOA/NOA报文", "提示", {
      //     confirmButtonText: "确定"
      //   });
      //   return;
      // }
      this.model.bpdgrp.rec.ownref = "";
      this.defaultAccountsN1100();
      await this.defaultFinmod();
      this.defaultBpdgrpRecTolratN1000();
    },
    //福费廷转卖类型变更
    async ffttypChange() {
      debugger;
      if (this.model.bpdgrp.rec.ffttyp == "") {
        this.model.bpdgrp.rec.bmhrat = "";
      }
      await this.defaultFinmod();
      this.defaultBpdgrpRecTolratN1000();
    },
    //融资类型变更
    async fintypChange() {
      // if (this.isBundFftmsg) {
      //   this.$alert("请先解绑LOA/NOA报文", "提示", {
      //     confirmButtonText: "确定"
      //   });
      //   return;
      // }
      this.model.bpdgrp.rec.ownref = "";
      this.model.bpdgrp.rec.ffttyp = "";
      if (this.model.dedgrp.rec.elcflg === "Y") {
        if (this.model.bpdgrp.rec.fintyp === "G") {
          this.model.bptp.rcssta = "WORE";
        } else {
          this.model.bptp.rcssta = "WIRE";
        }
      }
      this.defaultFinmodIntprdN1000();
      this.defaultForTypsN1000();
      this.defaultFinTypes();
      await this.defaultFinmod();
      this.defaultBpdgrpRecTolratN1000();
      this.defaultParties();
      this.changFintypSetInv();
    },
    //是否合格押汇变更
    purtypChange() {
      this.defaultFinTypes();
    },
    //是否合格贴现变更
    distypChange() {
      this.defaultFinTypes();
    }
  },
  computed: {
    isDisableCur() {
      if (
        this.model.bpdgrp.rec.pnttyp == "" &&
        this.model.bpdgrp.rec.fpdinr == ""
      ) {
        return false;
      } else {
        if (this.model.onlybptflg == "Y" && this.model.spt.sta != "") {
          return false;
        } else {
          return true;
        }
      }
    },
    changeFiaPtyTyp() {
      let ptytyp = "C";
      if (
        (this.model.bpdgrp.rec.fintyp == "F" ||
          this.model.bpdgrp.rec.fintyp == "G") &&
        this.model.bpdgrp.rec.fortyp == "2"
      ) {
        ptytyp = "B";
      }
      return ptytyp;
    },
    setPurtyp() {
      if (
        this.model.bpdgrp.rec.pnttyp === "BED" ||
        this.model.bpdgrp.rec.pnttyp === "BFD"
      ) {
        return ["NB0", "DSB"];
      } else {
        return ["DSB", "BO"];
      }
    }
  },
  watch: {
    "model.bpdgrp.rec.ownref": {
      handler(val, oldval) {
        this.model.finmod.fincod = val;
        this.model.bpdgrp.rec.fincod = this.model.finmod.fincod;
        this.model.blcgrp.rec.relref = val;
        this.model.zxbgrp.rec.relref = val;
      }
    }
  },
  created() {}
};
</script>

<style lang="less" scoped>
.eibs /deep/ .el-form-item__label {
  display: flex;
  justify-content: flex-end;
}
</style>