<template>
  <div class="eContainer">
    <div class="bus-button">
        <c-button type="primary" v-on:click="handleSave">{{ $t("buttons.save") }}</c-button>
        <c-button type="primary" v-on:click="handleCheck">{{ $t("buttons.check") }}</c-button>
    </div>
    <el-form :model="model" :rules="rules" ref="modelForm" label-width="150px" label-position="left" size="small" :validate-on-rule-change="false">
       <c-tabs v-model="tabVal" ref="elment" type="card" @tab-click="tabClick">
        
            <!--PD000016 -->
           <el-tab-pane label="Cancelation" name="canp">
                <m-canp :model="model" :codes="codes"/>
           </el-tab-pane>

            <!--PD000027 -->
           <!-- <el-tab-pane label="Liability" name="engp">
                <m-engp :model="model" :codes="codes"/>
           </el-tab-pane> -->

            <!--PD000000 -->
           <el-tab-pane label="Settlement" name="setpan">
                <m-setpan :model="model" :codes="codes"/>
           </el-tab-pane>

            <!--PD000000 -->
           <el-tab-pane label="Completion" name="coninfp">
                <m-coninfp :model="model" :codes="codes"/>
           </el-tab-pane>

            <!--PD000529 -->
           <el-tab-pane label="Message" name="docpan">
                <m-docpan :model="model" :codes="codes"/>
           </el-tab-pane>

            <!--PD000546 -->
           <el-tab-pane label="Attachments" name="doctre">
                <m-doctre :model="model" :codes="codes"/>
           </el-tab-pane>

            <!--PD000001 -->
           <el-tab-pane label="统一授信" name="limitbody">
                <m-limitbody :model="model" :codes="codes"/>
           </el-tab-pane>
       </c-tabs>
    </el-form>
  </div>
</template>
<script>
import Api from "~/service/Api"
import CodeTable from "~/config/CodeTable"
import Brtcan from "~/model/Brtcan"
import commonProcess from "~/mixin/commonProcess"
import commonFuncs from "~/mixin/commonFuncs"
import Check from "~/model/Brtcan/Check"
import Default from "~/model/Brtcan/Default"
import Pattern from "~/model/Brtcan/Pattern"
import Canp from "./Canp"
// import Engp from "./Engp"

import Setpan from "../../Public/Setpan"
import Coninfp from "../../Public/Coninfp"
import Docpan from "../../Public/Docpan"
import Doctre from "../../Public/Doctre"
import Limitbody from "../../Public/Limitbody"

export default {
    name: 'Brtcan',
    components:{
        "m-canp" : Canp,
        // "m-engp" : Engp,
        "m-setpan" : Setpan,
        "m-coninfp" : Coninfp,
        "m-docpan" : Docpan,
        "m-doctre" : Doctre,
        "m-limitbody" : Limitbody,

    },
    provide() {
        return {
            root: this
        }
    },
    mixins: [commonProcess, commonFuncs],    // 里面包含了Default、Check等的公共处理
    data(){
        return {
            tabVal: "canp",
            trnName: "brtcan",
            model: new Brtcan().data,
            checkRules: Check,
            defaultRules: Default,
            pattern: Pattern,
            rules: null,
            codes: {
            },
        }
    },
    methods:{
        async handleSave() {
            let result = await this.save();
            if (result.respCode == SUCCESS && Object.keys(result.fieldErrors).length == 0) {
                this.$notify({
                    title: "成功",
                    message: "保存成功",
                    type: "success",
                });
                this.$store.dispatch("TagsView/delView", this.$route)
                this.$router.go(-1)
            } else if(result.fieldErrors && Object.keys(result.fieldErrors).length > 0 ){
                const tab = this.showBackendErrors(result.fieldErrors)
                if (tab) {
                    // tab切换之后,需出发tab-click的事件
                    this.tabClick(tab);
                }
                this.$notify({
                    title: "错误",
                    message: "检核失败!",
                    type: "error",
                });
            } else{
                this.$notify({
                    title: "失败",
                    message: "保存失败",
                    type: "error",
                });
            }
        }
    },


    created:async function(){
        console.log("进入brtcan交易");
        let rtnmsg = await this.init({})
        if(rtnmsg.respCode == SUCCESS)
        {
           //TODO 处理数据逻辑
            this.updateModel(rtnmsg.data)
        }
        else
        {
            this.$notify.error({title: '错误',message: '服务请求失败!'});
        }


    }

}
</script>
<style>

</style>