<template>
    <div>
        <navbar title="预授分析"></navbar>
        <div class="wrapper">
            <van-form ref="form" :model="baseForm">
                <div class="jine">
                    <van-field v-model="baseForm.applyCreditAmt" label="申请授信额" placeholder="请输入" type="number"></van-field>
                    <span class="danwei" v-if="baseForm.applyCreditAmt">万元人民币</span>
                </div>
                
                <van-field v-model="baseForm.applyCreditDeadline" label="申请授信期限" placeholder="请输入"></van-field>

                <van-field v-model="baseForm.useAnaly" label="用途分析" placeholder="请输入" type="textarea" :row="3"></van-field>
                <van-field v-model="baseForm.riskAnaly" label="风险分析" placeholder="请输入" type="textarea" :row="3"></van-field>
                <van-field v-model="baseForm.signifyDisclosure" label="重大披露" placeholder="请输入" type="textarea"
                    :row="3"></van-field>

            </van-form>

        </div>
        <div class="footer">
            <div class="btn_box">
                <van-button type="primary" class="btn" @click="handleCommit">保存</van-button>
            </div>
        </div>
    </div>
</template>
<script>
import navbar from '../../../components/navbar/navbar.vue';
import { queryOperateCase, addOperateCase, updateOperateCase } from "@/service/api/report";
import {
    Icon,
    Field,
    Form,
    Button,
    Toast
} from 'vant';
export default {
    components: {
        navbar: navbar,
        VanIcon: Icon,
        VanForm: Form,
        VanField: Field,
        VanButton: Button
    },
    data() {
        return {
            baseForm: {
                applyCreditAmt: '',
                applyCreditDeadline: '',
                useAnaly: '',
                riskAnaly: "",
                signifyDisclosure: '',
                companyId:'',
            },

        }
    },
    created() {
        this.baseForm.companyId = sessionStorage.getItem('companyId'),
            this.initQueryOperateCase()
    },
    methods: {
        async initQueryOperateCase() {
            const params = {
                companyId: this.baseForm.companyId
            }
            let result = await queryOperateCase(params);
            if (result) {
                this.status = 2
                this.baseForm.applyCreditAmt = result.applyCreditAmt
                this.baseForm.applyCreditDeadline = result.applyCreditDeadline
                this.baseForm.useAnaly = result.useAnaly
                this.baseForm.riskAnaly = result.riskAnaly
                this.baseForm.signifyDisclosure = result.signifyDisclosure
            } else {
                this.status = 1
            }
        },
        async handleCommit() {
            console.log(this.baseForm, 'baseFormbaseForm')
            if (this.status == 1) {
                let result = await addOperateCase(this.baseForm);
                if (result) {
                    Toast.success('新增成功');
                    this.$router.go(-1)
                }
            } else {
                let result = await updateOperateCase(this.baseForm);
                if (result) {
                    Toast.success('修改成功');
                    this.$router.go(-1)

                }
            }
        },
        goDetail() { },
    }
}
</script>
<style lang="less" scoped>
.wrapper {
    padding-top: 46px;
    min-height: 100vh;
    font-size: 16px;
    padding-bottom: 60px;
}

.title {
    line-height: 45px;
    padding: 5px 15px;
    color: rgb(89, 89, 89);
}

.header {
    display: flex;
    justify-content: space-between;
    padding-right: 15px;
    align-items: center;
}

.header_btn {
    text-align: center;
}

.main_item {
    background: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 15px;
    color: rgb(89, 89, 89);
    line-height: 45px;
    margin-top: 1px;

}

.main_item_left {
    font-size: 14px;
}

.footer {
    position: fixed;
    bottom: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
}

.btn_box {
    width: 100%;
}

.btn {
    width: 100%;
}
.jine{
    display: flex;
    align-items: center;
    background-color: #fff;
    /deep/ .van-cell{
        width: 55%;
    }
}
.danwei{
    font-size: 14px;
}
</style>