<template>
    <div class="eibs-tab">
        <c-list-search @form-search="handleSearch">
            <template v-slot="searchSlot">
                <el-form class="m-table-search-form" ref="paramsForm" label-position="right" label-width="110px"
                    size="small">
                    <el-row>
                        <c-col :span="8">
                            <c-form-item label="业务编号" prop="cfaquep.ownref" style="width: 100%">
                                <c-input v-model="model.cfaquep.ownref" maxlength="16" placeholder="请输入业务编号"></c-input>
                            </c-form-item>
                        </c-col>
                        <c-col :span="8">
                            <el-form-item label="开立日期" prop="cfaquep.frmdat" style="width: 100%">
                                <c-col :span="11">
                                    <c-date-picker type="date" v-model="model.cfaquep.frmdat" style="width:100%"
                                        placeholder="请选择起始日期" value-format="yyyy-MM-dd"></c-date-picker>
                                </c-col>
                                <c-col :span="2" style="text-align: center">
                                    <label style="display: inline-block; width: 100%">-</label>
                                </c-col>
                                <c-col :span="11">
                                    <c-date-picker type="date" v-model="model.cfaquep.tildat" style="width:100%"
                                        placeholder="请选择截至日期" value-format="yyyy-MM-dd"></c-date-picker>
                                </c-col>
                            </el-form-item>
                        </c-col>
                        <c-col :span="8">
                            <el-form-item label="申报类型" prop="cfaquep.cfatyp" style="width: 100%">
                                <c-select v-model="model.cfaquep.cfatyp" style="width: 100%" placeholder="请选择申报类型"
                                    :code="codes.cfatyp1">
                                </c-select>
                            </el-form-item>
                        </c-col>
                    </el-row>
                    <el-row v-show="searchSlot.searchToggle">
                        <c-col :span="8">
                            <c-form-item label="申报号码" prop="cfaquep.rptno" style="width: 100%">
                                <c-input v-model="model.cfaquep.rptno" maxlength="28" placeholder="请输入申报号码">
                                </c-input>
                            </c-form-item>
                        </c-col>
                        <c-col :span="8">
                            <c-form-item label="查询日期类型" prop="cfaquep.dattyp" style="width: 100%">
                                <c-select v-model="model.cfaquep.dattyp" maxlength="1" style="width: 100%"
                                    placeholder="请选择查询日期类型" :code="codes.dattyp">
                                </c-select>
                            </c-form-item>
                        </c-col>
                        <c-col :span="8">
                            <c-form-item label="笔数" prop="cfaquep.sum" style="width: 100%">
                                <c-input v-model="model.cfaquep.sum" placeholder="请输入笔数" disabled>
                                </c-input>
                            </c-form-item>
                        </c-col>

                        <c-col :span="8">
                            <el-form-item label="业务所属行" prop="cfaquep.ownextkey" style="width: 100%">
                                <c-select v-model="model.cfaquep.ownextkey" style="width:100%" placeholder="请选择业务所属行"
                                    :code="codes.ownextkey4">
                                </c-select>
                            </el-form-item>
                        </c-col>
                        <c-col :span="8">
                            <c-form-item label="业务情况" prop="cfaquep.staflg" style="width: 100%">
                                <c-select v-model="model.cfaquep.staflg" maxlength="1" style="width: 100%"
                                    placeholder="请选择业务情况" :code="codes.staflg1">
                                </c-select>
                            </c-form-item>
                        </c-col>
                    </el-row>
                </el-form>
            </template>
        </c-list-search>
        <c-col :span="24" style="">
            <div style="border-bottom: 10px solid rgb(232, 232, 232)">
            </div>
        </c-col>
        <c-col :span="24" style="margin-top: 10px">
            <c-button class="medium_bcs" size="medium" style="margin-left: 0px" type="primary">导出Excel
            </c-button>
            <c-button class="medium_bcs" size="medium" type="primary">新增接口
            </c-button>
            <c-button class="medium_bcs" size="medium" type="primary">代付利息
            </c-button>
            <c-button class="medium_bcs" v-if="model.cfaquep.cfatyp == 'EAD'" size="small" type="primary"
                @click="toEadadd">新增外债海外代付
            </c-button>
            <c-button class="medium_bcs" v-if="model.cfaquep.cfatyp == 'EAF'" size="small" type="primary"
                @click="toEafadd">新增外债远期信用证
            </c-button>
            <c-button class="medium_bcs" v-if="model.cfaquep.cfatyp == 'EBA'" size="small" type="primary"
                @click="toEbaadd">新增对外担保
            </c-button>
            <c-button class="medium_bcs" v-if="model.cfaquep.cfatyp == 'ECA'" size="small" type="primary"
                @click="toEcaadd">新增国内外汇贷款
            </c-button>
        </c-col>

        <div style="height:90%">
            <c-col :span="24">
                <c-istream-table :list="stmData.data" :columns="stmData.columns" :showButtonFlg="true">
                    <!-- 自定义组件里加了最右边的一列”操作“ -->
                    <el-table-column fixed="right" prop="op" label="操作" width="200px">
                        <template slot="header">
                            <c-col :span="11" style="text-align: center"><span>操作</span></c-col>
                        </template>
                        <template slot-scope="scope">
                            <!-- 申请一个弹出主键放在插槽,加工已渲染的数据 -->
                            <c-button style="margin-left: 0" size="small" @click="getInfo(scope.$index, scope.row)">
                                详情
                            </c-button>
                            <c-button style="margin-left: 3px" size="small" @click="getAmend(scope.$index, scope.row)">
                                修改
                            </c-button>
                            <c-button style="margin-left: 3px" size="small" @click="getDelete(scope.$index, scope.row)">
                                删除
                            </c-button>
                        </template>
                    </el-table-column>
                </c-istream-table>
            </c-col>
        </div>

        <!-- <c-col :span="12">
            <c-form-item label="Selection" prop="eblstm">
                <c-input v-model="model.eblstm" :placeholder="$t('other.please_enter') + 'Selection'"></c-input>
            </c-form-item>
        </c-col>

        <c-col :span="12">
            <c-form-item label="EAD Selection" prop="eadstm">
                <c-input v-model="model.eadstm" :placeholder="$t('other.please_enter') + 'EAD Selection'"></c-input>
            </c-form-item>
        </c-col>

        <c-col :span="12">
            <c-form-item label="EAF Selection" prop="eafstm">
                <c-input v-model="model.eafstm" :placeholder="$t('other.please_enter') + 'EAF Selection'"></c-input>
            </c-form-item>
        </c-col>

        <c-col :span="12">
            <c-form-item label="EBA Selection" prop="ebastm">
                <c-input v-model="model.ebastm" :placeholder="$t('other.please_enter') + 'EBA Selection'"></c-input>
            </c-form-item>
        </c-col>

        <c-col :span="12">
            <c-form-item label="ECA Selection" prop="ecastm">
                <c-input v-model="model.ecastm" :placeholder="$t('other.please_enter') + 'ECA Selection'"></c-input>
            </c-form-item>
        </c-col>

        <c-col :span="12">
            <c-button size="small" type="primary" @click="onSerbut">
                {{ $t('cfasel.C0000010') }}
            </c-button>
        </c-col>

        <c-col :span="12">
            <c-button size="small" type="primary" @click="onDtlbut">
                {{ $t('cfasel.C0000011') }}
            </c-button>
        </c-col>

        <c-col :span="12">
            <c-button size="small" type="primary" @click="onAddbut">
                {{ $t('cfasel.C0000012') }}
            </c-button>
        </c-col>

        <c-col :span="12">
            <c-button size="small" type="primary" @click="onAmebut">
                {{ $t('cfasel.C0000013') }}
            </c-button>
        </c-col>

        <c-col :span="12">
            <c-button size="small" icon="el-icon-delete" @click="onDelbut">
                {{ $t('cfasel.C0000014') }}
            </c-button>
        </c-col>

        <c-col :span="12">
            <c-button size="small" type="primary" @click="onExpbut">
                {{ $t('cfasel.C0000016') }}
            </c-button>
        </c-col>

        <c-col :span="12">
            <c-button size="small" type="primary" @click="onAddbut2">
                {{ $t('cfasel.C0000017') }}
            </c-button>
        </c-col>

        <c-col :span="12">
            <c-button size="small" type="primary" @click="onAmelixi">
                {{ $t('cfasel.C0000019') }}
            </c-button>
        </c-col>

        <c-col :span="12">
            <c-button size="small" type="primary" @click="onExi">
                {{ $t('errcfa.C0000012') }}
            </c-button>
        </c-col> -->
    </div>
</template>
<script>
import Api from "~/service/Api"
import commonProcess from "~/mixin/commonProcess";
import CodeTable from "~/config/CodeTable"
import Event from "~/model/Cfasel/Event"
import Utils from "~/utils";

export default {
    inject: ['root'],
    props: ["model", "codes"],
    mixins: [commonProcess],
    data() {
        return {
            stmData: {
                columns: [
                    "0 1 \"业务流水\" 100 1 0:2 1 ",
                    "2 2 \"申报号码\" 220 1 0:0 1 ",
                    "3 3 \"业务参考号\" 150 1 0:0 1 ",
                    "4 4 \"柜员\" 100 1 0:2 1 ",
                    "5 5 \"日期\" 150 4 7:2 1 ",
                    // "6 6 \"申报类型\" 120 1 0:2 1 CFATYP",
                    { index: 6, position: 6, width: 120, pattern: 'code', label: '申报类型', code: this.codes.cfatyp1 },
                    "7 7 \"信息类型\" 120 1 0:2 1 ",
                    "8 8 \"操作类型\" 100 1 0:2 1 ",
                    // "9 9 \"状态\" 80 1 20:0 1 TransCFASTA",
                    { index: 9, position: 9, width: 100, pattern: 'code', label: '状态', code: this.codes.staflg1 },
                ],
                data: [],
            },
        }
    },
    methods: {
        ...Event,
        async handleSearch() {
            this.stmData.data = [];
            let frmdat = this.model.cfaquep.frmdat;
            if (!frmdat || frmdat == '') {
                this.$notify.error({ title: '错误', message: '查询开始日期必输!' });
                return;
            }
            let tildat = this.model.cfaquep.tildat;
            if (!tildat || tildat == '') {
                this.$notify.error({ title: '错误', message: '查询结束日期必输!' });
                return;
            }
            let rtnmsg = await this.executeRule("serbut")
            if (rtnmsg.respCode == SUCCESS) {
                //TODO 处理数据逻辑
                this.stmData.data = rtnmsg.data.eblstm.rows;
                console.log(this.stmData.data);
            }
            else {
                this.$notify.error({ title: '错误', message: '服务请求失败!' });
            }
        },
        async getTrnInfo(idx, row) {
            // this.model.infcon.objinr = row["INR"];
            // this.model.bodgrp.rec.inr = row["INR"];
            // this.model.infcon.chksubcon = "X";
            // console.log(row);
            // console.log(row.申报类型);
            // let url = row.申报类型.toLowerCase() + "inf";
            // this.$router.history.push("/business/" + url);

            console.log(row);
            let business = row.申报类型.toLowerCase() + "inf";
            let viewurl = "/business/" + business;
            const selIds = [idx + 1];
            const selDst = "eblstm" //列表对应后台模型中的stream
            let params = { selDst, selIds };
            console.log(params);
            this.executeRule("dtlbut", params).then((res) => {
                if ((res.respCode == SUCCESS)) {
                    Utils.copyValueFromVO(this.model, res.data);
                    // this.$router.push({ path: "business/inftrnpsDetail", query: { idx: idx}});
                    this.$router.push({ path: viewurl, query: {} });
                } else {
                    const h = this.$createElement;
                    const msg = res.respMsg || '请求执行失败!'
                    this.$notify.error({ title: '错误', message: h('p', { style: 'word-break:break-all;' }, msg) })
                }
            });


            // let rtnmsg = await this.executeDefault("dtlbut");
            // // if ((rtnmsg.respCode = SUCCESS)) {
            //     this.trnData.data = rtnmsg.data.infcon_trnstm.rows;
            //     console.log(this.trnData.data);
            // }
        },
        toEadadd() {
            this.$router.history.push("/business/eadadd");
        },
        toEafadd() {
            this.$router.history.push("/business/eafadd");
        },
        toEbaadd() {
            this.$router.history.push("/business/ebaadd");
        },
        toEcaadd() {
            this.$router.history.push("/business/ecaadd");
        },
        async getInfo(idx, row) {
            console.log(row);
            let business = row.申报类型.toLowerCase() + "inf";
            let viewurl = "/business/" + business;
            const selIds = [idx + 1];
            console.log(selIds);
            const selDst = "eblstm" //列表对应后台模型中的stream
            let params = { selDst, selIds };
            console.log(params);
            this.executeRule("dtlbut", params).then((res) => {
                if ((res.respCode == SUCCESS)) {
                    Utils.copyValueFromVO(this.model, res.data);
                    // this.$router.push({ path: "business/inftrnpsDetail", query: { idx: idx}});
                    this.$router.push({ path: viewurl, query: {} });
                } else {
                    const h = this.$createElement;
                    const msg = res.respMsg || '请求执行失败!'
                    this.$notify.error({ title: '错误', message: h('p', { style: 'word-break:break-all;' }, msg) })
                }
            });
        },
        async getAmend(idx, row) {
            let business = row.申报类型.toLowerCase() + "ame";
            let viewurl = "/business/" + business;
            const selIds = [idx + 1];
            const selDst = "eblstm" //列表对应后台模型中的stream
            let params = { selDst, selIds };
            this.executeRule("amebut", params).then((res) => {
                if ((res.respCode == SUCCESS)) {
                    Utils.copyValueFromVO(this.model, res.data);
                    // this.$router.push({ path: "business/inftrnpsDetail", query: { idx: idx}});
                    this.$router.push({ path: viewurl, query: {} });
                } else {
                    const h = this.$createElement;
                    const msg = res.respMsg || '请求执行失败!'
                    this.$notify.error({ title: '错误', message: h('p', { style: 'word-break:break-all;' }, msg) })
                }
            });
        },
        async getDelete(idx, row) {
            let business = row.申报类型.toLowerCase() + "del";
            let viewurl = "/business/" + business;
            const selIds = [idx + 1];
            const selDst = "eblstm" //列表对应后台模型中的stream
            let params = { selDst, selIds };
            this.executeRule("delbut", params).then((res) => {
                if ((res.respCode == SUCCESS)) {
                    Utils.copyValueFromVO(this.model, res.data);
                    // this.$router.push({ path: "business/inftrnpsDetail", query: { idx: idx}});
                    this.$router.push({ path: viewurl, query: {} });
                } else {
                    const h = this.$createElement;
                    const msg = res.respMsg || '请求执行失败!'
                    this.$notify.error({ title: '错误', message: h('p', { style: 'word-break:break-all;' }, msg) })
                }
            });
        }
    },
    created: function () {

    }
}
</script>
<style>

</style>