<template>
    <div class="eibs-tab">
        <c-col :span="24">
            <!-- ==================左边================ -->
            <c-col :span="12" style="padding-right: 20px">
                <!-- S0000039 : 结售汇业务参考号 -->
                <c-col :span="24">
                    <c-form-item :label="$t('fxtp.结售汇业务参考号')" prop="fxdgrp.rec.ownref">
                        <c-fullbox>
                            <c-input v-model="model.fxdgrp.rec.ownref" maxlength="16" disabled></c-input>
                            <template slot="footer">
                                <c-button style="margin: 0 0" size="small" type="primary"
                                          :disabled="getOwnrefFlg" @click="getOwnref">
                                    获取
                                </c-button>
                            </template>
                        </c-fullbox>
                    </c-form-item>
                </c-col>
                <!-- S0000041 : 业务负责人 -->

                <c-col :span="24">
                    <c-form-item label="业务负责人" prop="fxdgrp.rec.usr">
                        <c-input v-model="model.fxdgrp.rec.usr" maxlength="8" disabled></c-input>
                    </c-form-item>
                </c-col>
                <!-- S0000047 : 结售汇类型 -->

                <c-col :span="24">
                    <el-form-item :label="$t('fxtp.结售汇类型')" prop="fxdgrp.rec.fxtyp">
                        <c-select v-model="model.fxdgrp.rec.fxtyp" :code="codes.fxt_fxtyp" style="width:100%"
                                  :filterKey="['SS']"
                                  @change="defaultAccountsN1000">
                        </c-select>
                    </el-form-item>
                </c-col>

                <c-col :span="24">
                    <c-col :span="12">
                        <el-form-item label="Sale Amount" prop="fxdgrp.cbs.max.cur">
                            <c-select-cur v-model="model.fxdgrp.cbs.max.cur" style="width: 100%"
                                          dbCode="curtxt" @change="defaultAccAndRate" :expKey="['CNY']"></c-select-cur>
                        </el-form-item>
                    </c-col>
                    <c-col :span="12">
                        <el-form-item label-width="5px" prop="fxdgrp.cbs.max.amt">
                            <c-input-currency
                                    :currency="model.fxdgrp.cbs.max.cur"
                                    v-model="model.fxdgrp.cbs.max.amt"
                                    @change="defaultCalculateN1100"></c-input-currency>
                        </el-form-item>
                    </c-col>
                </c-col>
                <c-col :span="24">
                    <c-col :span="12">
                        <el-form-item label="Domestic Cur.Amount" prop="fxdgrp.cbs.nom1.cur">
                            <c-select-cur v-model="model.fxdgrp.cbs.nom1.cur" style="width: 100%" disabled
                                          dbCode="curtxt"></c-select-cur>
                        </el-form-item>
                    </c-col>
                    <c-col :span="12">
                        <el-form-item label-width="5px" prop="fxdgrp.cbs.nom1.amt">
                            <c-input-currency
                                    :currency="model.fxdgrp.cbs.nom1.cur" disabled
                                    v-model="model.fxdgrp.cbs.nom1.amt"></c-input-currency>
                        </el-form-item>
                    </c-col>
                </c-col>

                <!-- S0000060 : 对外牌价 -->

                <c-col :span="24">
                    <c-form-item :label="$t('fxtp.对外牌价')" prop="fxdgrp.rec.rat">
                        <c-input-currency disabled :precision='6' v-model="model.fxdgrp.rec.rat"></c-input-currency>
                    </c-form-item>
                </c-col>

                <!-- S0000061 : 中间价 -->
                <c-col :span="24">
                    <c-col :span="12">
                        <c-form-item :label="$t('fxtp.中间价')" prop="fxdgrp.rec.midrat">
                            <c-input-currency disabled :precision='6'
                                              v-model="model.fxdgrp.rec.midrat"></c-input-currency>
                        </c-form-item>
                    </c-col>

                    <c-col :span="12">
                        <el-form-item label-width="5px" prop="fxtp.cshflg">
                            <c-select v-model="model.fxtp.cshflg" disabled :code="codes.cshflg" style="width:100%">
                            </c-select>
                        </el-form-item>
                    </c-col>
                </c-col>

                <!-- S0000064 : 登记日期 -->

                <c-col :span="24">
                    <el-form-item :label="$t('fxtp.登记日期')" prop="fxdgrp.rec.opndat">
                        <c-date-picker type="date" v-model="model.fxdgrp.rec.opndat" style="width:100%"></c-date-picker>
                    </el-form-item>
                </c-col>

                <!-- S0000072 : 远期交割日 -->

                <c-col :span="24">
                    <el-form-item :label="$t('fxtp.远期交割日')" prop="fxdgrp.rec.setdat">
                        <c-date-picker type="date" v-model="model.fxdgrp.rec.setdat" disabled
                                       style="width:100%"></c-date-picker>
                    </el-form-item>
                </c-col>

                <!-- S0000073 : 择期交割起始日 -->

                <c-col :span="24">
                    <el-form-item :label="$t('fxtp.择期交割起始日')" prop="fxdgrp.rec.setdatfrm">
                        <c-date-picker type="date" v-model="model.fxdgrp.rec.setdatfrm" disabled
                                       style="width:100%"></c-date-picker>
                    </el-form-item>
                </c-col>
                <!-- S0000078 : 外币结算账号 -->

                <c-col :span="24">
                    <c-col :span="12">
                        <el-form-item :label="$t('fxtp.外币结算账号')" prop="fxdgrp.rec.dsp">
                            <c-select v-model="model.fxdgrp.rec.dsp" :code="codes.fxt_dsp" style="width:100%"
                                      :filterKey="['SP','HA','VT','LO']"
                                      @change="defaultAccountsN1000">
                            </c-select>
                        </el-form-item>
                    </c-col>

                    <c-col :span="12">
                        <el-form-item label-width="5px" prop="fxdgrp.rec.acc">
                            <c-select v-model="model.fxdgrp.rec.acc" style="width:100%">
                                <el-option
                                        v-for="(item, idx) in accLst"
                                        :key="idx"
                                        :label="item"
                                        :value="item"
                                ></el-option>
                            </c-select>
                        </el-form-item>
                    </c-col>
                </c-col>

                <!-- S0000075 : 交易主体 -->

                <c-col :span="24">
                    <el-form-item :label="$t('fxtp.交易主体')" prop="fxdgrp.rec.trnman">
                        <c-select v-model="model.fxdgrp.rec.trnman" :code="codes.trnman" style="width:100%">
                        </c-select>
                    </el-form-item>
                </c-col>

                <!-- S0000069 : 备注 -->

                <c-col :span="24">
                    <c-form-item :label="$t('fxtp.备注')" prop="fxdgrp.blk.remark">
                        <c-input type="textarea" v-model="model.fxdgrp.blk.remark" maxlength="35"
                                 show-word-limit></c-input>
                    </c-form-item>
                </c-col>
            </c-col>


            <!-- ==================右边================ -->
            <c-col :span="12" style="padding-right: 20px">
                <!-- S0000040 : 名称 -->

                <c-col :span="24">
                    <c-form-item :label="$t('fxtp.名称')" prop="fxdgrp.rec.nam">
                        <c-input v-model="defaultNam950" maxlength="40" disabled></c-input>
                    </c-form-item>
                </c-col>
                <c-col :span="24">
                    <el-card class="box-card">
                        <c-ptap :model="model" :requiredExtkey="true" :disabledExtkey="false" :disabled="false"
                                :isAdrblk="true" :haveAdrLabel="true"
                                :isShowCard="false" :argadr="{title: '结售汇申请人',grp: 'fxdgrp', rol: 'apl',}"
                                :label="{labelExtkey:'结售汇申请人',labelNam:'名称',labelAdrblk:'地址'}" ptytyp="C">
                        </c-ptap>
                    </el-card>
                </c-col>
                <!-- S0000062 : 询价编号 -->

                <c-col :span="24">
                    <c-form-item :label="$t('fxtp.询价编号')" prop="fxdgrp.rec.quoref">
                        <c-input v-model="model.fxdgrp.rec.quoref" maxlength="16" disabled></c-input>
                    </c-form-item>
                </c-col>
                <!-- S0000063 : 资金部编号 -->

                <c-col :span="24">
                    <c-form-item :label="$t('fxtp.资金部编号')" prop="fxdgrp.rec.fudref">
                        <c-input v-model="model.fxdgrp.rec.fudref" maxlength="16" disabled></c-input>
                    </c-form-item>
                </c-col>

                <!-- S0000065 : 起息日 -->

                <c-col :span="24">
                    <el-form-item :label="$t('fxtp.起息日')" prop="fxdgrp.rec.valdat">
                        <c-date-picker type="date" v-model="model.fxdgrp.rec.valdat" style="width:100%"></c-date-picker>
                    </el-form-item>
                </c-col>

                <!-- S0000074 : 择期交割截止日 -->

                <c-col :span="24">
                    <el-form-item :label="$t('fxtp.择期交割截止日')" prop="fxdgrp.rec.setdatto">
                        <c-date-picker type="date" v-model="model.fxdgrp.rec.setdatto" disabled
                                       style="width:100%"></c-date-picker>
                    </el-form-item>
                </c-col>

                <c-col :span="24">
                    <c-col :span="12">
                        <el-form-item :label="$t('fxtp.本币结算账号')" prop="fxdgrp.rec.dsp2">
                            <c-select v-model="model.fxdgrp.rec.dsp2" :code="codes.fxt_dsp2" style="width:100%"
                                      :filterKey="['SP','LO','HA']"
                                      @change="defaultAccountsN1000">
                            </c-select>
                        </el-form-item>
                    </c-col>

                    <c-col :span="12">
                        <el-form-item label-width="5px" prop="fxdgrp.rec.acc2">
                            <c-select v-model="model.fxdgrp.rec.acc2" style="width:100%">
                                <el-option
                                        v-for="(item, idx) in accLst2"
                                        :key="idx"
                                        :label="item"
                                        :value="item"
                                ></el-option>
                            </c-select>
                        </el-form-item>
                    </c-col>
                </c-col>

                <!-- S0000076 : 结售汇类型 -->

                <c-col :span="24">
                    <el-form-item :label="$t('fxtp.结售汇类型')" prop="fxdgrp.rec.trdout">
                        <c-select v-model="model.fxdgrp.rec.trdout" style="width:100%" dbCode="TRAOUT"
                                  :filterKey="[ '310','321','322','323','324','325','326','32X','331','332','333','410','420','421','422','423','431','432','440','441','442','450','460','461','462','470']">
                        </c-select>
                    </el-form-item>
                </c-col>
            </c-col>
        </c-col>
    </div>
</template>
<script>

    import Event from "../event";

    export default {
        inject: ['root'],
        props: ["model", "codes"],
        mixins: [Event],
        data() {
            return {
                accLst: [],
                accLst2: [],
            }
        },
        computed: {
            getOwnrefFlg: function () {
                let flg = this.model.fxdgrp.rec.fxtyp == '' || this.model.fxdgrp.apl.pts.ptainr == ''
                    || this.model.fxdgrp.cbs.max.cur == '' || this.model.fxdgrp.rec.ownref != ''
                return flg;
            },
            defaultNam950: function () {
                let amount = this.moneyFormat(this.model.fxdgrp.cbs.max.amt, this.model.fxdgrp.cbs.max.cur);
                let nam = this.getCodelabel(this.model.fxdgrp.rec.fxtyp, "fxt_fxtyp") + ","
                    + this.model.fxdgrp.cbs.max.cur + " " + amount
                this.model.fxdgrp.rec.nam = nam;
                return nam;
            },
        },
        methods: {
            //获取码值
            getCodelabel(value, codenam) {
                const codeobj = this.codes[codenam].find(obj => obj.value === value)
                return codeobj ? codeobj.label : value;
            },
        },
        created: function () {

        },
        watch: {
            //申请人变动 本外币下拉框需变化、账号、汇率变动
            'model.fxdgrp.apl.pts.ptyinr': {
                handler(newValue) {
                    if (newValue == "" || newValue == null) {
                        this.model.fxdgrp.rec.acc = "";
                        this.model.fxdgrp.rec.acc2 = "";
                        this.accLst = [];
                        this.accLst2 = [];
                        return
                    }
                    this.defaultAccAndRate();
                },
            },
        }
    }
</script>
<style></style>