<template>
    <div class="bus-button">        
            <c-button type="primary" v-on:click="save">提交</c-button>
            <c-button type="primary" v-on:click="pedding">暂存</c-button>
            <c-button type="primary" v-on:click="check">校核</c-button>
            <c-button  v-on:click="exit">退出</c-button>
    </div>
</template>
<script>
import commonApi from "~/mixin/commonApi"
import Utils from "~/utils"
export default {
    props:["$pntvm"],
    data(){
        return{            
        }
    },
    methods:{
        async save(){
            console.log(123)
            let vm = this.getVM();
            let result = await vm.save()
            console.log(result)
            if (result.respCode == SUCCESS) {
                this.$notify({
                    title: '成功',
                    message: '保存成功',
                    type: 'success'
                });
                this.$router.history.push("/business/trnrel")
            } else {
                this.$notify({
                    title: '失败',
                    message: '保存失败',
                    type: 'error'
                });
            }
        },
        async pedding(){
            let result = await this.getVM().pedding()
            console.log(result)
            if (result.respCode == SUCCESS) {
                this.$notify({
                    title: '成功',
                    message: '暂存成功',
                    type: 'success'
                });
                this.$router.history.push("/business/sptsel")
            } else {
                this.$notify({
                    title: '失败',
                    message: '暂存失败',
                    type: 'error'
                });
            }
        },
        async check(){
            let result = await this.getVM().checkAll()
            if(result.respCode != SUCCESS) {
                this.$notify.error({title: '错误',message: result.respMsg});
            } else {
                const fields = this.getVM().$refs.modelForm.fields
                const fieldErrors = result.fieldErrors;
                Utils.positioningErrorMsg(fieldErrors, fields)
            }
        },
        exit(){
            this.$confirm('您有未保存的数据，确定退出吗, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
            }).then(()=>{
                this.$router.history.push("/business/office")
            })
        },
        getVM(){
            return this.$pntvm
        }
    }
}
</script>
<style>
.bus-button {
  text-align: center;
}
</style>