<template>
    <c-page title="保证金收取">
        <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="right" size="small" :validate-on-rule-change="false">
            <c-tabs v-model="tabVal" ref="elment" type="card" @tab-click="myTabClick">
                
                    <!--PD000002 -->
                <el-tab-pane label="PD000002" name="opnp1">
                    <c-content>
                        <m-opnp1 :model="model" :codes="codes"/>
                    </c-content> 
                </el-tab-pane>
            </c-tabs>
                <c-grid-ety-prompt-dialog
                    ref="etyDialog"
                    :promptData="promptData"
                    v-on:select-ety="selectEty"
                >
                </c-grid-ety-prompt-dialog>
            </el-form>
        </div>
    </c-page>
</template>
<script>
import Api from "~/service/Api"
import CodeTable from "~/config/CodeTable"
import Fctopn from "~/model/Fctopn"
import commonProcess from "~/mixin/commonProcess"
import commonFuncs from "~/mixin/commonFuncs"
import Check from "~/model/Fctopn/Check"
import Default from "~/model/Fctopn/Default"
import Pattern from "~/model/Fctopn/Pattern"
import Opnp1 from "./Opnp1"


export default {
    name: "Fctopn",
    components:{
        "m-opnp1" : Opnp1,
    },
    provide() {
        return {
            root: this
        }
    },
    mixins: [commonProcess, commonFuncs],    // 里面包含了Default、Check等的公共处理
    data(){
        return {
            tabVal: "opnp1",
            trnName: "fctopn",
            model: new Fctopn().data,
            checkRules: Check,
            defaultRules: Default,
            pattern: Pattern,
            rules: null,
            codes: {
                cashcur: [],
                trmtyp: []
            },
        }
    },
    methods:{
        myTabClick(tab){
            this.tabClick(tab)
            /**
            *  do it yourself
            **/
        },
        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("进入fctopn交易");
        let rtnmsg = await this.init({})
        if(rtnmsg.respCode == SUCCESS)
        {
           this.updateModel(rtnmsg.data)
           //TODO 处理数据逻辑
            this.codes.cashcur = rtnmsg.codeSet.cashcur
            this.codes.trmtyp = rtnmsg.codeSet.trmtyp
        }
        else
        {
            this.$notify.error({title: '错误',message: '服务请求失败！'});
        }
    }
}
</script>
<style>

</style>
