<template>
  <div class="eibs-tab">
    <!-- <c-col :span="24" style="padding: 0 0 10px 0">
      <c-button size="small" type="primary" @click="onInfbutSearow">
        Search
      </c-button>
      <c-button size="small" type="primary" @click="onInfbutDsp">
        Display
      </c-button>
      <c-button size="small" type="primary" @click="onInfbutUserow">
        Use
      </c-button>
      <c-button size="small" type="primary" @click="onInfbutClr">
        Clear
      </c-button>
      <c-button size="small" type="primary" @click="onInfbutButprt">
        导Excel
      </c-button>
      <c-button size="small" type="primary" @click="onInfbutExi">
        Exit
      </c-button>
    </c-col> -->

    <c-list-search @form-reset="handleReset" @form-search="handleSearch">
      <template v-slot="searchSlot">
        <c-col :span="11" :offset="1">
          <el-form-item label="Own Reference" prop="infcon.seaownref">
            <c-input
              v-model="model.infcon.seaownref"
              maxlength="16"
              placeholder="请输入Own Reference"
            ></c-input>
          </el-form-item>
        </c-col>

        <c-col :offset="1" :span="5.5">
          <el-form-item label="Opening between" prop="infcon.opndatfrom">
            <c-date-picker
              type="date"
              v-model="model.infcon.opndatfrom"
              style="width: 100%"
              placeholder="请选择Opening between"
            ></c-date-picker>
          </el-form-item>
        </c-col>
        <c-col :span="5.5">
          <el-form-item label="Open Date to" prop="infcon.opndatto">
            <c-date-picker
              type="date"
              v-model="model.infcon.opndatto"
              style="width: 100%"
              placeholder="请选择Open Date to"
            ></c-date-picker>
          </el-form-item>
        </c-col>
        <el-row v-show="searchSlot.searchToggle">
          <c-col :span="11" :offset="1">
            <c-col :span="22">
              <el-form-item label="Party Reference" prop="infcon.searef">
                <c-input
                  v-model="model.infcon.searef"
                  maxlength="16"
                  placeholder="请输入Party Reference"
                ></c-input>
              </el-form-item>
            </c-col>
            <c-col :span="24">
              <el-form-item
                label="Select Single Party"
                prop="infcon.pty.extkey"
              >
                <c-input
                  v-model="model.infcon.pty.extkey"
                  maxlength="24"
                  placeholder="请输入Select Single Party"
                ></c-input>
              </el-form-item>
            </c-col>
            <c-col :span="24">
              <el-form-item label="Party Name/BIC" prop="infcon.seapty">
                <c-input
                  v-model="model.infcon.seapty"
                  maxlength="24"
                  placeholder="请输入Party Name/BIC"
                ></c-input>
              </el-form-item>
            </c-col>
            <c-col :span="24">
              <el-form-item label="Currency" prop="infcon.seacur">
                <c-select
                  v-model="model.infcon.seacur"
                  style="width: 100%"
                  placeholder="请选择Currency"
                >
                </c-select>
              </el-form-item>
            </c-col>

            <c-col :span="12">
              <el-form-item label="Responsible" prop="infcon.usr.extkey">
                <c-input
                  v-model="model.infcon.usr.extkey"
                  maxlength="8"
                  placeholder="请输入User ID"
                ></c-input>
              </el-form-item>
            </c-col>
            <c-col :span="12">
              <el-form-item label="Status" prop="infcon.seasta">
                <c-select
                  v-model="model.infcon.seasta"
                  style="width: 100%"
                  placeholder="请选择Status"
                >
                </c-select>
              </el-form-item>
            </c-col>
          </c-col>

          <!--右边-->

          <c-col :span="11" :offset="1">
            <c-col :span="24"
              ><el-form-item label="Name" prop="infcon.nam">
                <c-input
                  v-model="model.infcon.nam"
                  maxlength="40"
                  placeholder="请输入Name"
                ></c-input> </el-form-item
            ></c-col>
            <c-col :span="22">
              <el-form-item label="Handling Type" prop="infcon.hndtyp">
                <c-select
                  v-model="model.infcon.hndtyp"
                  style="width: 100%"
                  placeholder="请选择Handling Type"
                >
                </c-select>
              </el-form-item>
            </c-col>
            <c-col :span="24">
              <el-form-item label="Party Name" prop="infcon.pty.nam">
                <c-input
                  v-model="model.infcon.pty.nam"
                  maxlength="40"
                  placeholder="请输入External Visible Name"
                ></c-input>
              </el-form-item>
            </c-col>
            <c-col :span="20">
              <el-form-item label="Role" prop="infcon.searol">
                <c-select
                  v-model="model.infcon.searol"
                  style="width: 100%"
                  placeholder="请选择Role"
                >
                </c-select>
              </el-form-item>
            </c-col>
            
            <c-col :span="12">
              <el-form-item label="Amount between" prop="infcon.seaamtfr">
                <c-input
                  v-model="model.infcon.seaamtfr"
                  placeholder="0.00"
                ></c-input>
              </el-form-item>
            </c-col>
            <c-col :span="12">
              <el-form-item label="and" prop="infcon.seaamtto">
                <c-input
                  v-model="model.infcon.seaamtto"
                  placeholder="0.00"
                ></c-input>
              </el-form-item>
            </c-col>
          </c-col>
        </el-row>
      </template>
    </c-list-search>
    <c-col :span="24">
      <c-istream-table
        :list="stmData.data"
        :columns="stmData.columns"
        prop="infbut.dspstm"
      >
        <el-table-column fixed="right" prop="op" label="操作" width="210px">
          <template slot="header">
            <c-col :span="11" :offset="1" style="text-align: left"><span>操作</span></c-col>
            <c-col :span="10" style="text-align: center"
              ><c-button icon="el-icon-s-tools"></c-button
            ></c-col>
          </template>

          <template slot-scope="scope">
              <el-popover
                placement="top-start"
                title="历史信息"
                width="800"
                trigger="click"
                :ref="'popover_' + scope.row.IDX"
              >
              <div style="text-align: right; margin-top: -30px; margin-right: 5px; font-size: 16px;">
               <span class="el-icon-close" @click="closeTrn('popover_' + scope.row.IDX)"/>
              </div>
                <c-istream-table
                  :list="trnData.data"
                  :columns="trnData.columns"
                >
                  <el-table-column prop="op" label="操作" width="0">
                    <template slot-scope="scope">
                      <c-button
                        style="margin-left: 0"
                        size="small"
                        @click="display(scope.row['INR'])"
                      >
                        详情
                      </c-button>
                    </template>
                  </el-table-column>
                </c-istream-table>
                <c-button
                  style="margin-left: 0"
                  size="small"
                  @click="getTrnInfo(scope.$index, scope.row)"
                  slot="reference"
                >
                  详情
                </c-button>
                <!-- <c-button
                  style="margin-left: 0"
                  size="small"
                 
                >
                  关闭
                </c-button> -->
              </el-popover>

              <!-- <c-button
                style="margin-left: 0"
                size="small"
                @click="getTrnInfo(scope.$index,scope.row)"
              >
                详情
              </c-button> -->
              <c-button
                style="margin-left: 0"
                size="small"
                type="primary"
                @click="getButtons(scope.row['Reference'])"
              >
                处理
              </c-button>

              <c-button
                style="margin-left: 0"
                size="small"
                type="primary"
                @click="getDitSelInfo(scope.$index, scope.row)"
              >
                display
              </c-button>
            </template>


          <!-- <template slot-scope="scope">
            <c-button style="margin-left: 0" size="small" @click="onDetails"
              >详情
            </c-button>
            <c-button
              style="margin-left: 0"
              size="small"
              type="primary"
              @click="onInfbutDsp(scope.row)"
              >处理
            </c-button>
            <c-button
                style="margin-left: 0"
                size="small"
                type="primary"
                @click="getDitSelInfo(scope.$index, scope.row)"
              >
                info
              </c-button>
          </template> -->
        </el-table-column>
        <!--el-table-column prop="op" label="OP" width="100">placeholder="请输入display stream"</el-table-column-->
      </c-istream-table>
    </c-col>
    <el-dialog :visible.sync="initdialog" :title="'交易列表'" append-to-body>
      <div class="m-list-btns">
        <m-busbtn ref="childs" :ownref="ownref" @onChoose="onChoose"
          >11</m-busbtn
        >
      </div>
    </el-dialog>
  </div>
</template>
<script>
import Api from "~/service/Api";
import Utils from "~/utils/index";
import commonProcess from "~/mixin/commonProcess";
import CodeTable from "~/config/CodeTable";
import Event from "~/model/Infltd/Event";
import BusNavbar from "~/views/Business/Infltd/BusNavbar";

export default {
  inject: ["root"],
  props: ["model", "codes"],
  mixins: [commonProcess],
  components: { "m-busbtn": BusNavbar },
  data() {
    return {
      ownref: "",
      initdialog: false,
      dialogTableVisible: false,
      trnData: {
        columns: [
          '1 1 "编号" 200',
          '2 2 "交易名称" 120',
          // '3 3 "日期" 200',
          {index:3,position:3,width:110,pattern:'date',label:'日期'},
          // '4 4 "状态" 50',
          {index:4,position:4,width:100,pattern:'code',label:'状态',code:this.codes.relstaEN},
          '5 5 "币种" 80',
          '6 6 "金额" 110',
        ],
        data: [],
      },
      stmData: {
        columns: [
          '1 1 "Reference" 150 ',
          '8 2 "Party Number" 275',
          '9 2 "1st Beneficiary" 275',
          '11 3 "Party Number" 275',
          '12 3 "2nd Beneficiary" 275',
          // "18 5 \"MT\" 100",
          '3 4 "Opened" 200',
          '4 4 "Expired" 200',
          '5 4 "Closed" 200',
          '15 5 "Cur" 75',
          //'17 5 "Cur" 75',
          '16 6"Open Amt" 150',
          '18 7"Account Amt" 150',
        ],
        data: [],
      },
    };
  },
  methods: { ...Event ,
  closeTrn(refId){
       this.$refs[refId].doClose();
  },
  async  onChoose(code){
            //跳转交易
          this.$router.history.push("/business/" + code) 
          this.initdialog = false                    
        } ,
  async getTrnInfo(idx, row) {

      this.model.infcon.objinr = row["INR"];
      this.model.ltdgrp.rec.inr = row["INR"];
      this.model.infcon.chksubcon = "X";

      this.dialogTableVisible = true;
      let rtnmsg = await this.executeDefault("infcon.chksubcon");

      if ((rtnmsg.respCode = SUCCESS)) {
        this.trnData.data = rtnmsg.data.infcon_trnstm.rows;
      }
    },
    async getButtons(ownref){
        this.initdialog = true
        this.ownref = ownref
        console.log("ownref:" +ownref);
        setTimeout(()=>{
        this.$refs.childs.$emit("childmethods")
        },10)
      },
      async getDitSelInfo(idx,row){
          //TD中选中行触发
          var params = {selDst:"infbut.dspstm",selIds:[idx+1]}
          let rtnmsg = await this.executeRule("infbut.dspstm", params);  
          if(rtnmsg.respCode = SUCCESS){
            this.updateModel(rtnmsg.data);
            // Utils.copyValueFromVO(this.model, rtnmsg.data);
            //TD中点击display时触发
            params = {selDst:"infbut.dsp",selIds:[idx+1]}
            let rtnmsgNew = await this.executeRule("infbut.dsp", params); 

            if(rtnmsgNew.respCode = SUCCESS){
              console.log(rtnmsgNew);
              this.updateModel(rtnmsgNew.data);

              let rtnmsgOitset = await this.executeDefault("mtabut.coninf.oitset.oit"); 

                if(rtnmsgOitset.respCode = SUCCESS){
                  Utils.copyValueFromVO(this.model, rtnmsgOitset.data);

                }
            }
          }
          //触发父组件中updateShowPanel 事件,修改index中showPanel ,控制 index中组件的显示和隐藏
          this.$emit('updateShowPanel', true)
                  
    },
  },
  created: function () {},
};
</script>
<style>
</style>